On Wed, 2008-04-09 at 00:21 +0200, Jenda Krynicky wrote:
> From:                 [EMAIL PROTECTED]
> > I want to store  a hash into an array: e.g.: like this
> > 
> > #!/usr/bin/perl -v
> > 
> > print "Content-type: text/html\n\n";
> > 
> > $h{'hello'}="hello";
> 
> This accesses the hash named %h.

I'm confused by this.  "Access" normally means read, not assign.  A more
accurate statement is, "This modifies the hash '%h'."

> 
> > $h{'by'}="by";
> > $a[0]=$h;
> 
> This accesses the scalar named $h.
> 
> Those two are NOT related.
> 
> You should start your scripts with
> 
>  use strict;
>  use warnings;
> 
> to be shielded from this kind of errors.

Ah, no.  This shields you from errors like typos.  It does not protect
you from lack of experience.  To gain experience, you have to
experience.

> 
> In this case if you want the $a[0] to contain a reference to the hash 
> %h, you have to do it like this:
> 
> $a[0] = \%h;

If you look at my previous post, you will see that this is not the only
way to interpret what the OP wants.

As always, when somebody post a message requesting help, they post just
a tiny bit of what is causing them problems.  And since we, those who
can answer they problems, only have a tiny glimpse of what they're
really talking about, it would be presumptuous of us to assume that they
could mean only one thing (or one methodology).

And no, I'm not picking on you specifically; they are many here who
answer questions and think they are right and "My way is THE ONLY WAY."

Take this problem for example.  The OP has assigned a reference to a
hash to the first element of an array.  So what does the rest of the
array look like?  Is it an array of hash references?  Or is it an array
of mixed types?  If there is only one of them, then why did he choose an
array rather than a scalar?

These questions cannot be answer without seeing more of the code.  When
one answers a question, one should not assume there is only one answer
to them or that one's answer is THE ONLY WAY.

And yes, people who answer questions are going to get more criticisms
than those who posts questions.


-- 
Just my 0.00000002 million dollars worth,
    Shawn

99% of you are just big dumb apes!

+------------\
| Shangri La   \
| 40,000 KM     /
+------------/


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to