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

Re: How to make it simple?

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

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


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
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.