in reply to Re^3: (german) region code detection - request for thoughts
in thread (german) region code detection - request for thoughts

I like one regexp match more than several substring comparisons. And I didn't want a "huge" array in my code. Just one "simple" regex. My module for matching region codes and international country codes is 9K while the region codes alone are 32K.

32K is not a huge size nowadays, but I'm dated back from the ages of the C64 ;-)

Your solution is quite clever but would need some enhancements to provide for

  1. Different minimal lengths of region codes
  2. Different maximum lengths of region codes
  3. It sholud find those values on it's own

s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

Replies are listed 'Best First'.
Re^5: (german) region code detection - request for thoughts
by Krambambuli (Curate) on Aug 20, 2008 at 11:27 UTC
    1. Different minimal lengths of region codes
    2. Different maximum lengths of region codes
    3. It sholud find those values on it's own
    Update But... it's all there already ?
    There are no string comparisons, and the order of look-ups assures that the longest existent key/prefix always win.


    Oh, it's not, I just misunderstood your points. But definitely not hard to add, if really needed:
    use List::Util; my $min_prefix_length = min keys %prefixes; my $max_prefix_length = max keys %prefixes; my $prefix_length = $max_prefix_length; while ( $prefix_length-- >= $min_prefix_length) { last if exists $prefixes{ substr( $phone, 0, $prefix_length) }; } # Error/inexistent prefix if $prefix_length < $min_prefix_length;
    etc.

    Krambambuli
    ---

      Don't get me wrong. I just wanted to point out what was still missing, compared to my approach. I didn't want you to program that for me.

      Nevertheless ++ for your effort!


      s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
      +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e