Hi All,

My apologies for the previous incomplete message. I blame my webmail client.

I have an entire HTML template stored in $text. I want to use a RE to extract
several blocks of marked text, then perforn RE's on each block line by line in
a subroutine (&selection) and substitute that back into $text, i.e:

<snip>
65: $text =~ s{ <!--field--> ( .*? ) <!--end--> }
66:       { &selection( $1 ) }gsex;

..

83:             sub selection {
84:
85:                     my ( $name, $checked );
86:                     my $text = shift;
87:                     my $modified_text;
88:
89:                     for  ( split /\n/, $text ) {
90:     
91:                             {
92:                             m/name\s*=\s*"*(\w+)"*/;
93:                             $1 and $name = $1;
94:                             }
..

120:            $modified_text .= "$_\n";
121:            }
122:            return $modified_text;
123:    }
</snip>

The problem I seem to be having is on line 92/93. If the RE matches a value for
name='string", then I want that string to be stored in the variable $name. If
no match is found, I want the previous value of $name to persist.

However, it seems that if the pattern on line 92 doesn't match, then $name
inherits the value from the instance of $1 generated in the RE on line 66. I
have tried enclosing the second RE in braces (as shown), but the previous value
of $1 still seems to persist.

Can anyone tell me how I can make the value of $1 local to &selection? I have
tried "local $1;", but this has no effect either.

Any help much appreciated.

=====
I'm not tense. I'm just terribly, terribly alert.
-----------------------------------------------------
Team Artonomy - Drawing Business
Cartoons and illustration for web sites and business.

http://www.team-artonomy.com/
-----------------------------------------------------

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

Reply via email to