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



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Storing commands in $variables. Paulw0t Shell Programming and Scripting 7 08-08-2008 05:42 PM
storing variables in array.Please help nua7 Shell Programming and Scripting 7 07-17-2008 09:47 AM
Splitting the data and storing it into 2 variables jisha Shell Programming and Scripting 10 02-17-2008 10:40 PM
Storing pointer array in C arunkumar_mca UNIX for Dummies Questions & Answers 1 08-23-2007 08:49 AM
awk - storing data in variables 2nilotpal Shell Programming and Scripting 7 04-16-2004 05:32 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #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?
  #2 (permalink)  
Old 08-29-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
With a string in double quotes, the $1 gets interpolated at the time you define the string. Try single quotes and eval print $res;
  #3 (permalink)  
Old 08-29-2008
xist xist is offline
Registered User
  
 

Join Date: Nov 2007
Posts: 7
in this redaction:
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/) {
   eval print $res;
    }
}
close FILE;
doesn't work as well
  #4 (permalink)  
Old 08-29-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
I guess you need to eval the matching as well.
Sponsored Links
Closed Thread

Bookmarks

Tags
perl regex

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 10:01 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0