From: "sanket vaidya" <[EMAIL PROTECTED]>
> 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.
Nope. + is addition in Perl. Always. No matter the context. You get
the same result with
my $tmp = 1 + 2;
print "result is " . $tmp . "\n";
as with
print "result is " . (1 + 2) . "\n";
Perl adds the two numbers with no problem and only then if needed
converts the result from a number to the string.
The reason of the error message
Can't modify addition (+) in chop
is simple. chop() tries to modify its parameter so the parametr must
be something that can be modified. It must be a "lvalue": $variable,
$array[$element], $hash{'element'},
$some{more}[$complex][$structure], ...
Jenda
===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =====
When it comes to wine, women and song, wizards are allowed
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/