I'm unable to determine why my regex is failing. Here is my code:
my $email = "[email protected]";
my ($found) = $email =~ /(rise@dawn\.com)/;
print "Found: $found";
This results in the output:
C:\scripts\perl\sandbox>regex.pl
Found: rise.com
If I escape the @ sign, then I get no output at all:
my $email = "[email protected]";
my ($found) = $email =~ /(rise\@dawn\.com)/;
print "Found: $found";
C:\scripts\perl\sandbox>regex.pl
Found:
Could someone please enlighten me as to my errors.
in your declaration of $email
you are interpolating @dawn
This is due to quoting.
To avoid any hassle, just use single quotes like this:
my $email = '[email protected]';
my ($found) = $email =~ /(rise\@dawn\.com)/;
print "Found: $found";
Always use strict; use warnings;
at the top of your scripts!
It would warn you that there is an undeclared global variable @dawn
. Arrays can be interpolated into double quoted strings as well, so you need
my $email = "rise\@dawn.com";
my ($found) = $email =~ /(rise\@dawn\.com)/;
print "Found: $found";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With