[17402] in Perl-Users-Digest
Perl-Users Digest, Issue: 4822 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Nov 6 11:10:25 2000
Date: Mon, 6 Nov 2000 08:10:12 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <973527012-v9-i4822@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Mon, 6 Nov 2000 Volume: 9 Number: 4822
Today's topics:
problems creating a file <mdorrel@fsnet.co.uk>
Re: problems creating a file (Clay Irving)
Re: problems creating a file <nospam.newton@gmx.li>
Re: problems creating a file <gus@black.hole-in-the.net>
Re: problems creating a file <mdorrel@fsnet.co.uk>
Re: problems creating a file <tward10@jaguar.com>
Re: problems creating a file <crt@kiski.net>
Re: problems creating a file <mdorrel@fsnet.co.uk>
Re: Problems executing C program through perl via web (Tad McClellan)
Re: read > find > run <brian@bdjc.freeserve.co.uk>
Re: read last line only... <crt@kiski.net>
Search engine woes... acroapl@my-deja.com
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 6 Nov 2000 14:53:07 -0000
From: "Mike Dorrel" <mdorrel@fsnet.co.uk>
Subject: problems creating a file
Message-Id: <3a06cd57.0@energise.enta.net>
Hello,
The following simple script is supposed to create a one line text file,
but it is not working correctly and I get no error from the browser
when I run the script.
the script is placed in 'MyDomain/cgi-bin/create.cgi' and is supposed
to create the file as 'MyDomain/newfile.txt'.
#!/usr/bin/perl5
print "Content-type: text/html\n\n";
use CGI::Carp 'fatalsToBrowser';
if (open(LOGFILE, "> /newfile.txt")) {
print LOGFILE ("sample text.\n");
close(LOGFILE);
}
Thanks for any response.
Mike
------------------------------
Date: 6 Nov 2000 15:07:47 GMT
From: clay@panix.com (Clay Irving)
Subject: Re: problems creating a file
Message-Id: <slrn90dia3.q4v.clay@panix3.panix.com>
On Mon, 6 Nov 2000 14:53:07 -0000, Mike Dorrel <mdorrel@fsnet.co.uk> wrote:
>Hello,
>
>The following simple script is supposed to create a one line text file,
>but it is not working correctly and I get no error from the browser
>when I run the script.
>
>the script is placed in 'MyDomain/cgi-bin/create.cgi' and is supposed
>to create the file as 'MyDomain/newfile.txt'.
>
>
> #!/usr/bin/perl5
>
> print "Content-type: text/html\n\n";
> use CGI::Carp 'fatalsToBrowser';
>
> if (open(LOGFILE, "> /newfile.txt")) {
> print LOGFILE ("sample text.\n");
> close(LOGFILE);
> }
>
>
>Thanks for any response.
I bet your open failed, but I wouldn't know since you didn't test it...
--
Clay Irving <clay@panix.com>
Some mornings it just doesn't seem worth it to gnaw through the leather
straps.
- Emo Philips
------------------------------
Date: Mon, 06 Nov 2000 16:15:02 +0100
From: "Philip 'Yes, that's my address' Newton" <nospam.newton@gmx.li>
Subject: Re: problems creating a file
Message-Id: <liid0tcchjh5udcrqnenop18929mk6bnp1@4ax.com>
On Mon, 6 Nov 2000 14:53:07 -0000, "Mike Dorrel" <mdorrel@fsnet.co.uk>
wrote:
> the script is placed in 'MyDomain/cgi-bin/create.cgi' and is supposed
> to create the file as 'MyDomain/newfile.txt'.
I'm assuming you tried to access the newly created file by typing in
'http://MyDomain/newfile.txt' into your browser. However, the URL part
'/newfile.txt' is not the same as the file system location
'/newfile.txt' -- you created a file in the root directory of your
file system, whereas the web server was looking for a file in the top
directory of its document root. That might be something like
/home/yourname/public_html or /var/local/htdocs or, basically,
anything at all. It's unlikely to be / (the root directory of your
file system), however, so accessing '/newfile.txt' from the browser
will not get you the file that the operating system knows as
'/newfile.txt'.
Or maybe you failed to create the file, but you didn't output an error
message (including $! is handy here) to indicate that fact.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
If you're not part of the solution, you're part of the precipitate
------------------------------
Date: Mon, 06 Nov 2000 15:19:11 GMT
From: Gus <gus@black.hole-in-the.net>
Subject: Re: problems creating a file
Message-Id: <973523951.25155.3.nnrp-13.c29f015a@news.demon.co.uk>
Mike Dorrel <mdorrel@fsnet.co.uk> wrote:
> Hello,
> The following simple script is supposed to create a one line text file,
> but it is not working correctly and I get no error from the browser
> when I run the script.
/trimmed/
> if (open(LOGFILE, "> /newfile.txt")) {
> print LOGFILE ("sample text.\n");
> close(LOGFILE);
> }
So, when the open() fails, what then ?
if (open(LOGFILE,"> /newfile.txt")) {
print LOGFILE "sample text.\n";
close(LOGFILE) || die("Content-type: text/plain\n\nCan't close: $!");
}else{
# Deal gracefully with error
print STDERR "Couldn't open /newfile.txt, error was $!\n";
}
Regards,
_Gus
--
gus@black.hole-in-the.net
0x58E18C6D
82 AA 4D 7F D8 45 58 05 6D 1B 1A 72 1E DB 31 B5
http://black.hole-in-the.net/gus/
------------------------------
Date: Mon, 6 Nov 2000 15:34:26 -0000
From: "Mike Dorrel" <mdorrel@fsnet.co.uk>
Subject: Re: problems creating a file
Message-Id: <3a06d86e.0@energise.enta.net>
The example I am using is adapted from one which works in
Windows '98:
if (open(LOGFILE, ">>message.log")) {
print LOGFILE ("This is message number 1.\n");
print LOGFILE ("This is message number 2.\n");
close(LOGFILE);
}
I think it is possibly a permissions problem although I have tried
giving all permissions to all users without success.
Is there a switch I can use and does it have to be run from the
command line?
----- Original Message -----
From: "Clay Irving" <clay@panix.com>
Newsgroups: comp.lang.perl.misc
Sent: Monday, November 06, 2000 3:07 PM
Subject: Re: problems creating a file
> On Mon, 6 Nov 2000 14:53:07 -0000, Mike Dorrel <mdorrel@fsnet.co.uk>
wrote:
> >Hello,
> >
> >The following simple script is supposed to create a one line text file,
> >but it is not working correctly and I get no error from the browser
> >when I run the script.
> >
> >the script is placed in 'MyDomain/cgi-bin/create.cgi' and is supposed
> >to create the file as 'MyDomain/newfile.txt'.
> >
> >
> > #!/usr/bin/perl5
> >
> > print "Content-type: text/html\n\n";
> > use CGI::Carp 'fatalsToBrowser';
> >
> > if (open(LOGFILE, "> /newfile.txt")) {
> > print LOGFILE ("sample text.\n");
> > close(LOGFILE);
> > }
> >
> >
> >Thanks for any response.
>
> I bet your open failed, but I wouldn't know since you didn't test it...
>
> --
> Clay Irving <clay@panix.com>
> Some mornings it just doesn't seem worth it to gnaw through the leather
> straps.
> - Emo Philips
------------------------------
Date: Mon, 6 Nov 2000 15:19:00 -0000
From: "Trevor Ward" <tward10@jaguar.com>
Subject: Re: problems creating a file
Message-Id: <8u6i54$3k21@eccws12.dearborn.ford.com>
Mike Dorrel <mdorrel@fsnet.co.uk> wrote in message
news:3a06cd57.0@energise.enta.net...
> Hello,
>
> The following simple script is supposed to create a one line text file,
> but it is not working correctly and I get no error from the browser
> when I run the script.
>
> the script is placed in 'MyDomain/cgi-bin/create.cgi' and is supposed
> to create the file as 'MyDomain/newfile.txt'.
>
>
> #!/usr/bin/perl5
>
> print "Content-type: text/html\n\n";
> use CGI::Carp 'fatalsToBrowser';
>
xxxxxxxxx if (open(LOGFILE, "> /newfile.txt")) {
> if (open(LOGFILE, "> ../newfile.txt")) {
Perhaps not using the root / infront may mean the file will be found. Using
../ means up one directory.
Well this is all I can see hope it resolves it.
> print LOGFILE ("sample text.\n");
> close(LOGFILE);
> }
>
>
> Thanks for any response.
>
> Mike
>
>
------------------------------
Date: Mon, 6 Nov 2000 10:47:36 -0500
From: "Casey R. Tweten" <crt@kiski.net>
Subject: Re: problems creating a file
Message-Id: <Pine.OSF.4.21.0011061044130.14988-100000@home.kiski.net>
Today around 2:53pm, Mike Dorrel hammered out this masterpiece:
: the script is placed in 'MyDomain/cgi-bin/create.cgi' and is supposed
: to create the file as 'MyDomain/newfile.txt'.
:
:
: #!/usr/bin/perl5
:
: print "Content-type: text/html\n\n";
: use CGI::Carp 'fatalsToBrowser';
^^^^^^^^^^^^^^^
This is a good idea...
: if (open(LOGFILE, "> /newfile.txt")) {
: print LOGFILE ("sample text.\n");
: close(LOGFILE);
: }
but you aren't going to get any fatals on your open() unless you make
it so. You check to see if your open was successful, but you don't do
anything if it wasn't. Like check the error:
if ( open( FH, "> file" ) ) {
# [...]
} else {
die "Couldn't open ``file'': $!";
}
This will give you the problem right away, which is most likley
permissions.
--
print(join(' ', qw(Casey R. Tweten)));my $sig={mail=>'crt@kiski.net',site=>
'http://home.kiski.net/~crt'};print "\n",'.'x(length($sig->{site})+6),"\n";
print map{$_.': '.$sig->{$_}."\n"}sort{$sig->{$a}cmp$sig->{$b}}keys%{$sig};
my $VERSION = '0.01'; #'patched' by Jerrad Pierce <belg4mit at MIT dot EDU>
------------------------------
Date: Mon, 6 Nov 2000 15:48:48 -0000
From: "Mike Dorrel" <mdorrel@fsnet.co.uk>
Subject: Re: problems creating a file
Message-Id: <3a06da67.0@energise.enta.net>
I was watching to see if a file was created by using WS_FTP!
I'll try your suggestion now!
Thanks.
"Gus" <gus@black.hole-in-the.net> wrote in message
news:973523951.25155.3.nnrp-13.c29f015a@news.demon.co.uk...
> Mike Dorrel <mdorrel@fsnet.co.uk> wrote:
> > Hello,
>
> > The following simple script is supposed to create a one line text file,
> > but it is not working correctly and I get no error from the browser
> > when I run the script.
>
> /trimmed/
>
> > if (open(LOGFILE, "> /newfile.txt")) {
> > print LOGFILE ("sample text.\n");
> > close(LOGFILE);
> > }
>
> So, when the open() fails, what then ?
>
> if (open(LOGFILE,"> /newfile.txt")) {
> print LOGFILE "sample text.\n";
> close(LOGFILE) || die("Content-type: text/plain\n\nCan't close: $!");
> }else{
> # Deal gracefully with error
> print STDERR "Couldn't open /newfile.txt, error was $!\n";
> }
>
> Regards,
> _Gus
>
>
>
>
> --
> gus@black.hole-in-the.net
> 0x58E18C6D
> 82 AA 4D 7F D8 45 58 05 6D 1B 1A 72 1E DB 31 B5
> http://black.hole-in-the.net/gus/
------------------------------
Date: Mon, 6 Nov 2000 08:17:49 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Problems executing C program through perl via web
Message-Id: <slrn90dbrt.1s0.tadmc@magna.metronet.com>
On Sun, 05 Nov 2000 23:32:20 -0700, Daniel Cuaron <dcuaron@cs.nmsu.edu> wrote:
>
>Here's a snippet of code I'm having a problem with:
>
>#!/local/perl/bin/perl
That should be:
#!/local/perl/bin/perl -wT
use strict;
>$var=`ls`;
If you code it in native Perl it will be more portable than
if you "shell out" to OS-specific programs. It will run
faster too.
You can get a file listing in native Perl using opendir() and
friends, or even filename glob()ing.
>print "$var";
^ ^
^ ^
Those are useless, and therefore should not be there.
print $var; # works fine
>$outputcatch = ` ../code/cgitestparse ../code/input.txt `;
If you are using relative paths then you better be sure that
you are in the correct working directory.
I expect that this is what is causing your problem.
Either chdir() to the correct dir, or use absolute path names.
>print "$outputcatch";
More useless double quotes to slow down the maintenance programmer.
>$sitedata="output/output.txt";
>
>open(DAT,">$sitedata") || die("Cannot Open File");
You should include the $! special variable in your diagnostic message:
open(DAT, ">$sitedata") || die("Cannot Open '$sitedata' $!");
You haven't mentioned it, but I assume that you know how to find
these diag messages for your server setup (they usually end up in
a server log somewhere. Find out where.)
>On the shell, it runs fine, yet when I run it via Netscape, the output
>is blank.
Perl FAQ, part 9:
"My CGI script runs from the command line but not the browser."
"How can I get better error messages from a CGI program?"
>Is this a protection from the server that I can't get around?
Including $! would help answer that question.
>Are
>there servers that can support this (FREE!!)?
Nearly every server should support that.
I expect the server is fine and it is your program (your assumptions,
actually) that is broken.
>Am I a stupid piece of
>shit?
No.
( but leaving off warnings, strictures and taint checking push
you right up against the edge of such a characterization.
:-)
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 6 Nov 2000 14:01:14 -0000
From: "Brian Canning" <brian@bdjc.freeserve.co.uk>
Subject: Re: read > find > run
Message-Id: <8u6e2u$ei0$1@newsg3.svr.pol.co.uk>
what I am trying to achieve is, as the file is
read in if it finds <!--type--> is runs the create_types
and prints that. it doesn't have to replace it as its a comment
so it will not display anyway.
the create_types creates a drop down list and the create_music
creates a set of radio buttons.
so as the file is read in where the <!--type--> or <!--music--> is
it displays the create_types / create_music.
the file being read in is the template, I could imbed the hold lot by
hand, but this way must be quicker.
does that make sense now?
Brian
Dave Brondsema <brondsem@my-deja.com> wrote in message
news:8u52io$728$1@nnrp1.deja.com...
> In article <8u513d$gvo$1@newsg3.svr.pol.co.uk>,
> "Brian Canning" <brian@bdjc.freeserve.co.uk> wrote:
> > Hi all hows it going?
> >
> > i know i am doing somthing silly here but can't work it out
> >
> > i what to read in a file and exicute a sub when it find a comment
> > in the HTM file.
> > heres the script where am i going wrong?
> >
> > sub show_form {
> > open (formfile, "add.htm") || die print "Oh my god, where is the
> form file
> > called add.htm";
> > while (<formfile>) {
> > if ($_ =~ s/<!--type-->//){
>
> you don't want to substitute anything, use this instead:
> $_ =~ /<!--type-->/
> or just
> /<!--type-->/ (I think)
>
>
> > &create_types;
> > }
> > elsif ($_ =~ s/<!--music-->//){
> > &create_music;
> > }
> > else {
> > print $_;
> > }
> >
> > }
> > }
> >
> >
>
> --
> Dave Brondsema
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
------------------------------
Date: Mon, 6 Nov 2000 10:43:19 -0500
From: "Casey R. Tweten" <crt@kiski.net>
Subject: Re: read last line only...
Message-Id: <Pine.OSF.4.21.0011061041140.14988-100000@home.kiski.net>
Today around 11:17am, Enjoyer hammered out this masterpiece:
: I'm trying to read the last line of a file only, using print, any ideas ?
Well, you can't really _read_ using print().
Here's one solution:
print +(<FH>)[-1];
This is of course, dependent on what $/ is set to.
--
print(join(' ', qw(Casey R. Tweten)));my $sig={mail=>'crt@kiski.net',site=>
'http://home.kiski.net/~crt'};print "\n",'.'x(length($sig->{site})+6),"\n";
print map{$_.': '.$sig->{$_}."\n"}sort{$sig->{$a}cmp$sig->{$b}}keys%{$sig};
my $VERSION = '0.01'; #'patched' by Jerrad Pierce <belg4mit at MIT dot EDU>
------------------------------
Date: Mon, 06 Nov 2000 15:26:33 GMT
From: acroapl@my-deja.com
Subject: Search engine woes...
Message-Id: <8u6ij0$b9f$1@nnrp1.deja.com>
how can you match strings w/o capitaliztion being checked? Is there a
function like in C?
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 4822
**************************************