[31845] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3108 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 1 06:09:22 2010

Date: Wed, 1 Sep 2010 03:09:06 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 1 Sep 2010     Volume: 11 Number: 3108

Today's topics:
    Re: [CGI] How to set a 404 error? <rui.maciel@gmail.com>
    Re: [CGI] How to set a 404 error? <sherm.pendley@gmail.com>
    Re: [CGI] How to set a 404 error? <rui.maciel@gmail.com>
    Re: [CGI] How to set a 404 error? <sherm.pendley@gmail.com>
    Re: [CGI] How to set a 404 error? <hjp-usenet2@hjp.at>
    Re: [CGI] How to set a 404 error? <rui.maciel@gmail.com>
    Re: [CGI] How to set a 404 error? <kkeller-usenet@wombat.san-francisco.ca.us>
    Re: [CGI] How to set a 404 error? <hjp-usenet2@hjp.at>
    Re: [CGI] How to set a 404 error? <rui.maciel@gmail.com>
    Re: ActiveState Perl 5.10 on Windows XP - can't shell!! <NoSpamPleaseButThisIsValid3@gmx.net>
        Is /proc there (from Perl on BSD) <nospam-abuse@ilyaz.org>
    Re: Is /proc there (from Perl on BSD) <ben@morrow.me.uk>
        Multidimensional array <paul@pstech-inc.com>
    Re: perldoc (was: Re: FAQ 5.23...) <brian.d.foy@gmail.com>
    Re: perldoc (was: Re: FAQ 5.23...) <brian.d.foy@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 31 Aug 2010 11:40:07 +0100
From: Rui Maciel <rui.maciel@gmail.com>
Subject: Re: [CGI] How to set a 404 error?
Message-Id: <4c7cdc0e$0$6195$a729d347@news.telepac.pt>

Keith Keller wrote:

> On 2010-08-30, Rui Maciel <rui.maciel@gmail.com> wrote:
>> In a perl CGI script, is it possible to throw a 404 error?  If so, how is
>> it done?
> 
> Read the CGI module docs under "CREATING A STANDARD HTTP HEADER".

I've tried that and failed to get a 404 error page.  According to that section of the documentation, 
the header() function has an optional parameter to specify status codes in the following manner:

print header('text/html','404 Not found');

Yet, a perl CGI script that runs that function fails to set a 404 error page on the browser, which 
was the expected outcome. 

So, can anyone provide any clues on how to write a CGI script that sets a 404 error so that the 
browser displays it's default 404 page?


Thanks in advance,
Rui Maciel




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

Date: Tue, 31 Aug 2010 08:24:50 -0400
From: Sherm Pendley <sherm.pendley@gmail.com>
Subject: Re: [CGI] How to set a 404 error?
Message-Id: <m239tvdl65.fsf@sherm.shermpendley.com>

Rui Maciel <rui.maciel@gmail.com> writes:

> Keith Keller wrote:
>
>> On 2010-08-30, Rui Maciel <rui.maciel@gmail.com> wrote:
>>> In a perl CGI script, is it possible to throw a 404 error?  If so, how is
>>> it done?
>> 
>> Read the CGI module docs under "CREATING A STANDARD HTTP HEADER".
>
> I've tried that and failed to get a 404 error page.  According to that
> section of the documentation, the header() function has an optional
> parameter to specify status codes in the following manner:
>
> print header('text/html','404 Not found');

Yes, and when I tried that it worked as expected.

> Yet, a perl CGI script that runs that function fails to set a 404 error
> page on the browser, which was the expected outcome.

You expected a page? Did you print one?
 
> So, can anyone provide any clues on how to write a CGI script that
> sets a 404 error so that the browser displays it's default 404 page?

Ah, I see the misconception now. Browsers don't have default 404 pages,
servers do. The browser will display whatever content is sent after the
headers. You can use this capability to customize the look of your 404
page to fit that of your site - some amusing examples of this can be
found at <http://fab404.com/>.

For example, take this simple script:

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    use CGI qw(:standard);
    
    print header('text/plain', '404 Not Found');
    
    print "Move along, nothing to see here...\n";

Hitting it with "curl -i", which includes HTTP headers, shows this:

    HTTP/1.1 404 Not Found
    Date: Tue, 31 Aug 2010 12:13:22 GMT
    Server: Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8l DAV/2
    Transfer-Encoding: chunked
    Content-Type: text/plain; charset=ISO-8859-1
    
    Move along, nothing to see here...

Note the correct HTTP status on the first line. If I change the script
to print the default status, the response is:

    HTTP/1.1 200 OK
    Date: Tue, 31 Aug 2010 12:16:58 GMT
    Server: Apache/2.2.14 (Unix) mod_ssl/2.2.14 OpenSSL/0.9.8l DAV/2
    Transfer-Encoding: chunked
    Content-Type: text/plain; charset=ISO-8859-1
    
    Move along, nothing to see here...

The status is different, and it's logged differently in Apache's access
log, but the content is the same, and it's displayed the same way by
a browser.

sherm--

-- 
Sherm Pendley
                                   <http://camelbones.sourceforge.net>
Cocoa Developer


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

Date: Tue, 31 Aug 2010 14:44:24 +0100
From: Rui Maciel <rui.maciel@gmail.com>
Subject: Re: [CGI] How to set a 404 error?
Message-Id: <4c7d073a$0$6207$a729d347@news.telepac.pt>

Sherm Pendley wrote:

>> Yet, a perl CGI script that runs that function fails to set a 404 error
>> page on the browser, which was the expected outcome.
> 
> You expected a page? Did you print one?
> 
>> So, can anyone provide any clues on how to write a CGI script that
>> sets a 404 error so that the browser displays it's default 404 page?
> 
> Ah, I see the misconception now. Browsers don't have default 404 pages,
> servers do. The browser will display whatever content is sent after the
> headers.

Thanks for the help, Sherm.  I believed that the standard 404 pages that usually pop up were pre-
defined pages presented by the browser then a 404 error was returned and that the fancy 404 error 
pages were soft 404s.  

So to make matters clear, in essence a 404 page is created by printing a HTTP response with a 404 
status code followed by a set of entity header fields and a document informing the users of a 404 
error, is it?


Once again thanks for the help,
Rui Maciel


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

Date: Tue, 31 Aug 2010 10:02:37 -0400
From: Sherm Pendley <sherm.pendley@gmail.com>
Subject: Re: [CGI] How to set a 404 error?
Message-Id: <m2mxs2dgn6.fsf@sherm.shermpendley.com>

Rui Maciel <rui.maciel@gmail.com> writes:

> So to make matters clear, in essence a 404 page is created by printing
> a HTTP response with a 404 status code followed by a set of entity
> header fields and a document informing the users of a 404 error, is
> it?

Yes, exactly. The document can be as simple or as fancy as you like.
If you want to mimic your server's default document, just hit a non-
existent URL on your server, and save the HTML it sends in response.

sherm--

-- 
Sherm Pendley
                                   <http://camelbones.sourceforge.net>
Cocoa Developer


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

Date: Tue, 31 Aug 2010 20:49:10 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: [CGI] How to set a 404 error?
Message-Id: <slrni7qjl6.jev.hjp-usenet2@hrunkner.hjp.at>

On 2010-08-31 14:02, Sherm Pendley <sherm.pendley@gmail.com> wrote:
> Rui Maciel <rui.maciel@gmail.com> writes:
>
>> So to make matters clear, in essence a 404 page is created by printing
>> a HTTP response with a 404 status code followed by a set of entity
>> header fields and a document informing the users of a 404 error, is
>> it?
>
> Yes, exactly. The document can be as simple or as fancy as you like.
> If you want to mimic your server's default document, just hit a non-
> existent URL on your server, and save the HTML it sends in response.

It's interesting to note that what is displayed depends on the browser.

Firefox seems to treat a 404 response exactly like a 200 response: It
just displays the content sent by the server.

IE and Google Chrome display a browser specific error page instead
(but if I remember correctly IE does this only if the error page sent by
the server is very short).

	hp


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

Date: Tue, 31 Aug 2010 20:22:30 +0100
From: Rui Maciel <rui.maciel@gmail.com>
Subject: Re: [CGI] How to set a 404 error?
Message-Id: <4c7d567b$0$6203$a729d347@news.telepac.pt>

Peter J. Holzer wrote:

> It's interesting to note that what is displayed depends on the browser.
> 
> Firefox seems to treat a 404 response exactly like a 200 response: It
> just displays the content sent by the server.
> 
> IE and Google Chrome display a browser specific error page instead
> (but if I remember correctly IE does this only if the error page sent by
> the server is very short).

It appears you are correct.  While on Chromium 5 and Firefox it rendered a blank window, on 
Konqueror 4.4.2 it presented a browser-specific default 404 error page.  I thought that all browsers 
presented the user with a default 404 page but it appears that that is only wishful thinking.


Rui Maciel


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

Date: Tue, 31 Aug 2010 13:42:11 -0700
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: [CGI] How to set a 404 error?
Message-Id: <3260l7x9db.ln2@goaway.wombat.san-francisco.ca.us>

On 2010-08-31, Rui Maciel <rui.maciel@gmail.com> wrote:
>
> It appears you are correct.  While on Chromium 5 and Firefox it rendered a blank window, on 
> Konqueror 4.4.2 it presented a browser-specific default 404 error page.  I thought that all browsers 
> presented the user with a default 404 page but it appears that that is only wishful thinking.

This then begs the question, what are you trying to accomplish in
sending a 404 response to the client?

--keith

-- 
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://www.therockgarden.ca/aolsfaq.txt
see X- headers for PGP signature information



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

Date: Wed, 1 Sep 2010 00:29:22 +0200
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: [CGI] How to set a 404 error?
Message-Id: <slrni7r0i4.n2v.hjp-usenet2@hrunkner.hjp.at>

On 2010-08-31 20:42, Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us> wrote:
> This then begs the question, what are you trying to accomplish in
> sending a 404 response to the client?

Telling the client that the requested document isn't here?

	hp


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

Date: Wed, 01 Sep 2010 00:00:13 +0100
From: Rui Maciel <rui.maciel@gmail.com>
Subject: Re: [CGI] How to set a 404 error?
Message-Id: <4c7d897c$0$6204$a729d347@news.telepac.pt>

Keith Keller wrote:

> This then begs the question, what are you trying to accomplish in
> sending a 404 response to the client?

I'm exploring the idea of generating different pages according to the values passed through the 
PATH_INFO environment variable.  More specifically, the valid PATH_INFO values lead the script to 
generate pages while the invalid PATH_INFO values lead the script to send a 404.


Rui Maciel


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

Date: Wed, 01 Sep 2010 10:58:02 +0200
From: Wolf Behrenhoff <NoSpamPleaseButThisIsValid3@gmx.net>
Subject: Re: ActiveState Perl 5.10 on Windows XP - can't shell!!??
Message-Id: <4c7e159b$0$6889$9b4e6d93@newsspool2.arcor-online.net>

On 31.08.2010 00:20, Ben Morrow wrote:
> 
> Quoth Perl Junkie <perljunkie@gmail.com>:
>> On Aug 30, 3:22�pm, Ben Morrow <b...@morrow.me.uk> wrote:
>>>
>>> Do you have either COMSPEC or PERL5SHELL set to something weird in the
>>> environment? Are you attempting to do any of this from a non-standard
>>> terminal emulator (such as 4NT)?
> 
> I presume since you didn't answer that these are all 'no's?

I agree, this is an important question.

>>> What do you get if you run
>>>
>>> � � perl -le "system 'dir'; print ":$?:${^CHILD_ERROR_NATIVE}:$!:$^E:"
>>
>> Result is:
>>
>> :65280:65280:No such file or directory:The filename or extension is
>> too long:
> 
> Something else you could try: can you start processes with
> Win32::Process? That's a good deal closer to CreateProcess(3), so it
> might give us some idea of where the problem is. (It also might give an
> accurate error indication that hasn't been stomped on by some other
> code.)

Hm... indeed very strange. As Ben mentioned CreateProcess, another idea
came to my mind. Is a "Personal Firewall" installed on your machine or
any other "security" software? If yes, that could be the cause for these
problems.

Wolf


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

Date: Wed, 1 Sep 2010 06:34:18 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Is /proc there (from Perl on BSD)
Message-Id: <slrni7rsva.tc4.nospam-abuse@powdermilk.math.berkeley.edu>

How to check that /proc is working on BSD?  And check it from Perl?
On Linux and Solaris,

  -d "/proc/$$"

is TRUE.  Apparently (by indirect guesses from output on CPANtesters),
this does not work on 3 BSD test machines (Open-, Free- and Net-).
Neither does

 perl -wle 'open PR, qq(/proc/$$/cmdline) or die $!'

on the only BSD machine I can login into (FreeBSD 7.3).

According to WikiPedia, /proc should be available.  According to
FreeBSD manpages, the file /proc/$$/cmdline should be available.

How should I interpret this?  Is /proc "very optional", and disabled
by default?

Thanks,
Ilya

P.S.  Why do I need to know?  Since gdb command set (is documented to)
      depends on the fact...


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

Date: Wed, 1 Sep 2010 08:25:12 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Is /proc there (from Perl on BSD)
Message-Id: <onb1l7-vq81.ln1@osiris.mauzo.dyndns.org>


Quoth Ilya Zakharevich <nospam-abuse@ilyaz.org>:
> How to check that /proc is working on BSD?  And check it from Perl?

Well, the obvious answer is to check the output of `/sbin/mount` for

    procfs on /proc

A decent compromise might be to compare st_dev on a stat of "/" and
"/proc".

> On Linux and Solaris,
> 
>   -d "/proc/$$"
> 
> is TRUE.  Apparently (by indirect guesses from output on CPANtesters),
> this does not work on 3 BSD test machines (Open-, Free- and Net-).

Here (FreeBSD 8.1) that is *always* true. The directory /proc exists
even if procfs isn't mounted on it. (I'm pretty certain this is true of
at least Linux, as well.) You can, however, check 

    -d "/proc/$$".

> Neither does
> 
>  perl -wle 'open PR, qq(/proc/$$/cmdline) or die $!'
> 
> on the only BSD machine I can login into (FreeBSD 7.3).

That's...weird. (Unless that machine doesn't have procfs mounted, of
course.) Again, works here (and did when I was running 7.3); and
reliably fails when procfs isn't mounted.

> According to WikiPedia, /proc should be available.  According to
> FreeBSD manpages, the file /proc/$$/cmdline should be available.
> 
> How should I interpret this?  Is /proc "very optional", and disabled
> by default?

Yes. It's also vaguely deprecated, though as you say a number of things
still depend on it, so I'm not really sure what that means. AIUI the
supported alternative for new programs is the sysctl interface, but the
whole situation is still rather unsatisfactory.

Ben



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

Date: Wed, 1 Sep 2010 05:31:03 -0400
From: "Paul E. Schoen" <paul@pstech-inc.com>
Subject: Multidimensional array
Message-Id: <z3pfo.32106$st2.3361@newsfe09.iad>

I am trying to construct an array (or possibly a hash) which consists of 
arrays. It is organized as a series of records with four text fields:

Date, Time, Title, Description

I was able to get this to work with the following ugly but functional code:

  my @E_Dates = ("20100831", "20100910");
  my $E_Time = "14:00";     #Time in hh:mm format
  my $E_Title = "Example";
  my $E_Descr = "Line 1 \nLine2";

  my $Event_DB = [[$E_Dates[0], $E_Time, $E_Title, $E_Descr]];

  $E_Time = "18:00";     #Time in hh:mm format
  $E_Title = "Example Title 2";
  $E_Descr = "Example 2 Line 1 \nExample 2 Line2";

  @E_Details = ($E_Time, $E_Title, $E_Descr); # Array of three elements

  $Event_DB->[1] =[ $E_Dates[1], $E_Time, $E_Title, $E_Descr];

  print "$Event_DB->[0][0]"; #prints first Date
  print "$Event_DB->[0][1]"; #prints first Time
  print "$Event_DB->[0][2]"; #prints first Title
  print "$Event_DB->[0][3]"; #prints first Descr

  print "$Event_DB->[1][0]"; #prints second Date
  print "$Event_DB->[1][1]"; #prints second Time
  print "$Event_DB->[1][2]"; #prints second Title
  print "$Event_DB->[1][3]"; #prints second Descr

But when I tried to use an array, I could not use the two dimensional 
indexes:

  my @E_Dates = ("20100831", "20100910");     #Date in yyyymmdd format
  my $E_Time = "14:00";     #Time in hh:mm format
  my $E_Title = "Title1";
  my $E_Descr = "Descr1-Line1 \nDescr1-Line2";

  my @Event_DB = ($E_Dates[0], $E_Time, $E_Title, $E_Descr);

  $E_Time = "18:00";     #Time in hh:mm format
  $E_Title = "Title2";
  $E_Descr = "Descr2-Line1 \nDescr2-Line2";

  push( @{Event_DB}, $E_Dates[1], $E_Time, $E_Title, $E_Descr );

  for (my $i=0; $i<@Event_DB; $i+=4) {
    print "<p>";
    print "<h3>Title $i: $Event_DB[$i+2]</h3>\n";
    print "<br><h4>Date: $Event_DB[$i]</h4>\n";
    print "<br><h4>Time: $Event_DB[$i+1]</h4>\n";
    print "<br><h5>Description: $Event_DB[$i+3]</h5></p><hr>\n";
    }

I tried everything I could find and I had no success. I originally tried to 
create a hash with the date as the index and an array for the data, about 
like this:

  my @E_Dates = ("20100831", "20100910");
  my $E_Time = "14:00";     #Time in hh:mm format
  my $E_Title = "Example";
  my $E_Descr = "Line 1 \nLine2";
 # Hash with Date as sorting key, Array of Details
  my %Event_DB = (Date=>$E_Dates[0], Details=>[$E_Time, $E_Title, 
$E_Descr]);
  $E_Time = "18:00";     #Time in hh:mm format
  $E_Title = "Example Title 2";
  $E_Descr = "Example 2 Line 1 \nExample 2 Line2";
  @E_Details = ($E_Time, $E_Title, $E_Descr); # Array of three elements
 # Adding second record with push
  push @{ $Event_DB{Date=>$E_Dates[1]}}, Details=>[$E_Time, $E_Title, 
$E_Descr];
 # Alternate method (probably very wrong)
  %Event_DB(Date=>$E_Dates[1]) = Details=>[$E_Time, $E_Title, $E_Descr];

I would like to be able to sort the array or hash by date and then format it 
to be printed as HTML. I am more familiar with C and Borland Delphi Pascal 
where this would be simple. It's probably also simple in Perl but I can't 
figure out how to do it.

TIA,

Paul 



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

Date: Tue, 31 Aug 2010 18:40:20 -0400
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: perldoc (was: Re: FAQ 5.23...)
Message-Id: <310820101840200865%brian.d.foy@gmail.com>

In article <4c7c303e$1@news.>, Xiong Changnian <xiong108@xuefang.com>
wrote:

> I have seen no native POD method of applying color, right alignment, or 
> any sort of tables. (I don't speak of table abuse but semantic tables.) I 
> do without the first, fake the next, and suffer the third to print as 
> code, in which links are rendered inconsistently. 

Then you haven't read my Pod chapter in Mastering Perl. Most of the
stuff you want should come from style sheets, which is outside of the
Pod.

I'm not saying that Pod is perfect, or even the best format. I just
don't think you have enough experience with it to make the claims you
make.


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

Date: Tue, 31 Aug 2010 18:44:04 -0400
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: perldoc (was: Re: FAQ 5.23...)
Message-Id: <310820101844044251%brian.d.foy@gmail.com>

In article <4c7c3047$1@news.>, Xiong Changnian <xiong108@xuefang.com>
wrote:


> I am the last person to do this. You omit the critical qualification: a 
> position within the Perl community. I can't play much of a political 
> role; I lack the weight. 

Well, start eating more. I didn't have any weight when I started, but I
didn't whine about that holding me back.

Perl is very easy to contribute too, technically and socially.  Anyone
can submit patches, which are judge on their merit not their source.


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

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:

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 V11 Issue 3108
***************************************


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