As holli said, there is nothing wrong within the lines you posted. Ist this a command line app or do you try to do this from within CGI or mod_perl program?
Try a small modification on your code:
open HELLO, ">file.txt" or die "$!";
select HELLO or die "$!";
print "hi !";
and respond to this thread with the error message shown.
Regards
mwa | [reply] [d/l] |
If you want to add text to an existing file (that is, append new data at the end, rather than replacing all existing content), then the open statement should be like this -- and you should add error checking as well:
open HELLO, ">>file.text" or die "open failed: $!";
(note the two angle brackets instead of one)
As for the compilation error, you'd have to show us the actual text of the error message. If the message mentions a particular line number, you'd have to show us your code in such a way that we can tell what line that is. (Use "<code>" and "</code>" around the text of the script.)
| [reply] [d/l] |
hi,
I am assuming that you want to open a file and print "HI" in that if that is the case
do this way
#!/usr/bin/perl
open HELLO, ">file.txt";
select HELLO;
print HELLO "hi !";
| [reply] |
The code you show is correct (though, the select-call is unneccessary overkill). What error do you get?
| [reply] [d/l] |
I am getting a compilation error. Can anyone tell me where i am going wrong ?
Which error? See How (Not) To Ask A Question. Selecting the error and pasting it into the composition box
is easy.
Are you sure it is perl which is throwing the error? Maybe you are invoking that script as is,
and so bash (or whatever shell you have) gets it?
Maybe it is no error from perl, but from your shell?
--shmem
_($_=" "x(1<<5)."?\n".q·/)Oo. G°\ /
/\_¯/(q /
---------------------------- \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
| [reply] |
I bet you were confusing a runtime warning (likely because opening the file failed, and then next, you can't print to a filehandle that isn't open) with a compilation error. | [reply] |
Hi all, thanks for a quick response.
The script is working.
I am not getting that error again. dont know the reason for the same.
| [reply] |