Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Last index use in array slice

by LanX (Canon)
on Dec 03, 2012 at 03:37 UTC ( #1006779=note: print w/ replies, xml ) Need Help??


in reply to Last index use in array slice

First you have to understand that you're slicing a list not an array.

Then a range from $index .. -1 must be empty because the upper bound must be bigger than the lower one (the range operator has no idea that you mean the biggest index, it's just the number "minus 1")

When using arrays you can write something like @array[$index..$#array] but as already stated you're not slicing an array and there is nothing like a counter for "last list entry". (your $# is another beast)

In short, you can't slice a list till the end w/o much obfuscatory magic, so better do it the "normal" way with arrays:

my @array = split /\n/, $object->get_array; my @slice = @array[$index .. $#array];

HTH! =)

Cheers Rolf


Comment on Re: Last index use in array slice
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2014-12-20 23:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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





    Results (99 votes), past polls