English 中文(简体)
How do I find the compilation error in this Perl statement?
原标题:

I have this code:

my $orig_file_size = -s $file ;

Is throwing an error:

syntax error at ftp_4 line 33, near "$orig_file_size)"
Execution of ftp_4 aborted due to compilation errors.

Here is some more code:

 my $host = hpp411 ;
 my $user = sonalg ;
 my $pw   = Unix11! ;

 my $file = ftp_example.p_1 ;
 my $path = /enbusers3.p411/vdx/af/sonalg/oldproj ;
 my $orig_file_size = -s $file;

 my $ftp = Net::FTP->new($host, Debug => 1)
 or die "Could not connect to  $host : $@";
最佳回答

Check your source

According to the error message, you have a closing bracket after the variable like this:

my $orig_file_size) = -s $file ;

If so, just remove it.

问题回答

The nothing wrong with that statement. The problem is probably earlier in the file.

It s tempting to say the problem is with the previous line but given the difficulty in parsing Perl the problem could be anywhere higher up the file. The first things to look for are strings which haven t been closed properly and lines missing their terminating semicolon.

Your error message (but not your code as shown) suggests you have a stray parenthesis after $orig_file_size.

Do you actually have:

my $orig_file_size) = -s $file ;

If so, try:

my $orig_file_size = -s $file ;

or

my($orig_file_size) = -s $file ;




相关问题
Why does my chdir to a filehandle not work in Perl?

When I try a "chdir" with a filehandle as argument, "chdir" returns 0 and a pwd returns still the same directory. Should that be so? I tried this, because in the documentation to chdir I found: "...

How do I use GetOptions to get the default argument?

I ve read the doc for GetOptions but I can t seem to find what I need... (maybe I am blind) What I want to do is to parse command line like this myperlscript.pl -mode [sth] [inputfile] I can use ...

Object-Oriented Perl constructor syntax and named parameters

I m a little confused about what is going on in Perl constructors. I found these two examples perldoc perlbot. package Foo; #In Perl, the constructor is just a subroutine called new. sub new { #I ...

Where can I find object-oriented Perl tutorials? [closed]

A Google search yields a number of results - but which ones are the best? The Perl site appears to contain two - perlboot and perltoot. I m reading these now, but what else is out there? Note: I ve ...

热门标签