Hi Nora, On Wednesday 12 May 2010, HACKER Nora wrote: > > while ( my($sdir,$tdir) = each %{$stp_dirs{'mvb'}}) { > > print("SourceDir: $sdir\t\tTargetDir: $tdir\n"); > > } > > Is that 'mvb' intentional? Also, I don't understand why to put '\%' in front > of the values from the master hash. Nevertheless, I tried the alterations as > suggested but the error remains: > > Can't use string ("%mvb_dirs") as a HASH ref while "strict refs" in use at > /opt/data/magna/wartung/tools/get_lieferung.pl line 145. > > Any other hints? > > Kind regards, > Nora
You put an escape character '\' (no quote) to point to another hash (what follows / symbol, to be more precise). It's known as (hash/array/code) references. my %stp_dirs = ( 'mvb' => \%mvb_dirs, 'pkv' => \%pkv_dirs, 'av' => \%av_dirs, 'be' => \%be_dirs, 'vvw' => \%vvw_dirs ); Here, value for the key 'mvb' in the hash %stp_dirs is a reference to another hash (%mvb_dirs) and that's what the beauty with references as you can build a *big* data structure. Thomas took 'mvb' just for an example and his code should work fine. I've modified it a bit to get what exactly you wanted: #!/usr/bin/perl use strict; use warnings; # AV my %av_dirs = ( "dir11" => "dir12", "dir13" => "dir14" ); # BE my %be_dirs=( "dir21" => "dir22", "dir23" => "dir24" ); # MVB my %mvb_dirs= ("dir31" => "dir32", "dir33" => "dir34" ); # PKV my %pkv_dirs=( "dir41" => "dir42", "dir43" => "dir44" ); # VVW my %vvw_dirs=( "dir51" => "dir52", "dir53" => "dir54" ); # Master-Hash my %stp_dirs = ( "mvb" => \%mvb_dirs, "pkv" => \%pkv_dirs, "av" => \%av_dirs, "be" => \%be_dirs, "vvw" => \%vvw_dirs ); foreach my $sub_hash (keys %stp_dirs) { print 'Contents from %' . "$sub_hash\n"; while (my ($sdir,$tdir) = each %{$stp_dirs{$sub_hash}}) { print ("SourceDir: $sdir\t\tTargetDir: $tdir\n"); } } -- Regards, Akhthar Parvez K http://Tips.SysAdminGUIDE.COM UNIX is basically a simple operating system, but you have to be a genius to understand the simplicity - Dennie Richie -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/