Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

matching hash into an array



7:47 pm on Aug 3, 2009 (gmt 0)

5+ Year Member

I have a hash with keys and values.
001 => blah blah blah

Then i have an array [001, 002, 003, ...] and i want to match the keys {001} with the array [001] and replace it with the hash's value...
[blah blah blah, 002, 003, ...]

this is what i have, but obviously doesn't work...

open (ALL2, "file.txt") die print "can't open";
while (<ALL2>){
@Line = split(/\t/);
if ( $hash{$key} eq $Line){


[1][edited by: phranque at 8:35 am (utc) on Aug. 4, 2009]
[edit reason] disabled graphic smileys ;) [/edit]


9:07 pm on Aug 3, 2009 (gmt 0)

5+ Year Member

You have an array or you have a file? If you are actually trying to modify an array, that is easy, if you are trying to edit a file, that is a little more difficult. And considering the nature of your post, I doubt your real hash/array/file is anything like what you posted, so trying to give you suggestions without knowing the true nature of the data/file/array/hash is almost useless.


10:32 pm on Aug 3, 2009 (gmt 0)

5+ Year Member

I'm trying to edit a text file#1.
My file is like this
1 (tab) 001 (tab) 002 (tab) blah-blah

i turned that into an array with:
@Line = split(/\t/);

i made a Hash out of my other text file#2 which looks like:
001 yadda-yadda
002 yadda-yadda
if ($_ =~ /something/){
my $key = $1.;
my $genes = $3;
if ( defined ( $Genes{$key})){
$Genes{$key} = $3;
NOW, i want to take the value "blah-blah" and and substitute it in file#1

and i'm trying this, but doesn't work...
@Line = split(/\t/);
if ( $hash{$key} eq $Line[1] ){

so that my file#1 ends up looking like
1 yadda-yadda 002 blah-blah


3:06 am on Aug 4, 2009 (gmt 0)

5+ Year Member

Since you have this same question on at least 3 perl forums I'll not continue to reply here too.


3:11 am on Aug 4, 2009 (gmt 0)

5+ Year Member

no problem... i didn't know all the forums were connected

answering me in any one of them is okay, thanks


4:13 am on Aug 4, 2009 (gmt 0)

5+ Year Member

All the forums are not connected, unless you count that you can connect to them all on the internet, but just like you found them to ask a question, the people that reply to perl questions can find them.

Featured Threads

Hot Threads This Week

Hot Threads This Month