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

Re: Last index use in array slice

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

in reply to Last index use in array slice


(UPDATED code for clarification)

DB<123> $str =join '', a..h => "abcdefgh" DB<124> ( undef, undef, undef, undef , @rest) = split //, $str => ("a", "b", "c", "d", "e", "f", "g", "h") DB<125> @rest => ("e", "f", "g", "h")

with arbitrary index, we'll need a dummy array to swallow ignored entries:

DB<126> $index=4 => 4 DB<127> ( @ignore[1..$index] , @rest) = split //, $str => ("a", "b", "c", "d", "e", "f", "g", "h") DB<128> @rest => ("e", "f", "g", "h")

cause unfortunately this doesn't work:

DB<129> ( ( (undef) x $index ) , @rest) = split //, $str Can't modify repeat (x) in list assignment at (eval 65)[multi_perl5db. +pl:638] line 2, at EOF

Cheers Rolf

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

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2015-07-07 05:58 GMT
Find Nodes?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...

    Results (87 votes), past polls