Whats the reason for this??

J

JP

perl -e '1+1+1'
The answer is 3.

but

perl -e 'print (1+1)+1'

thje answer in this case is 2.
Any explination why I get geting a different value in the second case??

Thanks,
JP
 
A

Anno Siegel

JP said:
perl -e '1+1+1'
The answer is 3.

but

perl -e 'print (1+1)+1'

thje answer in this case is 2.
Any explination why I get geting a different value in the second case??

Consult the documentation of the function you're using. In "perldoc
-f printf", note the sentence beginning "Also be careful..." near the
end.

Anno
 
J

John W. Krahn

Anno said:
Consult the documentation of the function you're using. In "perldoc
-f printf", note the sentence beginning "Also be careful..." near the
end.

The OP will probably find that sentence easier using "perldoc -f print".

:)

John
 
E

Eric J. Roode

JP said:
perl -e '1+1+1'
The answer is 3.

but

perl -e 'print (1+1)+1'

thje answer in this case is 2.
Any explination why I get geting a different value in the second
case??

For Perl operators like print, the rule is "If it LOOKS like a function
call, it BEHAVES like a function call."

--
Eric
`$=`;$_=\%!;($_)=/(.)/;$==++$|;($.,$/,$,,$\,$",$;,$^,$#,$~,$*,$:,@%)=(
$!=~/(.)(.).(.)(.)(.)(.)..(.)(.)(.)..(.)......(.)/,$"),$=++;$.++;$.++;
$_++;$_++;($_,$\,$,)=($~.$"."$;$/$%[$?]$_$\$,$:$%[$?]",$"&$~,$#,);$,++
;$,++;$^|=$";`$_$\$,$/$:$;$~$*$%[$?]$.$~$*${#}$%[$?]$;$\$"$^$~$*.>&$=`
 
J

Jürgen Exner

JP said:
perl -e '1+1+1'
The answer is 3.

but

perl -e 'print (1+1)+1'

thje answer in this case is 2.
Any explination why I get geting a different value in the second case??

Maybe because (1+1) is 2?

jue
 
A

Arndt Jonasson

JP said:
perl -e '1+1+1'
The answer is 3.

but

perl -e 'print (1+1)+1'

thje answer in this case is 2.
Any explination why I get geting a different value in the second case??

Adding warnings often helps when 'perl' does something mystifying:

% perl -we 'print (1+1)+1'
print (...) interpreted as function at -e line 1.
Useless use of addition (+) in void context at -e line 1.
2
%
 
G

Glenn Jackman

At 2005-12-01 06:03AM said:
perl -e '1+1+1'
The answer is 3.

but

perl -e 'print (1+1)+1'

thje answer in this case is 2.
Any explination why I get geting a different value in the second case??

This may shed some light on the destination of the "lost" "+1":
perl -le '$result = print(3+5)+10; print $result'
8
11
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,176
Messages
2,570,947
Members
47,501
Latest member
Ledmyplace

Latest Threads

Top