That warning is just a warning, so you can turn it off if you want to.
while ($data_in =~ /<container><a>(.+?)<\/a><b>(.+?)<\/b><\/container> +(<\?query\?>)??/ig) { { no warnings 'uninitialized'; $data_out = "$2, $1$3 "; } # further processing }
When you turn off a warning that way, it's good to keep that change to the smallest scope possible. In this case, I've scoped it just to that one assignment. See perllexwarn for more.
Alternately, you could check whether $3 is defined:
while ($data_in =~ /<container><a>(.+?)<\/a><b>(.+?)<\/b><\/container> +(<\?query\?>)??/ig) { if ( defined $3 ) { $data_out = "$2, $1$3 "; } else { $data_out = "$2, $1 "; } # further processing }
Same thing but different:
while ($data_in =~ /<container><a>(.+?)<\/a><b>(.+?)<\/b><\/container> +(<\?query\?>)??/ig) { $data_out = ( defined $3 ) ? "$2, $1$3 " : "$2, $1 "; }
P. S.—Yay for warnings!
In reply to Re: Special Variables in Regular Expression
by kyle
in thread Special Variables in Regular Expression
by fiat
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |