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

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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


In reply to Re: Constants lists in array slices by kcott
in thread Constants lists in array slices by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2022-10-07 20:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (30 votes). Check out past polls.

    Notices?