[EMAIL PROTECTED] wrote:
>
> Thanks everyone for the help!
> I get an error on 'chop' when I use the following. Why is this so?
> Thanks
>
> use strict;
> use warnings;
> my @eightdecks = 1..20;
> my $last = chop ($eightdecks[0] + $eightdecks[2]);
>
> if ($last =~ /[0-5]/){
> print "yes match.\n";
> }else{print "not match\n"};
You can only chop a variable, because the last character is removed from
the target string.
my $last = do {
chop(my $sum = $eightdecks[0] + $eightdecks[2]);
};
will do the trick. It assigns the sum to $sum and then chops $sum and
returns the last character. Or, more simply, you can just write
my $last = substr $eightdecks[0] + $eightdecks[2], -1;
HTH,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/