Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
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 studying the Monastery: (2)
As of 2018-02-24 05:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When it is dark outside I am happiest to see ...














    Results (310 votes). Check out past polls.

    Notices?