in reply to Re: convert files unix2dos using perl script
in thread convert files unix2dos using perl script

thanks,but I get ERROR:
"Bareword "TR" not allowed while "strict subs" in use at test.cgi line 28.
Execution of test.cgi aborted due to compilation errors."

on this line:
$ftp->put(TR,$File); # must give remote name.

any idea what could be wrong ?
greetings
cc
  • Comment on Re^2: convert files unix2dos using perl script

Replies are listed 'Best First'.
Re^3: convert files unix2dos using perl script
by bart (Canon) on Jun 21, 2004 at 11:00 UTC
    Perl doesn't know you mean to pass a filehandle to that method, so it passes the bareword "TR" instead. You could try to pass \*TR instead.
    $ftp->put(\*TR,$File);
    Better yet, for a recent enough perl, use a lexical variable to hold the filehandle. It'll look cleaner.
    open my($tr), "unix2dos $File |" or die $!; # Or FQ path $ftp->binary(); # We translate, not the server. $ftp->put($tr,$File); # must give remote name.

    But, IMO, it's overkill to call an external program to handle this little task. Perl will convert line endings for you, when reading from a handle in text mode. Internally, on Windows, text data is Unix text data. So, all you need to do is open the file.

    open my($fh), $File or die $!; $ftp->binary(); # We translate, not the server. $ftp->put($fh,$File); # must give remote name.

    p.s. I really wonder why just transferring data in Ascii mode won't work. Are you sure you don't accidently have double carriage returns in your files?

      If I try
      $ftp->put(\*TR,$File);
      220 ttn208 Microsoft FTP Service (Version 5.0).
      Net::FTP=GLOB(0x834a938)>>> user anonymous
      Net::FTP=GLOB(0x834a938)<<< 331 Password required for anonymous.
      Net::FTP=GLOB(0x834a938)>>> PASS ....
      Net::FTP=GLOB(0x834a938)<<< 230 User anonymous logged in.
      Net::FTP=GLOB(0x834a938)>>> CWD /IN
      Net::FTP=GLOB(0x834a938)<<< 250 CWD command successful.
      unix2dos: converting file /home/transferfile to DOS format ...
      Net::FTP=GLOB(0x834a938)>>> TYPE I
      Net::FTP=GLOB(0x834a938)<<< 200 Type set to I.
      Net::FTP=GLOB(0x834a938)>>> PORT X,X,X,X,128,156
      Net::FTP=GLOB(0x834a938)<<< 200 PORT command successful.
      Net::FTP=GLOB(0x834a938)>>> STOR /home/transferfile
      Net::FTP=GLOB(0x834a938)<<< 550 /home/transferfile: The system cannot find the path specified.

      open my($tr), "unix2dos $File |" or die $!; # Or FQ path $ftp->binary(); # We translate, not the server. $ftp->put($tr,$File); # must give remote name.
      ...............................................................................
      550 /home/transferfile: The system cannot find the path specified.

      open my($fh), $File or die $!; $ftp->binary(); # We translate, not the server. $ftp->put($fh,$File); # must give remote name.
      ...............................................................................
      550 /home/transferfile: The system cannot find the path specified. -bash: 550: command not found

      and I don't get any transfer, but the path to the file is correct.