dReKurCe has asked for the wisdom of the Perl Monks concerning the following question:
Greetings Monks; My question is concerning the following code: How do I populate the hash with the token (letter or number)as a key and its binary representation as the value?
$file=pop @ARGV; chomp $file; open (MESG, "+<" ,"$file")|| die "Phile unavailable:$!\n"; while(){ $character=$_; @letters=split(/\n/ ,$character); foreach $letter(@letters){ $ascii=unpack ("C*" ,$letter); $bin=unpack ("b*",$letter); $ordinal=ord $letter; print "\n1)$letter\n"; print "2)$ordinal\n"; print "3)$ascii\n"; print "4)$bin\n"; push @bin ,$bin; } } my %letnet; foreach $letter(@letters){ foreach $binary(@bin){ $letnet->{$letter}=$binary; } } while (($key,$value)=each (%letnet)){ print "$key-->$value\n"; }
janitored by ybiC: format codeblock for legibility
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Populating A Hash
by Zaxo (Archbishop) on Mar 02, 2005 at 02:14 UTC | |
by dragonchild (Archbishop) on Mar 02, 2005 at 02:45 UTC | |
by Zaxo (Archbishop) on Mar 02, 2005 at 02:52 UTC | |
by fglock (Vicar) on Mar 02, 2005 at 03:37 UTC | |
by ambrus (Abbot) on Mar 02, 2005 at 10:07 UTC | |
by dragonchild (Archbishop) on Mar 02, 2005 at 13:34 UTC | |
|
Re: Populating A Hash
by chas (Priest) on Mar 02, 2005 at 02:11 UTC | |
by Anonymous Monk on Mar 02, 2005 at 20:22 UTC |