#!/usr/bin/env perl use warnings; use strict; my %table = ( barra => '/', cero => 0, uno => 1, dos => 2, tres => 3, cuatro => 4, cinco => 5, seis => 6, siete => 7, ocho => 8, nueve => 9 ); while (<DATA>) { if (/##(.*)##/) { my @words = split /\s+/, $1; my $pre = $`; my $post = $'; for (@words) { for my $key (keys %table) { if ($_ eq $key) {$_ = $table{$key}} } } print "$pre##", "@words", "##$post"; } else { print; } } __DATA__ (5/4/07 1:44:44 PM CDT) 7782719:##uno seis uno + + ##;pp (5/4/07 1:45:29 PM CDT) 7819953:##uno cinco cuatro##;pp (5/4/07 1:45:29 PM CDT) 7821389:##uno seis uno + + ##;pp (5/4/07 1:48:01 PM CDT) 7976990:##uno seis uno + + ##;pp (5/4/07 1:48:01 PM CDT) 7979657:## tres empaques##;pp (5/4/07 1:48:16 PM CDT) 7980901:##uno seis uno + + ##;pp (5/4/07 1:48:33 PM CDT) 8007951:##Tome tres empaques ##;pp (5/4/07 1:48:48 PM CDT) 8010439:##BEEP (375,2)## (5/4/07 1:48:48 PM CDT) 8011336:##Selección completa. ##;pp (5/4/07 1:48:48 PM CDT) 8012745:## andén Anden uno tres cinco##;pp
Produces this output:
(5/4/07 1:44:44 PM CDT) 7782719:##1 6 1##;pp (5/4/07 1:45:29 PM CDT) 7819953:##1 5 4##;pp (5/4/07 1:45:29 PM CDT) 7821389:##1 6 1##;pp (5/4/07 1:48:01 PM CDT) 7976990:##1 6 1##;pp (5/4/07 1:48:01 PM CDT) 7979657:## 3 empaques##;pp (5/4/07 1:48:16 PM CDT) 7980901:##1 6 1##;pp (5/4/07 1:48:33 PM CDT) 8007951:##Tome 3 empaques##;pp (5/4/07 1:48:48 PM CDT) 8010439:##BEEP (375,2)## (5/4/07 1:48:48 PM CDT) 8011336:##Selecci�n completa.##;pp (5/4/07 1:48:48 PM CDT) 8012745:## and�n Anden 1 3 5##;pp
This may not be the most efficient way to do this, considering that you have large files, but our fellow Monks will no doubt be able to help you optimize this.
In reply to Re: Substitution in conjunction with split or regx
by toolic
in thread Substitution in conjunction with split or regx
by qnguyen
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |