The UNIX and Linux Forums  


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
perl -write values in a file to @array in perl meghana Shell Programming and Scripting 27 06-07-2009 06:05 PM
How to Turn perl one-liners into full perl script? EDALBNUG UNIX for Dummies Questions & Answers 1 02-04-2009 10:49 AM
[Perl] Accessing array elements within a sed command in Perl script userix Shell Programming and Scripting 2 10-03-2008 01:05 PM
[PERL] Running unix commands within Perl Scripts userix Shell Programming and Scripting 1 05-28-2008 07:06 PM
Perl: Run perl script in the current process vino Shell Programming and Scripting 10 12-09-2005 10:45 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-04-2009
King Nothing King Nothing is offline
Registered User
  
 

Join Date: Oct 2008
Posts: 68
Perl reg exp

Hi,
I am using the following piece of code for extracting some data from in between some tags ...


Code:
$text =~ /<TAG1>(.*)<\/TAG1>.*<TAG2>(.*)<\/TAG2>.*<TAG3>(.*)<\/TAG4>.*<TAG5>(.*)<\/TAG5>/;
$tag1=$1;
print "\n$tag1";

But I am getting an error like
Use of uninitialized value in concatenation (.) or string.
The script is running fine on Perl 5.8 but not on 5.6.
Is this a version issue? If so then what is the workaround for it?
  #2 (permalink)  
Old 04-04-2009
KevinADC KevinADC is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2008
Posts: 731
Well, if it works on one and not the other, it could be a version issue but I don't know for sure. The regexp is probably better written like so:


Code:
$text =~ /<TAG1>(.*?)<\/TAG1>.*?<TAG2>(.*?)<\/TAG2>.*?<TAG3>(.*?)<\/TAG4>.*?<TAG5>(.*?)<\/TAG5>/;
$tag1 = defined $1 ? $1 : 'no match found';
print "\n$tag1";

If you reall only want to capture $1 you should remove all the other parentheses from the regexp as they are aslo capturing pattern matches and storing them in memory for no reason.
Closed Thread

Bookmarks

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 12:20 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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