The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
perl hash pritish.sas Shell Programming and Scripting 3 07-20-2009 05:53 AM
perl using hash mingming88 Shell Programming and Scripting 3 05-25-2009 06:44 AM
perl hash littleboyblu Shell Programming and Scripting 2 03-19-2009 03:01 PM
Perl Hash Harikrishna Shell Programming and Scripting 1 06-02-2008 11:45 PM
Hash in perl Harikrishna Shell Programming and Scripting 1 06-02-2008 04:00 AM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-21-2009
zedex zedex is offline
Registered User
  
 

Join Date: Feb 2007
Location: india,mumbai
Posts: 138
perl hash

Hi i am reading one file and creating Hash from the contents of it my issue is there are 3 different files in 3 different locations having same structure so for parsing these files i have one subroutine which returns hash after reading all the 3 files i need to create consolidated hash from three how to do it ?

i managed to do it just wondering are there any better ways to do the same ?

Code:
output of data::dumper 

   direct =>{ 
                 1 => {
                           'one' => '1',
                           'two' => '2',
                           'thr'  => '3',
                         }
                } ;
  indirect =>{ 
                 1 => {
                           'one' => '1',
                           'two' => '2',
                           'thr'  => '3',
                         }
                } ;

i want to copy this in new hash at the end 

# $ret is original hash 
# $n is new hash 
foreach my $k ( keys %$ret )
{
    foreach my $m ( keys %{$ret->{$k}} )
    {
        foreach my $n ( keys %{$ret->{$k}->{$m}} )
        {
            $n->{$k}->{$m}->{$n} = $ret->{$k}->{$m}{$n}
        }
    }
}

above code is working just wondering is this the right way ?? or there are any better ways to do this . i dont want to use module for this
  #2 (permalink)  
Old 07-21-2009
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
  
 

Join Date: Mar 2005
Location: leaf node in B+ tree
Posts: 2,952
Please use code tags only for CODE.

>>>

Did you mean all the data into 1 hash ?
Instead of returning hash from the sub module, pass hash reference to the sub module and manipulate the hash in the sub module itself. So, there is no need to do post processing over the hash-es returned.
  #3 (permalink)  
Old 07-21-2009
zedex zedex is offline
Registered User
  
 

Join Date: Feb 2007
Location: india,mumbai
Posts: 138
soory for putting comments & code in code tag ..

its of no use now coz requirement changed ... lol
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:29 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0