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

Re: How to make it simple?

by flyingmoose (Priest)
on Mar 26, 2004 at 18:22 UTC ( [id://340101]=note: print w/replies, xml ) Need Help??


in reply to How to make it simple?

This is a bit of an explanation on what the other monks were doing with @array.

splice(@array, 0, 8);

splice destructively removes elements from @array, so you have to ask if you really want to do that. Since you are not splicing elements into the array (like you would splice a rope), splice probably doesn't make sense in this context.

A slice (like you do with pizza or pie, not like a rope) (see below) seems to be what you want, and it is a little more intuitive to read. The splice just accesses the elements, without removing them.

@array[0..8];

The other monks comments on how to do a foreach still apply to. So you can just foreach over a slice. It's better than repeating statements or using a for loop with a counter variable. If you want just part of the array, you can specify the start and stop boundaries of slice using something like @array[1..6]

foreach $item (@array[1..6]) { $item =~ s/\.//g; }

So this modifies only certain elements of the array, and it's pretty darn clean to look at. You may to modify the indexes (indices) if 1..6 isn't what you want exactly, but you get the general idea.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-26 08:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found