greenFox has asked for the wisdom of the Perl Monks concerning the following question:
I am sure the re can be improved but really the problem seemed to be begging for a split:for ($etime){ my ($dd,$hh,$mm,$ss)=() # see man ps etime looks like [[dd-]hh:]mm:ss if ( /^(?:(?:(\d{1,2})-){0,1})(?:(?:(\d{2}):){0,1})(\d{1,2}):(\d{2}) +$/ ){ $dd = $1 || ''; $hh = $2 || ''; $mm = $3; $ss = $4; $etime_secs= $ss+($mm*60)+($hh*60*60)+($dd*24*60*60); } }
Which is much nicer though I am just itching to get rid of the lines to make sure $hh and $dd are initialised :) Can any-one see a better way?for ($etime){ # see man ps etime looks like [[dd-]hh:]mm:ss # if either $dd and $hh are not present then they will eat # up the $mm & $ss so split on a non digit and reverse it: my ($ss, $mm, $hh, $dd)= reverse split /\D/; $hh += 0; # stop warning as $hh may not be initialised $dd += 0; # same as $hh :) $etime_secs= $ss+($mm*60)+($hh*60*60)+($dd*24*60*60); }
--
Life is a tale told by an idiot -- full of sound and fury, signifying nothing. William Shakespeare, Macbeth
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: parsing etime field from solaris ps
by sauoq (Abbot) on May 30, 2003 at 02:57 UTC | |
by greenFox (Vicar) on May 30, 2003 at 04:58 UTC | |
|
Re: parsing etime field from solaris ps
by BrowserUk (Patriarch) on May 30, 2003 at 03:17 UTC | |
|
Re: parsing etime field from solaris ps
by Enlil (Parson) on May 30, 2003 at 02:49 UTC |