The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 08-29-2008
xist xist is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 7
perl: storing regex in array variables trouble

hi
this is an example of code:
Code:
use strict;
use warnings;
open FILE, "/tmp/result_2";
my $regex="\\[INFO\\] Starting program ver. (.*)";
my $res="Program started, version <$1> - OK.\n";
while (<FILE>) {
if ($_ =~ /($regex)/) {
   print "$res";
    }
}
close FILE;
This finds $regex and print out the $res, but "$1" doesn't work. I've tried <\$1> as well and other variations. How to make it work?