[21705] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3909 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 3 14:13:13 2002

Date: Thu, 3 Oct 2002 11:05:14 -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           Thu, 3 Oct 2002     Volume: 10 Number: 3909

Today's topics:
    Re: Can I control "send_te" HTML compression header? (Joe)
        cgi woes <paul.kirk@xilinx.com>
    Re: cgi woes <wsegrave@mindspring.com>
    Re: cgi woes <nuba@turmalina.dcc.ufmg.br>
    Re: cgi woes <flavell@mail.cern.ch>
    Re: Delete, then die - buy why? (Helgi Briem)
    Re: Delete, then die - buy why? news@roaima.freeserve.co.uk
    Re: Delete, then die - buy why? <s_grazzini@hotmail.com>
    Re: Delete, then die - buy why? <spikey-wan@bigfoot.com>
    Re: Delete, then die - buy why? <jurgenex@hotmail.com>
    Re: Downloading from a www server: Problem develop@gistenson.com
    Re: How to geta list of perl modules <usenet@tinita.de>
        IO::Select has limits? or how to use IO::Poll? <crudmail@cox.net>
        Keeping scripts running--socket server question (Robert Fentress)
    Re: Messages getting truncated. <nobull@mail.com>
    Re: Messages getting truncated. <pinyaj@rpi.edu>
    Re: Modifying FormMail <adam@connectpoint.co.uk>
    Re: Odd behavior for variables "a" and "b" (Tom Ewall)
    Re: odd regexp grouping issue (Shambo)
        perl loses controlling tty after exec on windows? (Average GG)
    Re: Perl script "rename" does not work... (Joel)
    Re: Perl script "rename" does not work... (Tad McClellan)
    Re: Perl Tutor Wanted - Mtn View, CA (Vishal Agarwal)
        question about speeding perl development <blahblahblah@blah.com>
    Re: reading Cobol PIC 9(6)V99 formats... <jpagnew@vcu.edu>
        reqex problem <majortom71@hotmail.com>
    Re: script.pl?parameter - can anyone help me figure thi <flavell@mail.cern.ch>
    Re: Speed optimization (with code) ctcgag@hotmail.com
    Re: Splice function with arrays (patric)
    Re: Trouble getting a status back from SMTP news@roaima.freeserve.co.uk
    Re: Trouble getting a status back from SMTP <tony_curtis32@yahoo.com>
    Re: Trouble getting a status back from SMTP <nobull@mail.com>
    Re: Two email things in Perl <adam@connectpoint.co.uk>
    Re: What is the best way for file/stream IO in Perl? <Tassilo.Parseval@post.rwth-aachen.de>
    Re: What is the best way for file/stream IO in Perl? <bart.lateur@pandora.be>
        Wow! A trivial regexp I can't do! <temp133@hotmail.com>
    Re: Wow! A trivial regexp I can't do! <Tassilo.Parseval@post.rwth-aachen.de>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 3 Oct 2002 08:08:17 -0700
From: joemercury@gmx.net (Joe)
Subject: Re: Can I control "send_te" HTML compression header?
Message-Id: <d6c57a14.0210030708.2c073a9a@posting.google.com>

> > So where can I control the compression header TE: to set it ON or OFF?
> 
> This is a bit ugly, but should work:
> 
>    push(@LWP::Protocol::http::EXTRA_SOCK_OPTS, SendTE => 0);

Thanks Gisle.
Might be ugly but it does work :).

I looked around and some people use this style to set the OPTS:
@LWP::Protocol::http::EXTRA_SOCK_OPTS=(LocalAddr => '1.2.3.4');

Is one style preferred over the other?

Anyway, I am on Windows 2000, "v5.6.1 built for MSWin32-x86-multi-thread"
and when using

   use warnings;

I get this warning and I don't know yet how to clear it:

D:\WINNT>"D:\Documents and Settings\aaaa\Desktop\Display.pl"
Name "LWP::Protocol::http::EXTRA_SOCK_OPTS" used only once: possible typo

Thanks again for your working solution.
j.


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

Date: Thu, 03 Oct 2002 16:13:37 +0100
From: Paul Kirk <paul.kirk@xilinx.com>
Subject: cgi woes
Message-Id: <3D9C5EA1.12C73722@xilinx.com>

Hello

I am trying to debug a simple piece of cgi code, I need to pass arguments to the cgi to pick for example name and email.

I have tried

name=paul; ./cginame.cgi

but it does not seem to work, how do I get this to work? My IT will not let me use the cgi section of the server until the script has been verified, which I am finding hard as I can not test it!

Cheers
Paul Kirk

--

/ /\/   Paul Kirk                              Xilinx Inc.
\ \     Customer Apps Engineer      203 Brooklands Road
/ /     Paul.Kirk@xilinx.com           Weybridge Surrey KT13 0RH
\_\/\  Eurosupport@xilinx.com       http://support.xilinx.com




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

Date: Thu, 3 Oct 2002 10:37:36 -0500
From: "William Alexander Segraves" <wsegrave@mindspring.com>
Subject: Re: cgi woes
Message-Id: <anhofn$qlg$1@slb5.atl.mindspring.net>

"Paul Kirk" <paul.kirk@xilinx.com> wrote in message
news:3D9C5EA1.12C73722@xilinx.com...
> Hello
>
> I am trying to debug a simple piece of cgi code, I need to pass arguments
to the cgi to pick for example name and email.
>
<snip>
> but it does not seem to work, how do I get this to work? My IT will not
let me use the cgi section of the server until the script has been verified,
which I am finding hard as I can not test it!

If you're allowed to install programs on your Windows workstation, you might
try IndigoPerl, available free from www.indigostar.com. After installation,
you'll have Perl and Apache on your workstation, where you'll be able to do
your testing.

Cheers.

Bill Segraves




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

Date: Thu, 3 Oct 2002 15:40:13 +0000 (UTC)
From: Nuba <nuba@turmalina.dcc.ufmg.br>
Subject: Re: cgi woes
Message-Id: <anhoct$84t$1@dcc.ufmg.br>

Paul Kirk <paul.kirk@xilinx.com> wrote:
: I am trying to debug a simple piece of cgi code, I need to pass arguments to the cgi to pick for example name and email.

Hello Paul Kirk

That's how I call my perl scrips when testing them on the shell : 
$ perl script.pl "name=value&name2=value2&nameN=valueN"  and so on...

And when a hardcore debugging is needed I use DDD :
$ ddd script.pl "name=value&name2=value2&nameN=valueN"  and so on...


It can also be usefull if you enable the debug pragma of the CGI module.
See man CGI for details.

Hope it helps,

Nuba
nuba@dcc.ufmg.br


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

Date: Thu, 3 Oct 2002 17:52:08 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: cgi woes
Message-Id: <Pine.LNX.4.40.0210031739300.27575-100000@lxplus072.cern.ch>

On Oct 3, Paul Kirk inscribed on the eternal scroll:

> I am trying to debug a simple piece of cgi code,

<digression>
It always puzzles me when folks claim their problem to be simple, even
though they haven't yet solved it.

I only recognise my problems to be (have been) simple ones _after_ I
know the solution!
</>

> I need to pass arguments to the cgi to pick for example name and
> email.

Danger, Will Robinson.  Any CGI script which uses email addresses
accepted from the web is only a whisker away from being a spam relay.

But to answer your question: CGI.pm has a simple (command-line
interface) debugging mode, as well as a -debug pragma mode which
accepts name=value parameter pairs from standard input.

> I have tried
>
> name=paul; ./cginame.cgi

That doesn't look like either of them to me, nor even a method which
might work in the absence of CGI.pm.  But assuming CGI.pm (and if not,
why not?) then:

http://stein.cshl.org/WWW/software/CGI/#debugging

good luck



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

Date: Thu, 03 Oct 2002 13:08:45 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Delete, then die - buy why?
Message-Id: <3d9c4047.2090340951@news.cis.dfn.de>

On Thu, 3 Oct 2002 12:56:13 +0100, "Richard S Beckett"
<spikey-wan@bigfoot.com> wrote:

>I have the following one line script:
>system ("del results.xls") or die "Can't delete old spreadsheet! $!\n";
>
>The file exists, and is deleted, but I then get the message:
>
>Can't delete old spreadsheet! No such file or directory
>I _really_ don't understand why!

>Can anyone see what I did wrong?

system commands return 0 if they are successful
and because it runs a daughter process, the
error is contained in $?, not $! as usual.

Therefore, your line should be:
system ("del $file) == 0 
   or die "Can't delete $file:$?\n";

BUT....

You should either give the full path to the
file to be deleted, or chdir to its directory.
I suspect that you are not really deleting the
file.

Also, it is more elegant to do the deleting without
shelling out to run a system command:

unlink $file or die "Cannot delete $file:$!\n"; 
-- 
Regards, Helgi Briem
helgi AT decode DOT is

                           A: Top posting
                           Q: What is the most irritating thing on Usenet?
                                           - "Gordon" on apihna


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

Date: Thu, 3 Oct 2002 14:26:55 +0100
From: news@roaima.freeserve.co.uk
Subject: Re: Delete, then die - buy why?
Message-Id: <vighna.quh.ln@moldev.cmagroup.co.uk>

Richard S Beckett <spikey-wan@bigfoot.com> wrote:
> system ("del results.xls") or die "Can't delete old spreadsheet! $!\n";

Take a look at the documentation for "system":

	The return value is the exit status of the program
	as returned by the "wait" call.  To get the actual
	exit value divide by 256.

A normal successful exit returns 0, so you need to negate the test in
this one case:

	system ("del results.xls") and die "Can't delete: $!\n";

As it happens, you can avoid the shell out by using built-in functions,
and this is generally more efficient (not to mention potentially more
portable):

	unlink 'results.xls' or die "...: $!\n";

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


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

Date: Thu, 03 Oct 2002 13:55:53 GMT
From: Steve Grazzini <s_grazzini@hotmail.com>
Subject: Re: Delete, then die - buy why?
Message-Id: <J%Xm9.52656$0H1.7259694@twister.nyc.rr.com>

news@roaima.freeserve.co.uk wrote:
> Richard S Beckett <spikey-wan@bigfoot.com> wrote:
>> system ("del results.xls") or die "Can't delete old spreadsheet! $!\n";
> 
> Take a look at the documentation for "system":
> 
> 	The return value is the exit status of the program
> 	as returned by the "wait" call.  To get the actual
> 	exit value divide by 256.
> 
> A normal successful exit returns 0, so you need to negate the 
> test in this one case:
> 
> 	system ("del results.xls") and die "Can't delete: $!\n";

$? is the wait() status, so that's what you usually report.

$! is probably not going to contain anything useful.

But if $? -- and the return value of system() -- is -1,
then perl's fork() or exec() has failed and $! will be 
set appropriately.

-- 
Steve

perldoc -qa.j | perl -lpe '($_)=m("(.*)")'


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

Date: Thu, 3 Oct 2002 17:05:49 +0100
From: "Richard S Beckett" <spikey-wan@bigfoot.com>
Subject: Re: Delete, then die - buy why?
Message-Id: <anhpu4$2hk$1@newshost.mot.com>


"Helgi Briem" <helgi@decode.is> wrote in message
news:3d9c4047.2090340951@news.cis.dfn.de...
> On Thu, 3 Oct 2002 12:56:13 +0100, "Richard S Beckett"
> <spikey-wan@bigfoot.com> wrote:
>
> >I have the following one line script:
> >system ("del results.xls") or die "Can't delete old spreadsheet! $!\n";
> >
> >The file exists, and is deleted, but I then get the message:
> >
> >Can't delete old spreadsheet! No such file or directory
> >I _really_ don't understand why!
>
> >Can anyone see what I did wrong?
>
> system commands return 0 if they are successful
> and because it runs a daughter process, the
> error is contained in $?, not $! as usual.
>
> Therefore, your line should be:
> system ("del $file) == 0
>    or die "Can't delete $file:$?\n";
>
> BUT....
>
> You should either give the full path to the
> file to be deleted, or chdir to its directory.
> I suspect that you are not really deleting the
> file.

The file was definitely deleted.

> Also, it is more elegant to do the deleting without
> shelling out to run a system command:
>
> unlink $file or die "Cannot delete $file:$!\n";

AHA! Thanks.




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

Date: Thu, 3 Oct 2002 09:36:01 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Delete, then die - buy why?
Message-Id: <3d9c71f2$1@news.microsoft.com>

Richard S Beckett wrote:
> I have the following one line script:
>
> system ("del results.xls") or die "Can't delete old spreadsheet!
> $!\n";
>
> The file exists, and is deleted, but I then get the message:
> Can't delete old spreadsheet! No such file or directory
> I _really_ don't understand why!
>
> Can anyone see what I did wrong?

You failed to Read The Fine Manual :-)
From "perldoc -f system"

            The return value is the exit status of the program as returned
            by the "wait" call. To get the actual exit value divide by 256.

jue




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

Date: Thu, 3 Oct 2002 17:05:36 +0000 (UTC)
From: develop@gistenson.com
Subject: Re: Downloading from a www server: Problem
Message-Id: <anhtd0$qod$1@flood.xnet.com>

Mina,

Your sample looks like what I need. I appreciate your help. (Let's see if 
I can avoid any SOC7s.)

Thanks again,
Dan


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

Date: 3 Oct 2002 17:09:51 GMT
From: Tina Mueller <usenet@tinita.de>
Subject: Re: How to geta list of perl modules
Message-Id: <anhtkv$efodq$2@fu-berlin.de>

In comp.lang.perl.misc Barry Kimelman <barryk2@delete_me.mts.net> wrote:
> How do you get a list of modules that are installed on your system
> (UNIX or windows) ? I know you can use perldoc to get info on a
> specific module, but I need to get a list of ALL the installed modules.

perldoc perllocal

hth, tina

-- 
http://www.tinita.de/        \  enter__| |__the___ _ _ ___
http://Movies.tinita.de/      \     / _` / _ \/ _ \ '_(_-< of
http://PerlQuotes.tinita.de/   \    \ _,_\ __/\ __/_| /__/ perception


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

Date: Thu, 03 Oct 2002 16:30:23 GMT
From: Joel Nelson <crudmail@cox.net>
Subject: IO::Select has limits? or how to use IO::Poll?
Message-Id: <3D9C7246.6FC48A6C@cox.net>

I am trying to build both client and server pieces that can be used to
stress test a server program being written at work.  We run these
scripts under windows (blech)...

The problem with the server piece is that I need to be able to handle at
least 1024 connections.  IO::Select seems to choke at 127
connections(clients time out), and I am having trouble trying to use
arrays of IO::Select objects.  I have also taken a look at IO::Poll but
I don't understand how to use it.  Does anyone know how I can handle
1024 connections?  Or point me to some good web sites or books that
cover this?  I have Lincoln Steins "Network Programming with Perl" but
it doesn't go into dealing with this many connections and I can't get
the IO::Poll example converted to work for me.  Help!!!!   :-)

The other piece I am writing is a single script that can launch the 1024
connections.  I'll probably run into the same issues for
lots-o-connections but I may be able to run the same script multiple
times in different DOS windows and even on multiple machines.  Of
course, I'd rather not.

Tx!



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

Date: 3 Oct 2002 10:27:32 -0700
From: rfentres@vt.edu (Robert Fentress)
Subject: Keeping scripts running--socket server question
Message-Id: <dcfa599d.0210030927.73524ef2@posting.google.com>

I've developed a socket server in perl for a flash-based chat
application.  I'm running it on a commercial web host, and though I
have my code in a loop that keeps the script open until I tell it to
close, I think there must be a timeout for perl scripts set on the
server, because the script shuts down automatically every few minutes.
 Does anybody know a way I can override this in my script, or do I
need to contact my server administrator?

Thanks,
Rob


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

Date: 02 Oct 2002 18:05:14 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Messages getting truncated.
Message-Id: <u9adlwojp1.fsf@wcl-l.bham.ac.uk>

"No Spam Please" <nospam@nospam.com> writes:

> We have an email support system which is implemented in
> Perl and invoked by having an alias in the aliases file...
> 
>     support: "|/some/path/supportscript.pl"
> 
> The script first sucks the whole message into a string like this...
> 
>     $/ = 0777;    # Don't break at newlines

> I've collected several of the truncated messages to see if I
> can find a pattern.

>     Message-ID: <DAC15316530ED511

I take it the last three characters are always "511".

> I'm wondering if my problem might be setting $/ = 0777 to make the
> <STDIN> give me the whole message.  Could Perl be assuming I meant
> "0777" as a string instead of 0777 the octal number (which would be
> 0x01FF and not possible in any 8 bit stream -- that's the point)

Actually Perl thinks you mean the string "511" since numeric value in
a string context is converted into a string using decimal.  There's
nothing special about $/ in this respect.

my $foo = 0777; # Sets $foo to the number 511
my $bar = "$foo"; # Sets $bar to string "511"

Is there any reason you can't just make $/ undef like everybody else?

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Thu, 3 Oct 2002 13:23:42 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: Messages getting truncated.
Message-Id: <Pine.A41.3.96.1021003132135.38584A-100000@vcmr-104.server.rpi.edu>

On 2 Oct 2002, Brian McCauley wrote:

>"No Spam Please" <nospam@nospam.com> writes:
>
>>     $/ = 0777;    # Don't break at newlines
>
>Actually Perl thinks you mean the string "511" since numeric value in
>a string context is converted into a string using decimal.  There's
>nothing special about $/ in this respect.
>
>my $foo = 0777; # Sets $foo to the number 511
>my $bar = "$foo"; # Sets $bar to string "511"
>
>Is there any reason you can't just make $/ undef like everybody else?

Because he was misled by the -0 switch to Perl.  Since doing

  perl -0777 -e '...'

sets $/ to undef, he thought that saying

  $/ = 0777;

might to something to that effect.

-- 
Jeff "japhy" Pinyan      RPI Acacia Brother #734      2002 Acacia Senior Dean
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



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

Date: Thu, 3 Oct 2002 14:35:47 +0000 (UTC)
From: "Adam Knowles" <adam@connectpoint.co.uk>
Subject: Re: Modifying FormMail
Message-Id: <anhkk2$of0$1@knossos.btinternet.com>

> So can you suggest how I'd modify Formmail (the one you suggested), so
that
> I can either pass the "target=_top" directive as part of the "redirect"
> value to the script, or so that the perl script itself will add the
> "target=_top" directive to the redirect URL?

First: yeh use the Perl mongers formmail not Matt's. I discovered this a
while back and its good advice :)

Second, although someone else hinted at the answer, they didn't give it
explicitly. You don't need to modify formmail.pl at all to achieve what you
need. You want to add the target='_top' attribute to the <form> tag in the
HTML that submits to the script.  Something like this:

<form action='formmail.pl' target='_top'>
    <input type='text'>
</form>

I've done this before and it works.

Adam Knowles.




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

Date: 3 Oct 2002 08:00:03 -0700
From: tewall@lycos.com (Tom Ewall)
Subject: Re: Odd behavior for variables "a" and "b"
Message-Id: <85bf428.0210030700.3935b2fc@posting.google.com>

Thanks all!


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

Date: 3 Oct 2002 06:22:24 -0700
From: shambo_p@yahoo.com (Shambo)
Subject: Re: odd regexp grouping issue
Message-Id: <72190192.0210030522.439a5e12@posting.google.com>

Tad, Uri, ...wow. Thanks very much, gentlemen.

best,
Shambo


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

Date: 3 Oct 2002 10:56:02 -0700
From: averagegg@hotmail.com (Average GG)
Subject: perl loses controlling tty after exec on windows?
Message-Id: <57cd3014.0210030956.4e20cf34@posting.google.com>

i have a perl script running 24x7 on some windows and linux machines.
at intervals, it checks cvs to see if itself has been updated and
if so, does a 'cvs up' of itself and then uses 'exec("perl
script.pl");'
to restart.
this does work but i've noticed that on windows 2000 the exec drops
it into the background while on linux it stays in the foreground.
this has a side effect and i would prefer it stayed in the foreground
on windows.
i have not been able to find any references to this in the newsgroups
nor the books that i have.
any suggestions?

thanks
agg


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

Date: 3 Oct 2002 06:05:15 -0700
From: joel_bearden@hotmail.com (Joel)
Subject: Re: Perl script "rename" does not work...
Message-Id: <5e99ce1d.0210030505.48f5909@posting.google.com>

Brian McCauley <nobull@mail.com> wrote in message news:<u9fzvookrg.fsf@wcl-l.bham.ac.uk>...
> joel_bearden@hotmail.com (Joel) writes:
> 
> >  my($DB_Dir) = '/usr/local/mysql/data/wb_20_test';
> >  opendir(SYSTEMDIR, $DB_Dir);
> >  @FileList = readdir(SYSTEMDIR);
> >  my($oldname);
> >  my($newname);
> >  foreach $oldname(@FileList) {
> >     if (-d $oldname) {     # if . or .., ignore
> >        next;
> >     } 
> 
> This, I think, is a mistake everyone makes the first time they use
> readdir() even though you are explicitly warned about it in the
> manual.
> 
> See "perldoc -f readdir"

Thanks for everyone's help...  Problem solved...  But can you issue a
"LOGFILE" write on a "or die"?


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

Date: Thu, 03 Oct 2002 14:13:18 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Perl script "rename" does not work...
Message-Id: <slrnapojrd.6q5.tadmc@magna.augustmail.com>

Joel <joel_bearden@hotmail.com> wrote:
> Brian McCauley <nobull@mail.com> wrote in message news:<u9fzvookrg.fsf@wcl-l.bham.ac.uk>...
>> joel_bearden@hotmail.com (Joel) writes:
>> 

>> >  opendir(SYSTEMDIR, $DB_Dir);


>  But can you issue a
> "LOGFILE" write on a "or die"?


I guess that LOGFILE is meant to be a previously open()ed filehandle?


   perldoc -f die

      Outside an "eval", prints the value of LIST to
      "STDERR" and exits with the current value of "$!" (errno).


So no, die() always writes to the STDERR filehandle and 
exit()s with a non-zero value.

print() lets you choose a filehandle to write to though.

So you can use print() instead, and then call exit() yourself:

   opendir(SYSTEMDIR, $DB_Dir) 
      or print(LOGFILE "could not opendir '$DB_Dir' $!"), exit $!;


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


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

Date: 3 Oct 2002 09:29:47 -0700
From: avishal@vsnl.net (Vishal Agarwal)
Subject: Re: Perl Tutor Wanted - Mtn View, CA
Message-Id: <be1aeb16.0210030829.7dd3664b@posting.google.com>

Check out 
http://www.stonehenge.com/merlyn/

There's a guy called Randal L. Schwartz. 
My guess is that everyone, who's anyone in perl - knows Randal He's
authoured many great articles for perl magazines/sites and
authrored/co-authoured many great perl books (eg. camel book, lama
book, effective perl etc. etc).

He has some training programme (according to his site)
Excerpts from his site (http://www.stonehenge.com/merlyn/)
=========
Perl Training Classes
Learn Perl now! To find out about my on-site and open-enrollment
classes, send a blank message to perl-training-info@stonehenge.com.
You'll get the answer back by email, so make sure your browser has
your correct address if you follow this link.
=========

You can't get Larry Wall to teach you and you should consider yourself
lucky if he can spend some time with you :)

Regards,
Vishal 


+++++++++++++++++++++
"Dick Penny" <penny1482@attbi.com> wrote in message news:<ygKm9.13753$Pz.14235@rwcrnsc51.ops.asp.att.net>...
> Is there a real guru in Mtn View, CA area whose got 1-2 hrs once a week for
> some Perl tutoring and Q's?  Initial subjects would be lists, arrays, greps,
> maps, their implicit iterators, and building functional chains to transform
> data. How much would you charge?


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

Date: Thu, 03 Oct 2002 16:44:34 GMT
From: "Hmmm..." <blahblahblah@blah.com>
Subject: question about speeding perl development
Message-Id: <St_m9.6638$lV3.655189@newsread1.prod.itd.earthlink.net>

I have worked on projects that use perl to access sybase databases, and to
generate html to display the data.  This is in a Sun/Solaris environment.

Does anyone know of a development tool that would accelerate the creation of
html screen layouts, automatically produce the perl that would display the
screens, and perhaps have some support for linking database fields to screen
fields?

Thanks.




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

Date: Thu, 03 Oct 2002 11:38:42 -0400
From: Jim Agnew <jpagnew@vcu.edu>
Subject: Re: reading Cobol PIC 9(6)V99 formats...
Message-Id: <3D9C6482.7742DB73@vcu.edu>

Thank you *ALL* for your kind hints and pointers...  what I may do in
the future is just write a *ick* cobol proggie to simply translate that
field, and pour it all into database tables where they really belong.

someone's comments about each language having it's "domain" in the world
is good..

Jim Agnew wrote:
> 
> People, subject says it all,
> 
> on a VMS system, try to read a Cobol PIC 9(6)V99 formats...
> 
> I'm a newbie trying to redo an accounting system from Cobol to something
> a little bit less unwieldy...  ;-)
> 
> so the question is how can Perl read that stuff? I think I'm wading thru
> most else ok,
> just time and beating my head on the books...
> 
> jim


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

Date: Thu, 3 Oct 2002 11:33:51 -0400
From: "péman" <majortom71@hotmail.com>
Subject: reqex problem
Message-Id: <uoZm9.11760$YK4.1342875@e3500-atl2.usenetserver.com>

Hello, I am currently involved with a small project that requires me to use
regex.  I am rather new to regex and know some simple forms of it, but I am
having trouble doing what I need to do.

I am using PHP to do my work, however I am using the PCRE (Perl Compatible
RegEx) functions.
This particular problem involves obtaining unknown (variable length)
word/words from
within the middle of a sentence.
For instance take the sentence:

The dog was happy that the <blank> ate the rat.

where <blank> may be any of the following:
cat
snake
big fat cat
long scary snake with a chipped tooth
 ...or any other word(s)/phrase

The best I have come up with (with some help) is this:
<?
$string="The dog was happy that the big ugly snake ate the rat.";
preg_match("/the (.+?) ate/",$string,$array);
$word1 = $array[0];
echo "$word1<br>";
?>

The result of this is:
the big ugly snake ate
where in my case I only need "big ugly snake".

More important is:
if I were to make the sentence
The dog was happy that thebig ugly snakeate the rat.

How can I pull the "big ugly snake" (no pun intended) out of this mess? It
sounds weird but I may need to use
this :(

Well if you can assist me I really do appreciate and if not I still
appreciate it :)

thanks in advance,
péman





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

Date: Thu, 3 Oct 2002 15:00:43 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: script.pl?parameter - can anyone help me figure this out?
Message-Id: <Pine.LNX.4.40.0210031441220.27575-100000@lxplus072.cern.ch>

On Oct 3, Nuba inscribed on the eternal scroll:

> I also noticed that, because of some cut-n-paste edition, my reply
> to Alan is giving the idea that I didn't care if it is malformed but it
> works. That's completely wrong. I DO CARE,

That's good to hear.  ;-)

> but I were surprised to find
> the script was working when called thru a webbrowser.

In truth, the CGI script is called from a web server.  That call
happens to have been initiated by a browser, but the key issue is the
software interface between the CGI process, and the web server process
which invoked it.  Failing to recognise that distinction does often
lead to real confusion, otherwise I wouldn't bother to stress the
point.

There are specifications for that interface, which are a bit off-topic
for a Perl language group, but do get a mention in the Perl FAQ part 9
(see for example http://www.perldoc.com/perl5.8.0/pod/perlfaq9.html
subheading "What is the correct form of response from a CGI script?".
Don't confuse those with the specification of the HTTP protocol
(RFC2616): there are deliberate similarities, but also some
significant distinctions.

In the CGI specification (talking now about parsed-headers scripts),
the preferred newline representation is the one which is native to the
platform; but implementers are asked to tolerate alternative
representations.  This probably explains why that defective sequence
is apparently working.

> But I get somewhat surprised of how
> noone found the way I solved the script.pl?parameter interesting or worth
> a comment. After all, that's the main point of the thread - or am I
> missing something ?

Usenet's a discussion forum.  Usenauts pick on anything that happens
to take their interest; conversely, if something doesn't appeal to us,
we leave it for someone else to tackle.  Sometimes that leaves the
primary question unaddressed; but if you wanted a help desk, you'd
expect to pay for the service, no?  I've often asked a question and
got no answer to it; but on the other hand I've often learned the
answers to questions which I'd never known I needed to ask.  So it
cuts both ways.

have fun



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

Date: 03 Oct 2002 16:21:51 GMT
From: ctcgag@hotmail.com
Subject: Re: Speed optimization (with code)
Message-Id: <20021003122151.383$aX@newsreader.com>

Da Witch <heather710101@yahoo.com> wrote:
>
> >p.s. caching the slice @nameslist[1..$#nameslist]  will get you ~15%
> >faster.
>
> Do you mean
>
>   my @temp = @nameslist[1..$#nameslist];
>   for(@temp) {
>     ...
>
> instead of
>
>   for(@nameslist[1..$#nameslist]) {
>     ...
>
> ?

Exactly, except that my @temp = @nameslist[1..$#nameslist]; has to
be before the outer loop (over the hash), so it's only executed once,
rather than immediately before the inner 'for', where it's executed as
often as the inner 'for' is.

(Obviously only works if @nameslist doesn't change during main(),
which it doesn't look like it does.)

I should say it got me ~15% faster.  I assume it would work for you too,
but YMMV.


Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
                    Usenet Newsgroup Service


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

Date: 3 Oct 2002 09:12:58 -0700
From: patrick_cusack@hotmail.com (patric)
Subject: Re: Splice function with arrays
Message-Id: <1ec975dc.0210030812.3a7035ca@posting.google.com>

Thanks for all of your input.  The whole time the autoincrement issue
was staring me in the face and I didn't even see it. Thanks.



Patrick


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

Date: Thu, 3 Oct 2002 14:21:34 +0100
From: news@roaima.freeserve.co.uk
Subject: Re: Trouble getting a status back from SMTP
Message-Id: <u8ghna.quh.ln@moldev.cmagroup.co.uk>

ee ee <ee@ee.ee> wrote:
> I have a small program which sends mail via SMTP.  [...]
> How do I trap the "250 ok" reply when a mail has been
> successfully sent or the "550" code when it fails.

> foreach (@DATA) {
>           $smtp->datasend("$_");
> }
> $smtp->datasend("\n");
> $smtp->dataend();

The documentation for Net::SMTP (which you appear to be using, although
you've not said it explicitly) states,

	Unless otherwise stated all methods return either a true
	or false value, with true meaning that the operation was a
	success.

It also references Net::Cmd, which states,

    dataend ()
	End the sending of data to the remote server. This is
	done by ensuring that the data already sent ends with
	CRLF then sending '.CRLF' to end the transmission.
	Once this data has been sent "dataend" calls
	"response" and returns true if "response" returns
	CMD_OK.

This seems pretty clear to me, so

	$ss = $smtp->datasend(...);
	print $ss ? 'Success' : 'Failure', "\n"

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


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

Date: Thu, 03 Oct 2002 08:36:11 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Trouble getting a status back from SMTP
Message-Id: <87it0jablg.fsf@limey.hpcc.uh.edu>

>> On Thu, 3 Oct 2002 11:40:17 +0000 (UTC),
>> "ee ee" <ee@ee.ee> said:

(is that you, mr. cummings? :-)

> I have a small program which sends mail via SMTP.  It
> works fine most of the time, but when it doesn't I can't
> trap the error message from the host.  I do the usual
> check to ensure that the SMTP connection has been opened
> ok, but other than setting debug on and watching it
> interactively I can't see if it has worked. How do I
> trap the "250 ok" reply when a mail has been
> successfully sent or the "550" code when it fails.

perldoc Net::SMTP

    ...
    The Net::SMTP class is a subclass of Net::Cmd and ...

perldoc Net::Cmd

    ...
    code ()
        Returns the 3-digit code from the last command. If a
        command is pending then the value 0 is returned

e.g.

    ... setup ...
    $smtp->expand('root');            # hopefully not allowed!
    print "Return code was ", $smtp->code, "\n";

         Return code was 550

(There are also higher level mail sending programs,
e.g. Mail::Sendmail, Mail::Mailer.)

hth
t


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

Date: 03 Oct 2002 17:44:49 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Trouble getting a status back from SMTP
Message-Id: <u9smznjwu6.fsf@wcl-l.bham.ac.uk>

"ee ee" <ee@ee.ee> writes:

> I have a small program which sends mail via SMTP.  It works fine most of the
> time, but when it doesn't I can't trap the error message from the host.  I
> do the usual check to ensure that the SMTP connection has been opened ok,
> but other than setting debug on and watching it interactively I can't see if
> it has worked. How do I trap the "250 ok" reply when a mail has been
> successfully sent or the "550" code when it fails.

> Now i'm probably being a little daft and completly missing the plot,

Yes, you are forgetting that when looking for the list of methods
provided by an OO module it is not only necessary to look at the
documentation for the module/class you are using but may also be
necessary to look at the documentation for the base class(es) thereof.

> but I would appreciate any help on this matter.

Take a look in the manual for Net::SMTP and note where it says "SEE
ALSO [base class]".  Do so and you'll find a method that "returns the
text message returned from the last command" and another that "returns
the 3-digit code from the last command. If a command is pending then
the value 0 is returned".

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Thu, 3 Oct 2002 14:01:26 +0000 (UTC)
From: "Adam Knowles" <adam@connectpoint.co.uk>
Subject: Re: Two email things in Perl
Message-Id: <anhijm$9ck$1@paris.btinternet.com>

> Mail::CheckUser should come close to that.

Like this then:

use Mail::CheckUser qw(check_email);
my $ok = check_email($email);

if($ok) {
  # The address is valid... Do stuff with it.
}

This taken from the ASPN online cookbook:
http://aspn.activestate.com/ASPN/Cookbook/Rx/Recipe/65255
Thanks for helping me find it!  I did read the 'perldoc -q mail' too but it
was a bit vague about why testing emails in this way isn't reliable. I think
the above is good enough for my needs.

> Here's the problem. This stores only the first line in the variable. To
> get it entirely, undef $/ temporarily:

Great, thanks for that. Here's the now-working script..

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

#!/usr/bin/perl -w
#
# $Id: makepage.pl

use strict;
use Fcntl ':flock'; # import LOCK_* constants

# PROGRAM INFORMATION
# -------------------

my $emailed_text = do { local $/; <STDIN> };

open(fileOUT, ">/www/www.connectpoint.co.uk/web/some_news.htm") or
die("Can't open file for writing: $!");
flock(fileOUT, LOCK_EX);
print fileOUT <<EOF;
<HTML>

<HEAD>
<TITLE>Adam's Perl Script</TITLE>
</HEAD>

<BODY>
<h3>Here's the message I got sent</h3>
<pre>$emailed_text</pre>
Thanks for visiting.
</BODY>

</HTML>
EOF

close(fileOUT);

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

This works for what I was trying to achieve. It was suggested to check the
return status of the flock, but the docs seem to state that if it can't get
the lock, it waits until it can..so presumably it can't come back 'false'
anyhow?  Should I add a 'or die' to it anyway?

I don't think I need to do the Binmode on the file since it's on a Linux
machine. And the suggestion for reading direct from the mailbox is a good
extension to the idea, but I prefer this more direct approach for this
purpose.

The last point made was that if the 'email text' contains nasty HTML or
javascript, it's not great. I'll make it use MIME::Tools or Parser to
extract just the bits I want out of the message it receives I think. But I
still have the problem with <script/> tags etc.. what can I do about that?
If it's only that tag I need to worry about I could easily remove all of
them before putting them in the file.. but are there other dangerous tags?

I want to keep most HTML tags since the idea is that I can subscribe the
address the script is attached to to an HTML newsletter that will then have
an automatic 'online' version..

Thanks for all your help guys, really useful stuff!

Adam Knowles




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

Date: 3 Oct 2002 13:48:03 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: What is the best way for file/stream IO in Perl?
Message-Id: <anhhqj$oj3$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Paul Dortman:

> I have a questions for Perl's guru.
> 
> What is the difference amoung IO::File, IO::Handle, FileHandle modules and
> standard operators and filehandles to access a file?

When dealing with files, the only two things you should have to worry
about is IO::File and using bare file handles. IO::Handle is one of the
base classes for IO::File. It defines common methods for all
file-handleish things. Even IO::Socket is actually derived from
IO::Handle.
So, IO::File just adds those things being unique to handles relating to
actual files.

As for FileHandle, I don't really see any benefits in using it. It is a
very thin wrapper around IO::File (also inheriting from it).

And there are file handles. One cool thing about IO::File and its
derivates is that they can be used like an ordinary filehandle:

    my $h = IO::File->new;
    $h->open("<file");
    while (<$h>) {
        ...
    }

That's one of Perl's trickeries that relies on the fact that HANDLE and
\*HANDLE basically behave the same in regards to some typical file
handle operations.

> What is the best way to access file and to deal with file?
> Where can I find more information on IO in Perl?

'the best' depends on the task. Most of the time I have been able to get
away using just ordinary plain handles. Also, since Perl 5.6.0 you no
longer have to worry about localizing your handles since you can do:

    open my $file, "file";

So a handle can behave very much like a lexical variable.

There are a number of spots where you find the desired information.

    perlop      ("I/O Operators")
    perlopentut (how to abuse open() to do funny things)

and the manpages for IO::File, IO::Handle and IO::Seekable. The methods
described therein usually exist for bare handles as Perl functions in
which case you would need to look up those in 'perlfunc'.

In case you are already using Perl 5.8.0, there is 'perldoc PerlIO::via'
that describes how to write IO layers that can act as filters for your
handles.

Tassilo
-- 
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;


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

Date: Thu, 03 Oct 2002 17:18:41 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: What is the best way for file/stream IO in Perl?
Message-Id: <qsuopuk9f3rgicelma79lmnen710lbncje@4ax.com>

Tassilo v. Parseval wrote:

>As for FileHandle, I don't really see any benefits in using it. It is a
>very thin wrapper around IO::File (also inheriting from it).

I think FileHandle was there first. So its importance is most of all of
historical nature.

-- 
	Bart.


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

Date: Thu, 3 Oct 2002 10:29:25 -0700
From: "Arvin Portlock" <temp133@hotmail.com>
Subject: Wow! A trivial regexp I can't do!
Message-Id: <anhupp$88c$1@agate.berkeley.edu>

I thought I knew regular expressions. But when I tried to do this one
I was amazed I didn't know how.

I want to replace all occurrences of the string "\n" (that's a backslash
and an 'n', not a newline) with a newline but only when they occur at
the end of a string. So I might have the following string:

"This is a line\n\n\n";

And I want to replace those last three '\n's with true newlines. I only
want this to happen when they're at the end of a string though. I know
how to do it with a while loop, but isn't there some cool way to do it
with a simple regular expression?

Obviously $string =~ s/\\n+$/\n/; doesn't do it.




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

Date: 3 Oct 2002 17:56:58 GMT
From: "Tassilo v. Parseval" <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Wow! A trivial regexp I can't do!
Message-Id: <ani0da$6rb$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Arvin Portlock:

> I thought I knew regular expressions. But when I tried to do this one
> I was amazed I didn't know how.
> 
> I want to replace all occurrences of the string "\n" (that's a backslash
> and an 'n', not a newline) with a newline but only when they occur at
> the end of a string. So I might have the following string:
> 
> "This is a line\n\n\n";
> 
> And I want to replace those last three '\n's with true newlines. I only
> want this to happen when they're at the end of a string though. I know
> how to do it with a while loop, but isn't there some cool way to do it
> with a simple regular expression?
> 
> Obviously $string =~ s/\\n+$/\n/; doesn't do it.

These quantifiers (+ in this case) only work on the character they
follow. But you have two characters, '\' and 'n', so you need to bundle
them:

    $string =~ s!((?:\\n)+)$!"\n" x (length($1)/2)!e;

Whenever you use parens for bundling characters and you don't want
anything captured, make them non-capturing by using ?:. This will make
the whole operation slightly quicker.

Tassilo
-- 
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;


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

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


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