> I have an email To field that I want regex on
> 
> The email is as so:
> 
> [EMAIL PROTECTED]
> 
> Im trying to get the number before the hyphen.
> 
> Currently I have it as so
> 
> my ($bookrefNumber, $discard) = split('-',$pop3MailContent{'To'});

You don't need to use $discard variable.

You can use splice to capture only the relevant fields.
change it to this...

my ($bookrefNumber) = (split(/-/,$pop3MailContent{'To'}))[0];

> but I dont like this method.

If you do not like this method then use regexp.

A simple regexp without any checks would be(assuming that all email-ids have
the format you specified). 

# This will capture all the numbers from the starting till it finds a hyphen
(-).
$pop3MailContent{'To'} =~ /^(\d+)-/;

#$1 contains the pattern matched within the parentheses. If no match is
found then $1 would be undef.
my $bookrefNumber = $1;

And if you want, go through perlre/perlretut. It has lots of information on
regular expressions.

--Ankur



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to