comma

J

James

$ perl -e '$a=3, $b=5, print $a, print $b'
531

perldoc -q comma ?
Just curious.

James
 
E

Eric J. Roode

$ perl -e '$a=3, $b=5, print $a, print $b'
531

perldoc -q comma ?
Just curious.

Curious about what?

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

James

Eric said:
$ perl -e '$a=3, $b=5, print $a, print $b'
531

perldoc -q comma ?
Just curious.

Curious about what?

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

$ perl -e '$a=3, $b=5, print $a, print $b'
Why do I get 531?

How does the comma work in this context? Is it documented?

James
 
P

Paul Lalli

$ perl -e '$a=3, $b=5, print $a, print $b'
Why do I get 531?

How does the comma work in this context? Is it documented?

Is *what* documented? What are you *expecting* to happen there? Why
do you think you should get anything other than 531? Perhaps if you
told us what your line of thinking is, we could help you understand
what's happening.

Try running that line with Deparsing and parenthesizing enabled. Does
this better help you understand what's happening?

perl -MO=Deparse,-p -e'$a=3, $b=5, print $a, print $b'
(($a = 3), ($b = 5), print($a, print($b)));
-e syntax OK

Paul Lalli
 
E

Eric J. Roode

$ perl -e '$a=3, $b=5, print $a, print $b'
531

perldoc -q comma ?
Just curious.

Curious about what?

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

$ perl -e '$a=3, $b=5, print $a, print $b'
Why do I get 531?

How does the comma work in this context? Is it documented?

You've never done "print $a, $b, $c, $d", before? The comma is simply
the list-item separator, separating the arguments to print.

The first two commas in your expression are "comma operators", which is
documented in `perldoc perlop`, under the "Comma operator".

The second is simply the separator of the list which is the argument to
your first print. The first print has some stuff to print. What stuff?
$a and... an expression. So it evaluates the expression (print $b).
This prints "5" to your output stream, and returns a value of 1 (because
it was successful. Then the first print knows it needs to print $a and
1. Which it does, so your output stream gets a 5, then a 3, then a 1.

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

robic0

Is *what* documented? What are you *expecting* to happen there? Why
...... Perhaps if you
told us ........
Who is **us** doode? Perhaps **you** can't answer the question!
 
E

Eric J. Roode

robic0 wrote in
James said:
Eric J. Roode wrote:
news:1134158373.748060.108620 @g49g2000cwa.googlegroups.com: [...]
How does the comma work in this context? Is it documented?

Is *what* documented? What are you *expecting* to happen there? Why
...... Perhaps if you
told us ........
Who is **us** doode? Perhaps **you** can't answer the question!

No, I'm just not very good at reading minds.

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

robic0

robic0 wrote in
James wrote:
Eric J. Roode wrote:
news:1134158373.748060.108620 @g49g2000cwa.googlegroups.com: [...]
How does the comma work in this context? Is it documented?

Is *what* documented? What are you *expecting* to happen there? Why
...... Perhaps if you
told us ........
Who is **us** doode? Perhaps **you** can't answer the question!

No, I'm just not very good at reading minds.
You have to have one first
 

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,950
Members
47,503
Latest member
supremedee

Latest Threads

Top