[18663] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 831 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri May 4 00:10:31 2001

Date: Thu, 3 May 2001 21:10:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <988949410-v10-i831@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 3 May 2001     Volume: 10 Number: 831

Today's topics:
        I am a Perl Newbie.....need some help please <gary.jeffery@btinternet.com>
    Re: I am a Perl Newbie.....need some help please (E.Chang)
    Re: I am a Perl Newbie.....need some help please <jboes@qtm.net>
        Installing Module (advice for new coder) <david115@home.com>
        Lightning Talks at YAPC::NA <mjd@plover.com>
    Re: Lightning Talks at YAPC::NA (Abigail)
    Re: Lightning Talks at YAPC::NA <mjd@plover.com>
    Re: need help with editing files (Tad McClellan)
    Re: Parsing <godzilla@stomp.stomp.tokyo>
    Re: Printing HTTP headers/body in perl <Jonathan.L.Ericson@jpl.nasa.gov>
    Re: Recursing a directory tree (Anno Siegel)
    Re: Recursing a directory tree <centreman_19@NOSPAMyahoo.com>
    Re: Removing attributes <Jonathan.L.Ericson@jpl.nasa.gov>
        Script or program <root@novastar.dtdns.net>
    Re: Script or program (Craig Berry)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 4 May 2001 00:01:51 +0100
From: "Gary Jeffery" <gary.jeffery@btinternet.com>
Subject: I am a Perl Newbie.....need some help please
Message-Id: <9csoai$l2u$1@uranium.btinternet.com>

can anybody tell me what is wrong with this script.......
it doesn't seem to be emailing anyone :(

#########################################

#!/usr/bin/perl

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

$recipient='me@visual-image.co.uk';
$sender='form@form.com';
$mailer='/usr/sbin/sendmail-t';

read(STDIN,$buffer,$ENV{CONTENT_LENGTH});
@pairs=split(/&/,$buffer);

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

 open(MAIL,"|$mailer");
 print MAIL "To: $recipient\n";
 print MAIL "From: $sender\n";
 print MAIL "Subject: tester\n\n";
 print MAIL "<table width=30%>\n";
 foreach $key(keys(%formdata))
 {
  print MAIL "<tr>";
  print MAIL "<td>$key</td>";
  print MAIL "<td>$formdata{$key}</td>";
  print MAIL "</tr>";
 }
 print MAIL "</table>";
close(MAIL);

print "Mail Sent... Thank You.";




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

Date: Thu, 03 May 2001 23:40:20 GMT
From: echang@netstorm.net (E.Chang)
Subject: Re: I am a Perl Newbie.....need some help please
Message-Id: <Xns9096C82E554E6echangnetstormnet@207.106.93.86>

"Gary Jeffery" <gary.jeffery@btinternet.com> wrote in 
<9csoai$l2u$1@uranium.btinternet.com>:

>can anybody tell me what is wrong with this script.......
>it doesn't seem to be emailing anyone :(
>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 
>
>> !/usr/bin/perl
>
>print "Content-type: text/html\n\n";
>
>$recipient='me@visual-image.co.uk';
>$sender='form@form.com';
>$mailer='/usr/sbin/sendmail-t';

                            ^
For starters, you need a space here.  Testing the return value on the open 
statement would have spotted that the open failed. 

Also, you should look into learning some more about Perl and CGI rather 
than copying bits of code from dubious sources.  There is an introductory  
Perl tutorial at http://www.netcat.co.uk/rob/perl/win32perltut.html, and 
you can find others in the reference section at http://www.perl.com/.  

I will leave it to others to slaughter the code you've provided. ;)

[snip]
-- 
EBC


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

Date: Thu, 03 May 2001 22:15:54 -0400
From: Jeff Boes <jboes@qtm.net>
Subject: Re: I am a Perl Newbie.....need some help please
Message-Id: <e834ftcaf0evotvbplfflt0ve1sah8npq3@4ax.com>

At some point in time, "Gary Jeffery" <gary.jeffery@btinternet.com> wrote:

>can anybody tell me what is wrong with this script.......
>it doesn't seem to be emailing anyone :(


And meanwhile:

At some point in time, echang@netstorm.net (E.Chang) wrote:

>"Gary Jeffery" <gary.jeffery@btinternet.com> wrote in 
><9csoai$l2u$1@uranium.btinternet.com>:
>
>I will leave it to others to slaughter the code you've provided. ;)
>
>[snip]


Ooh .. a code slaughter! 

<snik-snik-snik> go the knives against the whetstone...

>
>#########################################
>
>#!/usr/bin/perl

Always use " -w" on this line. -5 points.

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

You forgot 

  use strict;

-3 points. 

>
>$recipient='me@visual-image.co.uk';
>$sender='form@form.com';
>$mailer='/usr/sbin/sendmail-t';

As otherwhere noted, the "-t" is an option, so you need a space in front of it.
-1 point.  But there are far, far more portable ways to send mail. Check into
the various Mail:: modules. -2 points, and get thee to CPAN.


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


Awp! Yagh! Blech! Pfui! -10 points!

Ahem. This went out with the dinosaurs. The portable module CGI.pm is available
on your Perl installation, unless your sysadmin is a sadistic control freak.
Your convoluted code goes away, replaced by...

use CGI qw(:standard);
my $query = new CGI;
%formdata = $query->vars;

or very nearly that. The only catch will be in multivalued parameters, which
will be represented as an array reference, rather than a string with commas
inserted (which turns out to be much easier to use in coding, because you don't
have to worry about form fields that have commas in them to start with!).

Others here will tell you that use of CGI.pm is cheatin', and you should write
your own. Yeah. Sure. You should refine your own gasoline from crude oil before
setting out on your morning commute, too...

> open(MAIL,"|$mailer");

Uh-uh. -5 points. open() returns true/false so you can check the status before
you write to the file. Here, you should have something like:

open (MAIL, "|$mailer") or die "Can't start '$mailer', error is '$!'";


> print MAIL "To: $recipient\n";
> print MAIL "From: $sender\n";
> print MAIL "Subject: tester\n\n";
> print MAIL "<table width=30%>\n";

-1 point for style. print can take more than just one string, e.g.,

print MAIL <<"End_of_message";
To: $recipient
From: $sender
Subject: tester

<table width=30%>
End_of_message

However, it looks like you're hell-bent on sending HTML mail. That's not going
to work with a text-based email system like sendmail. You'll need to send the
HTML in a document, usually as an attachment, and it gets complex from here. You
may want to rethink this, and just send the table as a tab-delimited plain-text
file. Or you can start digging into CPAN and look for modules with 'MIME' in the
title. No deduction here, because you might have really wanted to send HTML as
plaintext, I can't tell.


> foreach $key(keys(%formdata))
> {
>  print MAIL "<tr>";
>  print MAIL "<td>$key</td>";
>  print MAIL "<td>$formdata{$key}</td>";
>  print MAIL "</tr>";

Again, this could be a block of text.

> }
> print MAIL "</table>";
>close(MAIL);
>
>print "Mail Sent... Thank You.";
>

Hope this helps!


--
~~~~~~~~~~~~~~~~|It is by caffeine alone I set my mind in motion, 
Jeffery Boes    |It is by the beans of Java that thoughts acquire speed, 
jboes@qtm.net   |The hands acquire shaking, the shaking becomes a warning, 
UIN 3394914     |It is by caffeine alone I set my mind in motion. 


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

Date: Thu, 03 May 2001 23:52:03 GMT
From: Dave Atherfold <david115@home.com>
Subject: Installing Module (advice for new coder)
Message-Id: <3AF1EF54.D84B4BA5@home.com>

First post to comp.lang.perl.misc.

My web host uses NT Servers:

I wanted to use DBI module, but this was not installed on my hosts
server. I was advised to upload this module myself, and address it with
the 'require' instead of the 'use' command.

I am receiving errors when using this module that indicate I have not
installed it correctly.

Could someone please point me to somewhere where I can find more
documentation on how to install modules on a Windows machine ( without
using PPM ) Could not find at ActiveState.

Thanks

Dave


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

Date: Thu, 03 May 2001 18:22:30 -0400
From: Mark-Jason Dominus <mjd@plover.com>
Subject: Lightning Talks at YAPC::NA
Message-Id: <20010503222230.29381.qmail@plover.com>


The submission deadline for long talks at Montreal YAPC is past, but
there's still plenty of space in the Lightning Talks program.  Please
propose a talk!

Lightning talks are five-minute talks.  They're easy to conceive and
to prepare.  They're a great way for beginning speakers to get their
feet wet.  They're a great way for experienced speakers to give extra
talks without hogging all the schedule time.

For more information about lightning talks, visit

        http://perl.plover.com/lightning-talks.html             (English)
        http://perl.plover.com/lightning-talks.fr.html          (French)

If you can't think of a topic and you'd like some suggestions, visit

        http://perl.plover.com/lightning-topics.txt             (English)
        http://perl.plover.com/lightning-topics.fr.txt          (French)

For more information about Montreal YAPC, visit:

        http://www.yapc.org/America/

To submit a lightning talk, send the title and description to:

        mjd-yapc-lightning+@plover.com

The description should be at most four sentences long.  Submitters
will be notified on 6 July 2001.

Mark-Jason Dominus 	  			                 mjd@plover.com


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

Date: Fri, 4 May 2001 01:00:34 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Lightning Talks at YAPC::NA
Message-Id: <slrn9f3vpi.ed5.abigail@tsathoggua.rlyeh.net>

Mark-Jason Dominus (mjd@plover.com) wrote on MMDCCCII September MCMXCIII
in <URL:news:20010503222230.29381.qmail@plover.com>:
""  
""  The submission deadline for long talks at Montreal YAPC is past, but
""  there's still plenty of space in the Lightning Talks program.  Please
""  propose a talk!
""  
""  The description should be at most four sentences long.  Submitters
""  will be notified on 6 July 2001.


3 weeks *after* the conference?


Abigail


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

Date: Thu, 03 May 2001 22:06:09 -0400
From: Mark-Jason Dominus <mjd@plover.com>
Subject: Re: Lightning Talks at YAPC::NA
Message-Id: <20010504020609.31173.qmail@plover.com>


> The description should be at most four sentences long.  Submitters
> will be notified on 6 July 2001.

Sorry for this error; I meant of course 6 June.

The submission deadline is 31 May.


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

Date: Thu, 3 May 2001 19:04:34 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: need help with editing files
Message-Id: <slrn9f3p01.1mv.tadmc@tadmc26.august.net>

Patrick Joyce <joycefive@earthlink.net> wrote:
>I want to create a perl program that will search through a bunch of html
>files

>it goes through all the folders but doesnt modify any files.

>$sss_path  = 'c:/webpages/somespecial';
>
>opendir (SSS, $sss_path);


You should check the return value:

   opendir(SSS, $sss_path) or die "could not open '$sss_path' directory $!";


>sub ChangeFile {
>
> local $path = shift;


   my $path = shift;

You should *always* prefer lexical variables over dynamic variables.


> foreach $file (<"$path/*.html">) {


As a style point, I suggest using the named form of glob rather
than angle brackets:

   foreach $file ( glob "$path/*.html" ) {


>  open (OLD, $file);


You should always, yes *always*, check the return value from open():

   open(OLD, $file) or die "could not open '$file'  $!";


>  open (NEW, ">$file.x");


You should always, yes *always*, check the return value from open():

   open(NEW, ">$file.x") or die "could not open '$file.x' $!";


>    print NEW "<div align=\"right\"><a href=\"http://207.244.72.79\"><img
>src=\"../pix/checkout.gif\" width=\"120\" height=\"20\" alt=\"Go to
>Checkout\" border=\"0\"></a></div>\n";


Use a single quoted string there and you won't have to obfuscate
what you are printing with all of those backslashes:

   print NEW  '<div align="right"><a href="http://207.244.72.79">'
           ,  '<img src="../pix/checkout.gif" width="120"'
           ,  ' height="20" alt="Go to Checkout" border="0"></a></div>'
           ,  "\n";



Check your return values. I'll bet the $! special variable will
show why your program is failing.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Thu, 03 May 2001 17:42:23 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Parsing
Message-Id: <3AF1FAEF.BE7203DB@stomp.stomp.tokyo>

Barry Allwood wrote:

(massive snippage)

> Ive Created A Program It works fine but the parsing has
> stopped working...


Your parser has not stopped working. You never
call your parser. I've employed indentation
and formatting to make your script easier to
read. It is a mess.

Find this:


if ( &readparse )
 {
  if ($Action eq "admin")
   { &AdminMenu }
  else 
   {&DoStart}
 }


Change to:


&readparse;

if ($Action eq "admin")
 { &AdminMenu }
else 
 { &DoStart }


Your program will at least print an opening
page with those changes. You need to write
a more robust and secure parser. I will refrain
from commenting on the remainder of your program.

I will comment this is a type of error which
is exceptionally difficult to overlook. My
suggestion is you avoid writing complex
programs until you have learned Perl much
better. Your current displayed skill level
indicates you need to improve, significantly.


Godzilla!


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

Date: 04 May 2001 03:43:43 +0000
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: Printing HTTP headers/body in perl
Message-Id: <86zoctkccw.fsf@jon_ericson.jpl.nasa.gov>

"Eric" <mail@NOSPAMericmarques.net> writes:

> I want to make a perl script
> to show the headers/content the browser sends to the script in the http
> request
> i dont mean to just print the environment variables
> i want to read the exact headers/body everything the browser sends to the
> script

I am sure consulting the documentation, FAQ and forums for CGI would
be revealing.
 
> i have an idea that this info is in the STDIN
> i tried
> print STDIN;
> but it didnt work printed nothing

Perhaps you meant:

  print <STDIN>;

Jon


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

Date: 3 May 2001 23:02:40 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Recursing a directory tree
Message-Id: <9cso2g$25a$1@mamenchi.zrz.TU-Berlin.DE>

According to Brandon Thornburg <centreman_19@NOSPAMyahoo.com>:

[snippage]
 
> I think I get so tired of seeing RTFM-ism that perceiving that combined with
> what seemed like blatant commercialism, that I snapped...I am fully aware
> that there ARE people out there who do no research on their own and want all
> their questions answered with no responsiblity. It's just that lately I also
> see a lot of times when all appearances point to a poster just lying in wait
> for any chance to show how blind someone is for not finding something in the
> perldocs. It's starting to look like the first post phenomenon, and it
> drives me nuts. So, my point is, you're right, Anno, but I stand behind the
> initial impulse that made me post what I did.

There is a lot to say about what you call RTFM-ism, and much of it
has been said and will be said again in similar discussions.  Let
me pick one single point to repeat here:

You demand fewer RTFM replies.  But an RTFM that says which manual
to read and what to look for, as is the norm, is far better than
no reply at all, even if given curtly.  The alternative, an
individually crafted answer, would probably be the higher-quality
product, but there you are asking for more than the group is
ready to deliver.  There is only a handful of posters who regularly
and reliably (both more or less) answer the flood of questions that
are brought up here.  Yes, it gets so you look out for postings
that can be answered by a pointer to the manual.  Unlike your
assumption, the motive is largely not mean-ness but the wish to
save time.

You will now ask why the tone can't be friendlier.  Someone else
please answer that.

Anno


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

Date: Thu, 3 May 2001 17:03:30 -0700
From: "Brandon Thornburg" <centreman_19@NOSPAMyahoo.com>
Subject: Re: Recursing a directory tree
Message-Id: <9csrto$r98$1@fremont.ohsu.edu>

Unlike your
> assumption, the motive is largely not mean-ness but the wish to
> save time.
>
> You will now ask why the tone can't be friendlier.  Someone else
> please answer that.

eh...I think that you, Anno, and many others have no tone of mean-ness, or
at least would be misunderstood if they were thought to.

I do, however, see enough "Why are you such a loser" RTFM-ism that, just as
people with simple questions need to be careful not to fall into the trap of
laziness, so do well-meaning perldoc posters need to be careful not to find
themselves associated with those that simply intend to mock. That is, if we
prize civility on Usenet. Do you see what I mean?

And yes, I understand that there are a handful of posters reliably answering
questions...they are not my target, or, if they are, I do not intend to
disrespect the help they give, simply the mentality they *appear* to have.

All this is only important if others besides myself think so; I often think
(and am probably right to) that I am much too tolerant of certain types of
questioners. I just sometimes feel that the energy spent by some berating
people for not understanding shows, unflatteringly, where the berater's
priorities lie.




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

Date: 04 May 2001 03:33:33 +0000
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: Removing attributes
Message-Id: <864rv1lrea.fsf@jon_ericson.jpl.nasa.gov>

"Philippe Hamel" <hamel@hotmail.com> writes:

> I'm trying to delete attributes from an LDAP entry using perl and associated
> modules.  I've figured out how to remove whole entries, but if I just want
> to delete attributes from an entry, how do I do that?

I don't know the first thing about LDAP (except that I once got
Netscape mail to search the jpl.nasa.gov LDAP server).  I know even
less how the protocol works.  I don't know the name of the perl module
that speaks LDAP.  You didn't give me any perl code to work with.  You
didn't give me an error message to parse.  You didn't give me any
hints as to what your problem is.  I see you cross-posted to an LDAP
group, but this is pretty much off-topic there too (unless there is
something about the protocol that makes deleting attributes
impossible).  Please consider posting some code.

Jon


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

Date: Fri, 4 May 2001 01:45:20 +0300
From: "novastar" <root@novastar.dtdns.net>
Subject: Script or program
Message-Id: <9csn21$grk$1@usenet.otenet.gr>

I have read several confusing opinions if a perl code should called script
or program . Due to my knowledge, scripts are executed line by line. If the
last line of a script has an error then the whole code will be executed
until the last line where an error will ocur. This is different in perl
where the whole script is parsed and then executed a compiled code from the
memory.If this is right then perl code should called program; is that
correct or not ?




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

Date: Thu, 03 May 2001 23:22:27 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Script or program
Message-Id: <tf3q1jev3um7d8@corp.supernews.com>

novastar (root@novastar.dtdns.net) wrote:
: I have read several confusing opinions if a perl code should called script
: or program . Due to my knowledge, scripts are executed line by line. If the
: last line of a script has an error then the whole code will be executed
: until the last line where an error will ocur. This is different in perl
: where the whole script is parsed and then executed a compiled code from the
: memory.If this is right then perl code should called program; is that
: correct or not ?

What you call it hardly matters, of course; this is a game for the
pedantic.  Perl occupies an ambiguous position in this regard.  It is not
executed line-by-line, but it is also not compiled (and linked) once to
create an image which is then executed when the program is run.  Instead,
it is compiled on each excecution (with certain exceptions that make
things still muddier).  So you can call it either one, and you'll still be
sure to piss half the pedants off. :)

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "God becomes as we are that we may be as he is."
   |               - William Blake


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

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


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