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
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|