On Mon, Aug 11, 2008 at 11:40 AM, Rob Dixon <[EMAIL PROTECTED]> wrote: > yitzle wrote: >> On Mon, Aug 11, 2008 at 9:52 AM, Dermot <[EMAIL PROTECTED]> wrote: >>> >>> 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? >> >> Not the way you are doing it. This would work, though: >> >> 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'; >> } >> ); > > - You are a frequent enough poster to know that bottom-posting is the > preferred > style on this group > > - What you have posted is identical to the code that the OP said didn't work > > - Your code won't even compile as it has semicolons where there should be > commas, so you cannot possibly have tested it > > Rob >
Sorry for the top-post. I did write working code and tested it with Data::Dumper but my copy/paste must have somehow screwed up. The code I have in my t.pl file is the same as Mr Shawn posted: my %_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'; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/