Hi Jeffrey.
>> There are several questions here, so I've answered in-line.
Rob, thanks a ton. that worked perfectly, as has the rest of the
processing of the larger hash. Thought i'd address the build portion
below, to see if i'm not utilizing PERL's strengths correctly. First PERL
i've written in 3+ years.
> 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 :)
thats actually what i mean, but said it backwards :)
> 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 building it in two for seperate for loops after reading two (LOG) files
into their own array.
The first one is built with (yes the TUX is hardcoded for now (i'll change
that)
foreach $line (@tux_data) {
$line =~ /^(\d+).+PSAPPSRV\.(\d+): ERROR: (.+)/;
$thetime =
substr($1,0,2).":".substr($1,2,2).":".substr($1,4,2);
$errors{'TUX'}{$2}{$thetime}{"msg".$i++} = substr($3,28,100);
}
The other log is built similarly, but uses PIDs($2) and dates($thetime)
from this array to filter out unwanted lines.
> 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.
I had done that in other pieces of my code, per perldsc or perllol,
but was not 100% sure of why, thanks for the explanation/demystification.
Seeing it in your own code, can make all the difference.
> 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.
and did, thanks for the visual.
> 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
I've been there, and keep re-re-re-re reading.
>>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
Thanks again.
Jeff
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>