rsiedl has asked for the wisdom of the Perl Monks concerning the following question:
Any help anyone could provide would be much appreciated.#!/usr/bin/perl use strict; use warnings; my @full_authors = ( "Smith, John", "Smith, John Ronald", "Johnson, Ja +mes", "James, Ray Jack", "Van der Burg, Jon", "O'Neil, Sarah" ); my @authors = ( "Smith J", "Jackson J", "James RJ", "Van der Burg J", +"O'Neil S" ); # Results should be: # Smith J = Smith, John # Jackson J = Jackson J # James RJ = James, Ray Jack # Van der Burg J = Van der Burg, Jon # O'Neil S = O'Neil, Sarah foreach my $author (@authors) { print "$author = "; # Regex rules # Last ' ' before all-uppercase word should become ', ' # Every singular or grouped capital letter # (i.e. F or RJ) should become F(.*) or R(.*) J(.*) # What I have so far $author =~ s/ (\w+?)\p{IsUpper}/, $1\(\.*\)/; print "[ $author ] : "; if ( my ($match) = ( grep $_ =~ /$author/, @full_authors ) ) { $author = $match; @full_authors = grep { $_ ne $match } @full_authors; } # end-if print "$author\n"; } # end-foreach exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regex help
by dragonchild (Archbishop) on Dec 09, 2004 at 15:03 UTC | |
by rsiedl (Friar) on Dec 09, 2004 at 15:11 UTC | |
by dragonchild (Archbishop) on Dec 09, 2004 at 15:15 UTC | |
by rsiedl (Friar) on Dec 09, 2004 at 15:18 UTC | |
by dragonchild (Archbishop) on Dec 09, 2004 at 15:27 UTC | |
| |
|
Re: regex help
by gopalr (Priest) on Dec 10, 2004 at 06:21 UTC | |
|
Re: regex help
by Animator (Hermit) on Dec 09, 2004 at 15:42 UTC | |
by Animator (Hermit) on Dec 09, 2004 at 15:49 UTC | |
by Animator (Hermit) on Dec 09, 2004 at 17:41 UTC | |
by rsiedl (Friar) on Dec 09, 2004 at 16:06 UTC | |
|
Re: regex help
by sasikumar (Monk) on Dec 09, 2004 at 15:07 UTC |