jamen_98 has asked for the wisdom of the Perl Monks concerning the following question:
I have a script that pulls the first line of the file below. The file looks like:
Label Location Pool Name Protection [NFK100L2] [MSL6000 Trinity: 1] MSL6000 01/19/2004 [NFK101L2] [MSL6000 Trinity: 5] MSL6000 01/19/2004
Many times it will only be 1 line long of data but it could be up to three. I need to extract the 1 and 5 and put it into a new file. Currently I only need to pull the first line, but in the near future I need unlimited.
This code works great for one line. I like the idea of just reading the line and then outputting it directly into the file, however when doing two lines, whether I use the \n or not, I only end up with the very last line (ie: 5). The code that works beautifully for one line is:
#!/usr/bin/perl -w use strict; system ("c:\\Perl\\DataPro\\convert.bat"); open(DPSLOTFILE, "< c:\\Perl\\DataPro\\newreport.txt") or die "Can't o +pen file: $!"; open(OUTFILE, "> c:\\Perl\\DataPro\\output.txt") or die "Can't open fi +le: $!"; while ( <DPSLOTFILE> ) { my $dpdrivloc = "MSL6000 Trinity"; if ( /\Q$dpdrivloc\E:\s*(\d+)/ ) { print OUTFILE "$1"; } } close OUTFILE; close DPSLOTFILE; open (OUTFILE, "< c:\\Perl\\DataPro\\output.txt") or die "Can't open f +ile: $!"; my $slotnumber = <OUTFILE>; print "$slotnumber"; system("c:\\Perl\\DataPro\\omnimm -eject \"MSL6000 Trinity\" $slotnumb +er -location \"blahblahblah\""); close OUTFILE;
Any ideas on how to edit this to write out more
than one slot number to the out file is appreciated!
Thanks! Ben
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Modify code help
by tcf22 (Priest) on Mar 26, 2004 at 19:58 UTC | |
|
Re: Modify code help
by dragonchild (Archbishop) on Mar 26, 2004 at 20:41 UTC | |
by flyingmoose (Priest) on Mar 26, 2004 at 20:48 UTC | |
|
Re: Modify code help
by Art_XIV (Hermit) on Mar 26, 2004 at 20:46 UTC | |
|
Re: Modify code help
by graff (Chancellor) on Mar 27, 2004 at 18:27 UTC |