Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Constants lists in array slices

by kcott (Archbishop)
on Jul 20, 2018 at 13:03 UTC ( [id://1218901]=note: print w/replies, xml ) Need Help??


in reply to Constants lists in array slices

G'day Rolf,

Some info first:

$ perl -v | head -2 | tail -1 This is perl 5, version 18, subversion 2 (v5.18.2) built for x86_64-li +nux-thread-multi $ alias perle alias perle='perl -Mstrict -Mwarnings -Mautodie=:all -E'

I first tried a cut-down version of your issue three different ways. All gave the correct slice; only the third had no warning message.

$ perle 'use constant X => (1,3); my @y = "a".."z"; say for @y[X]' Scalar value @y[X] better written as $y[X] at -e line 1. b d $ perle 'use constant X => (1,3); my @y = "a".."z"; say for @y[+X]' Scalar value @y[+X] better written as $y[+X] at -e line 1. b d $ perle 'use constant X => (1,3); my @y = "a".."z"; say for @y[X()]' b d

I then looked at these sections of constant: "List constants" and "CAVEATS".

The first of those (see the WEEKDAYS example) suggested a fourth way to try; this gave the correct slice and no error:

$ perle 'use constant X => 1,3; my @y = "a".."z"; say for @y[(X)]' b d

The second has:

"List constants are not inlined unless you are using Perl v5.20 or higher."

This perhaps suggests why [X] (and probably [+X]) had problems; although I'm very much guessing here and don't really know what's going on under the hood.

— Ken

Replies are listed 'Best First'.
Re^2: Constants lists in array slices
by LanX (Saint) on Jul 20, 2018 at 13:12 UTC
    > The second has: "List constants are not inlined unless you are using Perl v5.20 or higher."

    ah thanks, that's the relevant part I missed. :)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Log In?
Username:
Password:

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

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

    No recent polls found