A little extra
#!/usr/bin/perl
use strict;
my (@gerbal) = (
'Newbie',
'Notbie',
'Nutbie',
'Oldie',
);
foreach my $foot (@gerbal) {
print "$foot -- ";
if ($foot =~ /N(?:ew|ot)bie/) {
print " match found.\n";
} else {
print " no match.\n";
}
}
exit;
Results:
Newbie -- match found.
Notbie -- match found.
Nutbie -- no match.
Oldie -- no match.
This fun form contains a couple of mysteries.
Why use "(?:ew|ot)"?
Why not just use "(ew|ot)"?
Both would work. But they have different side-effects.
We'll leave the difference for you to discover later as you develop your Perl.
|