Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
I feel the need to ask, might it be easier to convert your numbers to the other firm's numbers? Or maybe not try to convert anyone's numbers, but use both yours and theirs and match them up using a database or something? Maybe if I understood how and why they seem to add 0 in very odd places, it would be easier to figure out how to deal with this. I'm not a regex person, so this is my stab at this:
#!/usr/bin/perl use strict; # We want to do the following: #counting starts at 0 # the 0 , 1 digits shoud be untouched # if the 2 digit is a 0 and the next digit is a 0 remove all 0 untill +first non 0 # if the 2 digit a 0 and the next is a non 0 remove the 0 # if the 3 digit is a 0 and follows by a 0 then remove all 0 except th +e 0 at 3 digit # if the 3 digit is a 0 and the next digit is a non 0 remove only the +0 # if the 4 digit is a 0 remove it and all following 0 untill non 0 foreach my $number (<DATA>) { chomp($number); # print $number . "\n"; my @digits = split("", $number); my $newnumber; my $i = 0; for ($i=0; exists($digits[$i]); $i++) { # print "I:$i, " . $digits[$i] . "\n"; if ($i < 2) { # 0, 1 digits should be untouched $newnumber .= $digits[$i]; next; } elsif ($i == 2) { # if the 2 digit is a 0 and the next digit is a 0 remove all 0 u +ntill first non 0 # if the 2 digit a 0 and the next is a non 0 remove the 0 if ($digits[$i] > 0) { $newnumber .= $digits[$i]; next; } elsif (($digits[2] == 0) && ($digits[3] == 0)) { for(my $j = 2; $digits[$j] == 0; $j++) { $i++; # we skip this digit } $newnumber .= $digits[$i]; } # no need for another else b/c we remove the 0 anyway } elsif ($i ==3) { # if the 3 digit is a 0 and follows by a 0 then remove all 0 exc +ept the 0 at 3 digit # if the 3 digit is a 0 and the next digit is a non 0 remove onl +y the 0 if (($digits[3] == 0) && ($digits[4] > 0)) { next; } elsif(($digits[3] == 0) && ($digits[4] == 0)){ $newnumber .= $digits[$i]; for (my $j = 4; $digits[$j] == 0; $j++) { $i++; } $newnumber .= $digits[$i]; } } elsif ($i == 4) { # if the 4 digit is a 0 remove it and all following 0 untill non + 0 if ($digits[4] == 0) { for (my $j=4; $digits[$j] == 0; $j++) { $i++; } $newnumber .= $digits[$i]; } else { $newnumber .= $digits[$i]; } } else { $newnumber .= $digits[$i]; } } print "$number -> $newnumber\n"; } __DATA__ 215000007801 300000324002 890000457651 210004563401 201045139158
I'm sure there is a serious performance hit for not using a regex.

In reply to Re^3: Stuck in komplexer regex, at least for me by xorl
in thread Stuck in komplexer regex, at least for me by ultibuzz

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 surveying the Monastery: (4)
    As of 2014-10-01 23:14 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      What is your favourite meta-syntactic variable name?














      Results (41 votes), past polls