Apr 19, 2007, 9:46 AM
Post #1 of 2
I thought I had a good grip on how to parse line by line reading from an input file, and this script works so far except for the field delimiter portion of it.
Parsing a line question
I thought using this method of reading a file I should be able to pull out fields from a text line by addressing them like awk - $1,$2, etc... but I get nothing at all.
I've tried passing different files to this program and get the same results. When I print my $stdrec var I DO see the whole line, but when I try and get a field from it, no go... what am I missing?
Please note, the if is always going to be true based on my input, it is just there as a test, the probflag prints a '1' which is what I would expect, but I get no return from the $percent var, where I would expect a number since the 5th field in an output line from lsps is the % used.
I have tried passing it a simple text file as well: "The quick brown fox jumped over the lazy dog" and I get the same results... do I need to read it as an array?
I don't want an alternative way in awk or shell to do this, I would like to learn why perl is not working for me...
#set global vars
#get paging usage
system ("rm $LogDir/paging.tmp");
system ("lsps -a > $LogDir/paging.tmp");
#verify and create new file var
open(PAGEOUT,$Pagefile) || die "can't open paging.out";
# begin loop to read paging
next if /Space/; #skip the header from lsps
if ( $stdrec=~/M/ )
print "$probflag $percent \n"; #DEBUG
}; #end while
Output is a 1 only, no other prints...