CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Strange message, when I split line into array

 



digioleg54
User

Oct 24, 2017, 7:16 AM

Post #1 of 6 (1644 views)
Strange message, when I split line into array Can't Post

I have a program, which open file, read the line and split it

Code
while(<RFILE>) 
{
chomp;
my @line = split(':',$_);
my ($dir,$sizemax);
$dir = $line[0];
$sizemax = $line[1];


And it shows the error:

Code
Global symbol "$line" requires explicit package name at /export/applications/dte/perl/PSSpaceMonitor.pl line 54.



Chris Charley
User

Oct 24, 2017, 11:12 AM

Post #2 of 6 (1637 views)
Re: [digioleg54] Strange message, when I split line into array [In reply to] Can't Post

The code you posted doesn't produce the error. The error is on line 54.


BillKSmith
Veteran

Oct 24, 2017, 1:57 PM

Post #3 of 6 (1635 views)
Re: [digioleg54] Strange message, when I split line into array [In reply to] Can't Post

Your error is not in the code that you show. Perhaps you omitted a subscript on line 54.

This is probably not directly related to your problem, but could be a big help. You can save a lot of this code by using command line switches. Refer to the perl document perlrun for the -n, -p, -a, and -F switches. Perl can open the file, loop through it, split the records, and possibly print your results with no code at all.
Good Luck,
Bill


digioleg54
User

Oct 24, 2017, 2:50 PM

Post #4 of 6 (1629 views)
Re: [BillKSmith] Strange message, when I split line into array [In reply to] Can't Post

this is further code:

Code
open(my $fh, '>', $logfile) or die "Could not open '$logfile', no such file or directory\n"; 
print $fh, "Diskspace report from the server: '$host'\n";
open(RFILE,"<$paramfile") or die "Fail to open $paramfile";
while(<RFILE>)
{
chomp;
my @line = split(':',$_);
my ($dir,$sizemax);
$dir = $line[0];
$sizemax = $line[1];
my $disk_info = df($dir);
my $disk_percent;
if ( defined $disk_info)
{
if ( defined $disk_info)
{
print $fh, "$host $line currently at $disk_percent '%' tolerance is $sizemax '%'\n";
}
}
else
{
print $fh, "$datestamp - Space Monitor - failed to run df\n";
exit ($failure1);
}

line 54 is

Code
print $fh, "$host $line currently at $disk_percent '%' tolerance is $sizemax '%'\n";



digioleg54
User

Oct 24, 2017, 2:57 PM

Post #5 of 6 (1628 views)
Re: [digioleg54] Strange message, when I split line into array [In reply to] Can't Post


Code
 if ( $disk_percent > $sizemax) 
{
if ( $disk_percent > $sizemax)
{
my $message = MIME::Lite->new(
From => $mail_sender,
To => $mail_recipient,
Subject => "Attention - disk space on $#host exceded Treshold",
Data => "Please check fisk space on $host",
)
$message->send() or die "Cannot send email: $!\n";
}
else
{
print $fh, "Disk space on $host is OK: $disk_percent '%'\n";
}



Code
Scalar found where operator expected at ./PSSpaceMonitor.pl line 72, near ") 
$message"
(Missing operator before $message?)
Global symbol "@host" requires explicit package name at ./PSSpaceMonitor.pl line 69.
syntax error at ./PSSpaceMonitor.pl line 72, near ")
$message"
Global symbol "$message" requires explicit package name at ./PSSpaceMonitor.pl line 72.

/code]


BillKSmith
Veteran

Oct 24, 2017, 8:59 PM

Post #6 of 6 (1620 views)
Re: [digioleg54] Strange message, when I split line into array [In reply to] Can't Post

Your error messages refer to three errors.

Line 54: You probably mean $_ rather than $line

Line 69: You probably mean $host rather than $#host

Line 71: Missing semicolon
Good Luck,
Bill

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives