Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Preventing unintended list expansion inside hash literals.

by dsheroh (Monsignor)
on Jan 05, 2017 at 10:00 UTC ( [id://1179005]=note: print w/replies, xml ) Need Help??


in reply to Preventing unintended list expansion inside hash literals.

If you want to force it to be a scalar, you can use the scalar keyword instead of a throwaway variable:
$ perl -MData::Printer -E 'sub some_sub { return 1 } ; %h = ( foo => s +ome_sub(), bar => 42 ); p %h' { bar 42, foo 1 } $ perl -MData::Printer -E 'sub some_sub { return } ; %h = ( foo => som +e_sub(), bar => 42 ); p %h' { 42 undef, foo "bar" } $ perl -MData::Printer -E 'sub some_sub { return } ; %h = ( foo => sca +lar some_sub(), bar => 42 ); p %h' { bar 42, foo undef }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1179005]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-25 19:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found