Hi Raphael! Welcome to Perl.
On Thursday 25 Feb 2010 12:41:30 raphael() wrote: > use strict; > use warnings; It's good that you're using strict and warnings; > use Data::Dumper; > > my @links = > ({ > name1 => 'http://www.abc.com/data/a/000/name1.txt', > name2 => 'http://www.abc.com/data/a/000/name2.txt', > }); This is an array of a single hash-reference with two keys - "name1" and "name2". If you want to have name3 , name4 etc. the best thing would be to point a key (say "name" at an array reference. { name => [ 'http://www.abc.com/data/a/000/name1.txt', 'http://www.abc.com/data/a/000/name2.txt', ], }, > > for my $element ( @links ) { > for my $name ( sort keys %$element ) { > print "$name --> ${$element}{name1}\n"; > } > } What are you trying to do here - for each key $name out of $element you print its "name1" key. You probably want (untested): « print "$name --> $element->{$name}\n"; » > # print Dumper( \...@links ); > > __END__ > > what I have is an array of anonymous hash. > How do I access "name2" (second hash key) independently? Without using a > loop? $links[0]{'name2'} , $links[0]->{'name2'} , $links[0]{name2} etc. > > Ex. I have to mkdir using "name2" then how can I pass it directly to a > scalar? > > my $scalar = $links ... > > $scalar should be 'name2' > You probably mean that it should be the *value* of name2. For more information about references consult the links at: http://perl-begin.org/topics/references/ > I am extremely new to references :| Regards, Shlomi Fish -- ----------------------------------------------------------------- Shlomi Fish http://www.shlomifish.org/ http://www.shlomifish.org/humour/ways_to_do_it.html Deletionists delete Wikipedia articles that they consider lame. Chuck Norris deletes deletionists whom he considers lame. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/