×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Help with regex

Help with regex

Help with regex

(OP)
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.

RE: Help with regex

Hi

Quote (thorntone)

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 --> thorntone.pl

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

print "Got $variable1 from $variable2.\n";

__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 --> command line

master # perl thorntone.pl 
Got 00000001.tif from 2251234567. 

Feherke.
feherke.ga

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close