Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: splitting arrays

by RazorbladeBidet (Friar)
on Apr 15, 2005 at 13:02 UTC ( [id://448140]=note: print w/replies, xml ) Need Help??


in reply to splitting arrays

splice perhaps? Your question is just a tad vague, care to give us more info?
--------------
"But what of all those sweet words you spoke in private?"
"Oh that's just what we call pillow talk, baby, that's all."

Replies are listed 'Best First'.
Re^2: splitting arrays
by Anonymous Monk on Apr 15, 2005 at 13:21 UTC
    Hi

    I am reading in a file of data, each line has 50 bits of tab-delimited data. I normally use split but for some reason, some items have lots of newline characters seperating the data and some don't. I am doing this within a while loop but it is considering every line as a separate record, not every item.

    while (<ARRAY_DATA>) { $line = $_; chomp ($line); @array = (); @array = split (/\s+/, $line); # other stuff here }
      So are you saying that inside that line of 50 items (I'm assuming you're using the term "bits" to mean "things" not 0 or 1) there are newline characters? If so, what is the line termination character - how do you know when you need to start on the next "line".
      --------------
      "But what of all those sweet words you spoke in private?"
      "Oh that's just what we call pillow talk, baby, that's all."
        sadly, there is no "line" termination character, i only know when to start the next one after 50 tab-delimited 'things' have been found
      If your goal is to read 50 items into an array on each pass of the loop:
      while (!eof DATA) { local $/="\t"; chomp(my @set = map {(eof) ? () : scalar(<DATA>)} 1..50); print "Set: ", join(',', @set), "\n"; }
      Use whatever filehandle is appropriate.
      Update: changed second eof to use "last file read" default form.

      Caution: Contents may have been coded under pressure.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (8)
As of 2024-04-24 09:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found