Hi Jeffrey.
There are several questions here, so I've answered in-line.
Jeffrey N Dyke wrote:
>
> I had a simple array in mind, but as i got reacquainted with PERL, with the
> help of the list, i realized i was thinking to small. (that's always
> dangerous)
On the contrary, I think thinking BIG is always more dangerous :)
> Anyway. I have an array/hash(still learning the technical differences)
> similar to
>
> (pardon syntax irregularities, just trying to show structure)
>
> [PROCCESSID]
> {DATESTRING}
> {MSGNUMBER} = MSGTEXT
> {MSGNUMBER} = MSGTEXT
> {MSGNUMBER} = MSGTEXT
> {MSGNUMBER} = MSGTEXT
> {DATESTRING}
> {MSGNUMBER} = MSGTEXT
> {MSGNUMBER} = MSGTEXT
> {MSGNUMBER} = MSGTEXT
> {MSGNUMBER} = MSGTEXT
> Which I'm having no problems working with.
OK
> I wanted to add a SERVERNAME above PROCESSID so it becomes:
>
> [SERVERNAME]
> [PROCCESSID]
> {DATESTRING}
> {MSGNUMBER} = MSGTEXT
> {MSGNUMBER} = MSGTEXT
> {MSGNUMBER} = MSGTEXT
> {MSGNUMBER} = MSGTEXT
> [PROCCESSID]
> {DATESTRING}
> {MSGNUMBER} = MSGTEXT
> {MSGNUMBER} = MSGTEXT
> {MSGNUMBER} = MSGTEXT
> {MSGNUMBER} = MSGTEXT
> [SERVERNAME]
> [PROCCESSID]
> {DATESTRING}
> {MSGNUMBER} = MSGTEXT
> {MSGNUMBER} = MSGTEXT
> {MSGNUMBER} = MSGTEXT
> {MSGNUMBER} = MSGTEXT
>
>
> ...etc.
OK. I'm starting to worry about how you're going to /build/ this data
before you access it, but anyway..
> I'm confused about how to get the count, and keys for the second array.
> For the first i was simply using
> $cnt = keys %tux_errors;
> and
> @tux_keys = keys %tux_errors;
You need to know /why/ these work; and that means understanding 'context'.
Because you're assigning to a scalar,
$cnt = keys %tux_errors;
put 'keys' in /scalar/ context, so it returns the number of keys in the hash. But
@tux_keys = keys %tux_errors
is assigning to an array, so 'keys' returns a list of the hash's key values
instead. 'keys' does different things according to how it's called.
> when i added an additional key, i thought i could use the following (i was
> wrong, of course)
>
> $cnt = keys %tux_errors{SERVERNAME};
> and
> @tux_keys = keys %tux_errors{SERVERNAME};
>
> When i try the above, i get compilation errors....
A hash relates once scalar (the key) to another scalar (the corresponding value).
Because scalars begin with '$' in Perl, a single element of %tux_errors
is $tux_errors{SERVERNAME}. If you try
print $tux_errors{SERVERNAME}
then you'll get something like
HASH(0x177f0ac)
to show that this is a hash /reference/. Now don't get dizzy, because the
syntax turns out OK in the end. To dereference this scalar, use
%{$tux_errors{SERVERNAME}}
and you'll be back on familiar ground. So that
$cnt = keys %{$tux_errors{SERVERNAME}};
@tux_keys = keys %{$tux_errors{SERVERNAME}};
will work fine.
> I'm sure if found a very difficult way to ask a simple syntax
> question...but hey, this is [EMAIL PROTECTED]
No problem. Most of us would think that this is exactly the sort of question
we were here for. And I don't think anyone would call it a 'simple syntax
question'. Anyway, since you say
> I have an array/hash (still learning the technical differences)
I suggest you start by reading
perldoc perldata
and then graduate to
perldoc perllol
which talks about 'lists of lists'. Here you're dealing with hashes of
hashes, which is a step beyond that, so don't worry if you're not clear
yet on what's going on.
HTH,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>