Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with regex

Status
Not open for further replies.

thorntone

IS-IT--Management
Mar 2, 2001
12
US
Hi. Long time IT pro, first time Perl user.

Trying to perform what I expect to be a straight forward parse of data strings from a file. The file is the output header info for a scanned file that is being picked up by a fax (yes, Fax) server.

The specific lines in question of the file are thus:
1. string ImageFileName = "00000001"; (there are a number of spaces preceeding the word "string")
2. string PhoneNumber = "2251234567"; (again, there are a number of spaces preceeding the word "string")

I wish to assign the value "00000001.tif" to a variable and 2251234567 to another.

I've attempted any number of "$line =~" variations to assign the values to $1 or $2, or any variable name without success.

Thanks.
 
Hi

thorntone said:
I've attempted any number of "$line =~" variations to assign the values to $1 or $2, or any variable name without success.
Next time please post what you tried so we can explain where it failed.

Code:
[b]while[/b] ($str = <DATA>) {
    $variable1 = [green][i]"$1.tif"[/i][/green] [b]if[/b] $str =~ [b]m[/b]/\bImageFileName\s*=\s*"(.+?)"/;
    $variable2 = $1 [b]if[/b] $str =~ [b]m[/b]/\bPhoneNumber\s*=\s*"(.+?)"/;
}

[b]print[/b] [green][i]"Got $variable1 from $variable2.\n"[/i][/green];

__DATA__
1.      string ImageFileName = "00000001";  (there are a number of spaces preceeding the word "string")

2.       string PhoneNumber = "2251234567";  (again, there are a number of spaces preceeding the word "string")
Code:
[navy]master #[/navy] perl thorntone.pl 
Got 00000001.tif from 2251234567.


Feherke.
feherke.ga
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top