Steve_BZ has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks,
What is the scope of the standard RegEx variables like $_, $' etc?
I'm trying to loop through a RegEx with the following code and replace all occurances of 'exhibit' with different verbs so that exhibit is not repeated (eg exhibit, show, reveal, display etc...). I'm using this code, but it crashes with 'variable not initialised' on the line $loc_end_pos = pos($_) - length($1);. I suspect $_ is being reset by __exhibit_verb_function. What do you think?
if (/(\{exhibit\})/) { $loc_exhibit_txt = $loc_observation_model->__exhibit_verb_function +($k-1+$gl_exhibit_verb_marker_idx, $gl_language_country, "G"); $loc_end_pos = pos($_) - length($1); $loc_string_out = $loc_string_out . substr($_,$loc_start_pos,$loc_ +end_pos-$loc_start_pos); # Add variable $loc_string_out = $loc_string_out . $loc_exhibit_txt ; # Ad +d variable $loc_start_pos=pos($_); }
Thanks for your help.
regards
Steve
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Scope of RegEx vars like $_
by JavaFan (Canon) on Mar 12, 2010 at 13:59 UTC | |
by Steve_BZ (Chaplain) on Mar 13, 2010 at 10:17 UTC | |
|
Re: Scope of RegEx vars like $_
by almut (Canon) on Mar 12, 2010 at 12:27 UTC | |
by Steve_BZ (Chaplain) on Mar 12, 2010 at 17:33 UTC | |
by Steve_BZ (Chaplain) on Mar 13, 2010 at 00:28 UTC | |
|
Re: Scope of RegEx vars like $_
by Anonymous Monk on Mar 12, 2010 at 11:59 UTC |