Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Substrings of unusual size!

by ww (Bishop)
on Oct 10, 2013 at 01:19 UTC ( #1057649=note: print w/ replies, xml ) Need Help??


in reply to Substrings of unusual size!

It's probably possible to do what you ask with regexen and length (to establish a $len for use as a quantifier). OTOH, I ran out of time to play with that, so here's (clumsy, verbose, but functional) code, inspired -- in part -- by RichardK's reply, above.

#!/usr/bin/perl -w use 5.016; use Data::Dumper; # 1057557a1 my @grec = ('G3301R7435459:LNI10708', 'GA4:99TGSFAZ3', 'GINSFAC2:"A_1"', ); my @erec = ('E99POLCOM|3||CAP01|66|3301R7435459|||||', 'E99INSFAC2|MSRA01_1||||||"LNI10708"|', 'E99TGSFAZ3|A4|||743|||"A_1"|||', ); my ($grec, $erec, @Grec_split, @Erec_split, $Grec_split, $Erec_split); for $grec(@grec) { $grec =~ s/^G//; my @Grec = split /:/, $grec; push @Grec_split, @Grec; } for $erec(@erec) { $erec =~ s/^E//; my @Erec = split /\|/, $erec; push @Erec_split, @Erec; # Better to eliminate empty fi +elds before push } my $i = 0; my $j = 0; if ( $i < ( $#Grec_split +2 ) ) { # +\d 1 if arrs are equal len +; 2 if unequal no warnings 'uninitialized'; # no warn for arrays w/differ +ent nums of elements while ( $Grec_split[$i] ) { if ( $Erec_split[$j] eq '' ) { say "\t DEBUG Skipping empty \$Erec_split[$j]: $Erec_spli +t[$j]"; if ( $j < ($#Erec_split +1) ) { $j++; say "\t DEBUG: \$j at Ln 41 after increment: $j "; } } if ( $Grec_split[$i] eq $Erec_split[$j] ) { say "\n --> \$Erec_split[$j]: $Erec_split[$j] MATCHES \$G +rec_split[$i]: $Grec_split[$i]\n"; $i++; } else { # say "\t Could NOT MATCH \$Erec_split[$j] (|$Erec_split[$ +j]|) IN \$Grec_split[$i] ( $Grec_split[$i] )"; # DEBUG if ( $j < ($#Erec_split +1) ) { $j++; } else { $j = 0; $i++; } } } $i++; } =head Execution 1057557a1.pl: DEBUG Skipping empty $Erec_split[2]: DEBUG: $j at Ln 41 after increment: 3 --> $Erec_split[5]: 3301R7435459 MATCHES $Grec_split[0]: 3301R7435459 DEBUG Skipping empty $Erec_split[8]: DEBUG: $j at Ln 41 after increment: 9 DEBUG Skipping empty $Erec_split[10]: DEBUG: $j at Ln 41 after increment: 11 DEBUG Skipping empty $Erec_split[12]: DEBUG: $j at Ln 41 after increment: 13 DEBUG Skipping empty $Erec_split[16]: DEBUG: $j at Ln 41 after increment: 17 DEBUG Skipping empty $Erec_split[19]: DEBUG: $j at Ln 41 after increment: 20 DEBUG Skipping empty $Erec_split[22]: DEBUG Skipping empty $Erec_split[2]: DEBUG: $j at Ln 41 after increment: 3 DEBUG Skipping empty $Erec_split[8]: DEBUG: $j at Ln 41 after increment: 9 DEBUG Skipping empty $Erec_split[10]: DEBUG: $j at Ln 41 after increment: 11 DEBUG Skipping empty $Erec_split[12]: DEBUG: $j at Ln 41 after increment: 13 --> $Erec_split[15]: A4 MATCHES $Grec_split[2]: A4 DEBUG Skipping empty $Erec_split[16]: DEBUG: $j at Ln 41 after increment: 17 DEBUG Skipping empty $Erec_split[19]: DEBUG: $j at Ln 41 after increment: 20 DEBUG Skipping empty $Erec_split[22]: DEBUG Skipping empty $Erec_split[2]: DEBUG: $j at Ln 41 after increment: 3 DEBUG Skipping empty $Erec_split[8]: DEBUG: $j at Ln 41 after increment: 9 DEBUG Skipping empty $Erec_split[10]: DEBUG: $j at Ln 41 after increment: 11 DEBUG Skipping empty $Erec_split[12]: DEBUG: $j at Ln 41 after increment: 13 DEBUG Skipping empty $Erec_split[16]: DEBUG: $j at Ln 41 after increment: 17 DEBUG Skipping empty $Erec_split[19]: DEBUG: $j at Ln 41 after increment: 20 DEBUG Skipping empty $Erec_split[22]: DEBUG Skipping empty $Erec_split[2]: DEBUG: $j at Ln 41 after increment: 3 DEBUG Skipping empty $Erec_split[8]: DEBUG: $j at Ln 41 after increment: 9 DEBUG Skipping empty $Erec_split[10]: DEBUG: $j at Ln 41 after increment: 11 DEBUG Skipping empty $Erec_split[12]: DEBUG: $j at Ln 41 after increment: 13 DEBUG Skipping empty $Erec_split[16]: DEBUG: $j at Ln 41 after increment: 17 DEBUG Skipping empty $Erec_split[19]: DEBUG: $j at Ln 41 after increment: 20 --> $Erec_split[21]: "A_1" MATCHES $Grec_split[5]: "A_1"

Obviously, this can be greatly improved; some possibilities can be found in the thread beginning at Parallel processing two arrays with different numbers of elements and in Q&A under arrays.

If I've misconstrued your question or the logic needed to answer it, I offer my apologies to all those electrons which were inconvenienced by the creation of this post.


Comment on Re: Substrings of unusual size!
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (11)
As of 2014-08-21 20:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (143 votes), past polls