On Mon, 2008-08-11 at 14:52 +0100, Dermot wrote:
> Hi,
>
> I am trying to make hash that refers to itself like this
>
> my %_HASH;
> %_HASH = (
> typeOne => {
> root => '/path/to/typeOne',
> logfile => $_HASH{typeOne}->{root}.'/logone.log';
> },
> typeTwo => {
> root => '/path/to/typeTwo',
> logfile => $_HASH{typeTwo}->{root}.'/logtwo.log';
> }
> );
>
>
> But nothing is initialised at this point so $_HASH{typeOne}->{root} is
> an uninitialized value when creating and logfile key.
>
> Is there a way around this?
> TiA,
> Dp.
>
Yes, you have to do it after-the-fact, so to speak.
#!/usr/bin/perl
use strict;
use warnings;
use utf8;
use Data::Dumper;
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent = 1;
$Data::Dumper::Maxdepth = 0;
my %_HASH;
%_HASH = (
typeOne => {
root => '/path/to/typeOne',
},
typeTwo => {
root => '/path/to/typeTwo',
}
);
$_HASH{typeOne}{logfile} = $_HASH{typeOne}{root} . '/logone.log';
$_HASH{typeTwo}{logfile} = $_HASH{typeTwo}{root} . '/logtwo.log';
print Dumper \%_HASH;
__END__
--
Just my 0.00000002 million dollars worth,
Shawn
"Where there's duct tape, there's hope."
"Perl is the duct tape of the Internet."
Hassan Schroeder, Sun's first webmaster
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/