# in this line the regex match is taking much longer than the chomp chomp ($line) if ($line =~ /\n$/); # why not just chomp (sorry nitpicking)
# in answer to your question, try something like this my @stuff; open(FILE, '/path/to/file') or die("error opening file: $!"); while(<FILE>) { chomp; @line = split(/\|/);
# now you'd do something to determine if this @line is the stuff you want, if so break if($thisiswhatimlookingfor) { @stuff = @line; last; } } close FILE;
#make sure we found stuff if($#stuff < 0) { die("Couldn't find the good stuff"); }
# the data you want is now @stuff print "I have found stuff!";
'
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.
ROB posted this at 02:46 — 1st April 2003.
They have: 447 posts
Joined: Oct 1999
# in this line the regex match is taking much longer than the chomp
chomp ($line) if ($line =~ /\n$/);
# why not just chomp (sorry nitpicking)
# in answer to your question, try something like this
my @stuff;
open(FILE, '/path/to/file') or die("error opening file: $!");
while(<FILE>) {
chomp;
@line = split(/\|/);
# now you'd do something to determine if this @line is the stuff you want, if so break
if($thisiswhatimlookingfor) {
@stuff = @line;
last;
}
}
close FILE;
#make sure we found stuff
if($#stuff < 0) { die("Couldn't find the good stuff"); }
# the data you want is now @stuff
print "I have found stuff!";
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.