On 5/16/07, Mathew Snyder <[EMAIL PROTECTED]> wrote:
I have a trouble ticket application that uses a regex to find a piece of information in an incoming email and auto populate a field if it is found. The line it will be looking for is CUSTOMER ENVIRONMENT customer_name where customer_name will never have a space making it one word. If I just want to pull from the line the customer_name would my regex look like $MatchString = "CUSTOMER ENVIRONMENT\s+(\w)"
Bad idea. Use qr() instead.
For what it's worth the line that will handle this is $found = ($Transaction->Attachments->First->Content =~ /$MatchString/m); I'm guessing that when used in an assignment like this, $1 will be used as the value. The contents of (\w) in this case. Is that correct?
snip Yes, the $1 match variable will hold the match if $found is true. A common idiom is therefore my $name; my $regex = qr/CUSTOMER ENVIRONMENT\s+(\w)/; if ($Transaction->Attachments->First->Content =~ /$regex) { $name = $1; } else { die "could not find name"; } Another way to write this is my $regex = qr/CUSTOMER ENVIRONMENT\s+(\w)/; my ($name) = $Transaction->Attachments->First->Content =~ /$regex/ or die "could not find name"; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/