Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

passing a multidimentional hash-sub-hash (to a sub and back again)

by Buckaroo Buddha (Scribe)
on Jun 30, 2000 at 18:45 UTC ( #20599=perlquestion: print w/replies, xml ) Need Help??

Buckaroo Buddha has asked for the wisdom of the Perl Monks concerning the following question:

i had this working at one point but it suddenly stopped
(grrr)
sub BackAndForth { my ($filename) = @_; # make multi-dimensional hash here ... it looks like # $ALLDATA{$filename}{$key1}{$key2}{$key3} = [@array] return (%ALLDATA); } my %ExternalHash = &BackAndForth('filename.csv'); %ExternalHash = &BackAndForth('filename2.csv');
   now i played around with it a bit and can't remember 
   what i may have changed ... $ here, % there (yadda yadda)

   if i do a variable dump on %ALLDATA i get ... 
%ALLDATA = ( 'key1' => HASH(0x9021f6c) 'key2' => HASH(0x90154a8) 'key3' => ARRAY(0x9015400) 0 value1 1 value2
   but if i do the same on %external i get 
%thisDataset = ( '' => HASH(0x876f324) 'key2' => HASH(0x9029220) empty hash)
       looking at the memory locations, we can see that 
       they're not the same hashes (but that should be 
       obvious cause i'm getting the return of a strange 
       set of data)

       where is the garbage coming from ?
            prehaps
return(\%ALLDATA) %external = (yadda yadda) or $external = (blah ...

Replies are listed 'Best First'.
RE: passing a multidimentional hash-sub-hash (to a sub and back again)
by Buckaroo Buddha (Scribe) on Jun 30, 2000 at 18:52 UTC
    </code>
    FYI
    
       it's  
        return(\%ALLDATA)
        $external = (blah blah blah)
    
        foreach $newkey (sort keys %$external) {
                #travels through the first level of that hash...
        }
      
    
      yes, i posted and answered my own question ... 
      leave me alone ;)
    
      it's good for the FAQ
    
      i'd liek to know why it does that though
    
Re: passing a multidimentional hash-sub-hash (to a sub and back again)
by ase (Monk) on Jul 01, 2000 at 00:34 UTC
    I think the answer to your question lies in the fact that return(%ALLDATA) returns a list of values (the keys and values of %ALLDATA while  return(\%ALLDATA)returns one value: a scalar that is a reference to the hash.
    Hope that helps,
    -ase

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://20599]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2019-08-25 07:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?