dhasaan has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -w use strict; #Matching a member of texlines with a member of update* #Last example, Fourth, is what needs to be done my @updateloc = ("LakeOsouth", "LakeOeast", "LakeO2", "LakeO"); my @updateloc1 = ("LakeOsouth/stuf", "LakeOeast/stuf", "LakeO2/stuf", +"LakeO/stuf"); my @texlines = ("LakeOsouth", "LakeOeast", "LakeO2", "LakeO"); # Works fine print "Zero\n"; foreach my $update (@updateloc){ for my $lin (@texlines){ if ($lin =~ /$update\b/){ if ($update =~ /$lin/) { print "match 1 reverse $lin $update\n"; }else{ print "bad match $update $lin\n"; } } } } # Getting 3 bad ones print "First\n"; foreach my $update (@updateloc){ for my $lin (@texlines){ if ($lin =~ /$update/){ if ($update =~ /$lin/) { print "match 1 reverse $lin $update\n"; }else{ print "bad match $update $lin\n"; } } } } # Getting 2 bad ones; the digit on end of $update iso a char is ok? print "Second\n"; foreach my $update (@updateloc){ for my $lin (@texlines){ if ($lin =~ /$update/g){ if ($update =~ /$lin/g) { print "match 1 reverse $lin $update\n"; }else{ print "bad match $update $lin\n"; } } } } # No good, anything to do with previous matches (the /g)? print "Third\n"; foreach my $update (@updateloc){ for my $lin (@texlines){ if ($lin =~ /$update/g){ if ($update =~ /$lin/g) { print "match 1 reverse $lin $update\n"; }else{ print "bad match $update $lin\n"; } } } } # Back to number Zero, so Third is influenced by Second? print "Third and a half\n"; foreach my $update (@updateloc){ for my $lin (@texlines){ if ($lin =~ /$update/){ if ($update =~ /$lin/) { print "match 1 reverse $lin $update\n"; }else{ print "bad match $update $lin\n"; } } } } #Finally the problem # This is what i need: match 1 reverse, doesn't happen print "Fourth\n"; foreach my $update (@updateloc1){ for my $lin (@texlines){ if ($lin =~ /$update/g){ if ($update =~ /$lin/g) { print "match 1 reverse $lin $update\n"; }else{ print "bad match $update $lin\n"; } }else{ if ($update =~ /$lin/g) { print "\tmatch 2 reverse $lin $update\n"; }else{ print "\tno match $update $lin\n"; } } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Match a chunk
by pc88mxer (Vicar) on Jun 11, 2008 at 22:53 UTC | |
|
Re: Match a chunk
by starbolin (Hermit) on Jun 12, 2008 at 02:41 UTC | |
by dhasaan (Initiate) on Jun 12, 2008 at 10:06 UTC | |
by Anonymous Monk on Jun 12, 2008 at 11:25 UTC | |
|
Re: Match a chunk
by Anonymous Monk on Jun 12, 2008 at 10:46 UTC | |
by dhasaan (Initiate) on Jun 13, 2008 at 13:36 UTC | |
|
Re: Match a chunk
by Anonymous Monk on Jun 13, 2008 at 06:54 UTC |