List Info

Thread: Help with Hashes of hashes




Help with Hashes of hashes
country flaguser name
United States
2007-02-19 03:55:55
 
  Hi all:
   
  I've few question regarding Hashes, hashes of hashes, my
understanding 
  of hashes is not quite clear.
   
  I got these error, sm1.list smoke.list sm0.list 1/8 5/8
1/8 G
   
  I did:
   
   $HashList = ();
    foreach my $a1 (list) {
      $HashList{$a1} = ReadFromList($a1) ;  # <--- Hash
of hash
   }
   
  # Function reads contents for file in this format and
returns a hash;
  # Filename -o "Values ....." 
  #
  sub ReadFromList {
   
    while <FILEFP> {
      $hash = $val...
   }
    return %hash;       <--- returning HASH
  }
   
  I got:
   
  perl didn't like it, 
   syntax error scr.pl line 151, near "$HashList{"
syntax error at scr.pl line 153, near "}"
Execution of scr.pl aborted due to compilation errors. 
   
  Question :
   
  1. Can I retun a hash ?, if not what's the alternative ?
   
  I tried to dump using Data:umper,
it printed something like 1/8 4/7 etc, 
   
  Thanks,Thama

 
---------------------------------
Any questions?  Get answers on any topic at Yahoo! Answers.
Try it now.

[Non-text portions of this message have been removed]



Unsubscribing info is here: h
ttp://help.yahoo.com/help/us/groups/groups-32.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://g
roups.yahoo.com/group/perl-beginner/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http
://groups.yahoo.com/group/perl-beginner/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:perl-beginner-digest@yahoogroups.com 
    mailto:perl-beginner-fullfeatured@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    perl-beginner-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.c
om/info/terms/
 

Re: Help with Hashes of hashes
country flaguser name
United States
2007-02-19 07:36:12
>>>>> "N" == N Thamma <nt557yahoo.com> writes:

N>   Hi all:
   
N>   I've few question regarding Hashes, hashes of
hashes, my understanding 
N>   of hashes is not quite clear.
   
N>   I got these error, sm1.list smoke.list sm0.list 1/8
5/8 1/8 G
   
N>   I did:
   
N>    $HashList = ();
N>     foreach my $a1 (list) {
N>       $HashList{$a1} = ReadFromList($a1) ;  # <---
Hash of hash
N>    }
   
N>   # Function reads contents for file in this format
and returns a hash;
N>   # Filename -o "Values ....." 
N>   #
N>   sub ReadFromList {
   
N>     while <FILEFP> {
N>       $hash = $val...
N>    }
N>     return %hash;       <--- returning HASH

That doesn't return a hash.  You can't return a hash.  You
can only
return a list.  And you can't have a "hash of
hashes", even though
the term is tossed around casually like that.  You can only
have a hash
of hashrefs.  See "perldoc perlreftut" (at your
commandline) for the
basics of references, so you can do this and many other
things with
complex data structures.

N>   }
   
N>   I got:
   
N>   perl didn't like it, 
N>    syntax error scr.pl line 151, near
"$HashList{" syntax error at scr.pl line 153, near
"}" Execution of scr.pl aborted due to compilation
errors. 
   
N>   Question :
   
N>   1. Can I retun a hash ?, if not what's the
alternative ?
   
N>   I tried to dump using Data:umper,
it printed something like 1/8 4/7 etc, 
   
N>   Thanks,Thama

 
N> ---------------------------------
N> Any questions?  Get answers on any topic at Yahoo!
Answers. Try it now.

N> [Non-text portions of this message have been removed]



N> Unsubscribing info is here: h
ttp://help.yahoo.com/help/us/groups/groups-32.html 
N> Yahoo! Groups Links






-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. -
+1 503 777 0095
<merlynstonehenge.com> <URL:http://www.ston
ehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy,
etc. etc.
See PerlTraining.Stonehenge.com for onsite and
open-enrollment Perl training!


Unsubscribing info is here: h
ttp://help.yahoo.com/help/us/groups/groups-32.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://g
roups.yahoo.com/group/perl-beginner/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http
://groups.yahoo.com/group/perl-beginner/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:perl-beginner-digest@yahoogroups.com 
    mailto:perl-beginner-fullfeatured@yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    perl-beginner-unsubscribe@yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.c
om/info/terms/
 

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )