(forwarded because forgot to „reply all”)

 

 

Von: HACKER Nora 
Gesendet: Montag, 21. Februar 2011 10:08
An: 'Parag Kalra'
Betreff: AW: Access single element of AOH

 

Hi,

 

Thanks for your reply, but it does not work. It produces an error and returns a 
wrong result.

 

oracle:/opt/data/magna/wartung/work/nora> ./test.pl PKV

Argument "PKV" isn't numeric in array element at ./test.pl line 72.

D:\mvbwiega\stp_be\LIEFERUNG

 

Kind regards, 
Nora 

 

 

Von: Parag Kalra [mailto:paragka...@gmail.com] 
Gesendet: Montag, 21. Februar 2011 10:00
An: HACKER Nora
Cc: beginners@perl.org
Betreff: Re: Access single element of AOH

 

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



 

Reply via email to