Please bottom post....

> Hi
> 
> I am scoping the  %response_values hash at the top. I dont understand
why it
> would need to be temporary as I am referancing that hash outside of
the loop
> when I iterate through.
> 

It doesn't have to be temporary, but you overstep the help that 'strict'
would have given you in finding at least one of your problems.  By
declaring it outside of the scope necessary, it is available later on in
your block when it likely doesn't need to be.

> I changed the syntax to referance the oids rather then the hash name and I
> get the following error:
> 
> Can't use string ("%response_values") as a HASH ref while "strict refs" in
> use at H:\nhsParseSnmpLog.pl line 72, <SNMP_L
> OG> chunk 78.
>

Exactly.  That is what you want to see, because this is telling you that
you are trying to use a string as a hash reference, which should tell
you that you don't have the structure you want. In other words, this
just told you that you shouldn't have quoted %response_values to begin with.
 
> Here is what I have:
> 
> .. SNIP.. 
> use strict;
> my (%request_hash,%response_hash);
> 
> .. SNIP...
> elsif ( m/RESPONSE:/ ) {
>               my
>
($time,$timeSecs,$request_id,$ip_address,%response_values,$oid,$oid_value);
> # Set these local to each record

Which is exactly what you haven't done, aka they are local to the
enclosing 'if' block, not the foreach. If you scope them inside of the
foreach, which should be sufficient from what you have shown us, then
'strict' will also complain later about using %response_values.

>               my @lines = split/\n/;
>               foreach my $line (@lines) {
>                       next if $line =~ m/REQUEST:/;
>                       $timeSecs=$1 if $line =~ m/# Time (\d+)\.\d+
> seconds/;
>                       $time=convertUtcToLocaltime($timeSecs);
>                       $request_id=$1 if $line =~ m/\[REQUEST_ID\] (\d+)/;
>                       $oid=$1 if $line =~ m/\[OBJECT_ID \] (.+)/;
>                       $oid_value =$1 if $line =~ m/[\[COUNTER   \]|\[GAUGE
> \]|\[INT       \]|\[TICKS     \]] (.+)/;
>                       $response_values{$oid}=$oid_value;
>               }
>               push @{$response_hash{$request_id}},{time => "$time",oids =>
> "%response_values"};

Right here the values you push can go out of scope because they will
still exist referenced inside of 'response_hash'.

>       }       
> 
> .. SNIP ..
> 
> foreach my $request (sort keys %response_hash) {
>       #print "Response to request_id $request\n";
>       foreach my $record(@{$response_hash{$request}}) {
>               #print "Time : $record->{time}\n";
>               foreach my $response (keys %{ $record->{'oids'} }) {
>               #foreach my $response ($record->{keys %response_values} )
>               
>                       print "Response to oid : $response =
> $record->{'oids'}{$response}\n";
>               }
>       }
>       #print "============================\n";
> }
> 
> I am thoroughly confused at this point :(
> 

That's fine, references are generally pretty difficult to "get" but once
you have gotten them you will have plenty of doors opened to you.  You
may want to read, if you haven't already:

perldoc perldsc
perldoc perllol
perldoc perlreftut
perldoc perlref

Come back when/if you have more questions,

http://danconia.org

[snip old posts]

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


Reply via email to