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;