Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^3: Stuck in komplexer regex, at least for me

by xorl (Deacon)
on Mar 28, 2007 at 20:39 UTC ( #607102=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Stuck in komplexer regex, at least for me
in thread Stuck in komplexer regex, at least for me

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.


Comment on Re^3: Stuck in komplexer regex, at least for me
Download Code
Re^4: Stuck in komplexer regex, at least for me
by ultibuzz (Monk) on Mar 29, 2007 at 07:21 UTC

    this conversion is not possible,woud be great ;)
    and they are unable to change there 12 year old process because noone know how to change it.
    we both find it stupid to fill up the numbers with 0 so they are a 12 digit number ;/
    and so they are unable to change this and we can not work with nonsens numbers ( the 0 fileld up ones) we need to workaround it.
    from 12mio numbers 162 are not correct and this we can accept ;),50% of these numbers are crap anyway so its a nice failure quota and can be checkt by a human

    kd ultibuzz

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2014-08-01 03:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (256 votes), past polls