Front page | perl.beginners |
Postings from June 2012
refine the code
Thread Next
From:
lina
Date:
June 5, 2012 01:04
Subject:
refine the code
Message ID:
CAG9cJm=ViWDQr4kMeEtN6GNTtDQ9H1KPJC156EsMPOjFKEubJw@mail.gmail.com
Hi,
I wrote one, but don't know make it mature.
Here is what I am going to do.
"43 43 40 1",
"A c #FFFFFF " /* "0" */,
"B c #F8F8F8 " /* "0.0385" */,
"C c #F2F2F2 " /* "0.0769" */,
"D c #EBEBEB " /* "0.115" */,
"E c #E5E5E5 " /* "0.154" */,
"F c #DEDEDE " /* "0.192" */,
"G c #D8D8D8 " /* "0.231" */,
"H c #D1D1D1 " /* "0.269" */,
"I c #CBCBCB " /* "0.308" */,
"J c #C4C4C4 " /* "0.346" */,
"K c #BEBEBE " /* "0.385" */,
"L c #B7B7B7 " /* "0.423" */,
"M c #B1B1B1 " /* "0.462" */,
"N c #AAAAAA " /* "0.5" */,
"O c #A3A3A3 " /* "0.538" */,
"P c #9D9D9D " /* "0.577" */,
"Q c #969696 " /* "0.615" */,
"R c #909090 " /* "0.654" */,
"S c #898989 " /* "0.692" */,
"T c #838383 " /* "0.731" */,
"U c #7C7C7C " /* "0.769" */,
"V c #767676 " /* "0.808" */,
"W c #6F6F6F " /* "0.846" */,
"X c #696969 " /* "0.885" */,
"Y c #626262 " /* "0.923" */,
"Z c #5C5C5C " /* "0.962" */,
"a c #555555 " /* "1" */,
"b c #4E4E4E " /* "1.04" */,
"c c #484848 " /* "1.08" */,
"d c #414141 " /* "1.12" */,
"e c #3B3B3B " /* "1.15" */,
"f c #343434 " /* "1.19" */,
"g c #2E2E2E " /* "1.23" */,
"h c #272727 " /* "1.27" */,
"i c #212121 " /* "1.31" */,
"j c #1A1A1A " /* "1.35" */,
"k c #141414 " /* "1.38" */,
"l c #0D0D0D " /* "1.42" */,
"m c #070707 " /* "1.46" */,
"n c #000000 " /* "1.5" */,
/* x-axis: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 */
/* y-axis: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 */
"hebZWbdddXeecbYRQKKLNRVZaZWYWSOIKNOPPPNONTA",
"nlkgjmlmlgmnkhnimjfejnnnnnjiighdigbYWSPJDAT",
Translated the first "hebZWbdddXeecbYRQKKLNRVZaZWYWSOIKNOPPPNONTA" into value.
Here is the code I wrote so far (it works)
$ more translate
#!/usr/bin/env perl
use strict;
use warnings;
use autodie qw(open close);
use 5.012;
my $file = "dm_0.xpm";
open my $fh, '<', $file;
my %dict;
while (<$fh>){
if(/\"[A-Za-z] c /){
push my @array, split ' ',$_;
foreach($array[0]){
s/\"//g;
};
foreach($array[5]){
s/\"//g;
}
$dict{$array[0]}=$array[5];
}
if(/\"([A-Za-z]+)\",/){
push my @value, split '',$1;
foreach (@value){
print $dict{$_}," ";
}
last;
}
}
The output is
1.27 1.15 1.04 0.962 0.846 1.04 1.12 1.12 1.12 0.885 1.15 1.15 1.08
1.04 0.923 0.654 0.615 0.385 0.385 0.423 0.5 0.654 0.808 0.962 1 0.962
0.846 0.923 0.846 0.692 0.538 0.308 0.385 0.5 0.538 0.577 0.577 0.577
0.5 0.538 0.5 0.731 0
A further question, I have a series of those files, here this script
only handle one.
Here is the short bash I used
$ for f in *.xpm ; do more translate | sed s/'dm_0.xpm'/$f/g > temp ;
chmod +x temp ; ./temp; done
Can it be integrated into translate.pl file?
Thanks with best regards,
Thread Next