[Omaha.pm] Count occurrences of the value of an attribute in XML

Andy Lester andy at petdance.com
Tue May 29 19:04:51 PDT 2007


On May 29, 2007, at 7:39 PM, Jay Hannah wrote:

> $ perl -lne '/rt="(\w+)"/; print $1' RevData.DALMAN.20070529.xml |  
> uniq

Actually, this is wrong.  You cannot rely on the value of $1 if the  
m// did not match.  Your "optimization" to /rt.../ && print $1 is  
necessary or else it is wrong.

See http://perl101.org/regexes.html "Don't use capture variables  
without checking that the match succeeded."

xoxo,
Andy

--
Andy Lester => andy at petdance.com => www.petdance.com => AIM:petdance






More information about the Omaha-pm mailing list