[VPM] bizzare perl code question

Michael Joyce michael at negativespace.net
Thu Jan 22 15:25:27 CST 2004


Don't forget that within the regex, \d means match a digit, not /d, 
which will (since you've used the m// form) delimit the end of the 
regex, try to apply a nonexistent /d switch and generate a syntax 
error, and probably a warning.

Michael

On Jan 22, 2004, at 11:51 AM, Peter Scott wrote:

> 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/
>
>
>
Michael S. Joyce
http://www.negativespace.net - all things in between




More information about the Victoria-pm mailing list