Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: how to split

by reasonablekeith (Deacon)
on Dec 18, 2007 at 09:54 UTC ( #657632=note: print w/replies, xml ) Need Help??

in reply to how to split

If you can guarantee that the greater-than sign won't appear in your data, then you might as well use that as your end-of-line marker (your example shows confused usage of this, so you might want to look up the 'slurp' idiom). Each read from the file gets one set of results (the first read is blank, because we've set '>' as an end of line marker, but we're checking our data so it's okay). This can then be split to header/line data and pushed to the array.

Note that the whole thing is in curly brackets so that our value for $/ gets restored for any subsequent code (really, look up the slurp idiom.)

use strict; use warnings; use Data::Dumper; my (@header, @lin); { open FILE, "/home/guest/align.txt" or die("Error reading file: $!"); local $/ = '>'; while (my $result_set = <FILE>) { $result_set =~ s/>$//; # trim trailing EOL marker if ($result_set =~ m/^(.*?)(Query:.*)$/s) { push @header, $1; push @lin, $2; } } }; print Dumper(\@header); print Dumper(\@lin);
my name's not Keith, and I'm not reasonable.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (3)
As of 2022-08-08 04:15 GMT
Find Nodes?
    Voting Booth?

    No recent polls found