Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

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

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (3)
    As of 2018-01-21 06:07 GMT
    Find Nodes?
      Voting Booth?
      How did you see in the new year?

      Results (227 votes). Check out past polls.