[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [FWP] Constants as array refs



On Mar 23, Steve Lane said:

>   foreach (@{ CARRAY() })
>
>works, but i bet someone can come up with a better solution.

As someone just wrote, use the syntactic sugar of +.  It comes in handy in
places like:

  sub list_to_hash_ref {
    { @_ }
  }

Perl thinks that's just a naked block.  Blegh.

  sub list_to_hash_ref {
    +{ @_ }  # sure, the weak could use return() ;)
  }

Yay.  It also helps in cases where don't want tons of parentheses:

  print (2 + 2) * 5;  # prints 4 (!!)
  # print(2 + 2) prints 4, and then returns 1 (if successful)
  # and then 1 is multiplied by 5
  # -w would whine about 1 * 5 being used in void context:
    # print (...) interpreted as function...
    # Useless use of integer multiplication in void context...

  print +(2 + 2) * 5;
  print ((2 + 2) * 5);

Yay.  I feel like I helped make a difference today. :)  Oh, and see my
post about sorting, Schwartzian transforms, and Guttman-Rosler transforms,
at perlguru.com: http://www.perlguru.com/forum/Forum2/HTML/000208.shtml

Yay again.

-- 
MIDN 4/C PINYAN, NROTCURPI, US Naval Reserve             japhy@pobox.com
http://www.pobox.com/~japhy/                  http://pinyaj.stu.rpi.edu/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/


==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe