[17303] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4725 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 25 18:11:00 2000

Date: Wed, 25 Oct 2000 15:10:31 -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: <972511829-v9-i4725@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 25 Oct 2000     Volume: 9 Number: 4725

Today's topics:
    Re: How to tell if a directory is empty (Linux). <Lackas@clackas.de>
        IO::Socket, HTTP POST vs. GET <jihad.battikha@sharewire.com>
    Re: memory allocation and my <tim@ipac.caltech.edu>
    Re: memory allocation and my <mauldin@netstorm.net>
        Newbie 5defcon5@my-deja.com
    Re: numbering matches <Allan@due.net>
    Re: numbering matches <mjcarman@home.com>
    Re: numbering matches (Craig Berry)
    Re: Object destructors not working properly? <tim@ipac.caltech.edu>
    Re: Object destructors not working properly? <MBalenger@worldnet.att.net>
        Objects <two_roads_diverged@my-deja.com>
    Re: Objects <uri@sysarch.com>
    Re: perl -MO=CC,-O2,-oprog.c prog.pl ?? <Jonathan.L.Ericson@jpl.nasa.gov>
    Re: perl -MO=CC,-O2,-oprog.c prog.pl ?? <tim@ipac.caltech.edu>
        Perl extension in C on Win98 <david@nomail.please>
        perl not resolving dns in a cgi script <dpalmeNOSPAM@unitedtraffic.com>
    Re: Perl Program Problem (Noghri)
        Problemi con Perl !! <teokfss@tiscalinet.it>
    Re: Processing an Email (sendmail) attachment with Perl <gary@dkstat.com>
    Re: regex changes in 5.6 <ren.maddox@tivoli.com>
    Re: regular expression joelyhughes@my-deja.com
    Re: renaming local() (David Wall)
    Re: socket flushing problem <uri@sysarch.com>
        Spaces to tab equilibrium1@my-deja.com
    Re: Two Perl-ODBC Problems - Help! <gellyfish@gellyfish.com>
        update a <SELECT> button <maxime.fruit@libertysurf.fr>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Wed, 25 Oct 2000 21:58:21 +0200
From: Christian Lackas <Lackas@clackas.de>
Subject: Re: How to tell if a directory is empty (Linux).
Message-Id: <uleevsssdnfhoath5f20ut49jeq5r9g3ht@clackas.de>

On 25 Oct 2000 16:11:10 +0200, mriedel@neuearbeit.de (Marko R. Riedel)
wrote:

Hello Marko,

>Please respond if you know of a more perlish and/or more efficient way
>(less code) to rewrite my procedure.

>sub dirIsEmpty {
>  my ($name) = @_;
>  my ($result, $entry) = (1);
>
>  opendir DIR, $name or die "can't opendir $name: $!";
>
>  while (defined ($entry = readdir DIR)){
>    if(! ($entry  =~ /^\.{1,2}$/)){
>      $result = 0;
>      last;
>    } 
>  }
>
>  closedir DIR;
>  return $result;
>}

You can write it a little bit shorter:

sub dirIsEmpty {
        opendir D, $_[0] or die $!;
        (my @a=readdir D) <= 2;
}

or with 5.6.0+
sub dirIsEmpty {
        opendir my $x, $_[0] or die $!;
        (my @a=readdir $x) <= 2;
}
The handle is implicitly closed if $x runs out of scope.

dewa mata
 Christian

-- 
Wenn der Blitz den Saustall streift, glaubt so manches Schwein, es pfeift.
http://www.clackas.de/ Perl Delphi Linux MP3 Searchengines Domainchecker


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

Date: Wed, 25 Oct 2000 17:49:36 -0400
From: Jihad Battikha <jihad.battikha@sharewire.com>
Subject: IO::Socket, HTTP POST vs. GET
Message-Id: <39F75570.C2942928@sharewire.com>

I'm having a mental block with something that might be simple, but I'm
not sure how to deal with it.

I'm trying to create a simple HTTP logging daemon using low-level socket
code rather than some high-level modules like LWP::UserAgent,
HTTP::Daemon, HTTP::Request, or HTTP::Response.  I don't want to go into
detail as to why I want a lower level of control, but part of the reason
is to manipulate chucks of the headers mid-stream (back and forth) and
to help me with debugging other scripts which *do* use high-level
modules.

Anyway, here's an extremely simple snippet which works fine for requests
without body entities:

my $server = IO::Socket::INET->new(LocalPort => 8010,
                                   Type      => SOCK_STREAM,
                                   Listen    => 10) or die "$@\n";
my $client;
while ($client = $server->accept()) {
  my ($METHOD, $URI, %HEADERS);
  last if (/^\r\n$/);
  if (/^([A-Z]+)\s+(.+)\s+HTTP/) {
    ($METHOD, $URI) = ($1, $2);
  } elsif (/^(.+?):\s*(.+)/) {
    $HEADERS{$1} = $2;
  }
}

What I'm having a problem grasping is how to grab the entity/message
body (payload) for methods like POST or PUT.  From what I understand,
the content for a POST comes after the normal headers (after the first
CRLF - empty line) which means I need to continue fetching from the
$client handle, even after the first CRLF (\r\n) in order to get the
POST data.  However, when I do this, the $client socket seems to block
and I'm never able to grab the POST data (I'm testing with MSIE and NN).

What am I missing?  Does the $client socket need some sort of response
from the server before sending the rest of the request?  How do I keep
the socket from blocking?  I'm on Win32 using Perl 5.005 (so I fork() is
not available).  The rest of my script works fine and handles multiple
connections, and the connections go through it transparently - except
for requests containing a "payload" like POST or PUT.  I've read through
the HTTP/1.1 RFC but could not discern an answer from it.  I also tried
sifting through higher-level modules like HTTP::Daemon, but they're all
a bit too intricate for me to completely comprehend.

-- 
Jihad Battikha <jihad.battikha@sharewire.com>
  Sharewire, Inc. --- http://www.sharewire.com/
    - Free forms, programs, and content for web sites.
    - No assembly required.

Disclaimer:
Before sending me commercial e-mail, the sender must first agree
to my LEGAL NOTICE located at: http://www.highsynth.com/sig.html




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

Date: Wed, 25 Oct 2000 12:20:08 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: memory allocation and my
Message-Id: <39F73268.31DE8846@ipac.caltech.edu>

Jim Mauldin wrote:
> 
> As a related matter, it should be noted that if my @data is declared in
> the outermost part of the while loop:
> 
> while(<FILE>) {
>    my @data;
>    if(/^foo/) {
>       @data = split(/:/);
>       &sub_func(\@data);
>    }
> }
> 
> it is only created once (and, of course, goes out of scope at the end of
> the while loop).

This does not appear to be true in general:

perl -wle 'my $r; for (0..1) { my @a=(0); if(! $_) { $r=\@a; @a=(1); } print
"$_: $$r[0] $a[0]"; }'
0: 1 1
1: 1 0

--

-- Tim Conrow         tim@ipac.caltech.edu                           |


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

Date: Wed, 25 Oct 2000 21:03:04 GMT
From: Jim Mauldin <mauldin@netstorm.net>
Subject: Re: memory allocation and my
Message-Id: <39F74A11.408CAD05@netstorm.net>

Tim Conrow wrote:
> 
> Jim Mauldin wrote:
> >
> > As a related matter, it should be noted that if my @data is declared in
> > the outermost part of the while loop:
> >
> > while(<FILE>) {
> >    my @data;
> >    if(/^foo/) {
> >       @data = split(/:/);
> >       &sub_func(\@data);
> >    }
> > }
> >
> > it is only created once (and, of course, goes out of scope at the end of
> > the while loop).
> 
> This does not appear to be true in general:
> 
> perl -wle 'my $r; for (0..1) { my @a=(0); if(! $_) { $r=\@a; @a=(1); } print
> "$_: $$r[0] $a[0]"; }'
> 0: 1 1
> 1: 1 0

Ah, yes, but when you start using references you have a whole different
kettle of fish.  As long as the reference exists, so does its referant,
even though you can only reach it indirectly.  Consider the following:

{
  my $z= 17;
  $r=\$z;
}
print $$r;

Even though $z was declared as a lexical inside a block, it's value is
still accessable via the reference outside the block.

-- Jim


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

Date: Wed, 25 Oct 2000 20:09:20 GMT
From: 5defcon5@my-deja.com
Subject: Newbie
Message-Id: <8t7el8$tn6$1@nnrp1.deja.com>

I am writing a web page that has a form taking in a username and
password.  I would like to verify this username and password against
the system password file.  Is there a module or something to help me do
this and can someone give me an example of how this module is used.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 25 Oct 2000 14:14:49 -0400
From: "Allan M. Due" <Allan@due.net>
Subject: Re: numbering matches
Message-Id: <8t780q$80q$1@slb1.atl.mindspring.net>



<drtsq@my-deja.com> wrote in message news:8t70ve$gtf$1@nnrp1.deja.com...
: I am trying to number matches in a string, by that I mean I want to insert a
: number prior to each match. So, given $animals="dog cat rat cat mouse llama
: cat cat rat", and if I want to number each "cat" I'd end up with
: $animals="dog 1) cat rat 2) cat mouse llama 3) cat 4) cat rat". The nearest
: FAQs I could find was in  perlfaq4 was "How do I change the Nth occurrence
of
: something?" and "How can I count the number of occurrences of a substring
: within a string?" but thats not really what I want. Any suggestions?

my %count;
my $animals="dog cat rat cat mouse llama cat cat rat catamount";

@count{split(/ /,$animals)} = map 1,split(/ /,$animals);
$animals =~ s/ (cat)(?= )/' '.$count{$1}++.")$1"/eg;
print $animals;

just to make it a tad more generic, leaving first and last animals as an
exersize for the OP.
--
$email{'Allan M. Due'} = ' All@n.Due.net ';
--random quote --
If the automobile had followed the same development cycle as the computer, a
Rolls-Royce would today cost $100, get one million miles to the gallon, and
explode once a year, killing everyone inside.
 - Robert X Cringely




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

Date: Wed, 25 Oct 2000 12:55:23 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: numbering matches
Message-Id: <39F71E8B.1632CAC1@home.com>

drtsq@my-deja.com wrote:
> 
> I am trying to number matches in a string, by that I mean I want to
> insert a number prior to each match. So, given 
> $animals="dog cat rat cat mouse llama cat cat rat", and if I want 
> to number each "cat" I'd end up with
> $animals="dog 1) cat rat 2) cat mouse llama 3) cat 4) cat rat". 

Here's a very simple-minded approach:
------------------------------------------------------------------
#!/usr/bin/perl -w
use strict;

my $animals = 'dog cat rat cat mouse llama cat cat rat';
my $match   = 'cat';

my $count;
my @critters = split(/\s/, $animals);

$animals = '';

foreach (@critters) {
    if ($_ eq $match) {
        $count++;
        $animals .= "$count) $_ ";
    }
    else  {
        $animals .= "$_ ";
    }
}
chop($animals); # Get rid of trailing space

print "$animals\n";
------------------------------------------------------------------
Here's another using a regex:
------------------------------------------------------------------
#!/usr/bin/perl -w
use strict;

my $animals = 'dog cat rat cat mouse llama cat cat rat';
my $match   = 'cat';
my $count = 0;
sub repl {
    my $val = shift;
    $count++;
    return "$count) $val";
}

$animals =~ s/\b($match)\b/&repl($1)/eg;

print $animals;
------------------------------------------------------------------

There are undoubtably other methods.

-mjc


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

Date: Wed, 25 Oct 2000 20:32:19 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: numbering matches
Message-Id: <svegqjfjjqpl59@corp.supernews.com>

drtsq@my-deja.com wrote:
: I am trying to number matches in a string, by that I mean I want to insert a
: number prior to each match. So, given $animals="dog cat rat cat mouse llama
: cat cat rat", and if I want to number each "cat" I'd end up with
: $animals="dog 1) cat rat 2) cat mouse llama 3) cat 4) cat rat".

  $_ = 'dog cat rat cat mouse llama cat cat rat';
  my $index = 0;
  s/\b(cat)\b/++$index . ") $1"/eg;

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Quidquid latine dictum sit, altum viditur."
   |


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

Date: Wed, 25 Oct 2000 11:13:46 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: Object destructors not working properly?
Message-Id: <39F722DA.C8143878@ipac.caltech.edu>

Interesting thread. Very educational, and a little scary.

Sverre Froyen wrote:
> 
> I am seeing a similar problem.  Consider the Perl script:
> 
> test.pl
> ------
> #!/usr/local/bin/perl
> use Director;
> $d = Director->new();

In accordance with the explanation (quoted elsewhere in this thread) by Michael
Balenger <MBalenger@worldnet.att.net>, you can fix the problem by undef'ing $d
explicitly.

> 
> and the Perl modules:
> 
> #!/usr/local/bin/perl
> #
> # Class Director
> #

Interestingly, you can also fix the problem by adding

use strict;
use warnings;

in this file. Either one alone won't fix the problem, but adding both does. I'd
love to hear an explanation of this.

Is anyone taking the POV that this is a bug? This level of surprise behavior
even if explicable, seems ... unfortunate.

--

-- Tim Conrow         tim@ipac.caltech.edu                           |


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

Date: Wed, 25 Oct 2000 19:18:53 GMT
From: "Michael Balenger" <MBalenger@worldnet.att.net>
Subject: Re: Object destructors not working properly?
Message-Id: <xmGJ5.5773$MR3.322911@bgtnsc04-news.ops.worldnet.att.net>

> > That had a better answer: Because the containing object was actually
> > contained by another object.  I had created a module level cache to
> > speed up subsequent lookups.  The cache was held in a file scoped
> > hash.  That hash referenced my containers.
>
> Such caches should contain weak references.

Weak references?

Being a 5.005 kinda' guy, I didn't understand, so I looked at my (recently
received, but not yet consumed) 3rd Edition of the Camel Book.  Page 266 -
"Garbage Collection, Circular References, and Weak References" contains a
discussion of circular references { my $a; $a = \$a; } and caches.  It
concisely (in 1 page) pulls together all the thoughts I rambled through in
my previous posting.  Check it out!!!

To quote the final paragraph:
    "To use this feature, you need the WeakRef package from CPAN, which
contains additional documentation.  Weak references are an experimental
feature.  But hey, somebody's gotta be the guinea pig."

More power through weak referencing!!!

Without even reading about the package, however, solving these kinds of
"bugs/problems/issues" appears to me to be a chicken-and-egg problem.  If I
originally knew enough to "use WeakRef", I'd have also known enough to
END{ undef %cache }".  The hard part here isn't the syntax, it's the
semantics - a complex brew infused with scoping rules; lifetime rules; and
multi-pass, reference-counted GC.

--
Mike Balenger
    MBalenger@att.net   (or MichaelRunningWolf@att.net)
    (732)809-3613   cell

        All mammals learn by playing.





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

Date: Wed, 25 Oct 2000 18:45:06 GMT
From: two_roads_diverged <two_roads_diverged@my-deja.com>
Subject: Objects
Message-Id: <8t79nf$p77$1@nnrp1.deja.com>

Thanks in advance.

Is there are particular name given to the dot as used
in "object.method?"


--
Thanks for your Time.

Joey


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 25 Oct 2000 19:36:36 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Objects
Message-Id: <x7itqgn263.fsf@home.sysarch.com>

>>>>> "trd" == two roads diverged <two_roads_diverged@my-deja.com> writes:

  trd> Thanks in advance.
  trd> Is there are particular name given to the dot as used
  trd> in "object.method?"

yes, we call it illegal perl syntax.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Wed, 25 Oct 2000 11:49:37 -0700
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: perl -MO=CC,-O2,-oprog.c prog.pl ??
Message-Id: <39F72B41.8FF16837@jpl.nasa.gov>

Richard Lawrence wrote:
> and a (fairly scarey looking) c file. But when I look at the code it
> references header files such as
> 
> #include "EXTERN.h"
> #include "perl.h"
> #include "XSUB.h"
> #include "cc_runtime.h"
> 
> which I don't have.
> 
> Does anyone know where I can find these header files or can anyone show
> me what I'm doing wrong?

These are included in the perl source distrubution.  You really should
read perldoc -q compile, which talks about why this might not be a good
idea.

Jon
-- 
Knowledge is that which remains when what is
learned is forgotten. - Mr. King


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

Date: Wed, 25 Oct 2000 12:08:18 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: perl -MO=CC,-O2,-oprog.c prog.pl ??
Message-Id: <39F72FA2.9992CAC4@ipac.caltech.edu>

Richard Lawrence wrote:
> I saw something somewhere that mentioned that you could convert perl
> code to c using the line:
> 
>   perl -MO=CC,-O2,-oprog.c prog.pl
> 
> So I gave it a go with a simple hello world program and true enough I
> got:
> 
> Prescan
> Saving methods
> Loaded B
> Loaded IO
> Loaded Fcntl
> prog.pl syntax OK
> 
> and a (fairly scarey looking) c file. But when I look at the code it
> references header files such as
> 
> #include "EXTERN.h"
> #include "perl.h"
> #include "XSUB.h"
> #include "cc_runtime.h"
> 
> which I don't have.
> 
> Does anyone know where I can find these header files or can anyone show
> me what I'm doing wrong?

Those files came with your perl distribution and will reside where ever that is
on your disk.

See

perldoc -q 'compile.*Perl.*C'

This FAQ entry has some warnings to ground your expectations. The bottom line is
you probably don't want to try and do anything useful compiling Perl into C.
Yet. If you decide to sally forth anyway, read

perldoc perlcompile
perldoc perlembed

--

-- Tim Conrow         tim@ipac.caltech.edu                           |


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

Date: Wed, 25 Oct 2000 22:02:01 GMT
From: "David A Ireland" <david@nomail.please>
Subject: Perl extension in C on Win98
Message-Id: <tLIJ5.15015$Ab3.80262@news-server.bigpond.net.au>

I'm trying to create an elementary Perl extension in C using Perl 5.005_05
(ActivePerl Build 522) under Windows 98se. I'm following the instructions
for
the very basic "Hello World" example in the perlxstut manual.

When I try C:>perl makefile.pl
I get the messages:
-----
Checking if your kit is complete...
Looks good

General failure reading device
Abort, Retry, Fail?
-----
And then all sorts of nasty problems that generally require a reboot.

Any advice?

David Ireland





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

Date: Wed, 25 Oct 2000 13:39:41 -0500
From: "D.W." <dpalmeNOSPAM@unitedtraffic.com>
Subject: perl not resolving dns in a cgi script
Message-Id: <8t79o8$hv9$1@nntp9.atl.mindspring.net>

I have a section of code which used the system parameter to resolve an ip
address to a host name; but its not working.  It returns a null or blank
field.

This is running on an apache server, which has hostname lookups on.

Is there something else I should check or a module that needs to be
installed?

Douglas





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

Date: Wed, 25 Oct 2000 19:52:17 GMT
From: noghri@nospam.com (Noghri)
Subject: Re: Perl Program Problem
Message-Id: <39f739e0.14702851@enews.newsguy.com>

Ouch...well thanks for helping me get started
-Noghri

On Wed, 25 Oct 2000 07:07:37 -0400, tadmc@metronet.com (Tad McClellan)
wrote:

>On Wed, 25 Oct 2000 04:16:57 GMT, Noghri <noghri@nospam.com> wrote:
>>First off I have this perl script that I've been trying to get to run.
>>Here's a copy of the script.
>>**********************************************************************************
>>#!/usr/local/bin/perl
>
>
>#!/usr/local/bin/perl -w
>use strict;
>
>
>
>>print "\nWhat would you like the password to be?  ";
>>$pword=<stdin>;
>>print "\nRepeat?  ";
>>$ppword=<stdin>;
>>
>>while($ppword ne $pword)
>
>
>A policy where everyone's password must end with a newline is
>rather strange...
>
>
>>chdir(~);
>
>
>~ is expanded by the _shell_ ...
>
>... but this is Perl, not the shell. Tilde does not mean home dir in Perl.
>
>You should be checking the return value too. Just because you
>_asked_ to change dirs doesn't mean you _did_ change dirs.
>
>
>   chdir or die "could not chdir to home directory  $!";
>
>
>>if (-e public_html) {chdir(public_html);}
>        ^^^^^^^^^^^
>
>Barewords are bad.
>
>Strings should be quoted.
>
>
>>system "chmod 755
>>public_html"
>
>
>Perl has a builtin chmod() function, no need to shell-out for that.
>
>
>>sub fixindex()
>>{ 
>>$#file=0;
>
>
>Global variables are Bad!
>
>
>>open(INDEX,"<index.html");
>
>
>Check the return value.
>
>Just because you _asked_ to open a file doesn't mean you _did_ open a file.
>
>
>>foreach $line <INDEX>
>
>
>Syntax error.
>
>The damn program doesn't even compile!
>
>I'm not reading any more of it.
>
>>I can't seem to figure out exactly what's wrong. Could someone help me
>>out here?
>
>
>There are *dozens* of things wrong!
>
>Delete the program and start over.



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

Date: Wed, 25 Oct 2000 20:58:24 +0200
From: "NightFlier" <teokfss@tiscalinet.it>
Subject: Problemi con Perl !!
Message-Id: <8t7ago$4ll$1@pegasus.tiscalinet.it>

    Ciao, ho un problema molto semplice, non riesco a far funzionare il
Perl.
    Ho scaricato ActivePerl buil 615 e voglio farlo avviare uno script che
converte i file *.bin in file *.txt (si chiama tbin2txt.pl), beh NON CE LA
FACCIO!! Il commando che metto è "c:\perl\perl.exe tbin2txt.pl texture.bin >
text.txt", premo INVIO, esce il terminale dove si fa lo scrolling del
contenuto del texture.bin ma non esce nessun file *.txt !!!!!!!  Gli scripts
li ho mesi nella directory c:\per\bin\, dove ho messo anche il texture.bin..
Ho windows98, il DCOM è apposto, mscvr.dll apposto, ma nON funziona!
Qualcuno ha qualche spiegazione per tutto questo???




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

Date: Wed, 25 Oct 2000 11:38:11 -0700
From: Gary <gary@dkstat.com>
Subject: Re: Processing an Email (sendmail) attachment with Perl
Message-Id: <39F72893.2280150C@dkstat.com>

Martien Verbruggen wrote:

> On Tue, 24 Oct 2000 07:56:25 -0700,
>         Gary Artim <gary@dkstat.com> wrote:
> > Martien Verbruggen wrote:
> >
> > > On Mon, 23 Oct 2000 20:06:07 -0700,
> > >         Gary J. Artim <gartim@ix.netcom.com> wrote:
> > > > Question: Can you act as an email client using Perl and
> > > > read emails and process attached files as data? We have
> > >
> > > Me, personally? Nope :)
> > >
> > > > a Website where some of the clients refuse to use our
> > > > upload page, but will email us attached, tab-delimited
> > > > files. I'd like to get them thru Perl and auto upload them
> > > > to my mysql database. Has anyone done this.
> > >
> > > You should probably have a look at the many mail related modules on
> > > CPAN. Start at search.cpan.org.
> > >
> > > You probably might be interested in Graham Barr's MailTools to parse
> > > the mail, MIME::Base64 and/or the MIMETools package, and if you need
> > > to pull it from a POP server or IMAP server you may need
> > > Mail::POP3Client, Net::POP3, Mail::IMAPClient or Net::IMAP.
> >
> > I'll have a look. We are running FreeBSD sendmail and an Apache web
> > server. We use PINE
> > as an email client, don't have any POP3 running, but I could set that up
> > and try the POP client.
>
> If you can access the mailbox directly, maybe Mail::Folder by Kevin
> Johnson is something you can use. However, I would probably write a
> script that processes single emails, and invoke that from your
> ~/.forward or maybe from procmail, depending on whether you need to
> filter other mail as well. It's not hard to do. I run a few scripts
> here, using Mail::Internet from Graham Barrs MailTools package. All it
> needs to do is read one single email message from STDIN, with
>
> my $mail = Mail::Internet->new(\*STDIN);
>
> and it's a doddle. I can't imagine decomposing the mail into
> attachments would be too hard either, although I haven't done that
> myself.  Since the script reads from STDIN, you might even be able to
> use it from pine, by piping the email message through it (although I
> don't know whether pine can do that. Mutt can)
>
> Writing a full client that access mail boxes and does the right
> and correct locking might be a bit onerous. if you had IMAP or POP, it
> would be easier.
>
> Martien
> --
> Martien Verbruggen              |
> Interactive Media Division      |
> Commercial Dynamics Pty. Ltd.   | values of Beta will give rise to dom!
> NSW, Australia                  |

Hi Martien,
Thanks for all the advice. I decided to install the qpopper on the mail
server end. Then install net::pop3 and mime::base64 on
the client side. Hopefully I can get at the attached file and convert it back
to tabdelimited for loading to mysql. If this NEWs
item is still around I'll post the result. Thanks again,
Gary



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

Date: 25 Oct 2000 14:37:57 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: regex changes in 5.6
Message-Id: <m3snpk1zl6.fsf@dhcp11-177.support.tivoli.com>

davidhj@mail.com writes:

> I have a subroutine which seems to be working in perl 5.004 but not 5.6.
> It's meant to read a file, removing comments after "#", and break it up
> into HTML-ish chunks by splitting before each "<" (I know this is not a
> perfect way of doing this!)
> sub readform
> {
> open (FORM, "< form.htm") || &error("Throw an error");
> local $/ = undef;
> while (<FORM>)

Kind of strange to loop when you have just set $/ to slurp in the
entire file at once.  This loop only runs once...

> 	{
> 	s/(#.*\n)?//g; 		# get rid of comments
> 				# btw, I know the ()? is unnecessary -
> 				# could this be causing problems?

In addition to what you've already mentioned, this also removes
newlines if the line has a comment, but not otherwise.  That seems
rather arbitrary.

> 	s/#.*$//;		# get rid of comment at EOF
> 	@form = split (/.{0}(?=<)/);

What is that ".{0}" trying to do?  Match any character 0 times?
Doesn't seem to be much point in that....  Even so, it should still
split on "<" (without removing it).

> 	}
> close FORM;
> }
> 
> In 5.004 this works well, and I get some nice html-ish chunks in @form.
> In 5.6 @form seems to be empty.

On some simple test data, it works fine for me with 5.6.  Looks like
the problem is elsewhere.  Perhaps you could post a self-contained
example that doesn't work.  Something like this, though as I said,
this works for me:

#!/usr/local/bin/perl -w
use strict;
my @form;
local $/ = undef;
while (<DATA>) {
    s/(#.*\n)?//g; # get rid of comments
                   # btw, I know the ()? is unnecessary -
                   # could this be causing problems?

    s/#.*$//;# get rid of comment at EOF
    @form = split (/.{0}(?=<)/);
}
print "TAG: $_\n" for @form;
__DATA__
<here is a tag> # and a <comment>
<and another tag>
# and <another comment>
__END__                       


and here it is without the silly loop... and a few other changes...

#!/usr/local/bin/perl -w
use strict;
my $data = join "", <DATA>;
$data =~ s/#.*//g;         # take out all the trailing comments
                           # works because . doesn't match \n
$data =~ tr/\n//d;         # I decided to get rid of those newlines
print "TAG: $_\n" for split /(?=<)/, $data;
__DATA__
<here is a tag> # and a <comment>
<and another tag>
# and <another comment>
__END__                       

-- 
Ren Maddox
ren@tivoli.com


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

Date: Wed, 25 Oct 2000 19:31:27 GMT
From: joelyhughes@my-deja.com
Subject: Re: regular expression
Message-Id: <8t7cef$rpu$1@nnrp1.deja.com>

Thanks for your input guys - I will think a bit more!


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Wed, 25 Oct 2000 15:06:40 -0400
From: darkon@one.net (David Wall)
Subject: Re: renaming local()
Message-Id: <8FD892B8Bdarkononenet@206.112.192.118>

epa98@doc.ic.ac.uk (Edward Avis) wrote in
<xn93dhlkpu9.fsf@sync27.doc.ic.ac.uk>: 

>darkon@one.net (David Wall) writes:
>
>>I just finished reading Larry Wall's speech at 
>>http://archive.develooper.com/perl6-meta@perl.org/msg00427.html.  In
>>it, he mentions the possibility of renaming local() (in the paragraph
>>beginning 'Rename the local operator?'). If you'll listen to a
>>suggestion from someone who knows nothing about Perl internals, then
>>what about renaming it to 'this'?  
>
>That would confuse C++ programmers.  You should never do that :-)
>
>How about 'dynamically_scoped'?  Hmm, too verbose.  'dynamic'?

Well, bugger.  I didn't know C++ had a 'this'. The only C I've ever needed 
was enough to port a spaghetti-code Fortran program into somewhat-
structured C. That was ten years ago, and I've not needed C since then, 
much less C++.

So 'this' is out, my and our are already in use.  I'd bet 'private' has 
other meanings in other languages as well, besides being misleading.  I 
don't like 'temporary' because it's too long.  Larry Wall suggested 
'meanwhile', which has a nice sound, but I think it's too long, too.

Oh well, it was fun while it lasted. I do have some other ideas that I 
don't like quite as well: nonce, ghost, shadow, wraith, ringer, dummy, and 
phony. I'd be surprised if another computer language had a 'nonce' keyword.

-- 
David Wall  (no relation -- obviously, I suppose -- to Larry)
darkon@one.net


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

Date: Wed, 25 Oct 2000 18:50:13 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: socket flushing problem
Message-Id: <x7n1fsn4be.fsf@home.sysarch.com>

>>>>> "RBN" == Rod B Nussbaumer <bomr@lin01.triumf.ca> writes:

  RBN> Okay, I've read loads of stuff about doing TCP socket IO in perl, 
  RBN> and have a fair grasp of the basic concepts.  I've managed to
  RBN> write/modify some simple client & server testbeds, and now that 
  RBN> I'm trying to do something useful, I've bumped into a problem
  RBN> I can't solve for myself.  

use IO::Socket to replace much of your code below.

  RBN> While we're in the neighbourhood, can someone please explain
  RBN> the semantics behind 'print SOCK', 'send( SOCK,..)', and
  RBN> 'syswrite( SOCK, ... )'?  As you can see from the enclosed
  RBN> code fragments, I've tried all three methods, but from 
  RBN> this test, they all seem to behave identically.

print is a buffered output and it first writes the data into a perl
buffer and then if $| is set, flushes it to the OS buffer. syswrite
writes directly to the OS buffer and $| has no effect on it. i prefer
syswrite for all socket IO. send is basically the same as syswrite but
for sockets only (syswrite can work on files) and it can add some
special flags such as marking this message as MSG_OOB (out-of-band).

read perlipc and focus on the socket parts.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Wed, 25 Oct 2000 20:41:24 GMT
From: equilibrium1@my-deja.com
Subject: Spaces to tab
Message-Id: <8t7ghi$vlr$1@nnrp1.deja.com>

I'm trying to come up with a regex pattern that will evaluate the space
at the beginning of the line up to the non-whitespace characters in
such a way that 4 spaces are converted to tab characters and any extra
space characters left over are converted to null.
So far I have this:
$line=~s/( {4}/\t/g;

But this converts any spaces after the beginning whitespace as well,
and it doesn't convert 2 or 3 spaces into null. In other words, I am
trying to format some ASP code, but wish to leave the code (all the
characters after the initial white space) alone. Any suggestions?


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 25 Oct 2000 20:39:08 +0100
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Two Perl-ODBC Problems - Help!
Message-Id: <8t7css$san$1@orpheus.gellyfish.com>

On Tue, 24 Oct 2000 13:38:00 -0400 Stephan Gross wrote:
> 1) I'm running a SQL query on an Access database that I know has 1060
> rows.  However, the query only returns about 860.  Why the truncation?
> I thought it might be the MAXBUFSIZE but I tripled it and still the
> same result.
> 

Dont know havent seen the query you are running.

> 2) Same code as above -  I'm querying for the contents of a row which
> has 28 fields.  I get them all back, then repeat the query using the
> values I just obtained.  When I print out the SQL Statement, it looks
> fine, but when I run it, it gives me ODBC error
> Error:[-3100] [1] [0] "[Microsoft][ODBC Microsoft Access Driver]
> Syntax error (comma) in query expression 

Then you have an error in the SQL you are generating.

I am sceptical because you havent shown us anything.

/J\
-- 
Jonathan Stowe                      |     
<http://www.gellyfish.com>          |      This space for rent
                                    |


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

Date: Thu, 26 Oct 2000 00:02:28 +0200
From: Maxime <maxime.fruit@libertysurf.fr>
Subject: update a <SELECT> button
Message-Id: <39F75874.27B515F7@libertysurf.fr>

I am programming PERL (and Javascript with perl)
I have two <SELECT> buttons with different <OPTION>. The stuff is that i
choose a option in the first button, then by a "onchange" event i have
to submit the same page but now the second option button is updated. I
mean that all the second option's button depends on the choice of the
first one. how can i do this with perl ? sending a parameters with the
submit ? is CGI.pm will do that ?


Thanks !



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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V9 Issue 4725
**************************************


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