Access single element of AOH

Access single element of AOH

am 21.02.2011 09:46:43 von HACKER Nora

------_=_NextPart_001_01CBD1A3.DD38FEF9
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

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=20
use strict;
use warnings;

my $stp =3D $ARGV[0];

my $object =3D [
{ 'stp' =3D> 'AV'
, 'lieferung' =3D> 'D:\mvbwiega\stp_be\LIEFERUNG'
, 'hvb' =3D> 'H:\stp-be\LIEFERUNG'
, 'tux' =3D> 'Releaseschein-2004\Server\Tuxedo'
, 'ubbconfig' =3D> 'beispiel_ubbconfig.txt'
},
{ 'stp' =3D> 'BE'
, 'lieferung' =3D> 'D:\mvbwiega\stp_be\LIEFERUNG'
, 'hvb' =3D> 'H:\stp-be\LIEFERUNG'
, 'tux' =3D> 'Releaseschein-2004\Server\Tuxedo'
, 'ubbconfig' =3D> 'beispiel_ubbconfig.txt'
},
{ 'stp' =3D> 'PKV'
, 'lieferung' =3D> 'D:\mvbwiega\stp_pkv\Releases'
, 'hvb' =3D> 'H:\stp-pkv\Releases'
, 'tux' =3D> 'RS_2004\Tuxedo'
, 'ubbconfig' =3D> '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,=20
Nora=20




------_=_NextPart_001_01CBD1A3.DD38FEF9--

RE: Access single element of AOH

am 21.02.2011 09:54:14 von sachin.malesha

I was able to print with the below line. Be sure that you are passing a val=
ue 0-2 as an argument to your script since you have only three elements in =
your array.

print "$object->[$stp]{'stp'}\n";

Regards,
Sachin

-----Original Message-----
From: HACKER Nora [mailto:nora.hacker@stgkk.at]=20
Sent: Monday, February 21, 2011 2:17 PM
To: beginners@perl.org
Subject: Access single element of AOH

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=20
use strict;
use warnings;

my $stp =3D $ARGV[0];

my $object =3D [
{ 'stp' =3D> 'AV'
, 'lieferung' =3D> 'D:\mvbwiega\stp_be\LIEFERUNG'
, 'hvb' =3D> 'H:\stp-be\LIEFERUNG'
, 'tux' =3D> 'Releaseschein-2004\Server\Tuxedo'
, 'ubbconfig' =3D> 'beispiel_ubbconfig.txt'
},
{ 'stp' =3D> 'BE'
, 'lieferung' =3D> 'D:\mvbwiega\stp_be\LIEFERUNG'
, 'hvb' =3D> 'H:\stp-be\LIEFERUNG'
, 'tux' =3D> 'Releaseschein-2004\Server\Tuxedo'
, 'ubbconfig' =3D> 'beispiel_ubbconfig.txt'
},
{ 'stp' =3D> 'PKV'
, 'lieferung' =3D> 'D:\mvbwiega\stp_pkv\Releases'
, 'hvb' =3D> 'H:\stp-pkv\Releases'
, 'tux' =3D> 'RS_2004\Tuxedo'
, 'ubbconfig' =3D> '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,=20
Nora=20




--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: Access single element of AOH

am 21.02.2011 09:59:47 von Parag Kalra

--001636c5a4e51e52e5049cc71740
Content-Type: text/plain; charset=UTF-8

print $object->[$stp]->{'lieferung'},"\n";

~Parag



On Mon, Feb 21, 2011 at 12:46 AM, HACKER Nora 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
>
>
>
>

--001636c5a4e51e52e5049cc71740--

AW: Access single element of AOH

am 21.02.2011 10:09:08 von HACKER Nora

Hi,

Thanks for your reply. The argument I want to pass on is not numeric but =
a string - is that possible?

Kind regards,=20
Nora=20


> -----Ursprüngliche Nachricht-----
> Von: Malesha, Sachin [mailto:sachin.malesha@siemens.com]
> Gesendet: Montag, 21. Februar 2011 09:54
> An: HACKER Nora
> Cc: beginners@perl.org
> Betreff: RE: Access single element of AOH
>=20
> I was able to print with the below line. Be sure that you are passing =
a value 0-
> 2 as an argument to your script since you have only three elements in =
your
> array.
>=20
> print "$object->[$stp]{'stp'}\n";
>=20
> Regards,
> Sachin
>=20
> -----Original Message-----
> From: HACKER Nora [mailto:nora.hacker@stgkk.at]
> Sent: Monday, February 21, 2011 2:17 PM
> To: beginners@perl.org
> Subject: Access single element of AOH
>=20
> Hello,
>=20
> 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:
>=20
> #!/usr/bin/perl
> use strict;
> use warnings;
>=20
> my $stp =3D $ARGV[0];
>=20
> my $object =3D [
> { 'stp' =3D> 'AV'
> , 'lieferung' =3D> 'D:\mvbwiega\stp_be\LIEFERUNG'
> , 'hvb' =3D> 'H:\stp-be\LIEFERUNG'
> , 'tux' =3D> =
'Releaseschein-2004\Server\Tuxedo'
> , 'ubbconfig' =3D> 'beispiel_ubbconfig.txt'
> },
> { 'stp' =3D> 'BE'
> , 'lieferung' =3D> 'D:\mvbwiega\stp_be\LIEFERUNG'
> , 'hvb' =3D> 'H:\stp-be\LIEFERUNG'
> , 'tux' =3D> =
'Releaseschein-2004\Server\Tuxedo'
> , 'ubbconfig' =3D> 'beispiel_ubbconfig.txt'
> },
> { 'stp' =3D> 'PKV'
> , 'lieferung' =3D> 'D:\mvbwiega\stp_pkv\Releases'
> , 'hvb' =3D> 'H:\stp-pkv\Releases'
> , 'tux' =3D> 'RS_2004\Tuxedo'
> , 'ubbconfig' =3D> 'beispiel_ubbconfig.txt'
> }
> ];
>=20
> And these were (some of) my failing attempts:
>=20
> 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.
>=20
> 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
>=20
> 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.
>=20
> 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?
>=20
> Thanks in advance,
> Nora
>=20
>=20
>=20


--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

WG: Access single element of AOH

am 21.02.2011 10:09:42 von HACKER Nora

------_=_NextPart_001_01CBD1A7.135A57FA
Content-Type: text/plain;
charset="utf-8"
Content-Transfer-Encoding: base64

KGZvcndhcmRlZCBiZWNhdXNlIGZvcmdvd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VudCAi QVYiIGlzbid0IG51
bWVyaWMgaW4gYXJyYXkgZWxlbWVudCBhdCAuL3Rlc3QucGwgbGluZQ0KNzIu DQo9PT4gICAgIEQ6
XG12YndpZWdhXHN0cF9iZVxMSUVGRVJVTkcgICAgIyBhbHdheXMgcmVzdWx0 IG9mIGZpcnN0IGhh
c2gsDQpubyBtYXR0ZXIgd2hpY2ggcGFyYW1ldGVyIGdpdmVuDQoNCnByaW50 ICIkb2JqZWN0LT57
JHN0cH17J2xpZWZlcnVuZyd9XG4iOw0KPT0+ICAgICBQc2V1ZG8taGFzaGVz IGFyZSBkZXByZWNh
dGVkIGF0IC4vdGVzdC5wbCBsaW5lIDcyLg0KPT0+ICAgICBObyBzdWNoIHBz ZXVkby1oYXNoIGZp
ZWxkICJBViIgYXQgLi90ZXN0LnBsIGxpbmUgNzIuDQoNClNvbWVob3cgSSBv bmx5IHNlZW0gdG8g
ZmluZCBleGFtcGxlcy9leHBsYW5hdGlvbnMgd2l0aCAnZm9yZWFjaCdlcywN Cmxvb3Bpbmcgb3Zl
ciB0aGUgd2hvbGUgQU9IIC4uLiBJcyBpdCBldmVuIHBvc3NpYmxlIHdoYXQg SSB3YW50IHRvDQpy
ZWFsaXplPyBPciBkbyBJIGhhdmUgdG8gY2hhbmdlIG15IGRhdGEgc3RydWN0 dXJlIHRvIGEgSGFz
aCBvZiBIYXNoZXMsDQp3b3VsZCB0aGF0IGJlIGJldHRlci9lYXNpZXI/DQoN ClRoYW5rcyBpbiBh
ZHZhbmNlLA0KTm9yYQ0KDQoNCg0KIA0KDQo=

------_=_NextPart_001_01CBD1A7.135A57FA--

RE: Access single element of AOH

am 21.02.2011 10:16:29 von sachin.malesha

You cannot pass a string as an argument since you have an AOH, i.e. an arra=
y containing hash references. Arrays are indexed starting from 0.

If you want to pass a string, then you will need to construct HOH i.e Hash =
of Hash and then print the object as
print "$object->{$stp}->{'stp'}\n";

Hope this clarifies.

Regards,
Sachin
-----Original Message-----
From: HACKER Nora [mailto:nora.hacker@stgkk.at]=20
Sent: Monday, February 21, 2011 2:39 PM
To: Malesha, Sachin; beginners@perl.org
Subject: AW: Access single element of AOH

Hi,

Thanks for your reply. The argument I want to pass on is not numeric but a =
string - is that possible?

Kind regards,=20
Nora=20


> -----Ursprüngliche Nachricht-----
> Von: Malesha, Sachin [mailto:sachin.malesha@siemens.com]
> Gesendet: Montag, 21. Februar 2011 09:54
> An: HACKER Nora
> Cc: beginners@perl.org
> Betreff: RE: Access single element of AOH
>=20
> I was able to print with the below line. Be sure that you are passing a v=
alue 0-
> 2 as an argument to your script since you have only three elements in you=
r
> array.
>=20
> print "$object->[$stp]{'stp'}\n";
>=20
> Regards,
> Sachin
>=20
> -----Original Message-----
> From: HACKER Nora [mailto:nora.hacker@stgkk.at]
> Sent: Monday, February 21, 2011 2:17 PM
> To: beginners@perl.org
> Subject: Access single element of AOH
>=20
> Hello,
>=20
> I want to get the value of a key of a Hash that is part of an Array of Ha=
shes,
> 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:
>=20
> #!/usr/bin/perl
> use strict;
> use warnings;
>=20
> my $stp =3D $ARGV[0];
>=20
> my $object =3D [
> { 'stp' =3D> 'AV'
> , 'lieferung' =3D> 'D:\mvbwiega\stp_be\LIEFERUNG'
> , 'hvb' =3D> 'H:\stp-be\LIEFERUNG'
> , 'tux' =3D> 'Releaseschein-2004\Server\Tuxedo'
> , 'ubbconfig' =3D> 'beispiel_ubbconfig.txt'
> },
> { 'stp' =3D> 'BE'
> , 'lieferung' =3D> 'D:\mvbwiega\stp_be\LIEFERUNG'
> , 'hvb' =3D> 'H:\stp-be\LIEFERUNG'
> , 'tux' =3D> 'Releaseschein-2004\Server\Tuxedo'
> , 'ubbconfig' =3D> 'beispiel_ubbconfig.txt'
> },
> { 'stp' =3D> 'PKV'
> , 'lieferung' =3D> 'D:\mvbwiega\stp_pkv\Releases'
> , 'hvb' =3D> 'H:\stp-pkv\Releases'
> , 'tux' =3D> 'RS_2004\Tuxedo'
> , 'ubbconfig' =3D> 'beispiel_ubbconfig.txt'
> }
> ];
>=20
> And these were (some of) my failing attempts:
>=20
> 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.
>=20
> 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
>=20
> 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.
>=20
> 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?
>=20
> Thanks in advance,
> Nora
>=20
>=20
>=20


--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

AW: Access single element of AOH

am 21.02.2011 10:33:03 von HACKER Nora

Perfectly clear, thanks, works already :-)

Kind regards,=20
Nora=20



> -----Ursprüngliche Nachricht-----
> Von: Malesha, Sachin [mailto:sachin.malesha@siemens.com]
> Gesendet: Montag, 21. Februar 2011 10:16
> An: HACKER Nora; beginners@perl.org
> Betreff: RE: Access single element of AOH
>=20
> You cannot pass a string as an argument since you have an AOH, i.e. an =
array
> containing hash references. Arrays are indexed starting from 0.
>=20
> If you want to pass a string, then you will need to construct HOH i.e =
Hash of
> Hash and then print the object as print "$object->{$stp}->{'stp'}\n";
>=20
> Hope this clarifies.
>=20
> Regards,
> Sachin
> -----Original Message-----
> From: HACKER Nora [mailto:nora.hacker@stgkk.at]
> Sent: Monday, February 21, 2011 2:39 PM
> To: Malesha, Sachin; beginners@perl.org
> Subject: AW: Access single element of AOH
>=20
> Hi,
>=20
> Thanks for your reply. The argument I want to pass on is not numeric =
but a
> string - is that possible?
>=20
> Kind regards,
> Nora
>=20
>=20
> > -----Ursprüngliche Nachricht-----
> > Von: Malesha, Sachin [mailto:sachin.malesha@siemens.com]
> > Gesendet: Montag, 21. Februar 2011 09:54
> > An: HACKER Nora
> > Cc: beginners@perl.org
> > Betreff: RE: Access single element of AOH
> >
> > I was able to print with the below line. Be sure that you are =
passing a value
> 0-
> > 2 as an argument to your script since you have only three elements =
in your
> > array.
> >
> > print "$object->[$stp]{'stp'}\n";
> >
> > Regards,
> > Sachin
> >
> > -----Original Message-----
> > From: HACKER Nora [mailto:nora.hacker@stgkk.at]
> > Sent: Monday, February 21, 2011 2:17 PM
> > To: beginners@perl.org
> > Subject: Access single element of AOH
> >
> > 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 =3D $ARGV[0];
> >
> > my $object =3D [
> > { 'stp' =3D> 'AV'
> > , 'lieferung' =3D> 'D:\mvbwiega\stp_be\LIEFERUNG'
> > , 'hvb' =3D> 'H:\stp-be\LIEFERUNG'
> > , 'tux' =3D> =
'Releaseschein-2004\Server\Tuxedo'
> > , 'ubbconfig' =3D> 'beispiel_ubbconfig.txt'
> > },
> > { 'stp' =3D> 'BE'
> > , 'lieferung' =3D> 'D:\mvbwiega\stp_be\LIEFERUNG'
> > , 'hvb' =3D> 'H:\stp-be\LIEFERUNG'
> > , 'tux' =3D> =
'Releaseschein-2004\Server\Tuxedo'
> > , 'ubbconfig' =3D> 'beispiel_ubbconfig.txt'
> > },
> > { 'stp' =3D> 'PKV'
> > , 'lieferung' =3D> 'D:\mvbwiega\stp_pkv\Releases'
> > , 'hvb' =3D> 'H:\stp-pkv\Releases'
> > , 'tux' =3D> 'RS_2004\Tuxedo'
> > , 'ubbconfig' =3D> '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
> >
> >
> >
>=20


--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/