homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

matching hash into an array

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

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)

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)

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)

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)

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)

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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved