Hi all, well I have the problem solved. The script uptime.pl is appended below in it entirety. The problem lies with the @db array (populated by 'more-ing' it). From this array I want $db$i+16 and $db$i+17. From the command line, the program works and I get what I want. But when uptime.pl is accessed from a CGI script, $db$i+16 and $db$i+17 are returning different data and so the script sets @dataset values to '0'. If I change the @db indicies to $db$i+18 and $db$i+19, then I get what I want. Looks like through CGI, I get some extra lines added to the more'd file. Anyway, to avoid this, I have incorporated uptime.pl into the main CGI script (don't know why I didn't do that in the first place!). Thank you all for your help. Regards, Stacy.
#!/usr/local/bin/perl use Date::Calc qw(Delta_DHMS); @receivers = qw(70CM 50CM H-OH MULTIBEAM GALILEO MULTIBAND METHANOL K-BAND); $dbfile = 'rxdb.dat'; #Get last modify time of DB file rxdb.dat $mtime = (stat("$dbfile"))[9]; ($fsec,$fmin,$fhour,$fmday,$fmonth,$fyear) = localtime($mtime); #Get current time ($nsec,$nmin,$nhour,$nmday,$nmonth,$nyear) = (localtime(time))[0..5]; #Get current time ($nsec,$nmin,$nhour,$nmday,$nmonth,$nyear) = (localtime(time))[0..5]; #Open DB and see if receivers are present and available foreach $package (@receivers) { open(DB, "$dbfile") or die "Can't open $dbfile!: $!"; $i = 0; while ($line = <DB>) { if ($line =~ m/package(\s+)= $package/i) { last } $i++; } close(DB); #$i lists the 'package =' line of the receiver we #want. To determine if it is present and available, #we require 'yes' to be found on lines $i+18 and #$i+19 @db = `more $dbfile`; if ($db[$i+18] =~ m/yes/ && $db[$i+19] =~ m/yes/) { #Selected receiver is present & available. #Calculate difference between file date and current date. ($days, $hours) = Delta_DHMS( $fyear+1900, $fmonth+1, $fmday, $fhour, $fmin, $fsec, $nyear+1900, $nmonth+1, $nmday, $nhour, $nmin, $nsec); $total = sprintf "%3.0f", ($days*24)+$hours; } else { $total = 0; } print "$package $total\n"; }

In reply to Re: Re: Re: backticks in CGI by Anonymous Monk
in thread trouble populating array with input from a file by maderman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.