print $object->[$stp]->{'lieferung'},"\n"; ~Parag
On Mon, Feb 21, 2011 at 12:46 AM, HACKER Nora <nora.hac...@stgkk.at> wrote: > Hello, > > I want to get the value of a key of a Hash that is part of an Array of > Hashes, whereas the correct hash to work with is being determined by the > value of another key which is passed as an argument when calling the > script, but haven't yet figured out how. This is my AOH: > > #!/usr/bin/perl > use strict; > use warnings; > > my $stp = $ARGV[0]; > > my $object = [ > { 'stp' => 'AV' > , 'lieferung' => 'D:\mvbwiega\stp_be\LIEFERUNG' > , 'hvb' => 'H:\stp-be\LIEFERUNG' > , 'tux' => 'Releaseschein-2004\Server\Tuxedo' > , 'ubbconfig' => 'beispiel_ubbconfig.txt' > }, > { 'stp' => 'BE' > , 'lieferung' => 'D:\mvbwiega\stp_be\LIEFERUNG' > , 'hvb' => 'H:\stp-be\LIEFERUNG' > , 'tux' => 'Releaseschein-2004\Server\Tuxedo' > , 'ubbconfig' => 'beispiel_ubbconfig.txt' > }, > { 'stp' => 'PKV' > , 'lieferung' => 'D:\mvbwiega\stp_pkv\Releases' > , 'hvb' => 'H:\stp-pkv\Releases' > , 'tux' => 'RS_2004\Tuxedo' > , 'ubbconfig' => 'beispiel_ubbconfig.txt' > } > ]; > > And these were (some of) my failing attempts: > > print "$object{'lieferung'}{$stp}\n"; > ==> Global symbol "%object" requires explicit package name at > ./test.pl line 71. > ==> Execution of ./test.pl aborted due to compilation errors. > > print "$object->[$stp]{'lieferung'}\n"; > ==> Argument "AV" isn't numeric in array element at ./test.pl line > 72. > ==> D:\mvbwiega\stp_be\LIEFERUNG # always result of first hash, > no matter which parameter given > > print "$object->{$stp}{'lieferung'}\n"; > ==> Pseudo-hashes are deprecated at ./test.pl line 72. > ==> No such pseudo-hash field "AV" at ./test.pl line 72. > > Somehow I only seem to find examples/explanations with 'foreach'es, > looping over the whole AOH ... Is it even possible what I want to > realize? Or do I have to change my data structure to a Hash of Hashes, > would that be better/easier? > > Thanks in advance, > Nora > > > >