jperkins has asked for the wisdom of the Perl Monks concerning the following question:
Good morning monks! I'm hoping that posting my issue here someone will be able to point me in the right direction.
I believe myself to be a fairly competent bash coder, and I'm starting to take on perl as my new language (and I'm loving it so far). I am having trouble with a piece of code that I'm working with, and I was hoping to find someone that could point me in the right direction.
tmpfile is a smartctl output. The line I'm trying to capture is:my $hours; open( SMRT, "/root/perk/tmpfile" ); while( <SMRT> ){ chomp (); if (/Power_On_Hours(.*)/i) { $hours = $1 ; } @time = split(' ',$hours); print "Power on hours = $time[7]\n"; } close(SMRT);
9 Power_On_Hours 0x0032 099 099 000 Old_age Always - 916
My thinking about it, is that I should put that line into a variable, than split it with spaces into an array and call the last line by $time[7], which should return "916".
However when I'm running it, it's doing something crazy:
Power on hours = --snipped, above repeats 20 times-- Power on hours = 916 --snipped, above repeats 20 times--
I would greatly appreciate the wisdom from anyone who can point me in the direction I need to go.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Pulling lines from file, noob style
by toolic (Bishop) on Feb 17, 2010 at 17:28 UTC | |
by jperkins (Initiate) on Feb 17, 2010 at 17:33 UTC | |
by xyzzy (Pilgrim) on Feb 17, 2010 at 17:43 UTC | |
by johngg (Canon) on Feb 17, 2010 at 22:56 UTC |