[18346] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 514 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Mar 17 14:10:44 2001

Date: Sat, 17 Mar 2001 11:10:11 -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: <984856211-v10-i514@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 17 Mar 2001     Volume: 10 Number: 514

Today's topics:
        Print to file <lostshade@home.com>
    Re: Print to file <lostshade@home.com>
    Re: Print to file <len.green@ntlworld.com>
    Re: Print to file <godzilla@stomp.stomp.tokyo>
    Re: Print to file (Randal L. Schwartz)
    Re: Print to file (Garry Williams)
    Re: problem with file lock that is not removed (Garry Williams)
        Simple Email @ Parsing Solution? <dave.davis@ultrainteractive.com>
    Re: Status: 403 Forbidden (Si Ballenger)
    Re: Status: 403 Forbidden (Tony L. Svanstrom)
    Re: Status: 403 Forbidden nobull@mail.com
    Re: Subroutine in separate files (Damian James)
    Re: Username/password from an HTML form <mark-lists@webstylists.com>
    Re: ZPT, a next-generation template technology <rossi@earthling.net>
    Re: ZPT, a next-generation template technology <akuchlin@mems-exchange.org>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sat, 17 Mar 2001 15:32:55 GMT
From: "LostShade" <lostshade@home.com>
Subject: Print to file
Message-Id: <HsLs6.184313$B6.41058280@news1.rdc1.md.home.com>

Hello,

Im moving all my Perl scripts from a Unix server to Win98 with Webserver
Pro. Everything works perfectly in the switch except when I try to print to
a file.

open(OUTF,">main.txt");
flock(OUTF,2);
seek(OUTF,0,0);
print OUTF "$kc\n";
close(OUTF);

This Opens the file, or creates a new one if it does not allready exist. If
it does exist it sets it to overwrite and removes all data curently in it.
It appears to die when it gets to the Print statement. Since it does create
or alter the files I presume there is no problem with permissions.

The error I receive is: CGI output from C:/WebSite/Perl5/bin/newtitle.pl
contained no blank line separating header and data (most likely a broken CGI
program)

Is there another statement I must make with this before I begin writing to
the file? Or another way to do this?

Thanks,
Lostshade







------------------------------

Date: Sat, 17 Mar 2001 15:49:16 GMT
From: "LostShade" <lostshade@home.com>
Subject: Re: Print to file
Message-Id: <0ILs6.184320$B6.41067009@news1.rdc1.md.home.com>

For anyone who might be wondering it appears
flock(OUTF,2);
is what was causing the crash. With out that it writes perfectly. I guess
Perl for windows doesn't support this.

Anyone know if without that statement it will automatically prevent two
people from writing to a file at the same time? Or know another way to use a
command like this in windows?

Thanks again,
Lostshade



LostShade wrote in message ...
>Hello,
>
>Im moving all my Perl scripts from a Unix server to Win98 with Webserver
>Pro. Everything works perfectly in the switch except when I try to print to
>a file.
>
>open(OUTF,">main.txt");
>flock(OUTF,2);
>seek(OUTF,0,0);
>print OUTF "$kc\n";
>close(OUTF);
>
>This Opens the file, or creates a new one if it does not allready exist. If
>it does exist it sets it to overwrite and removes all data curently in it.
>It appears to die when it gets to the Print statement. Since it does create
>or alter the files I presume there is no problem with permissions.
>
>The error I receive is: CGI output from C:/WebSite/Perl5/bin/newtitle.pl
>contained no blank line separating header and data (most likely a broken
CGI
>program)
>
>Is there another statement I must make with this before I begin writing to
>the file? Or another way to do this?
>
>Thanks,
>Lostshade
>
>
>
>
>




------------------------------

Date: Sat, 17 Mar 2001 16:15:33 -0000
From: "len.green" <len.green@ntlworld.com>
Subject: Re: Print to file
Message-Id: <E4Ns6.1284$Q4.520907@news2-win.server.ntlworld.com>

Win32 does not support flock();

try using semaphore files;

Len


LostShade <lostshade@home.com> wrote in message
news:0ILs6.184320$B6.41067009@news1.rdc1.md.home.com...
> For anyone who might be wondering it appears
> flock(OUTF,2);
> is what was causing the crash. With out that it writes perfectly. I guess
> Perl for windows doesn't support this.
>
> Anyone know if without that statement it will automatically prevent two
> people from writing to a file at the same time? Or know another way to use
a
> command like this in windows?
>
> Thanks again,
> Lostshade
>
>
>
> LostShade wrote in message ...
> >Hello,
> >
> >Im moving all my Perl scripts from a Unix server to Win98 with Webserver
> >Pro. Everything works perfectly in the switch except when I try to print
to
> >a file.
> >
> >open(OUTF,">main.txt");
> >flock(OUTF,2);
> >seek(OUTF,0,0);
> >print OUTF "$kc\n";
> >close(OUTF);
> >
> >This Opens the file, or creates a new one if it does not allready exist.
If
> >it does exist it sets it to overwrite and removes all data curently in
it.
> >It appears to die when it gets to the Print statement. Since it does
create
> >or alter the files I presume there is no problem with permissions.
> >
> >The error I receive is: CGI output from C:/WebSite/Perl5/bin/newtitle.pl
> >contained no blank line separating header and data (most likely a broken
> CGI
> >program)
> >
> >Is there another statement I must make with this before I begin writing
to
> >the file? Or another way to do this?
> >
> >Thanks,
> >Lostshade
> >
> >
> >
> >
> >
>
>




------------------------------

Date: Sat, 17 Mar 2001 09:41:23 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Print to file
Message-Id: <3AB3A1C3.92E4B69D@stomp.stomp.tokyo>

LostShade wrote:
 
> For anyone who might be wondering it appears
> flock(OUTF,2); is what was causing the crash.
> With out that it writes perfectly. I guess
> Perl for windows doesn't support this.


Guessing is not a viable methodolgy for programming.


There is a work around to emulate file locking
on a Win 32 box. Basic principles are displayed
by this code snippet:


while ( -e "filelock.tmp" )
 { sleep(1); }

open(FILELOCK,"> filelock.tmp");
print FILELOCK "file is locked";
close(FILELOCK);
chmod 0660,'filelock.tmp';

# manipulate your data file here

unlink 'filelock.tmp';

 
> Anyone know if without that statement it will automatically
> prevent two people from writing to a file at the same time?
> Or know another way to use a command like this in windows?

You have not precisely indicated what "statement" nor
what "command" you are referencing. A presumption is
made you are referencing "flock(OUTF,2)" lacking any
clarity on your part.

A Windows system, either 16 bit or 32 bit, many Win programs
will deny access to a file currently opened by another program
if you or a program attempt a write / modification. However,
I have never tested this via a web server. I do not know if
Windows is capable of producing this access denial for a
web server. You should note, not all programs will create
this access denied condition, most but not all. It would
not be prudent of you to depend on Windows to write protect
a file for your circumstances.


Godzilla!


------------------------------

Date: 17 Mar 2001 10:50:52 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Print to file
Message-Id: <m1ofv0qlf7.fsf@halfdome.holdit.com>

>>>>> "Godzilla!" == Godzilla!  <godzilla@stomp.stomp.tokyo> writes:

Godzilla!> There is a work around to emulate file locking
Godzilla!> on a Win 32 box. Basic principles are displayed
Godzilla!> by this code snippet:


Godzilla!> while ( -e "filelock.tmp" )
Godzilla!>  { sleep(1); }

Godzilla!> open(FILELOCK,"> filelock.tmp");

Basic fragile principles, that is.

There's a race condition between testing for the sentinel file, and
actually creating it.  So two processes will occasionally end up both
believeing they have the exclusive access to the resource.

If Kira follows up to this message with "I've never seen that",
consider that it means that she's been lucky, or doesn't have a very
heavily loaded web site. :)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


------------------------------

Date: Sat, 17 Mar 2001 19:00:32 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: Print to file
Message-Id: <kvOs6.71$ez4.3127@eagle.america.net>

On Sat, 17 Mar 2001 15:32:55 GMT, LostShade <lostshade@home.com>
wrote:

>Im moving all my Perl scripts from a Unix server to Win98 with Webserver
>Pro. Everything works perfectly in the switch except when I try to print to
>a file.
>
>open(OUTF,">main.txt");
>flock(OUTF,2);
>seek(OUTF,0,0);
>print OUTF "$kc\n";
>close(OUTF);

I suppose it's moot since you're moving this to a Windows system
(where flock() is a problem), but this code is *broken*.  

You are truncating the file *before* locking it.  You are *not*
protected by the lock!  

The perlopentut manual page discusses the correct way to accomplish
what you seem to want by using sysopen() with O_WRONLY | O_CREAT and
an explicit truncate().  

Again, it may be moot, but you really should use the constants
supplied by Fcntl (LOCK_EX) instead of magic numbers.  

One last point that isn't moot: *always* check the results of open(),
flock() and seek().  *Always* check the result of close() on an output
file.  

-- 
Garry Williams


------------------------------

Date: Sat, 17 Mar 2001 17:51:42 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: problem with file lock that is not removed
Message-Id: <OuNs6.52$ez4.2324@eagle.america.net>

On Fri, 16 Mar 2001 11:27:59 +0100, Sander van Gennip <svg@wanadoo.nl>
wrote:

>I am using the following scheme in updating a file:
>
>===================
>  open(DATA,"+<$file");
>  flock(DATA,LOCK_EX);

You should *always* check the result of both of those functions before
proceeding.  

>  @log = <DATA>;
>
>  ... some code that modifies @log ...
>
>  seek DATA,0,0;
>  truncate DATA,0;
>
>  foreach $line (@log) {
>
>    print(DATA $line);
>  }  

   print DATA @log;

>  flock(DATA,LOCK_UN);
>  close(DATA);

It's probably not related to your problem, but you should *not* unlock
a file that you have updated with LOCK_UN.  Closing the file will
unlock it *after* the buffers have been flushed.  Newer perl's claim
to protect you from this race condition, but it is just poor practice.  

Also, you should *always* check the result of a close() on an output
file.  The error you get on a full disk will be reported at close()
time.  

>The problem is the following: once in about 200 script calls the file
>seems to remain locked, and any script calls following it wait forever
>for the lock to be granted. If I download, remove and upload the file
>everything works again.

Do you have any other locking going on?  Do other programs lock this
file?  Have you enabled warnings?  This code "looks" okay (with the
exception of the comments I made).  I cannot see a potential for
deadlock here.  

When the deadlock occurs, have you tried to run truss (or its
equivalent in Linux) on the blocking processes?  That would at least
print the system call that the process was blocked in.  One process
(the one holding the lock) will be blocked in some system call and
that may give a hint to what's going on.  

-- 
Garry Williams


------------------------------

Date: Sat, 17 Mar 2001 13:25:45 -0500
From: Dave Davis <dave.davis@ultrainteractive.com>
Subject: Simple Email @ Parsing Solution?
Message-Id: <B6D91659.112D%dave.davis@ultrainteractive.com>

I'm trying to grab an email address from a form, and paste it back into a
sendmail message as a recipient.  What's the simplest solution to handling
the obvious problem (the @ character hangs... in the non-variable lines its
escaped with /@ for sending).

I can fix this with a fairly long cut/reassembly routine, but I know there
HAS to be some simple solution I'm missing.

Pardon my ignorance. TIA for any help!


-d-

Dave Davis



------------------------------

Date: Sat, 17 Mar 2001 14:46:42 GMT
From: shb@vnet.net (Si Ballenger)
Subject: Re: Status: 403 Forbidden
Message-Id: <3ab37851.548180692@166.82.1.9>

You might try something like below:

#!/usr/local/bin/perl
print "Content-type: text/plain", "\n";
print "Status: 403 Forbidden\n\n";

On Sat, 17 Mar 2001 09:48:14 +0000, In off the Post
<pbm@NOSPAMiotp.demon.co.uk> wrote:

>I need to send a 403 HTTP header, which will then be handled by an
>Apache ErrorDocument (which works) which will re-direct the user to a
>specified page.
>
>Why doesn't this perl script work?
>
>print "Status: 403 Forbidden\n\n";
>
>Cheers,
>Peter
>-- 
> In off the Post, PO Box 442, NOTTINGHAM, NG1 1PE. ENGLAND
> Phone: +44 (0) 115 941 5132     Fax: +44 (0) 115 941 1634
> e-mail: pbm@iotp.co.uk              http://www.iotp.co.uk



------------------------------

Date: Sat, 17 Mar 2001 15:57:04 GMT
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: Status: 403 Forbidden
Message-Id: <1eqfaym.g850q3108ewz8N%tony@svanstrom.com>

In off the Post <pbm@NOSPAMiotp.demon.co.uk> wrote:

> Alan,
>         You pedantic fool!

Fanclub of Alan, take out your killfiles, open them, take evil guy's
e-mailaddress and... *PLONK*


;-)

        /Tony... =)


------------------------------

Date: 17 Mar 2001 17:00:10 +0000
From: nobull@mail.com
Subject: Re: Status: 403 Forbidden
Message-Id: <u9y9u4l49x.fsf@wcl-l.bham.ac.uk>

shb@vnet.net (Si Ballenger) writes in untrimmed jeoparpdy style which
is usally a good sign of someone not too clued-in: 

> On Sat, 17 Mar 2001 09:48:14 +0000, In off the Post
> <pbm@NOSPAMiotp.demon.co.uk> wrote:
> 
> >I need to send a 403 HTTP header, which will then be handled by an
> >Apache ErrorDocument (which works) which will re-direct the user to a
> >specified page.
> >
> >Why doesn't this perl script work?
> >
> >print "Status: 403 Forbidden\n\n";

> You might try something like below:
> 
> #!/usr/local/bin/perl
> print "Content-type: text/plain", "\n";
> print "Status: 403 Forbidden\n\n";

You appear to be answering the inverse of the question!

If the OP's observed and desired senamtics were exchanged then adding
a "Content-type" header would have been my first thought.

Still, like I said before, this has nothing to do with Perl - this is
an Apache question.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


------------------------------

Date: 17 Mar 2001 14:12:57 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: Subroutine in separate files
Message-Id: <slrn9b6s6r.50s.damian@puma.qimr.edu.au>

Dave Cross chose Sat, 17 Mar 2001 13:49:20 +0000 to say this:
>...
>Note that any advice regarding the use of LWP as a solution to your
>problem is so completely off-track that anyone giving that advice
>should be laughed out of the newsgroup.
>

At first, I found this sentence puzzling in the extreme. I quickly realised,
however, that David was referring to comments made by some denizen of my
scorefile (one of the -9999 folk). So to clear things up, I disabled
scoring and rebuilt the thread. 

The result surprised me: I had some time ago decided to kill not just
Godzilla's posts, but also any followups to them. This helps me to
entertain the illusion of a troll-free newsgroup. But I was still surprised
that I had managed to opt out of such a large thread in advance.

Do other people kill followups as well? In some ways I'm sad to miss uri's
comments, eg, even though I'd like to think that I'm saving my usenet time
for his 'better side' :-). 

Chers,
Damian
-- 
@;=0..23;@;{@;}=split//,<DATA>;while(@;){for($;=@;;--$;;){next if($:=rand($;
+1))==0+$;;@;[$;,$:]=@;[$:,$;]}print map{$;{$_}}(@| ,@;);push@|,shift@;if$;[
0]==@|;$|=1;select$&,$&,$&,1/80;print"\b"x(@;+@|)}print"\n"__END__
Just another Perl Hacker


------------------------------

Date: Sat, 17 Mar 2001 10:18:09 -0800
From: Mark Thompson <mark-lists@webstylists.com>
Subject: Re: Username/password from an HTML form
Message-Id: <58a7btoetc8mbenogtt37auroje63ls86i@4ax.com>

On 17 Mar 2001 10:11:41 +0000, nobull@mail.com wrote:

>Mark Thompson <mark-lists@webstylists.com> writes:
>
>> I've set up a simple password protection system using basic
>> authentication with an .htaccess file and password file that works.
>> When someone requests a page that is protected, the browser brings up
>> a dialog box that asks for the username and password and if they enter
>> the correct information, it gives them what they're looking for.
>> 
>> What I'd like to do is have username and password fields on an HTML
>> form with a submit button instead of a popup window that has the same
>> functionality.
>> 
>> Is this something that is possible?
>
>Yes.
>
>> I've spent all evening looking at
>> FAQs and Perl manuals but haven't been able to find anything that says
>> this is possible to do (I also haven't seen anything that says it's
>> not possible either.)
>
>Of course not, because this has has nothing to do with Perl.  The
>basic approach (HTML form with two fields, one a password field, a
>script to validate the username/password against a file and then a
>session ID using hidden fields, URL or cookie) is the same regardless
>of the language chosen.
>
>You may want to take a look at CGI::Persistent 

I was more looking for a way to avoid CGI altogether for everything
but the initial validation of the username and password.  I really
wanted to avoid having to validate every access when Apache already
has something in there for allowing one to have continued access, all
that I'm thinking needs to be done is to have it so that CGI can push
the username and password into the browser and let the browser handle
the authentication from then on using the basic authentication scheme
in Apache.

FYI, I had checked FAQs for CGI (hoping to find a generic way to apply
in Perl, for Perl (to find a specific way), and for Apache (to see if
I can find anything there that would either confirm a way to do what I
want or deny it. 


------------------------------

Date: Sat, 17 Mar 2001 16:19:42 +0100
From: "Thorsten Roskowetz" <rossi@earthling.net>
Subject: Re: ZPT, a next-generation template technology
Message-Id: <98vv9e$96f$01$1@news.t-online.com>

"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote:
> However, cl.perl.misc gets enough offtopic crap as it is. Don't post
> future announcements here.

You might not be aware of it but because of

http://www.zope.org/Wikis/zope-perl/

Hamish's post wasn't as off-topic as you think and certainly
not crap.

Regards,
Thorsten




------------------------------

Date: 17 Mar 2001 12:08:36 -0500
From: Andrew Kuchling <akuchlin@mems-exchange.org>
Subject: Re: ZPT, a next-generation template technology
Message-Id: <3ditl8migb.fsf@ute.cnri.reston.va.us>

"Hamish Lawson" <hamish_lawson@btinternet.com> writes:
> The approach that the ZPT project is pursuing is to attach the control-
> flow, formatting and placeholder directives as *attributes* of standard
> XHTML tags. The example above thus becomes something like:

After a glance at the initial specs, I like it; it looks like a
simpler processing language than XSLT, and one more suited to
interfacing with some other imperative language.  Given the recent
squabbling over the scripting features in XSL, there's probably a
significant niche for something like this.

You've notified various generic scripting communities, but you should
also really let the XML community know about this work; they're more
likely to take an interest.  Send a note to mailing lists such as
xml-dev, or to news sites such as xmlhack.com, xml.com, and
xml.coverpages.org.  comp.text.xml exists, but discussion is
relatively low-level and few serious developers hang out there.

--amk



------------------------------

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 V10 Issue 514
**************************************


home help back first fref pref prev next nref lref last post