Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re^8: Perl list items

by Anonymous Monk
on Jul 10, 2012 at 08:37 UTC ( [id://980841]=note: print w/replies, xml ) Need Help??


in reply to Re^7: Perl list items
in thread Perl list items

To clarify  @$c[0] means the same as  @{$c}[0] meaning dereference $c, take array slice

So

$ perl -e " use Data::Dump; my $c = [qw/ a b c/]; dd @$c[1,2]; " ("b", "c")

While References quick reference lists this item explicitly (item 2), its somewhat documented in perlreftut/perlref but its not recommended

Replies are listed 'Best First'.
Re^9: Perl list items
by AnomalousMonk (Archbishop) on Jul 10, 2012 at 09:13 UTC
    To clarify @$c[0] means the same as @{$c}[0] meaning dereference $c, take array slice

    Well... I'm not sure it's that much more clear. After all, "I know what I mean, ..."

    I'm still puzzled by the absence of a "... better written as ..." warning. Maybe the usage is just too far off the beaten track for warnings to stumble over.

    >perl -wMstrict -le "my @c = ('foo'); print @c[0]; ;; my $c = ['bar']; print @{$c}[0]; print @ $c [0]; " Scalar value @c[0] better written as $c[0] at -e line 1. foo bar bar

      I'm still puzzled by the absence of a "... better written as ..." warning.

      Because the code is different :) Because @warnme... is different from @$derefNowarn...

      For verbosity see diagnostics, try  perl -Mdiagnostics -e " @ARGV[0] "

        Because the code is different :)

        True, the code is different, but the expressions are all equivalent: they're all 'degenerate' single-item slices.

        Because @warnme... is different from @$derefNowarn...

        I don't understand the significance of this statement. Are scalar derefs in this context (single-item slices) simply not warned about? If so, is there a rationale for this? (I could understand if this was simply beyond the scope of the warnings system as it now stands. After all, you can't warn about everything.)

        For verbosity see diagnostics...

        diagnostics are indeed more verbose, but don't throw more light, for me, on this (admittedly somewhat trivial) problem. Oh well, going to bed now...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-04-19 20:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found