rscott212 has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to write a script that will read in a file into an array line by line. When it gets to the line starting with arcserve.nlm, I want my script to put that line and all other lines after that one until it reaches 2 blank lines into a temporary file. This arcserve.nlm will be somewhere in the middle of the file, but the line will start with arcserve.nlm.
Please help! I am having problems jumping to the line beginning with arcserve.nlm, then starting my conditions with this line, giving me every line until I reach 2 blank lines together. Below is what I have started:
use strict; use File::Basename; ##******** Variables ********## my $filepath = 'c:\a\netware'; my $dump = 'Netware_hw.txt'; my $arc = 'ARCSERVE.NLM'; my $serverfile = 'dallas.txt'; opendir (SOFTWARE, "$filepath"); chdir $filepath; open (SERVER, "<$serverfile") or die "Can't open the file\n"; open (OUTPUT, ">>$filepath\\$dump"); print OUTPUT "$name~"; my @lines= <SERVER>; foreach my $line (@lines) { if ($line =~ m/$arc/) { split(/^\n/; print OUTPUT "$line~";} } } close (OUTPUT); closedir (SERVER); closedir (SOFTWARE);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(jeffa) Re: Searching for variable then blank lines
by jeffa (Bishop) on Mar 14, 2002 at 05:27 UTC | |
by tstock (Curate) on Mar 14, 2002 at 06:14 UTC | |
by jeffa (Bishop) on Mar 14, 2002 at 12:12 UTC | |
by rscott212 (Sexton) on Mar 14, 2002 at 19:38 UTC | |
by jeffa (Bishop) on Mar 15, 2002 at 15:05 UTC | |
|
Re: Searching for variable then blank lines
by tstock (Curate) on Mar 14, 2002 at 04:51 UTC | |
by rscott212 (Sexton) on Mar 14, 2002 at 05:29 UTC | |
by tstock (Curate) on Mar 14, 2002 at 05:54 UTC |