I have a line like this:
$var = '123456d';
or maybe
$var = '123456';
If it matters, there will be at most 6 digits of at least 5. The numbers do not have alpha, spaces or special characters.
In my Perl script, I need to delete and return the last alpha character and a string without an alpha character.
I suppose you can use \ D and crop? or chop? but, there should be an easy way to quickly get both vars.
my $numbers =~ s/\D+?$var//;
my $alpha = substr($var, 0, -1);
or
my $alpha = chop($var);
then if aZ and so on to check if it is an alpha symbol.
Or the limit of my decision:
$alpha = $var;
$alpha =~ s/[0-9]//ig;
$var =~ s/[a-Z]//ig;
$numbers = $var;
therefore the result:
($numbers == '123456')
($alpha eq 'd') (or '' if nothing)
It seems to me that this is too trivial to ask here, but I just cannot find or write an applicable solution.
= ~ s - , .
...
, ! 2 -! var ($ alpha eq 'dd')
to0:
$var =~ s{^([0-9]+).*}{$1}i;