Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Matching a Word Exactly

by karlgoethebier (Abbot)
on Oct 09, 2014 at 11:30 UTC ( [id://1103286] : note . print w/replies, xml ) Need Help??


in reply to Matching a Word Exactly

BTW, proper indention and omitting unnecessary whitespace isn't a bad thing :-)

use strict; use warnings; while (<DATA>) { if ( $_ =~ m/\bGuinea\b/ ) { print "We have a match\n"; # m/\bGuinea\b$/ matches Guinea at end # m/^\bGuinea\b$/ matches Guinea at the beginning } else { print "We do not have a match\n"; } } __DATA__ Papua New Guinea I live in Guinea Guinea Bissau Equatorial Guinea

See also Perltidy.

Best regards, Karl

«The Crux of the Biscuit is the Apostrophe»