in reply to Re: No xml module please
in thread No xml module please
kvale: if you must introduce this person to the evil of regexes ;), at least watch out for a subtle bug that you've introduced. What happens if your first match succeeds and the rest fail? The subsequent variables will be set to the first one's value, thus hampering error checking. I would rewrite that as follows:
my ($file) = $string =~ /<file>([^<]+)/; my ($line) = $string =~ /<line>([^<]+)/; my ($type) = $string =~ /<type>([^<]+)/; my ($codee) = $string =~ /<codee>([^<]+)/; my ($desc) = $string =~ /<desc>([^<]+)/;
That should be a bit safer. Or better yet, go with a hash:
my %info; # a better name should be picked foreach ( qw/ file line type codee desc / ) { my ($info{$_}) = $string =~ /<\Q$_\E>([^<]+)/; }
Cheers,
Ovid
Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: No xml module please
by kvale (Monsignor) on Jul 18, 2002 at 19:25 UTC |