[22550] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4771 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 27 18:36:03 2003

Date: Thu, 27 Mar 2003 15:35:40 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 27 Mar 2003     Volume: 10 Number: 4771

Today's topics:
        URL Redirection Headers <notspam@spamfree.dud>
    Re: URL Redirection Headers <nwzmattXX@XXnetscape.net>
    Re: URL Redirection Headers <emschwar@yahoo.com>
    Re: URL Redirection Headers <nobull@mail.com>
    Re: URL Redirection Headers <notspam@spamfree.dud>
    Re: URL Redirection Headers <notspam@spamfree.dud>
    Re: URL Redirection Headers <flavell@mail.cern.ch>
    Re: URL Redirection Headers <nwzmattXX@XXnetscape.net>
        Using perl to read/write Excel and Foxpro? <annoyed@you.now>
        using unix "at" from perl script <adam_fernie@hotmail.com>
    Re: using unix "at" from perl script news@roaima.freeserve.co.uk
    Re: using unix "at" from perl script <rev_1318@hotmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 26 Mar 2003 18:40:01 GMT
From: Sean O'Dwyer <notspam@spamfree.dud>
Subject: URL Redirection Headers
Message-Id: <notspam-788266.13400126032003@syrcnyrdrs-02-ge0.nyroc.rr.com>

Hi,

I'm working on a little URL redirection/stats routine but keep getting 
the following error:

>malformed header from script. Bad header=HTTP/1.0 302 Found:

The code I'm using is copied from "Perl 5 for Dummies" and looks like 
this...



print <<"EndFound";
HTTP/1.0 302 Found
Location: $the_url
Content-Type: text/html

<head><title>Redirection Information</title></head>
<body>If you're reading this, your Web browser does not support 
redirection. That's OK! Simply select <a href=\"&the_url\">this link</a> 
and you will be taken to the advertiser you selected.</body>
EndFound




The result of the script is the generation of 404 error on the server. 
So I send it a URL and I get back a standard 404 - file not found page.

Any ideas?

Thanks in advance,

Sean


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

Date: Wed, 26 Mar 2003 19:21:31 GMT
From: Matt <nwzmattXX@XXnetscape.net>
Subject: Re: URL Redirection Headers
Message-Id: <u7kamvsqr.fsf@XXnetscape.net>

Sean O'Dwyer <notspam@spamfree.dud> writes:

> Hi,
> 
> I'm working on a little URL redirection/stats routine but keep getting 
> the following error:
> 
> >malformed header from script. Bad header=HTTP/1.0 302 Found:
> 
> The code I'm using is copied from "Perl 5 for Dummies" and looks like 
> this...
> 
> 
> 
> print <<"EndFound";
> HTTP/1.0 302 Found
> Location: $the_url
> Content-Type: text/html

As the error states, `HTTP/1.0 302 Found' is not a valid HTTP
header. Have a look at:

http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.2
and
http://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html#sec7.1

Basically, HTTP headers are in the form of `Header-name: value'.

<snip> 
> The result of the script is the generation of 404 error on the server. 
> So I send it a URL and I get back a standard 404 - file not found page.
> 

Not sure what you mean by "send it a URL".

Matt
-- 
Remove the X's to reply directly.


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

Date: 26 Mar 2003 12:25:30 -0700
From: Eric Schwartz <emschwar@yahoo.com>
Subject: Re: URL Redirection Headers
Message-Id: <etoptoeaq1h.fsf@wormtongue.emschwar>

Matt <nwzmattXX@XXnetscape.net> writes:
> As the error states, `HTTP/1.0 302 Found' is not a valid HTTP
> header. Have a look at:
> 
> http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.2
> and
> http://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html#sec7.1

And then use CGI.pm, which takes care of all of that for you:

#!/usr/bin/perl
use warnings;
use strict;
use CGI qw/:standard/;

print redirect($the_url);

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


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

Date: 26 Mar 2003 21:04:52 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: URL Redirection Headers
Message-Id: <u94r5px2iz.fsf@wcl-l.bham.ac.uk>

Sean O'Dwyer <notspam@spamfree.dud> writes:

> I'm working on a little URL redirection/stats routine but keep getting 
> the following error:
> 
> >malformed header from script. Bad header=HTTP/1.0 302 Found:

Looks like you are using a CGI script that's written to work in the
"non parsed header" mode of CGI with your web server configured for
the default "parsed header" mode.

> print <<"EndFound";
> HTTP/1.0 302 Found
> Location: $the_url
> Content-Type: text/html

> Any ideas?

Change "HTTP/1.0" to "Status:".

Note: your question has nothing in the slightest to do with Perl.  The
answer would have been exactly the same regardless of the language in
which your CGI script was written.

I vaguely recall that if you use the CGI Perl module rather than
rolling your own CGI response headers then it automatically adjusts
according the the NPH setting.  Then again I've never felt the need to
use NPH mode.


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

Date: Wed, 26 Mar 2003 21:47:21 GMT
From: Sean O'Dwyer <notspam@spamfree.dud>
Subject: Re: URL Redirection Headers
Message-Id: <notspam-676246.16472026032003@syrcnyrdrs-02-ge0.nyroc.rr.com>

In article <u94r5px2iz.fsf@wcl-l.bham.ac.uk>,
 Brian McCauley <nobull@mail.com> wrote:

> Looks like you are using a CGI script that's written to work in the
> "non parsed header" mode of CGI with your web server configured for
> the default "parsed header" mode.
> 
> > print <<"EndFound";
> > HTTP/1.0 302 Found
> > Location: $the_url
> > Content-Type: text/html
> 
> > Any ideas?
> 
> Change "HTTP/1.0" to "Status:".

Dear Brian,

Thanks for this info, which fixed the problem immediately. Sorry to post 
inappropriately, but thanks for your help.

Kind regards,

Sean


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

Date: Wed, 26 Mar 2003 21:48:53 GMT
From: Sean O'Dwyer <notspam@spamfree.dud>
Subject: Re: URL Redirection Headers
Message-Id: <notspam-E7A348.16485326032003@syrcnyrdrs-02-ge0.nyroc.rr.com>

In article <etoptoeaq1h.fsf@wormtongue.emschwar>,
 Eric Schwartz <emschwar@yahoo.com> wrote:

> > As the error states, `HTTP/1.0 302 Found' is not a valid HTTP
> > header. Have a look at:
> > 
> > http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.2
> > and
> > http://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html#sec7.1
> 
> And then use CGI.pm, which takes care of all of that for you:
> 
> #!/usr/bin/perl
> use warnings;
> use strict;
> use CGI qw/:standard/;
> 
> print redirect($the_url);


Thanks to all.

Sean


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

Date: Wed, 26 Mar 2003 22:19:48 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: URL Redirection Headers
Message-Id: <Pine.LNX.4.53.0303262201420.4023@lxplus090.cern.ch>

On Wed, Mar 26, Matt inscribed on the eternal scroll:

> > >malformed header from script. Bad header=HTTP/1.0 302 Found:

Perl FAQ part 9 is your starting point for enlightenment.

<
http://www.perldoc.com/perl5.8.0/pod/perlfaq9.html#What-is-the-correct-form-of-response-from-a-CGI-script-
>

> > print <<"EndFound";
> > HTTP/1.0 302 Found
> > Location: $the_url
> > Content-Type: text/html

> As the error states,

 ...it's a malformed response from the script, alright.

> `HTTP/1.0 302 Found' is not a valid HTTP header.

Wrong answer on two counts.  1. the context is that of a CGI response,
and 2. you're looking in the wrong part of RFC2616 anyway.

> Have a look at:
>
> http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.2

In relation to HTTP (as opposed to CGI) I give you:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.1

The hon Usenaut is trying to write an HTTP status line.  But this is
an inappropriate thing to do in a parsed-headers script.

> Basically, HTTP headers are in the form of `Header-name: value'.

For a parsed headers script, as the FAQ points out:

 The similarity between CGI response headers (defined in the CGI
 specification) and HTTP response headers (defined in the HTTP
 specification, RFC2616) is intentional, but can sometimes be
 confusing.

> > The result of the script is the generation of 404 error on the server.
> > So I send it a URL and I get back a standard 404 - file not found page.
>
> Not sure what you mean by "send it a URL".

I'm not sure that I understand just what the questioner has in mind at
that point either, but I suspect they're trying some kind of fixup.

If in fact they can deduce a good URL instead of the bad one that was
presented, then I'd agree that some kind of 3xx response is
reasonable.

Fact is, the CGI specification says that the use of a Location: CGI
response header with a fully-specified URL will result in a 302 status
by default anyway, so (for a parsed-headers script) there's no need to
send one.  But if some other status was wanted, let's say 301, then
the correct response from a parsed-headers script would be the _CGI_
response header:

Status: 301 Permanently moved

Note that this has NO counterpart as an HTTP "header", because in
HTTP protocol this would be the "status line" per section 6.1.

BUT:

As another has already commented, CGI.pm can happily do this in a
specification-conforming fashion, adjusting for parsed or NPH scripts
and so on.  So there's no need to tangle with such detail, but if you
insist on tangling with it, I'm going to have to insist you get it
right  ;-}

good luck

Am I supposed to add anything about books "for Dummies"?  I guess
I'd better keep my own counsel on that...


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

Date: Thu, 27 Mar 2003 07:49:19 GMT
From: Matt <nwzmattXX@XXnetscape.net>
Subject: Re: URL Redirection Headers
Message-Id: <uadfhpg5w.fsf@XXnetscape.net>

"Alan J. Flavell" <flavell@mail.cern.ch> writes:

> On Wed, Mar 26, Matt inscribed on the eternal scroll:
> 
> > > >malformed header from script. Bad header=HTTP/1.0 302 Found:
> 
> Perl FAQ part 9 is your starting point for enlightenment.
> 
> <
> http://www.perldoc.com/perl5.8.0/pod/perlfaq9.html#What-is-the-correct-form-of-response-from-a-CGI-script-
> >
> 
> > > print <<"EndFound";
> > > HTTP/1.0 302 Found
> > > Location: $the_url
> > > Content-Type: text/html
> 
> > As the error states,
> 
> ...it's a malformed response from the script, alright.
> 
> > `HTTP/1.0 302 Found' is not a valid HTTP header.
> 
> Wrong answer on two counts.  1. the context is that of a CGI response,
> and 2. you're looking in the wrong part of RFC2616 anyway.
> 
> > Have a look at:
> >
> > http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.2
> 
> In relation to HTTP (as opposed to CGI) I give you:
> http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6.1
> 
> The hon Usenaut is trying to write an HTTP status line.  But this is
> an inappropriate thing to do in a parsed-headers script.
> 
> > Basically, HTTP headers are in the form of `Header-name: value'.
> 
> For a parsed headers script, as the FAQ points out:
> 
>  The similarity between CGI response headers (defined in the CGI
>  specification) and HTTP response headers (defined in the HTTP
>  specification, RFC2616) is intentional, but can sometimes be
>  confusing.
> 

I stand corrected. :-)

-- 
Remove the X's to reply directly.


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

Date: Thu, 27 Mar 2003 11:21:48 -0600
From: Ivan Marsh <annoyed@you.now>
Subject: Using perl to read/write Excel and Foxpro?
Message-Id: <b5vbt8$6st$1@grandcanyon.binc.net>

Hey Folks,

I'm new to the Perl groups and I'm at the "Hello World" point in my 
experience with Perl. If my question is outside the purview of the groups 
I've posted to please let me know.

My next project is to parse MS Excel spreadsheets into either Foxpro or 
dBase .dbf files. For cross-compatibility sake (Linux, SCO and Win32 
platforms all being used here), and using tools that are already common to 
our site, I'm hoping that Perl will be a good tool to do this.

Can anyone point in to some resources for using Perl with these file 
formats? Required/available modules, example code etc...

thx i.m.


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

Date: Thu, 27 Mar 2003 14:43:25 -0000
From: "Adam Fernie" <adam_fernie@hotmail.com>
Subject: using unix "at" from perl script
Message-Id: <f6Ega.132$qi3.99@newsfep3-gui.server.ntli.net>

Hi,

I want to get my perl script to execute on the unix command line the "at"
program that will schedule a job for later on.

In unix you type:

> at now + 5 minutes [return]
> /home/me/program.exe [return]
> [control-D]

I've tried with backticks using:

`at now + 5 minutes\n /home/me/program.exe\n\cD`;

but it seems to ignore the control-d at the end of the line.

Anybody any idea what im doing wrong?

Thanks in advance.

Adam




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

Date: Thu, 27 Mar 2003 15:30:00 +0000
From: news@roaima.freeserve.co.uk
Subject: Re: using unix "at" from perl script
Message-Id: <od5v5b.354.ln@moldev.cmagroup.co.uk>

Adam Fernie <adam_fernie@hotmail.com> wrote:
> I want to get my perl script to execute on the unix command line the "at"
> program that will schedule a job for later on.

> I've tried with backticks using:
> `at now + 5 minutes\n /home/me/program.exe\n\cD`;

> Anybody any idea what im doing wrong?

Yes. At least two things, maybe more.

1. You're using backticks but you're discarding the output. Read the
FAQ -
	perldoc -q backticks

2. You're confusing the process of typing literally at a terminal with
what's actually going on.

The "at" command reads from standard input. In your interactive session
this happens to end up being your terminal, and you signify its completion
with (in your case) Ctrl/D. So, you'd need something like this -

	open (AT, "| at now + 5 minutes") or die "Can't start 'at': $!";
	print AT "/home/me/program.exe\n" or die "Can't write to 'at': $!";
	close AT or die "Can't complete 'at': $!";

Actually, if you don't mind a dirty shortcut you can simplify this
somewhat -

	system ('echo /home/me/program.exe | at now + 5 minutes') and
	    die "Can't 'at': $!";

Chris
-- 
@s=split(//,"Je,\nhn ersloak rcet thuarP");$k=$l=@s;for(;$k;$k--){$i=($i+1)%$l
until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}


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

Date: Thu, 27 Mar 2003 16:42:02 +0100
From: "Paul van Eldijk" <rev_1318@hotmail.com>
Subject: Re: using unix "at" from perl script
Message-Id: <pan.2003.03.27.15.42.01.622230@hotmail.com>

On Thu, 27 Mar 2003 14:43:25 +0000 Adam Fernie wrote:

> Hi,
> 
> I want to get my perl script to execute on the unix command line the "at"
> program that will schedule a job for later on.
> 
> In unix you type:
> 
>> at now + 5 minutes [return]
>> /home/me/program.exe [return]
>> [control-D]
> 
> I've tried with backticks using:
> 
> `at now + 5 minutes\n /home/me/program.exe\n\cD`;
> 
> but it seems to ignore the control-d at the end of the line.
> 
> Anybody any idea what im doing wrong?
> 
> Thanks in advance.
> 
> Adam

Try something like:

#!/usr/bin/perl

use warnings;
use strict;

my $at = 'at now +5 minutes';

open AT, "|-", $at or die "can't start at: $!\n";

print AT "ls -l\n";
print AT "date\n";

close AT or die "can't close at: $!\n";

Cheers,
Paul

-- 
$_=q{ ^4;c;14;1b:a^5;16:c^17:e^a;11;19:h^9;15:j^0:k^18:l^13
:n^6:o^7:p^10:r^b;12;1a:s^2:t^3;8:u^1};s{(?<=[;^])(\d)?([\d
abc])}{$a=$1;$2=~/([abc])/?$a*13+ord($1)%87:$1*13+$2}egx;
for(split/:/){($a,@_)=split/[;^]/;@@[@_]=($a)x@_}print@@



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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.  

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 4771
***************************************


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