[EMAIL PROTECTED] wrote:
> 
> #========================================================
> #!/usr/bin/perl
> use strict;
> #       IF I do not assign {}, nothing is printed
> my($hash) = {};
> &getArray($hash);
> 
> #       IF I do not engulf array-ref within {} as @{$hash->{array}}
> #       an error message NOT AN ARRAY reference is generated
> map {print "$_\n"} @{$hash->{array}};
> 
> sub getArray{
>         my($hash)       = shift;
>         $hash->{array}  = [1,2,3,4,5];
> }
> #========================================================
> 
> a) When a hash reference is essentially a SCALAR, why should I explicitly
> denote the hash variable as
>         my($hash)       = {};
> and not simply
>         my($hash);
> 

my $hash; is equavalent to my $hash = undef;
You can't pass an undef value to a subroutine which will use and want to
change it.

Instead my $hash = {}; creates a pointer to an empty hash.
This hash, of course, you can change in a subroutine.

> b) I thought that an array can be dereferenced simply by @$arrayRef
> notation. However, in the code sample I have sent, I am forced to use
> @{$arrayRef} notation. Why do I need the Chain-braces?
> 

I'm not sure about the exact reasons.
But it becomes very reasonable if you look at 

%$hash->{1}->{2}->{3}.
Here perl just can't know what you'd mean:
%{$hash}->{1}->{2}->{3} or
%{$hash->{1}}->{2}->{3} or
%{$hash->{1}->{2}->{3}}

I've never thought about, because in my opinion it's better to read with
the brackets.
@$hash->{array} would I read as make a list of the reference th $hash
and then do something with.

But you mean make a list of something in bracket :-)


Greetings,
Andrea

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to