Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Slicing an array variable with a -1 or any negative number doesn't work

by ikegami (Pope)
on Nov 29, 2017 at 18:36 UTC ( #1204548=note: print w/replies, xml ) Need Help??


in reply to Slicing an array variable with a -1 or any negative number doesn't work

The syntax for an array slice is @NAME[LIST], not @NAME[NUM..NUM]. What that means is that .. is just an ordinary range operator in this scenario.

The range operator (in list context) returns an ascending sequence of numbers starting with its LHS operand and ending with its RHS operand. For example, 0..3 produces the foud scalars 0, 1, 2 and 3, while 0..-1 doesn't produce anything.

Replace

@$row[0..-1]

with

@$row[0..@$row-1]

or

@$row[0..$#$row]

or just

@$row

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1204548]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2018-06-20 01:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?



    Results (116 votes). Check out past polls.

    Notices?