[29509] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 753 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 14 14:09:57 2007

Date: Tue, 14 Aug 2007 11:09:16 -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           Tue, 14 Aug 2007     Volume: 11 Number: 753

Today's topics:
    Re: (Re)announcing APL 2007 <bob@cosy.com>
        ANNOUNCE: Etk::Perl v0.07 chady.kassouf@gmail.com
    Re: conditional regular expressions <morfysster@gmail.com>
    Re: conditional regular expressions <wahab@chemie.uni-halle.de>
        Feedback form using cgi script <cwei83@gmail.com>
    Re: Feedback form using cgi script <pgovern@u.washington.edu>
    Re: Feedback form using cgi script <mritty@gmail.com>
    Re: Feedback form using cgi script <paduille.4061.mumia.w+nospam@earthlink.net>
    Re: Feedback form using cgi script <cwei83@gmail.com>
    Re: Pagination II <glex_no-spam@qwest-spam-no.invalid>
    Re: Pagination II <webmaster@valleywebnet.com>
    Re: Pagination II <glex_no-spam@qwest-spam-no.invalid>
    Re: perl DBI OO <brian.d.foy@gmail.com>
    Re: PERL Skipping a Call to a Sub. <joe+usenet@sunstarsys.com>
    Re: PERL Skipping a Call to a Sub. anno4000@radom.zrz.tu-berlin.de
    Re: PERL Skipping a Call to a Sub. <framness@athenet.net>
    Re: PERL Skipping a Call to a Sub. <spamtrap@dot-app.org>
    Re: PERL Skipping a Call to a Sub. anno4000@radom.zrz.tu-berlin.de
    Re: PERL Skipping a Call to a Sub. <mritty@gmail.com>
    Re: Perl, Pipes and error return codes <njc@cookie.uucp>
    Re: Perl, Pipes and error return codes <mritty@gmail.com>
    Re: Perl, Pipes and error return codes xhoster@gmail.com
    Re: Perl, Pipes and error return codes <mritty@gmail.com>
    Re: Perl, Pipes and error return codes (Jens Thoms Toerring)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 14 Aug 2007 10:54:51 -0700
From:  Bob Armstrong <bob@cosy.com>
Subject: Re: (Re)announcing APL 2007
Message-Id: <1187114091.809246.308200@x40g2000prg.googlegroups.com>

On Aug 6, 7:20 am, Paul Mansour <p...@carlislegroup.com> wrote:
> APL2007 Roll Call: Is anyone going to this?

 I'm thinking of going also , setting up some arrangement to provide
an introductory tutorial to my free and open 4th.CoSy .

My website is transiting between hosts so I don't recommend even
looking at it right now . But by the end of the month I should be
uploading a system with the Forth integrated and usable multiple
windows ala K's "electric gui" .

Hopefully by conference time , I'll have my recursive , quite APLish
syntax , interpreter working .



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

Date: Tue, 14 Aug 2007 09:40:54 GMT
From: chady.kassouf@gmail.com
Subject: ANNOUNCE: Etk::Perl v0.07
Message-Id: <JMrLu3.125L@zorch.sf-bay.org>

This is the perl bindings for Etk (Enlightenment ToolKit).
This module makes it easy to write Etk based applications in perl
using an object-oriented approach.

The latest version is always in the Enlightenment CVS repositories:
http://enlightenment.org/p.php?p=download/cvs
Stable releases are uploaded to CPAN.

--
Chady Kassouf
chady.kassouf@gmail.com
http://chady.net/




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

Date: Tue, 14 Aug 2007 14:04:50 -0000
From:  Morfys <morfysster@gmail.com>
Subject: Re: conditional regular expressions
Message-Id: <1187100290.902309.228380@w3g2000hsg.googlegroups.com>

> I could understand this intended
> to match a string like
>
>     "open(X,X,X), 3"
> or
>     "open(X,X), 2"

that's what I meant. ;)



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

Date: Tue, 14 Aug 2007 16:24:45 +0200
From: Mirco Wahab <wahab@chemie.uni-halle.de>
Subject: Re: conditional regular expressions
Message-Id: <f9shfv$2ovq$1@nserver.hrz.tu-freiberg.de>

Morfys wrote:
>> I could understand this intended
>> to match a string like
>>
>>     "open(X,X,X), 3"
>> or
>>     "open(X,X), 2"
> 
> that's what I meant. ;)

OK, then there are some solutions available,
my first trial would be something like:

 ...
my @strings = (
  "open(X,X,X), 1",
  "open(X,X,X), 3",
  "open(X,X,X), 31",
  "open(X,X), 2",
  "open(X,X), 23",
  "open(X,X), 32" );

my $n;
no strict 'refs';
my $rg = qr{\(
               (\w?)[,)]?
               (\w?)[,)]?
               (\w?)[,)]?
               (\w?)[,)]?
              ,\s+
              (??{ scalar(grep ${$_} ,1..@+) })
              $
            }x;

print "\n$_" for grep /$rg/, @strings
 ...

which is still simple and will work up to four
"entities". To make a more comprehensive version -
is left to you ;-)

The "Trick" is to check the capture groups (\w)
for 'trueness' (in grep) and take the 'number'
of positively grepped items as the content
(will be "2" or "3") of the dynamic regex
part (??{ ... }).


Regards

M.


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

Date: Tue, 14 Aug 2007 09:10:46 -0700
From:  LaMoRt <cwei83@gmail.com>
Subject: Feedback form using cgi script
Message-Id: <1187107846.094640.269580@i13g2000prf.googlegroups.com>

Hi there!

I have some problem in sending mail out from the server using the
script below
and it come error 500 internal error, pls contact server
administrator

Is there any problem with the code or ...?

Pls advise as i'm new in the cgi script :


#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);


if ($ENV{'REQUEST_METHOD'} eq 'POST') {

	read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});

	@pairs = split(/&/, $buffer);

	foreach $pair (@pairs) {
		($name, $value) = split(/=/, $pair);
		$value =~ tr/+/ /;
		$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
		$FORM{$name} = $value;
	}


open (MESSAGE,"| /usr/sbin/sendmail -t");

	print MESSAGE "To: test\test.com\n";
	print MESSAGE "From: " . $FORM{name} . ", reader\n";
	print MESSAGE "Reply-to: " . $FORM{email} . "(" . $FORM{name} . ")
\n";

	print MESSAGE "Subject: Feedback from $FORM{name} \n\n";

	print MESSAGE "$FORM{name} wrote:\n\n";
	print MESSAGE "Comment: $FORM{comment}\n\n";
	print MESSAGE "Sent by: $FORM{name} ($FORM{email}).\n";

close (MESSAGE);

&thank_you; #method call
}



sub thank_you {

print "Content-type: text/html\n\n";

print <<EndStart;

	<html>
	<head>
	<title>Thank You</title>
	</head>

	<body bgcolor="#ffffff" text="#000000">

	<h1>Thank You</h1>

	<p>Your feedback has been received. Thanks for sending it.</p>

	<hr>


EndStart

	print "<p>You wrote:</p>\n";
	print "<blockquote><em>$FORM{comment}</em></blockquote>\n\n";

print <<EndHTML;

	</body>
	</html>

EndHTML

exit(0);
}



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

Date: Tue, 14 Aug 2007 09:27:51 -0700
From:  patrick <pgovern@u.washington.edu>
Subject: Re: Feedback form using cgi script
Message-Id: <1187108871.343785.209510@j4g2000prf.googlegroups.com>

On Aug 14, 9:10 am, LaMoRt <cwe...@gmail.com> wrote:
> Hi there!
>
> I have some problem in sending mail out from the server using the
> script below
> and it come error 500 internal error, pls contact server
> administrator
>
> Is there any problem with the code or ...?
>
> Pls advise as i'm new in the cgi script :
>
> #!/usr/bin/perl
> use CGI::Carp qw(fatalsToBrowser);
>
> if ($ENV{'REQUEST_METHOD'} eq 'POST') {
>
>         read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
>
>         @pairs = split(/&/, $buffer);
>
>         foreach $pair (@pairs) {
>                 ($name, $value) = split(/=/, $pair);
>                 $value =~ tr/+/ /;
>                 $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
>                 $FORM{$name} = $value;
>         }
>
> open (MESSAGE,"| /usr/sbin/sendmail -t");
>
>         print MESSAGE "To: test\test.com\n";
>         print MESSAGE "From: " . $FORM{name} . ", reader\n";
>         print MESSAGE "Reply-to: " . $FORM{email} . "(" . $FORM{name} . ")
> \n";
>
>         print MESSAGE "Subject: Feedback from $FORM{name} \n\n";
>
>         print MESSAGE "$FORM{name} wrote:\n\n";
>         print MESSAGE "Comment: $FORM{comment}\n\n";
>         print MESSAGE "Sent by: $FORM{name} ($FORM{email}).\n";
>
> close (MESSAGE);
>
> &thank_you; #method call
>
> }
>
> sub thank_you {
>
> print "Content-type: text/html\n\n";
>
> print <<EndStart;
>
>         <html>
>         <head>
>         <title>Thank You</title>
>         </head>
>
>         <body bgcolor="#ffffff" text="#000000">
>
>         <h1>Thank You</h1>
>
>         <p>Your feedback has been received. Thanks for sending it.</p>
>
>         <hr>
>
> EndStart
>
>         print "<p>You wrote:</p>\n";
>         print "<blockquote><em>$FORM{comment}</em></blockquote>\n\n";
>
> print <<EndHTML;
>
>         </body>
>         </html>
>
> EndHTML
>
> exit(0);
>
>
>
> }- Hide quoted text -
>
> - Show quoted text -

You're missing the @ - print MESSAGE "To: test\@test.com\n";



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

Date: Tue, 14 Aug 2007 09:32:18 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: Feedback form using cgi script
Message-Id: <1187109138.188495.130120@k79g2000hse.googlegroups.com>

On Aug 14, 12:10 pm, LaMoRt <cwe...@gmail.com> wrote:
> I have some problem in sending mail out from the server using the
> script below
> and it come error 500 internal error, pls contact server
> administrator

perldoc -q 500

> Is there any problem with the code or ...?

There are many problems with this code.  Which of them might be
causing your error is impossible to determine with what you've given
us.

> Pls advise as i'm new in the cgi script :
>
> #!/usr/bin/perl

You're not using strict, or warnings.
use strict;
use warnings;

> use CGI::Carp qw(fatalsToBrowser);

The fact that you're using CGI::Carp, and yet still getting an HTTP
500 suggests that this program isn't being executed at all.  Check the
permissions of the script, and make sure the webserver user has
permission to execute it.

You're not using the CGI module, and instead trying to parse the HTTP
content yourself.
use CGI qw/:standard/;

> if ($ENV{'REQUEST_METHOD'} eq 'POST') {
>
>         read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
>
>         @pairs = split(/&/, $buffer);
>
>         foreach $pair (@pairs) {
>                 ($name, $value) = split(/=/, $pair);
>                 $value =~ tr/+/ /;
>                 $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
>                 $FORM{$name} = $value;
>         }

Eliminate all of the above, and replace with:
my %FORM;
$FORM{$_} = param($_) for param();

> open (MESSAGE,"| /usr/sbin/sendmail -t");

You're not checking the return value of this pipe.  You have no way of
knowing if the /usr/sbin/sendmail program even exists, let alone if it
was successfully started.

open my $MESSAGE, '| /usr/sbin/sendmail -t'
  or die "Could nost start sendmail: $!";

>
>         print MESSAGE "To: test\test.com\n";
>         print MESSAGE "From: " . $FORM{name} . ", reader\n";
>         print MESSAGE "Reply-to: " . $FORM{email} . "(" . $FORM{name} . ")
> \n";
>
>         print MESSAGE "Subject: Feedback from $FORM{name} \n\n";
>
>         print MESSAGE "$FORM{name} wrote:\n\n";
>         print MESSAGE "Comment: $FORM{comment}\n\n";
>         print MESSAGE "Sent by: $FORM{name} ($FORM{email}).\n";

Replace all of those MESSAGE filehandles with $MESSAGE.

> close (MESSAGE);

You're not checking the return value of closing this pipe, to know if
sendmail had any problems:
close $MESSAGE or die "Error when closing sendmail: $! ($?)\n";

>
> &thank_you; #method call

That's not a method call, it's a subroutine call, and you shouldn't be
calling it with the & on the front.

thank_you(); #subroutine call

>
> }
>
> sub thank_you {
>
> print "Content-type: text/html\n\n";

print header();

>
> print <<EndStart;
>
>         <html>
>         <head>
>         <title>Thank You</title>
>         </head>
>
>         <body bgcolor="#ffffff" text="#000000">

print start_html(-title => "Thank You");

>
>         <h1>Thank You</h1>
>
>         <p>Your feedback has been received. Thanks for sending it.</p>
>
>         <hr>

print h1("Thank you"),
      p("Your feedback has been received.  Thanks for sending it.),
      hr();

>
> EndStart
>
>         print "<p>You wrote:</p>\n";
>         print "<blockquote><em>$FORM{comment}</em></blockquote>\n\n";

print p("You wrote:"), blockquote(em($FORM{comment}));

>
> print <<EndHTML;
>
>         </body>
>         </html>
>
> EndHTML

print end_html();

>
> exit(0);

no need for that at all.

Paul Lalli



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

Date: Tue, 14 Aug 2007 11:44:02 -0500
From: "Mumia W." <paduille.4061.mumia.w+nospam@earthlink.net>
Subject: Re: Feedback form using cgi script
Message-Id: <13c3o99kb5e6343@corp.supernews.com>

On 08/14/2007 11:10 AM, LaMoRt wrote:
> Hi there!
> 
> I have some problem in sending mail out from the server using the
> script below
> and it come error 500 internal error, pls contact server
> administrator
> [...]

Look into the server logs to see what error was generated by your script.


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

Date: Tue, 14 Aug 2007 10:13:01 -0700
From:  LaMoRt <cwei83@gmail.com>
Subject: Re: Feedback form using cgi script
Message-Id: <1187111581.627531.79590@i13g2000prf.googlegroups.com>

Thanks all for the help..

I will try out the solution u all give and tested it.




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

Date: Tue, 14 Aug 2007 10:10:34 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Pagination II
Message-Id: <46c1c5ea$0$491$815e3792@news.qwest.net>

JimJx wrote:
> On Aug 13, 3:34 pm, "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
> wrote:
[...]
> I made the changes that you suggested, but when I print $sql, I get
> 'select * from valley where category like ? limit 5, 5'
> 
> Which I can tell is definitely not what I want.....

Well, what do you want? Once you know that, then modify
your program accordingly.  There is plenty of documentation
and online examples for MySQL.


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

Date: Tue, 14 Aug 2007 16:10:09 -0000
From:  JimJx <webmaster@valleywebnet.com>
Subject: Re: Pagination II
Message-Id: <1187107809.459551.66770@b79g2000hse.googlegroups.com>

On Aug 14, 11:10 am, "J. Gleixner" <glex_no-s...@qwest-spam-
no.invalid> wrote:
> JimJx wrote:
> > On Aug 13, 3:34 pm, "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
> > wrote:
> [...]
> > I made the changes that you suggested, but when I print $sql, I get
> > 'select * from valley where category like ? limit 5, 5'
>
> > Which I can tell is definitely not what I want.....
>
> Well, what do you want? Once you know that, then modify
> your program accordingly.  There is plenty of documentation
> and online examples for MySQL.

That's the problem in a nutshell.....

I have been modifying and trying different things that I have found
online, but there doesn't seem to be a good pagination script for
PERL, just for PHP.

So I am stuck with still getting the second page of the results and
all of the other pages being blank.....



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

Date: Tue, 14 Aug 2007 11:26:02 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Pagination II
Message-Id: <46c1d79b$0$10296$815e3792@news.qwest.net>

JimJx wrote:
> On Aug 14, 11:10 am, "J. Gleixner" <glex_no-s...@qwest-spam-
> no.invalid> wrote:
>> JimJx wrote:
>>> On Aug 13, 3:34 pm, "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
>>> wrote:
>> [...]
>>> I made the changes that you suggested, but when I print $sql, I get
>>> 'select * from valley where category like ? limit 5, 5'
>>> Which I can tell is definitely not what I want.....
>> Well, what do you want? Once you know that, then modify
>> your program accordingly.  There is plenty of documentation
>> and online examples for MySQL.
> 
> That's the problem in a nutshell.....
> 
> I have been modifying and trying different things that I have found
> online, but there doesn't seem to be a good pagination script for
> PERL, just for PHP.

Really? It's not terribly difficult, but I'm curious what modules
you tried that didn't work?  There seems to be a lot of them
available:

http://search.cpan.org/search?query=pagination&mode=all

> 
> So I am stuck with still getting the second page of the results and
> all of the other pages being blank.....
> 

Forget about trying to do pagination, for now.  Read the
documentation for MySQL's LIMIT syntax, to see what
is wrong with your SQL.  Until you understand the
SQL you're just wasting time "trying different things."


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

Date: Mon, 13 Aug 2007 12:04:27 -0500
From: brian d  foy <brian.d.foy@gmail.com>
Subject: Re: perl DBI OO
Message-Id: <130820071204271101%brian.d.foy@gmail.com>

In article <1187015701.377762.127150@22g2000hsm.googlegroups.com>,
<"jtbutler78@comcast.net"> wrote:

> I have a module that I instantiate a DBI connection from.  My question
> is - I am doing the right way?  It works but I dont know know I am
> making a connection to the DB each time I call getResults or am I only
> using the first connection I make.  

Although it looks like you're fine in this situation, if you're ever
curious what DBI is doing, you can use tracing feature:

   DBI->trace($level);

See the DBI docs for details

-- 
Posted via a free Usenet account from http://www.teranews.com



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

Date: Tue, 14 Aug 2007 09:26:01 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: PERL Skipping a Call to a Sub.
Message-Id: <87bqdab63a.fsf@gemini.sunstarsys.com>

framness <framness@athenet.net> writes:

> Greetings,
>
> I am coding up an online order entry application and its been going
> fairly well but I have run into a roadblock on something I know is
> going to be a head slapper. It seems unlikely but it almost appears as
> if the call to LogAttack is being skipped over. Can you spot anything
> wrong?

[...]

> Below is the code for LogAttack
> ============================
> sub LogAttack() {
               ^^

Try dropping the parens.

-- 
Joe Schaefer


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

Date: 14 Aug 2007 13:33:43 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: PERL Skipping a Call to a Sub.
Message-Id: <5idp9nF3patc6U1@mid.dfncis.de>

framness  <framness@athenet.net> wrote in comp.lang.perl.misc:
> Greetings,
> 
> I am coding up an online order entry application and its been going
> fairly well but I have run into a roadblock on something I know is
> going to be a head slapper. It seems unlikely but it almost appears as
> if the call to LogAttack is being skipped over. Can you spot anything
> wrong?
> 
> I have the following code snippet:
> ================
> my $TextFieldValue = $SubFields->param($FieldName);
> my $SubmittingIP   = $SubFields->param('ip');
> if(CSSAttack($TextFieldValue)) {
>    print LOGFILE "about to log attack.\n";
>          LogAttack($SubmittingIP, $AttackLogFile, "CSS Attack",
> $FieldName,  $TextFieldValue);
>          print LOGFILE "Past LogAttack.\n";
> }
> ================
> 
> Both the pre & post call log entries show up in my general log, but I
> see no indication PERL actually falls down into the LogAttack code.
> 
> Now, I have various print statements to create entries in my general
> log but none of them show up, not even the first one. Nor does the
> application crash as the form returns to the browser in roughly the
> state I expect it.
> 
> 
> Below is the code for LogAttack
> ============================
> sub LogAttack() {
> #Subroutine to log suspected attacks.
> #Take in the cgi object, the path & attack log file, field name, &
> value
> #Format a log entry with time, date, IP of attack, type of attack,
> field name, & value and write to the Attack Log
>    print LOGFILE "in LogAttack\n";

[snip]

Are the first bit of code and LogAttack compiled in the same package?
Are you running under "warnings"?

Anno


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

Date: Tue, 14 Aug 2007 06:53:35 -0700
From:  framness <framness@athenet.net>
Subject: Re: PERL Skipping a Call to a Sub.
Message-Id: <1187099615.207100.74090@19g2000hsx.googlegroups.com>

On Aug 14, 8:33 am, anno4...@radom.zrz.tu-berlin.de wrote:
> framness  <framn...@athenet.net> wrote in comp.lang.perl.misc:
>
>
>
> > Greetings,
>
> > I am coding up an online order entry application and its been going
> > fairly well but I have run into a roadblock on something I know is
> > going to be a head slapper. It seems unlikely but it almost appears as
> > if the call to LogAttack is being skipped over. Can you spot anything
> > wrong?
>
> > I have the following code snippet:
> > ================
> > my $TextFieldValue = $SubFields->param($FieldName);
> > my $SubmittingIP   = $SubFields->param('ip');
> > if(CSSAttack($TextFieldValue)) {
> >    print LOGFILE "about to log attack.\n";
> >          LogAttack($SubmittingIP, $AttackLogFile, "CSS Attack",
> > $FieldName,  $TextFieldValue);
> >          print LOGFILE "Past LogAttack.\n";
> > }
> > ================
>
> > Both the pre & post call log entries show up in my general log, but I
> > see no indication PERL actually falls down into the LogAttack code.
>
> > Now, I have various print statements to create entries in my general
> > log but none of them show up, not even the first one. Nor does the
> > application crash as the form returns to the browser in roughly the
> > state I expect it.
>
> > Below is the code for LogAttack
> > ============================
> > sub LogAttack() {
> > #Subroutine to log suspected attacks.
> > #Take in the cgi object, the path & attack log file, field name, &
> > value
> > #Format a log entry with time, date, IP of attack, type of attack,
> > field name, & value and write to the Attack Log
> >    print LOGFILE "in LogAttack\n";
>
> [snip]
>
> Are the first bit of code and LogAttack compiled in the same package?
> Are you running under "warnings"?
>
> Anno

Yes, they are in the same package and no I am not running with
warnings. How would do that with a cgi?



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

Date: Tue, 14 Aug 2007 10:48:56 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: PERL Skipping a Call to a Sub.
Message-Id: <m2lkce41ev.fsf@dot-app.org>

framness <framness@athenet.net> writes:

> no I am not running with warnings.

Why not? Perl's quite helpful - unless you tell it not to be, which is
what you're doing.

> How would do that with a cgi?

Same as in any other script:

use strict;
use warnings;

sherm--

-- 
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: 14 Aug 2007 15:52:57 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: PERL Skipping a Call to a Sub.
Message-Id: <5ie1epF3mk4t0U1@mid.dfncis.de>

framness  <framness@athenet.net> wrote in comp.lang.perl.misc:
> On Aug 14, 8:33 am, anno4...@radom.zrz.tu-berlin.de wrote:
> > framness  <framn...@athenet.net> wrote in comp.lang.perl.misc:
> >
> >
> >
> > > Greetings,
> >
> > > I am coding up an online order entry application and its been going
> > > fairly well but I have run into a roadblock on something I know is
> > > going to be a head slapper. It seems unlikely but it almost appears as
> > > if the call to LogAttack is being skipped over. Can you spot anything
> > > wrong?
> >
> > > I have the following code snippet:
> > > ================
> > > my $TextFieldValue = $SubFields->param($FieldName);
> > > my $SubmittingIP   = $SubFields->param('ip');
> > > if(CSSAttack($TextFieldValue)) {
> > >    print LOGFILE "about to log attack.\n";
> > >          LogAttack($SubmittingIP, $AttackLogFile, "CSS Attack",
> > > $FieldName,  $TextFieldValue);
> > >          print LOGFILE "Past LogAttack.\n";
> > > }
> > > ================
> >
> > > Both the pre & post call log entries show up in my general log, but I
> > > see no indication PERL actually falls down into the LogAttack code.
> >
> > > Now, I have various print statements to create entries in my general
> > > log but none of them show up, not even the first one. Nor does the
> > > application crash as the form returns to the browser in roughly the
> > > state I expect it.
> >
> > > Below is the code for LogAttack
> > > ============================
> > > sub LogAttack() {
> > > #Subroutine to log suspected attacks.
> > > #Take in the cgi object, the path & attack log file, field name, &
> > > value
> > > #Format a log entry with time, date, IP of attack, type of attack,
> > > field name, & value and write to the Attack Log
> > >    print LOGFILE "in LogAttack\n";
> >
> > [snip]
> >
> > Are the first bit of code and LogAttack compiled in the same package?
> > Are you running under "warnings"?
> >
> > Anno
> 
> Yes, they are in the same package and no I am not running with

Okay.  Otherwise the filehandles 'LOGFILE' would have been different
handles, explaining the effect you are seeing.

> warnings. How would do that with a cgi?

It works in a CGI script like in any other.  Put "use warnings" early
in the code.

Anno


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

Date: Tue, 14 Aug 2007 09:45:08 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: PERL Skipping a Call to a Sub.
Message-Id: <1187109908.918757.182630@g4g2000hsf.googlegroups.com>

On Aug 14, 11:52 am, anno4...@radom.zrz.tu-berlin.de wrote:
> framness  <framn...@athenet.net> wrote in comp.lang.perl.misc:
> > On Aug 14, 8:33 am, anno4...@radom.zrz.tu-berlin.de wrote:

> > > Are you running under "warnings"?

> > no I am not running with warnings. How would do that with
> > a cgi?
>
> It works in a CGI script like in any other.  Put "use
> warnings" early in the code.

I'm wagging my finger at both Sherm and Anno, who gave a technically
correct answer to this question, while (I'm assuming) knowing that
that's really not what the OP meant.

To the OP: After enabling warnings in your code as both Sherm and Anno
said, you will need to either:
(1) Look in your web server's error log.  That is where the warnings
will go, because that is where STDERR has been redirected.
(2) add the following lines to your script, and then view the source
of the output, as they will cause warnings to be printed as HTML
comments (and thus not actually seen by the browser):
use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;
#whatever setup you need before printing the header...
print header();
warningsToBrowser(1);

You need to not "turn on" warningsToBrowser until after you've printed
the header, so as to not interphere with the HTTP response status
line.  Perl will queue up any warnings that are generated, and then
print them all as HTML comments once you've turned on this feature
with the warningsToBrowser(1) line.

Paul Lalli



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

Date: Tue, 14 Aug 2007 08:11:25 -0500
From: Neil Cherry <njc@cookie.uucp>
Subject: Re: Perl, Pipes and error return codes
Message-Id: <slrnfc3aft.uf7.njc@cookie.uucp>

On Tue, 14 Aug 2007 07:00:30 -0500, Neil Cherry wrote:
> On 14 Aug 2007 04:28:33 GMT, xhoster@gmail.com wrote:
>> ncherry@comcast.net wrote:
>>> I need to run an external script and have its output displayed to
>>> the user while running. No problem something like this works fine:
>>>
>>> open(IN, "cat file|");
>>> while(<IN>) {
>>>   print ;
>>> }
>>> close IN;
>>>
>>> But what if cat returns an error in the middle of cat'ng the file?
>>
>> Then cat will probably print a message to stderr.  Also, "close IN" will
>> return false and $! and $? will be set accordingly.  See the
>> "If the file handle came from a piped open" section of perldoc -f close.
>
> Oh, do the obvious. :-)

One interesting thing, the return codes are in multiples of 256. So an
error 2 from the piped command return 512 not 2.

open(IN, "cat file|") || die "Error on pipe: $! $?";
while(<IN>) {
   print ;
}
close IN || die "Error on close: $! $?";

If 'file' doesn't exist cat returns 1 as an error code. The above
Perl code returns 256 (Error on close:  256 at foo.pl line 5)..

-- 
Linux Home Automation         Neil Cherry       ncherry@linuxha.com
http://www.linuxha.com/                         Main site
http://linuxha.blogspot.com/                    My HA Blog
Author of:    	Linux Smart Homes For Dummies


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

Date: Tue, 14 Aug 2007 07:04:07 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: Perl, Pipes and error return codes
Message-Id: <1187100247.237850.302870@g4g2000hsf.googlegroups.com>

On Aug 14, 9:11 am, Neil Cherry <n...@cookie.uucp> wrote:
> One interesting thing, the return codes are in multiples of
> 256. So an error 2 from the piped command return 512 not 2.
>
> open(IN, "cat file|") || die "Error on pipe: $! $?";
> while(<IN>) {
>    print ;}
>
> close IN || die "Error on close: $! $?";
>
> If 'file' doesn't exist cat returns 1 as an error code. The above
> Perl code returns 256 (Error on close:  256 at foo.pl line 5)..

perldoc pervar
     $CHILD_ERROR
     $?      The status returned by the last pipe close, backtick
             (``) command, successful call to wait() or
             waitpid(), or from the system() operator.  This is
             just the 16-bit status word returned by the wait()
             system call (or else is made up to look like it).
             Thus, the exit value of the subprocess is really
             ("$? >> 8"), and "$? & 127" gives which signal, if
             any, the process died from, and "$? & 128" reports
             whether there was a core dump.  (Mnemonic:  similar
             to sh and ksh.)

Paul Lalli



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

Date: 14 Aug 2007 15:10:24 GMT
From: xhoster@gmail.com
Subject: Re: Perl, Pipes and error return codes
Message-Id: <20070814111026.276$3K@newsreader.com>

Paul Lalli <mritty@gmail.com> wrote:
> On Aug 13, 10:38 pm, Neil Cherry <n...@cookie.uucp> wrote:
> > I need to run an external script and have its output displayed to
> > the user while running. No problem something like this works fine:
> >
> > open(IN, "cat file|");
> > while(<IN>) {
> >   print ;
> > }
> >
> > close IN;
>
> Please explain to me why you would open a pipe to cat, which does
> nothing but output the contents of the file, rather than simply
> opening the file itself.

Perhaps because he is reducing the script to simplest possible code that
demonstrates that which he wants to demonstrate, and therefore replaced
My_solution_to_fermats_last_problem_not_implemented_in_perl with cat?

I mean, isn't that what we tell people to do before they post here?

> open(IN, '<', 'file');
> while (<IN>) {
>   print;
> }
> close IN;

That really wouldn't illustrate the very question he is asking about, now
would it?


Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Tue, 14 Aug 2007 08:40:12 -0700
From:  Paul Lalli <mritty@gmail.com>
Subject: Re: Perl, Pipes and error return codes
Message-Id: <1187106012.817198.59230@q75g2000hsh.googlegroups.com>

On Aug 14, 11:10 am, xhos...@gmail.com wrote:
>
> That really wouldn't illustrate the very question he is asking
> about, now would it?

No, it wouldn't.  I was honestly wondering why he was using cat to
begin with.  If it was to reduce the problem to a postable example,
super.  If it was because he thought he *had* to use cat instead of
just reading a file, then I would have liked to correct him.

You'll notice that no where in my post did I accuse him of doing
anything wrong.  I merely asked for the reason he was doing it.

Paul Lalli



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

Date: 14 Aug 2007 16:51:35 GMT
From: jt@toerring.de (Jens Thoms Toerring)
Subject: Re: Perl, Pipes and error return codes
Message-Id: <5ie4snF3onvlaU1@mid.uni-berlin.de>

Neil Cherry <njc@cookie.uucp> wrote:
> On Tue, 14 Aug 2007 07:00:30 -0500, Neil Cherry wrote:
> > On 14 Aug 2007 04:28:33 GMT, xhoster@gmail.com wrote:
> >> ncherry@comcast.net wrote:
> >>> I need to run an external script and have its output displayed to
> >>> the user while running. No problem something like this works fine:
> >>>
> >>> open(IN, "cat file|");
> >>> while(<IN>) {
> >>>   print ;
> >>> }
> >>> close IN;
> >>>
> >>> But what if cat returns an error in the middle of cat'ng the file?
> >>
> >> Then cat will probably print a message to stderr.  Also, "close IN" will
> >> return false and $! and $? will be set accordingly.  See the
> >> "If the file handle came from a piped open" section of perldoc -f close.
> >
> > Oh, do the obvious. :-)

> One interesting thing, the return codes are in multiples of 256. So an
> error 2 from the piped command return 512 not 2.

That's documented - right shift it by 8 ($? >> 8) to get at the
return code, from the lower 7 bits of the low byte ($? & 127) you
should be able to find out which signal (if any) killed the pro-
gram and $? & 128 tells you if the program produced a core dump.
See also "perldoc perlvar".
                                Regards, Jens
-- 
  \   Jens Thoms Toerring  ___      jt@toerring.de
   \__________________________      http://toerring.de


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 V11 Issue 753
**************************************


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