<<ENFofFTP "here-documnet" question 
Author Message
 <<ENFofFTP "here-documnet" question

I am tring to use the "here-document" in the following program.

system ("ftp -n localhost <<ENDofFTP");
   user cscdata cscdata
   cd /usr2/cscdata/OUT1
   hash
   ls * aaa
   bye
ENDofFTP

Got the following error message:

Bare word found where operator expected at test1 line 8, near "cd"
syntax error at test1 line 8, near "cd "
Execution of test1 aborted due to compilation errors.

I know that <<ENDofFTP is evaluated differently in shell. How should I
write this.

Thanks,

Kerry Hu.



Sun, 02 Nov 1997 03:00:00 GMT  
 <<ENFofFTP "here-documnet" question

Quote:
>I am tring to use the "here-document" in the following program.
>system ("ftp -n localhost <<ENDofFTP");
>   user cscdata cscdata
>   cd /usr2/cscdata/OUT1
>   hash
>   ls * aaa
>   bye
>ENDofFTP
>Got the following error message:
>Bare word found where operator expected at test1 line 8, near "cd"
>syntax error at test1 line 8, near "cd "
>Execution of test1 aborted due to compilation errors.
>I know that <<ENDofFTP is evaluated differently in shell. How should I
>write this.

One tactic is to enclose the entire shell command, including "<<ENDofFTP"
and everything, in the double quotes, like so:

system ("ftp -n localhost <<ENDofFTP
   user cscdata cscdata
   cd /usr2/cscdata/OUT1
   hash
   ls * aaa
   bye
ENDofFTP");

A bit more readable would be to use two layers of <<, the outer being the
perl operator, the inner layer the shell operator with the same syntax:

system (<<ENDofSHELL);
  ftp -n localhost <<ENDofFTP
    user cscdata cscdata
    cd /usr2/cscdata/OUT1
    hash
    ls * aaa
    bye
ENDofFTP
ENDofSHELL

--
Hope this helps,

HansM



Sun, 02 Nov 1997 03:00:00 GMT  
 <<ENFofFTP "here-documnet" question

Quote:


>  >I am tring to use the "here-document" in the following program.
>>>--- mucho deletion  --->>>

You might also try using "open" and "print"--

open(FTP, "|ftp -n localhost");
print FTP<<"ENDofFTP";
user cscdata cscdata
cd /usr2/cscdata/OUT1
hash
ls * aaa
bye
ENDofFTP

::::::::<<<<Internetworking The Desktop>>>>::::::::::

Systems Engineer        +1.206.447.0300(phone)
SPRY Inc.               +1.206.447.9008(fax)
Try the online help...  http://support.spry.com
::::::::::::<<<<http://www.spry.com>>>>::::::::::::::



Sun, 02 Nov 1997 03:00:00 GMT  
 <<ENFofFTP "here-documnet" question
[Posted from: comp.lang.perl]

Quote:

> I am tring to use the "here-document" in the following program.

> system ("ftp -n localhost <<ENDofFTP");
>    user cscdata cscdata
>    cd /usr2/cscdata/OUT1
>    hash
>    ls * aaa
>    bye
> ENDofFTP

Try it this way:

  system ("ftp -n localhost <<ENDofFTP
     user cscdata cscdata
     cd /usr2/cscdata/OUT1
     hash
     ls * aaa
     bye
  ENDofFTP");

The entire command, including the here document, must be passed to
'system'.

A better way to do this in perl, however, is like this:

  open(FTP, "| ftp -n localhost") || die "unable to invoke process";

  print FTP "user cscdata cscdata
  cd /usr2/cscdata/OUT1
  hash
  ls * aaa
  bye\n";

  close (FTP);

I hope this help.

--
 Lloyd Zusman           01234567 <-- The world famous Indent-o-Meter.

   To get my PGP public key automatically mailed to you, please
   send me email with the following string as the subject or on a
   line by itself in the message (leave off the quotation marks):
                   "mail-request public-key"



Sun, 02 Nov 1997 03:00:00 GMT  
 <<ENFofFTP "here-documnet" question

Quote:

> I am tring to use the "here-document" in the following program.
> system ("ftp -n localhost <<ENDofFTP");
>    user cscdata cscdata
>    cd /usr2/cscdata/OUT1
>    hash
>    ls * aaa
>    bye
> ENDofFTP
> Got the following error message:
> Bare word found where operator expected at test1 line 8, near "cd"
> syntax error at test1 line 8, near "cd "
> Execution of test1 aborted due to compilation errors.
> I know that <<ENDofFTP is evaluated differently in shell. How should I
> write this.

Here documents are not expanded inside quotes, just as back quotes are
not evaluated in double quotes.  Okay, so you change the above to read:

system("ftp -n localhost " . <<EOFofFTP);
.....
ENDofFTP

That doesn't work because the heredoc is being expanded by perl, and thus
the ftp commands are being put on the command line instead of being fed
into ftp's stdin.  Since you're trying to fed ftp's stdin, why not do so
explicitly?

# "You sense the presense of tchrist near by...better check return values..."
open(FTP, "|ftp -n localhost")        || die "Unable to fork for ftp";
print FTP <<ENDofFTP              || die "Unable to write to ftp";
user cscdata cscdata
.....
ENDofFTP
close(FTP);
$? == 0 || die "ftp failed, return code $?";

Philip Guenther

----------------------------------------------------------------
Philip Guenther                 UNIX Systems and Network Administrator

Gustavus Adolphus College       St. Peter, MN 56082-1498
I am _not_ a representative sample of the Gustavus Community.  Yeah, right...



Mon, 03 Nov 1997 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. ^<<<<<<<<<<<~~ with \n

2. print <<"EOF";

3. print <<"ending_print_tag";

4. ^<<<<<<<<<<< ~~ format question

5. One question about useage "<>"

6. Question on Cutting and Paste things in a File <<<<<<<<

7. How to "$block_of_text<<"EOT" while "use strict"?

8. How can I make @<<<<<<<<< variable ?

9. Tcl "exec" construct with "<<", in Perl

10. How can grep the 8th of Field <<<<<<<<

11. problem with <input type="image".....

 

 
Powered by phpBB® Forum Software