lina wrote:
Hi,

Hello,

I have a file,

  cat try.xpm
a 1
b 2
c 3
d 4

abbbcaaaadddb


I wish to use perl to translate the last line into the numerical value.

#!/usr/bin/perl

use warnings;
use strict;

open FILE, "<try.xpm" or die $!;

my @line =<FILE>;

while (<FILE>) {
        print $_;
}

strangely it print me nothing out,

Thanks for any suggestions,

$ echo "
a 1
b 2
c 3
d 4

abbbcaaaadddb

" | perl -e'
use warnings;
use strict;

my %translate;

while ( <> ) {
    if ( / ( [[:alpha:]] ) \s+ ( [[:digit:]] ) /x ) {
        $translate{ $1 } = $2;
        }
    elsif ( / ^ ( [[:alpha:]]+ ) $ /x ) {
        s/(.)/$translate{$1}/g;
        print;
        }
    }
'
1222311114442




John
--
Any intelligent fool can make things bigger and
more complex... It takes a touch of genius -
and a lot of courage to move in the opposite
direction.                   -- Albert Einstein

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to