[VPM] bizzare perl code question

Peter Scott peter at PSDT.com
Thu Jan 22 13:51:10 CST 2004


At 11:45 AM 1/22/2004 -0800, Carl B. Constantine wrote:
>I have some perl code (written by someone else) that seems most ugly and
>ineffecient.

Right on both counts.

>Here it is:
>
>     my ($tmpout,$pgCount);
>         $tmpout = `/usr/bin/psselect -p1- $dataFile 2>&1 /dev/null | 
> tail -1`;
>         $tmpout =~ /Wrote [0-9]* pages/;
>         $pgCount = $&; # find the match from the above line
>         $pgCount =~ /[0-9]+/; # be sure the number is in the 
> appropriate range
>         $pgGuess = $&; # match the above
>
>It seems to me, I could replace it with something a little better, like
>this:
>
>     my ($tmpout, $pgGuess);
>         $tmpout = `/usr/bin/psselect -p1- $dataFile 2>&1 /dev/null | 
> tail -1`;
>     ($pgGuess) = $tmpout=~ /Wrote (/d+) pages/;
>
>Am I off or would not my code be the same as above?

Nope, you're spot on.

If you want to divest yourself of one of those variables you can reduce 
the above to:

my ($pgGuess) = `/usr/bin/psselect -p1- $dataFile 2>&1 /dev/null | tail -1`
                 =~ /Wrote (/d+) pages/;

assuming you don't need $tmpout for something else.
-- 
Peter Scott
Pacific Systems Design Technologies
http://www.perldebugged.com/
*** New! *** http://www.perlmedic.com/




More information about the Victoria-pm mailing list