Hi

You get the error on chop because anything given with chop function is
considered as string (In other words chop acts on string). So perl considers
the '+' operator you provide with chop as string rather than addition
operator.This is how your task can be accomplished.

use warnings;
use strict;

my @eightdecks = 1..20;
my $temp =$eightdecks[0] + $eightdecks[2];
my $last = chop($temp);
print "Temp = $last";

Hope this helps.


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, April 02, 2008 1:42 PM
To: beginners@perl.org
Subject: Re: how to extract the last digit

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"};




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to