"Normandin, Jason" wrote:

> 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.
>
> 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.
>
> 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);

Best not to do this.  it is good that they are soped within the sub, but would
be even better if you declare them at the time they are used, or just prior to
their first use.


>
> # Set these local to each record
>                 my @lines = split/\n/;

                my %response_values;

>
>                 foreach my $line (@lines) {
>                         next if $line =~ m/REQUEST:/;
>                         my $timeSecs=$1 if $line =~ m/# Time (\d+)\.\d+
> seconds/;
>                         my $time=convertUtcToLocaltime($timeSecs);
>                         my $request_id=$1 if $line =~ m/\[REQUEST_ID\] (\d+)/;
>
>                         my $oid=$1 if $line =~ m/\[OBJECT_ID \] (.+)/;
>                         my $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"};
>         }
>
> .. SNIP ..

Just snip?  If this is getting long enough that you need to ship, then it is
getting too long to be in one sub.

Start at the top again.  What data do you have to work with, in what form?  What
kind of information do you want out of the process in what form?  Unfortunately
%response_hash is so genral as to say nothing about the meaning of the data in
context.

I have the feeling that, if you take a fresh look at the original problem with a
view to what you have to work with, and what end result you want to achieve, we
can help you find much more straightforward means to get there.

Joseph


-- 
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