Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: How to scan a file, find a character string and print from that string to EOF

by myocom (Deacon)
on Aug 30, 2002 at 16:59 UTC ( [id://194177]=note: print w/replies, xml ) Need Help??


in reply to How to scan a file, find a character string and print from that string to EOF

Without changing your code too much, you might do something like this. The basic idea is that you have a flag telling you whether you've hit DETS01 yet or not, then flip the flag when you hit it.

#!/usr/bin/perl -w open (INPUT, "target.txt") or die "can't read from target:$!\n"; open (OUTPUT1, ">file1.txt") or die "can't write to file1.txt:$!\n"; open (OUTPUT2, ">file2.txt") or die "can't write to file2.txt:$!\n"; # # my $firsthalf = 1; while (<INPUT>) { if ($_ =~ /^DETS01/) { $firsthalf = 0; } if ($firsthalf) { print OUTPUT1 $_; } else { print OUTPUT2 $_; } } close (INPUT); close (OUTPUT1); close (OUTPUT2);

Edit: Removed commas after filehandles in prints. Thanks, tadman!

"One word of warning: if you meet a bunch of Perl programmers on the bus or something, don't look them in the eye. They've been known to try to convert the young into Perl monks." - Frank Willison

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-03-28 21:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found