[tpm] dereferencing anonymous hashes

Uri Guttman uri at stemsystems.com
Tue Apr 10 14:19:11 PDT 2007


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

  RJ> $x = (); is a list assignment to a scalar.  scalar conversion
  RJ> results in the scalar ($x that is) being assigned the count of the
  RJ> number of items in the list.  0 or zero.

wrong result and wrong explanation. you can't have a list in scalar
context by definition. in this case the () are just doing grouping of
nothing so it is just like saying my $x and the value in $x is undef.

perl -lwe '$x = () ; print $x'
Use of uninitialized value in print at -e line 1.

you can only get the number of elements in an array by putting it in
scalar context. and () does not make a list. parens only do grouping in
perl, and never directly make a list.

uri

-- 
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