
BillKSmith
Veteran
Jan 4, 2013, 5:17 AM
Post #31 of 35
(7966 views)
|
Re: [Laurent_R] Match string in multi-line file
[In reply to]
|
Can't Post
|
|
Note the code in post 25.
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:
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:
The value of TRANSID is 'valueNeeded' Good Luck, Bill
(This post was edited by BillKSmith on Jan 4, 2013, 6:07 AM)
|