A
Andrew DeFaria
I thought I understood Perl regexs pretty well but this one confuses me.
What am I doing wrong here?
#!/usr/bin/perl
use
strict;
use
warnings;
$_ = "#if __LDBL_SIZE == 80
block";
if (/^#.*= (\d*)/)
{
print "Pattern matched \$1 =
\"$1\"\n";
} else
{
print "Pattern did not
match\n";
}
if (/^#.*(\d*)/)
{
print "Pattern matched \$1 =
\"$1\"\n";
} else
{
print "Pattern did not
match\n";
}
Outputs:
Pattern matched $1 =
"80"
Pattern matched $1 = ""
Why does the second pattern fail?!?
What am I doing wrong here?
#!/usr/bin/perl
use
strict;
use
warnings;
$_ = "#if __LDBL_SIZE == 80
block";
if (/^#.*= (\d*)/)
{
print "Pattern matched \$1 =
\"$1\"\n";
} else
{
print "Pattern did not
match\n";
}
if (/^#.*(\d*)/)
{
print "Pattern matched \$1 =
\"$1\"\n";
} else
{
print "Pattern did not
match\n";
}
Outputs:
Pattern matched $1 =
"80"
Pattern matched $1 = ""
Why does the second pattern fail?!?