LINUX.IE, website of the Irish Linux Users' Group
Tux rules!

   
Home
New Users
Articles
Download
Projects
Community
Vendors

  Print Version
Email to...
 
Archives:


planetILUG

Recent News

News Archive


Join the
ILUG
on FaceBook


Join the
ILUG
on LinkedIn


Join the
ILUG SETI
Group



















 
 :: Mailing Lists

[ILUG] Re: [Webdev] Perl references

[ILUG] Re: [Webdev] Perl references

Fergal Daly fergal at esatclear.ie
Mon Sep 25 23:27:46 IST 2000


Is params a ref to a hash or hash who's values are refs to scalars? If the 
former, then something is a little weird and you can ignore the rest of 
this, if the latter, try

perl -e '$params={moo => "baa"};print $$params{"moo"}."\n"'

vs

perl -e '%params=(moo => "baa");print $$params{"moo"}."\n"'

vs

perl -e '%params=(moo => \"baa");print $$params{"moo"}."\n"'

the first gives 'baa' whereas the second and third give blankness. I think 
it's because dereferencing has a higher precedence than hash lookup (check 
the man page to find out for sure). So perl evaluates $$params first then 
looks up the key moo in the resulting hash. You want

perl -e '%params=(moo => \"baa");print ${$params{"moo"}}."\n"'

to look up moo then dereference the resulting scalar. Sticking a

use strict;

at the top of your code will stop this sort of thing happening,

Fergal





More information about the ILUG mailing list
Read this without the formatting.
                                                                                                    

 

Hosted by HEAnet


Maintained by the ILUG website team. The aim of Linux.ie is to support and help commercial and private users of Linux in Ireland. You can display ILUG news in your own webpages, read backend information to find out how. Networking services kindly provided by HEAnet, server kindly donated by Dell. Linux is a trademark of Linus Torvalds, used with permission. No penguins were harmed in the production or maintenance of this highly praised website. Looking for the Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!
RSS Version
Powered by Dell