Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Indexing multiplicate firstnames with regex

by whakka (Hermit)
on May 27, 2009 at 15:54 UTC ( #766456=note: print w/ replies, xml ) Need Help??


in reply to Indexing multiplicate firstnames with regex

This works (no regexes necessary):

#!/usr/bin/perl use strict; use warnings; my %first; while ( <DATA> ) { chomp; my ($fn,$ln) = split; push @{$first{$fn}}, $ln; } for my $fn ( keys %first ) { my @ln = @{$first{$fn}}; if ( @ln == 1 ) { print $fn,' ',$ln[0],"\n"; } else { my $c = 1; print $fn,$c++,' ',$_,"\n" for @ln; } } __DATA__ George Fortran Jessi Heavens Bill Clinton Barack Obama Bill Gates Steve Jobs Bill Green George Bush
This doesn't preserve the ordering, though.


Comment on Re: Indexing multiplicate firstnames with regex
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (19)
As of 2015-07-29 17:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (266 votes), past polls