cjacksonjr has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to let the user put in the times they are trying to get Db info for and I keep getting the error message below. I don't know how to fix. User Input is in sub routine GetAlarmInfo. Error Message: Can't use string ("10") as a symbol ref while "strict refs" in use at quenchNotifLogTable1.pl line 61.
#! /usr/local/bin/perl -w # A perl program to analyze the notifAlarmLog Table and quench times use FileHandle; use IPC::Open2; use Symbol; # use Tk; use Sybase::CTlib; use Time::Local; use strict; my(%dispatch) = (); my(%systemNames); systemNames(); # fill in the hash of PS system names my $dbAlarms = new Sybase::CTlib 'harmless','harmless','OPSYB1','notif +LogTable'; $dbAlarms->ct_sql("use TomTest"); %dispatch = (help =>\&Help, info =>\&GetAlarmInfo); my $numberOfArgs = @ARGV; if($numberOfArgs == 0) { Help(); exit 1; } my($what) = shift(@ARGV); my($whatLower) = $what; $whatLower =~ tr/[A-Z]/[a-z]/; if ($what eq undef) { Help(); exit 1; } if(exists($dispatch{$whatLower})) { &{$dispatch{$whatLower}}(@ARGV); exit 0; } Help(); exit; sub GetAlarmInfo { use strict; #Given a time in (X) seconds find the number of Alarms occurring for + each PS #Given a time in seconds find the number of Alarms occurring w/in (Y +) seconds AFTER a Quench Event for each PS #Both sorted by number of occurrences my $sql = "SELECT distinct name FROM notifAlarmLog"; my $NameCount = 0; # count number of PS my(@rows,$row); @rows = $dbAlarms->ct_sql($sql); foreach $row (@rows) { $NameCount++; # see how many power supplies there are $sql = "SELECT * FROM notifAlarmLog WHERE name like '$row->[0]'"; my($supply,@supplies); @supplies = $dbAlarms->ct_sql($sql); # count all alarms for each PS my $count = @supplies; # count how many alarms occur within user specified time given in +seconds my $AlarmCount = 0; # count how many alarms occur w/in (X) seconds after a QUENCH EVEN +T (user specified in seconds)? my $QuenchCount = 0; # work done here!!! my $AlarmFilter = $_[0]; if ($AlarmFilter >= 0) { my $QuenchFilter = $_[1]; foreach $supply (@supplies) { $AlarmCount++ if(($supply->[4] - $supply->[3]) <= <$AlarmFilter>) +; #Line 61 my $dbEvents = new Sybase::CTlib 'harmless','harmless','OPSYB1','f +illeventsT'; $dbEvents->ct_sql("use rhic_au_fy01_fill"); my $sql = "SELECT * FROM fillEventsT WHERE rhicTime like 'Oct%' and (event like 'ev-bque +nch' or event like 'ev-yquench')"; my(@fills,$fill); @fills = $dbEvents->ct_sql($sql); foreach $fill (@fills) { # how many alarms occur w/in 10 seconds a +fter a QUENCH EVENT? $QuenchCount++ if(($supply->[3] - $fill->[0]) <= <$QuenchFilter> +) and (($supply->[3] - $fill->[0]) > 0); } } } #filter out alarms that occur w/in 10 seconds after a Quench EVENT my $diff = $count - $QuenchCount; my ($f1,$adoName,$f3) = split(":",$row->[0]); my $SiteWideName = $main::systemNames{$adoName} . ":$f3"; # print ":$adoName: :$SiteWideName: \n"; print "$SiteWideName, $AlarmCount, $count, $QuenchCount, $diff \n" +; } print "There were $NameCount Power Supplies that alarmed in Oct. 200 +1. \n"; } sub systemNames { # fill in the systenName hash use strict; my $dbAdo = new Sybase::CTlib 'harmless','harmless','OPSYB1','notifL +ogTable'; $dbAdo->ct_sql("use serverAdo"); my $sql = "SELECT name,systemName from adoInst where name like 'psWa +tch%'"; my(@rows,$row); @rows = $dbAdo->ct_sql($sql); foreach $row (@rows) { $main::systemNames{$row->[0]} = $row->[1]; # print "<$row->[0]> <$row->[1]> \n"; } } sub Help { #display help for this tool print "Alarm and Quench Tool- A program for user to input times in +seconds to: \n 1. Exclude Alarms that last LESS THAN <X> seconds. \n 2. Exclude Alarms that occur within <Y> seconds AFTER a Quench. \n Both are sorted by number of occurrences \n List of Commands: <Info> Given the times in seconds, find the number of occurrencs + for Alarms and for Alarms after a Quench. Enter in form: XX YY \n"; }

Replies are listed 'Best First'.
Re: help with user inputs
by tommyw (Hermit) on Aug 14, 2002 at 14:16 UTC

    Whoa! That's deeply unpleasant to try to read. A few more blank lines, deeper indentation, and, most importantly, an attempt to strip the problem down to the bare essentials, would help. The last might well lead you to the problem...

    Ok, line 61:

    $AlarmCount++ if(($supply->[4] - $supply->[3]) <= <$AlarmFilter>); #L +ine 61
    $AlarmFilter is, of course, a filehandle? It's set by $my $AlarmFilter = $_[0];, so where does that value come from? Oh, &{$dispatch{$whatLower}}(@ARGV);

    So, no, it's the first command line parameter. Guess that'll be a problem then.

    --
    Tommy
    Too stupid to live.
    Too stubborn to die.

Re: help with user inputs
by suaveant (Parson) on Aug 14, 2002 at 14:16 UTC
    $AlarmFilter seems to be an integer, why are you putting it in <>? take away those brackets and it should work. That syntax is for reading data from a handle or globbing a directory....

    Update Rereading your first paragraph, and especially your title, I realize you are trying to get user input... to do so you probably want

    my $input = <>;
    or something similar. This will return a line of user input, complete with a newline at the end... but what is the value you are trying to pass in? A default? A prompt?

                    - Ant
                    - Some of my best work - (1 2 3)

Re: help with user inputs
by fruiture (Curate) on Aug 14, 2002 at 14:19 UTC

    Well, first of all let me be pedantic:

    &gt; my($what) = shift(@ARGV); &gt; my($whatLower) = $what; &gt; $whatLower =~ tr/[A-Z]/[a-z]/; $whatLower = lc($what); &gt; if ($what eq undef) { well, if $what is undef you already have 2 warnings before you detect it. On with tr/// (or lc()) and the next ri +ght here. rather write: my $what = shift @ARGV; unless( defined $what and exists $dispatch{lc($what)} ){ Help(); exit defined($what) ? 0 : 1 } $dispatch{$whatLower}->(@ARGV); exit 0;

    Line 61 may be that one:

    $AlarmCount++ if(($supply->[4] - $supply->[3]) <= <$AlarmFilter>)

    What should the user enter as second argument that you can do a readline() operation on it (since $AlarmFilter is $_[0] and $_[0] is $ARGV[1])? It must be a file handle therefor and it surely isn't. Maybe you just want to skip the <> Operator?!

    btw.: it's exactly the same with $Quenchfilter a few lines later...

    update, [ and ] ...

    --
    http://fruiture.de