Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: How to eval an array element in regex's substitution

by ikegami (Patriarch)
on Oct 27, 2010 at 06:48 UTC ( #867630=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my $s = 'Hello [2][1]';
    my @a = ('x','y','z');
    ...
       $s =~ s/\[(\d{1,2})\]/$array_name->[$1]/g;
    }
    print $s;
    
  2. or download this
    my $s = 'Hello [2][1]';
    my @a = ('x','y','z');
    ...
    my $array_ref = do { no strict 'refs'; \@$array_name };
    $s =~ s/\[(\d{1,2})\]/$array_ref->[$1]/g;
    print $s;
    
  3. or download this
    my $s = 'Hello [2][1]';
    my @a = ('x','y','z');
    my $array_ref = \@a;
    $s =~ s/\[(\d{1,2})\]/$array_ref->[$1]/g;
    print $s;
    
  4. or download this
    my $s = 'Hello [2][1]';
    my @a = ('x','y','z');
    $s =~ s/\[(\d{1,2})\]/$a[$1]/g;
    print $s;
    

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://867630]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2023-05-31 16:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?