Advertisement
cwchen

replace abc with 123

Jun 30th, 2014
490
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.97 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. use strict;
  4. use warnings;
  5. our (%replace_list);
  6.  
  7. sub BEGIN {
  8.     our %replace_list;
  9.     $replace_list{'a'..'z'} = (1..9, map {0} 1..17)
  10. }
  11.  
  12. sub replace_abc_123 {
  13.     my $string = shift;
  14.    
  15.     my $output = "";
  16.     for my $e (split //, $string) {
  17.         if ($e =~ /[[:alpha:]]/) {
  18.             $output .= $replace_list{lc $e};
  19.         }
  20.         else {
  21.             $output .= $e
  22.         }
  23.     }
  24.  
  25.     return $output;
  26. }
  27.  
  28. while (my $line = <DATA>) {
  29.     $line =~ s{rename ([\w_]+) "([\w\.]+)"}
  30.               {"rename " . replace_abc_123($1) .
  31.                " \"" . replace_abc_123($2) . "\"" }e;
  32.     $line =~ s{instanceRef ([\w_]+)}
  33.               {"instanceRef " . replace_abc_123($1)}e;
  34.     print "$line";
  35. }
  36.  
  37. __END__
  38. (port I0 (direction INPUT))
  39. (instance (rename ABC_1def "CBA.gh3") (viewRef X)
  40. (portRef I0 (instanceRef ABC_1def))
  41. (portRef I1 (instanceRef iJk_1def))
  42. (port LO (direction OUTPUT))
  43. (portRef O (instanceRef ABC_1def))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement