Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Programatically detecting a change in letters

by lodin (Hermit)
on Sep 03, 2007 at 19:44 UTC ( [id://636776]=note: print w/replies, xml ) Need Help??


in reply to Programatically detecting a change in letters

Here's a somewhat different approach that works if you only want to anchor at just /^N[aeiou]/.

my %anchors = map { $_ => 1 } qw/ Na Ne Ni No Nu /; while (my $line = <DATA>) { my ($number, $item) = split ' ', $line; my ($first_two) = $item =~ /^(..)/ or die "Word too short: $line"; if (delete $anchors{$first_two}) { print "Insert '$first_two' anchor here!\n"; } print $line; } __DATA__ 1930: Nails <-- #Na here 1939: Navy 1940: Nazi 1941: Nearsighted <-- #Ne here 1942: Neck 1961: Newspaper_Reporter 1963: Nickname <-- #Ni here 1964: Niece 1971: Nipples 1972: Nobility <-- #No here 1973: Noise 1981: November 1982: Nuclear_Bomb <-- #Nu here 1984: Numbers
Result:
Insert 'Na' anchor here! 1930: Nails <-- #Na here 1939: Navy 1940: Nazi Insert 'Ne' anchor here! 1941: Nearsighted <-- #Ne here 1942: Neck 1961: Newspaper_Reporter Insert 'Ni' anchor here! 1963: Nickname <-- #Ni here 1964: Niece 1971: Nipples Insert 'No' anchor here! 1972: Nobility <-- #No here 1973: Noise 1981: November Insert 'Nu' anchor here! 1982: Nuclear_Bomb <-- #Nu here 1984: Numbers

lodin

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://636776]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-03-29 11:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found