CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner: Re: [Laurent_R] Match string in multi-line file: Edit Log



BillKSmith
Veteran

Jan 4, 2013, 5:17 AM


Views: 1990
Re: [Laurent_R] Match string in multi-line file

Note the code in post 25.

Code
while ($FileTemp = <PARSEFILE>){  
$FileTemp =~ s/:/\n/g;

The string is made into a multi-line string by changing the colons to newlines. We know that there are multiple colons from the file format in post 1.

UPDATE: The following code and output was added to this post to demonstrate the solution:


Code
use strict; 
use warnings;
*PARSEFILE = *DATA;
while (my $FileTemp = <PARSEFILE>){
$FileTemp =~ s/:/\n/g;
my $value1 = $2 if $FileTemp =~ /^(TRANSID),(\w+)/m;
print "The value of $1 is '$value1'\n" if defined $value1;
}
__DATA__
newline1:FieldCostant1,value1:FieldCostant2,value2:FieldCostant3,value3
newline4:FieldCostant1,value1:TRANSID,valueNeeded:FieldCostant3,value3
newline2:FieldCostant1,value1:FieldCostant2,value2:FieldCostant3,value3
newline3:FieldCostant1,value1:FieldCostant2,value2:FieldCostant3,value3

Output:

Code
The value of TRANSID is 'valueNeeded'

Good Luck,
Bill

(This post was edited by BillKSmith on Jan 4, 2013, 6:07 AM)


Edit Log:
Post edited by BillKSmith (Veteran) on Jan 4, 2013, 6:07 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives