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

Re^2: What is the difference between $array[1] and @array[1]?

by JavaFan (Canon)
on Apr 07, 2009 at 16:13 UTC ( [id://756064]=note: print w/replies, xml ) Need Help??


in reply to Re: What is the difference between $array[1] and @array[1]?
in thread What is the difference between $array[1] and @array[1]?

(If you use slices with just one element you will get a warning though.)

That depends on how you write the slice:

@a = (1 .. 5); say @a[1]; # Warning say @a[1..1]; # No warning say @a[1,]; # No warning @b = 1; say @a[@b]; # No warning
Four one element slices, but only one warns.

Frankly, I find the warning a bit silly; specially the warning if the slice is used in rvalue context. There isn't anything else the programmer could have reasonably meant. And in Perl6, @a[1] is going to be the required syntax anyway.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2025-01-15 06:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (46 votes). Check out past polls.