Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Comment on

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

Greetings Monks,

I know I'm doing something very silly here that has likely been asked and answered countless times before, but my meditation this Monday morning lacks insight.

I'd like to take a slice of an array returned from a method without first assigning the array. Furthermore I'd like the slice to be from an abritrary index to the last index in the array. For example:

my @slice = ( split /\n/, $object->get_array )[$index .. -1];

However, on attempting this I find that the slice contains no values - this makes some sense as there is no overlapping region in the range bounded by the indexes (the region counting forward in the array from index a to the region counting back from the end of the array to index b).(Apologies for the fuzzy language here as I wasn;t sure how to word the terms).

Unfortunately, when I attempt to use $# as the second index for the array slice, I get the warning:

$# is no longer supported at -e line 1.

I do however get a slice containing a single value (the first value of the array). I know I'm clearly overlooking something here, but what? It would be trivial to change this line to first assign the array returned by the split and then use ~~@array as the index of the last value, but this has me trumped.


In reply to Last index use in array slice by ltp

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others about the Monastery: (8)
    As of 2014-12-25 00:34 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Is guessing a good strategy for surviving in the IT business?





      Results (159 votes), past polls