View Single Post
Old Apr 30th, 2005, 2:16 PM   #2
mackenga
Professional Programmer
 
Join Date: Mar 2005
Location: Glasgow, Scotland
Posts: 317
Rep Power: 4 mackenga is on a distinguished road
You could use array slices. With your 20-element @example array example, to get the first five items into @first and the rest into @second, I believe you could do:

@first = @example[0..4];
@second = @example[5..];

I'm not 100% sure of the syntax off the top of my head (not sure if just leaving off the upper bound is the right thing to do in the second line there). But I definitely think array slices are your answer.

Hope this helps.

P.S.: I noticed a bug in your code there; if ">" is the first character of the 'filename' argument to open(), it opens for writing, creating the file or truncating it to zero length. What you want is "<".

Last edited by mackenga; Apr 30th, 2005 at 2:18 PM. Reason: Noticed a bug
mackenga is offline   Reply With Quote