[tpm] dereferencing anonymous hashes

Uri Guttman uri at stemsystems.com
Thu Apr 12 08:21:17 PDT 2007

>>>>> "RJ" == Rob Janes <janes.rob at gmail.com> writes:

  RJ> I guess I've just never seen $x = (); before.  doesn't seem very
  RJ> useful unless it's a list expression.

  RJ> [robj at localhost ~]$ perl -e '$x=(5,44); print "$x\n";'
  RJ> 44

  RJ> [robj at localhost ~]$ perl -e '$x=@x=(5,44); print "$x\n";'
  RJ> 2

  RJ> So the comma operator behaves differently in a scalar context from
  RJ> how it behaves in a list context.

i will repeat this again. THERE IS NO SUCH THING AS A LIST IN SCALAR
CONTEXT. what you see there in the first line is the comma operator
which just returns its right side expression. in an actual list the
comma is NOT AN OPERATOR but a separator. it is pure syntax in a list
and no opcodes are generated.

  RJ> [robj at localhost ~]$ perl -e 'sub x { print "side effect\n"; return 5 } $x=
  RJ> (x,44); print "$x\n";'
  RJ> side effect
  RJ> 44

  RJ> Showing that the comma operator is useful for side effects in
  RJ> scalar context mode.

useful? that is what it is designed for. it was taken from c which has
the same operator but no list context to confuse things.


Uri Guttman  ------  uri at stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org

More information about the toronto-pm mailing list