Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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.

In reply to Re: Substrings of unusual size! by ww
in thread Substrings of unusual size! by Jalcock501

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others browsing the Monastery: (10)
    As of 2014-07-29 21:58 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (229 votes), past polls