Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^2: conditional statements in list constructors

by AnomalousMonk (Bishop)
on Mar 27, 2014 at 15:10 UTC ( #1079942=note: print w/replies, xml ) Need Help??


in reply to Re: conditional statements in list constructors
in thread conditional statements in list constructors

Taking a reference to a list actually returns a list of references to each item in the original list. ... probably ... good ... to avoid ...:

$arrayref = \(...);

E.g.:

c:\@Work\Perl\monks>perl -wMstrict -le "my $not_really_an_arrayref = \('one', 'two', 'three'); print $$not_really_an_arrayref; " three

Replies are listed 'Best First'.
Re^3: conditional statements in list constructors
by kcott (Bishop) on Mar 27, 2014 at 18:44 UTC

    Good point; however, the way you'd normally dereference an arrayref generates a fatal runtime error:

    $ perl -le ' my $think_this_is_an_arrayref = \(qw{one two three}); print qq{Probably not dereference like this: $$think_this_is_an_ar +rayref}; print qq{Probably would dereference like this: @$think_this_is_an_ +arrayref}; ' Probably not dereference like this: three Not an ARRAY reference at -e line 4.

    -- Ken

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2022-05-26 17:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (93 votes). Check out past polls.

    Notices?