[19257] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1452 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 6 14:05:37 2001

Date: Mon, 6 Aug 2001 11:05:09 -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: <997121109-v10-i1452@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 6 Aug 2001     Volume: 10 Number: 1452

Today's topics:
    Re: 3 very easy ones 4 u <bcaligari@fireforged.com>
    Re: Active State <justsayno2nt@here.com>
    Re: Allowing ONLY letters and spaces in regular express (Alan Barclay)
    Re: Allowing ONLY letters and spaces in regular express (Anno Siegel)
    Re: Allowing ONLY letters and spaces in regular express (Logan Shaw)
    Re: automatic array elements (Anno Siegel)
        Automatic running <nathan.randle@ntlworld.com>
    Re: Automatic running <tsee@gmx.net>
    Re: Automatic running <jurgenex@hotmail.com>
    Re: config for @INC ... more info <dan@nospam_dtbakerprojects.com>
    Re: config for @INC ... more info <tom.melly@ccl.com>
    Re: config for @INC ... more info <dan@nospam_dtbakerprojects.com>
        Java parser? <kj0@mailcity.com>
    Re: Java parser? <brentdax1@earthlink.net>
    Re: Perl - Reading the contents of a DIR <brentdax1@earthlink.net>
        Perl Logical Knot Problem <stephen.p.harris@worldnet.att.net>
    Re: Perl Logical Knot Problem (John J. Trammell)
    Re: Perl Logical Knot Problem <brentdax1@earthlink.net>
    Re: Perl Logical Knot Problem <godzilla@stomp.stomp.tokyo>
    Re: Perl multithreading on WIN32 - Help needed <brentdax1@earthlink.net>
    Re: Problems with the localtime function !!!! (Alan Barclay)
    Re: Regular Expression <ren@tivoli.com>
    Re: Reporting Questionable Programming Activity (Jacqui caren)
    Re: searching hash with array values <tzz@beld.net>
    Re: Translate VB-Script into Perl (isterin)
    Re: validate IP address <brentdax1@earthlink.net>
    Re: Xerces XML for Windows (Tad McClellan)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 6 Aug 2001 16:06:18 +0200
From: "B. Caligari" <bcaligari@fireforged.com>
Subject: Re: 3 very easy ones 4 u
Message-Id: <9km81g01cks@enews1.newsguy.com>


"Paul Fortescue" <paul@net366.com> wrote in message
news:997089125.14312.0.nnrp-13.d4f094e4@news.demon.co.uk...
> Sorry to bother you gurus, I learnt some Perl at the weekend and I have
> realised that it is a fantastically easy language to learn and very, very
> powerful. however, I can't find 3 things in the FAQ. Could anyone help me?
I
> am at home with C/C++/Java etc.
>
> 1) How do I equivalent a #include? I have some subroutines which I don't
> want to edit anymore, but I don't want them cluttering up my code some I
> want do the equivalent of #include mysub.pl

How about modules?

perldoc perlmod

>
> 2) How do I find the number of occurrences of "abc" in "abcdefabc" for
> example? m// and s/// do everything but return the count as far as I can
> see. Also can I m// for an exact match, eg a password without checking the
> match and the string length?

$count = @{[$string =~ m/abc/g]};

>
> 3) not so important, my code works but I can't help thinking it's not as
> clever/small/efficient as it could be. I want to find all the files
> containing a string, and how many of them there are, and what the highest
> numbered suffix is. the files are called filetype.1, filetype.2 etc. I
have
> written
> $fn="./";
> opendir DH, $fn;
> @fils=readdir(DH);
> $type="filetype.";
> @this=grep (/$type/, @fils);
> foreach $this (@mail) {
> $this=~s/$type//g;
> }
> @this = sort {$b <=> $a} @this;
> $count=@this;
> print "$type files : the largest one is $this[0], and the total number is
> $count\r\n";
> exit;

I didn't get exactly what you meant, but I use this script for quick 'stats'
on my gnutella download folder.

my %filez;
opendir(DOWN, ".");
for (readdir DOWN) {m/^.+\.(.+?)$/ && $filez{$1}++}
closedir(DOWN);
foreach (sort keys %filez) { print "$_\t$filez{$_}\n" }

or (yucky)

my %filez;
for (<*.*>) {m/^.+\.(.+?)$/ && $filez{$1}++}
foreach (sort keys %filez) { print "$_\t$filez{$_}\n" }

>
> Thanks in advance and sorry to be so boring! Maximum respect to those of
you
> who have mastered this strange and wonderful language ...
> Paul

B





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

Date: Mon, 6 Aug 2001 14:54:34 GMT
From: justsayno2nt <justsayno2nt@here.com>
Subject: Re: Active State
Message-Id: <3B6EAFAA.8442C00B@here.com>

Reminds me when I first got a computer a billion years ago. The doc said
hit the alt key and then any key. I had never heard of an 'alt' key but
found it. But I could not find that darn 'any' on the keyboard. Then it
dawned on me, duh, they must literally mean 'any key'. I remember
writing some documentation for a DOS utility program I wrote. I used the
statement 'at the command line blah blah'. The first users came over
immediately and asked what's the command line? Is that the same as the
'command prompt', which is how they as referred to it and had never
heard of 'command line'?

semantics, it will get you every time. 



Tim Schmelter wrote:
> 
> Drew wrote:
> 
> > "Adam Stewart" <Stewy@Chartermi.net> wrote in message news:<tkoose7di0467d@corp.supernews.com>...
> > > For a while now I have been interested in learning perl. So I recently
> > > installed Active State Perl on my computer. My operating system is Windows
> > > 98, just so you know. First thing is it says to run there example program to
> > > make sure it is working correctly. Now the problem is where do I run this
> > > program from? It says to type <perl example.pl> at the command line, but it
> > > doesnt say where this command line is, and i've looked all over with out
> > > success.
> > >
> > > Does anyone understand what I am saying? Your help is appreciated. Actualy I
> > > would prefer for you to email me than to respond here as I may not get back
> > > here for a few days.
> > >
> > > Thank you,
> > > Stewyyyyyyyy
> >
> > "Command line" refers to does command prompt.  click "start" -> "run"
> > -> type "command".  use the CD command to get the directory where the
> > file is.  then type "perl example.pl".
> 
> I don't know about anyone else, but I actually *felt* myself lock into a generation gap reading this
> thread. :-(>>>~ (Which is the emoticon for "I've got a long gr[ea]y beard", I'm going to say.)
> 
> --
> Tim Schmelter
> Public Key available from http://www.keyserver.net
> CAD7 2ABB 05A4 2F00 4CAE 7D2F 127C 129A 7173 2951


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

Date: 6 Aug 2001 13:58:43 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: Allowing ONLY letters and spaces in regular expression??
Message-Id: <997106282.745942@elaine.furryape.com>

In article <MPG.15d7ea32bfbdc78598970c@news.edmonton.telusplanet.net>,
Carlos C. Gonzalez  <miscellaneousemail@yahoo.com> wrote:
>This is what can make Perl so confusing sometimes.  That different 
>symbols can mean different things in the context.  When Perl is confusing 
>like this I suppose it is tantamount to learning how to speak Chinese.  I 
>understand that words in that language are also somewhat dependent on the 
>context in which they are spoken.  

This is true in many human languages, including English. In written
English; Polish the table, said the Polish man. Here the word 'Polish'
is used for both making something shiny, and for someone from Poland.
Blue is used both for a colour, and for depression (A blue mood), etc.




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

Date: 6 Aug 2001 16:32:06 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Allowing ONLY letters and spaces in regular expression??
Message-Id: <9kmgq6$poo$1@mamenchi.zrz.TU-Berlin.DE>

According to Tassilo von Parseval  <Tassilo.Parseval@post.rwth-aachen.de>:
> Carlos C. Gonzalez wrote:
> 
> >This is what can make Perl so confusing sometimes.  That different 
> >symbols can mean different things in the context.  When Perl is confusing 
> >like this I suppose it is tantamount to learning how to speak Chinese.  I 
> >understand that words in that language are also somewhat dependent on the 
> >context in which they are spoken.
> >
> 
> Yes, as to context Perl is complex and subtle. There is one thing that 
> can be said about Perl, for the good or for the bad: It is friendly to 
> the beginner in the sense that it provides a new user with the means to 
> tackle respectable problems that he wouldn't even get close with other 
> languages. After a while it gets immensly rich. You compare it with 
> Chinese...well, it is not that hard. ;-) But to me Perl always appeared 
> to be the computer language being closest to a human languages. The 
> design and concept of this language are marvellous.

Perl is like human languages in more respects.  For one, it is
changing.  Most computer languages are designed from a static
description which makes later modifications difficult.  Perl has
avoided this straightjacket and keeps absorbing user feedback as
it goes along.  This makes it a developing language.  It also means
that Perl has a history which it helps to know in order to understand
why some things are the way they are.  This isn't always an immediate
advantage; just look at filehandles and their various behaviors.
Try to explain (defend?) that without referring to history :)  But
this historical experience will also make sure that Perl 6 will have
the neatest I/O mechanism imaginable, never mind what it will be.

Another thing that takes Perl close to natural languages is the very
TIMTOWDTI.  This often allows us to put a bit of program in a form
that expresses clearly what we are doing and why, which beats
add-on comments anytime.  For an example, in a well written Perl
program the use of an array index usually indicates that the operation
can't be done in a single (foreach-) pass over the array and tells
the reader a bit about what to expect.  So besides the "Do What I
Mean" (which I consider more of a curse than a blessing), a principle
of "Say What You Mean" is possible in Perl, and that *is* a blessing.
Oh, and prefix that with "Don't" for obfuscated programs :)

Anno


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

Date: 6 Aug 2001 12:45:34 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Allowing ONLY letters and spaces in regular expression??
Message-Id: <9kml3u$d6j$1@charity.cs.utexas.edu>

In article <997106282.745942@elaine.furryape.com>,
Alan Barclay <gorilla@elaine.furryape.com> wrote:
>This is true in many human languages, including English. In written
>English; Polish the table, said the Polish man. Here the word 'Polish'
>is used for both making something shiny, and for someone from Poland.
>Blue is used both for a colour, and for depression (A blue mood), etc.

For a more extreme example, take this valid and meaningful sentence:

	Buffalo buffalo buffalo Buffalo buffalo.

The first two words are a noun phrase describing animals
also known as bison who are from (or otherwise associated
with) a certain city in New York State.  The last two words
are the same phrase repeated.  The middle (third) word is a
verb meaning to intimidate, deceive, or confuse.

Speaking of confusing, that sentence is very confusing.  Does that
mean English is a bad language?  No, because a good writer would
realize that'd be confusing and wouldn't write a sentence like that.

  - Logan
-- 
"Our grandkids love that we get Roadrunner and digital cable."
(Advertisement for Time Warner cable TV and internet access, July 2001)


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

Date: 6 Aug 2001 15:17:15 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: automatic array elements
Message-Id: <9kmcdr$lme$1@mamenchi.zrz.TU-Berlin.DE>

According to Tassilo von Parseval  <Tassilo.Parseval@post.rwth-aachen.de>:
> Tassilo von Parseval wrote:
> 
> > Les Ander wrote:
> >
> >> Hi,
> >> i would like to build an array automatically.
> >> i know that @arr=(1..10) fills the @arr with elements 1 to 10.
> >>
> >> But i want to fill @arr with elements from 10..100 with every 10th
> >> elements. For example in matlab i can say a=[10:10:100]
> >> which will make a=(10, 20, 30, ..,100)
> >>
> >> Can i do some thing similar with perl (i.e. can i give an arbitrary
> >> increment to fill up the array?)
> >>
> >
> > You could do it thus:
> > my @array;
> > $array[$_ * 10] for (1 .. 10); 
> 
> 
> Ah, nonsense of course!
> $array[$_] = $_ * 10 for (1 .. 10);

Probably better written as

    @array = map 10*$_, 1 .. 10;

"map" is the universal array constructor in Perl, when .. isn't good
enough.

Anno


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

Date: Mon, 6 Aug 2001 18:32:12 +0100
From: "Nathan Randle" <nathan.randle@ntlworld.com>
Subject: Automatic running
Message-Id: <0yAb7.10568$3K2.1410895@news6-win.server.ntlworld.com>

Is there any way of making a script run automatically at a certain time on
the server with absolutely no human intervention.

thanks in advance
Nathan




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

Date: Mon, 6 Aug 2001 19:52:53 +0200
From: "Steffen Müller" <tsee@gmx.net>
Subject: Re: Automatic running
Message-Id: <9kmlc6$1dk$00$1@news.t-online.com>

"Nathan Randle" <nathan.randle@ntlworld.com> schrieb im Newsbeitrag
news:0yAb7.10568$3K2.1410895@news6-win.server.ntlworld.com...
> Is there any way of making a script run automatically at a certain time on
> the server with absolutely no human intervention.

Yes. This is not related to perl, though.

Unix: use a cron job.
Windows: Use the task scheduler.

Regards,
Steffen Müller




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

Date: Mon, 6 Aug 2001 10:53:18 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Automatic running
Message-Id: <3b6ed98c$1@news.microsoft.com>

"Nathan Randle" <nathan.randle@ntlworld.com> wrote in message
news:0yAb7.10568$3K2.1410895@news6-win.server.ntlworld.com...
> Is there any way of making a script run automatically at a certain time on
> the server with absolutely no human intervention.

Just like you would do to setup a scheduled run of any other program,
nothing special needed:
- "cron" on Unix
- "at" in the Windows world
Don't know about Mac.






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

Date: Mon, 06 Aug 2001 16:05:52 GMT
From: Dan Baker <dan@nospam_dtbakerprojects.com>
Subject: Re: config for @INC ... more info
Message-Id: <3B6EC0AD.CF3D94F7@nospam_dtbakerprojects.com>



Tom Melly wrote:
> 
> "Dan Baker" <dan@nospam_dtbakerprojects.com> wrote in message
> news:3B6E99F4.E09DA1D7@nospam_dtbakerprojects.com...
> 
> <snip>
> 
> Compare reg settings?
> 
> HKEY_LOCAL_MACHINE/SOFTWARE/ActiveState and ./Perl ?
-----------
activestate has subfolders
   ActivePerl :
      522 - default
   PerlScript :
      1.0 -
         EnabledZones
         NoCaseCompare

Perl has
   bindir  C:\usr\bin

I dont have my desktop unpacked yet, so I can't compare, but do these
values look right? Is the value for bindir so that the .exe can be
found, or does it define the working dir? (would everything break if I
change it to "." ? For some other executables I remember seeing a
windows dialog somewhere for setting a value for "Opens in..." to set
the working directory, but I can't find anything similar for perl.

D


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

Date: Mon, 6 Aug 2001 17:32:08 +0100
From: "Tom Melly" <tom.melly@ccl.com>
Subject: Re: config for @INC ... more info
Message-Id: <3b6ec688$0$8510$ed9e5944@reading.news.pipex.net>

"Dan Baker" <dan@nospam_dtbakerprojects.com> wrote in message
news:3B6EC0AD.CF3D94F7@nospam_dtbakerprojects.com...

> activestate has subfolders
>    ActivePerl :
>       522 - default
>    PerlScript :
>       1.0 -
>          EnabledZones
>          NoCaseCompare
>
> Perl has
>    bindir  C:\usr\bin
>

Hmm, the major diff to my reg settings (win95 and 2000) is that the Perl bindir
ends with Perl.exe, whereas yours ends with just the directory.... that MIGHT be
the culprit.

Also, under ActiveState, I have CurrentVersion = 623 (620 on 2000)and default is
value not set. Also, I have a subdir under activeperl, called 623 (620 on 2000)
which has the key default = C:\Perl\

I don't think the perlscript settings are relevent.

> I dont have my desktop unpacked yet, so I can't compare, but do these
> values look right? Is the value for bindir so that the .exe can be
> found, or does it define the working dir? (would everything break if I
> change it to "." ?

I think it would (break). I don't have a win98 system to compare with. Assuming
your desktop is win98, I'd check it out on that when you get the chance....

> For some other executables I remember seeing a
> windows dialog somewhere for setting a value for "Opens in..." to set
> the working directory, but I can't find anything similar for perl.

I think that's just for shortcuts IIRC.





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

Date: Mon, 06 Aug 2001 16:48:46 GMT
From: Dan Baker <dan@nospam_dtbakerprojects.com>
Subject: Re: config for @INC ... more info
Message-Id: <3B6ECABC.2E891776@nospam_dtbakerprojects.com>



Tom Melly wrote:

> Hmm, the major diff to my reg settings (win95 and 2000) is that the Perl bindir
> ends with Perl.exe, whereas yours ends with just the directory.... that MIGHT be
> the culprit.
-----
nope... tried it

> 
> Also, under ActiveState, I have CurrentVersion = 623 
----
I'm still using 522 because I had loaded the ImageMagik and a couple
other modules I didnt want to mess with a new version from Activestate.
;)


bummer, I was hoping someone would have run into this. Its a big pain to
have to go into all my little utilities and add an explicit chdir() line
to set the working directory. After adding a chdir with the explicit
path to wherever the script is,then everything runs fine.

D


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

Date: 6 Aug 2001 11:52:58 -0400
From: kj0 <kj0@mailcity.com>
Subject: Java parser?
Message-Id: <9kmegq$4ha$1@panix3.panix.com>





I need to modify a large amount of Java code (I need to add a
debugging line to all the methods in several files).  I would like to
do this with Perl.  For this task, it would be useful to have a Java
parsing module that can keep track of the "lexical state" of the Java
source code as it's being read in.  (I.e. something like "current
token is token #3 in expression #2 of statement #4 of method foo(int,
float, boolean) of class Bar of package com.quux.frotz".)

Does anybody know of a Perl module for parsing Java source code that
would facilitate this task?  (I couldn't find one in CPAN, but maybe I
was not searching by the right keywords).

Thanks!

KJ



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

Date: Mon, 06 Aug 2001 16:18:53 GMT
From: "Brent Dax" <brentdax1@earthlink.net>
Subject: Re: Java parser?
Message-Id: <Nrzb7.328$nb4.60788@newsread1.prod.itd.earthlink.net>

"kj0" <kj0@mailcity.com> wrote in message
news:9kmegq$4ha$1@panix3.panix.com...
> I need to modify a large amount of Java code (I need to add a
> debugging line to all the methods in several files).  I would like to
> do this with Perl.  For this task, it would be useful to have a Java
> parsing module that can keep track of the "lexical state" of the Java
> source code as it's being read in.  (I.e. something like "current
> token is token #3 in expression #2 of statement #4 of method foo(int,
> float, boolean) of class Bar of package com.quux.frotz".)
>
> Does anybody know of a Perl module for parsing Java source code that
> would facilitate this task?  (I couldn't find one in CPAN, but maybe I
> was not searching by the right keywords).

I'm not aware of a Java parsing module.  You might be able to build a parser
yourself with Parse::RecDescent or any of the other Parse:: modules,
however.

--Brent Dax
brentdax1@earthlink.net




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

Date: Mon, 06 Aug 2001 16:26:50 GMT
From: "Brent Dax" <brentdax1@earthlink.net>
Subject: Re: Perl - Reading the contents of a DIR
Message-Id: <ezzb7.345$nb4.55762@newsread1.prod.itd.earthlink.net>

"Bart Van der Donck" <bart@nijlen.com> wrote in message
news:a2xb7.15946$lB.3097142@afrodite.telenet-ops.be...
> > I simply want to
> > a) find out the number of files in a directory
> > b) copy them into an array of structure of some sort to be moved to
> > another dir.
>
> # yourdir is where your files are located
> # otherdir is where your files should be copied into
> # (remember the /-signs at the beginning and at the end)
> $yourdir="/path/to/your/dir/";
> $otherdir="/path/to/otherdir/";
> $ls=`ls $yourdir`;
> @arr=split /\n/, $ls;
> foreach (@arr)
> {`cp $yourdir$_ $otherdir`; $count++;}
> print "Directory $yourdir has $count files in it.\n";
> print "These files have been copied into $otherdir.\";

Except that that isn't portable, and since he mentioned ActivePerl, he's
probably on Win32.  The opendir approach is better.

--Brent Dax
brentdax1@earthlink.net




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

Date: Mon, 06 Aug 2001 15:36:50 GMT
From: "Stephen Harris" <stephen.p.harris@worldnet.att.net>
Subject: Perl Logical Knot Problem
Message-Id: <mQyb7.4536$1p1.402752@bgtnsc04-news.ops.worldnet.att.net>

Hi,

I am new to Perl and just took a course this summer. As usual
the final assignment was a guestbook. The guestbook has
three required fields(name, email and comment) which seemed
to work OK.

The problem came up with the optional fields. I tried to set it up
so that it would approve the form if they did not fill out the
phone and zip code. But if they did fill it out then it would warn
them of and incomplete field or not all digits used.

Two fields one for  zip: XXXX   and one for code: XXXX
Three fields for area: ###  pre: ### and local: ####

Next I'll show the code I used for this filtering. What this produced
is anomalous results. I'm wondering (I'm new) if the strange results
were caused because procedural nots are not quite the same as
mathematical nots(according to the online version of SICP/Scheme).

@desired = ("zip","code","area","pre","local");  # 1 below code
foreach $i (@desired) {                                        # 2 below
code
    if  ($FORM{$i} ne  ""                                       # 3 below
code
 &&  $FORM{'zip'}  !~ /^[0-9]{5}$/g &&  $FORM{'code'} !~/^[0-9]{4}$/g
 &&  $FORM{'area'} !~ /^[0-9]{3}$/g &&  $FORM{'pre'}  !~ /^[0-9]{3}$/g
 &&  $FORM{'local'}  !~ /^[0-9]{4}$/g) {

#1 I read my keys into an array
#2 I also tried $_ rather than $i with no difference
# 3 I had ++ after "if ($FORM{$i}_++_ ne ""  but took it out without
difference

#4The code prints an error message if any of the numerical fields
are not precisely the required number of digits, otherwise approves.
The "" says if they dont fill it out, then thats ok too, just checks
optional
fields _with_ entries.

So if there were five wrong enties (each field partially done) then
there would be five error messages printed, one for each partial field.
If the required fields were filled out, then these error messages would
be followed by the Thank You message.

But if two fields were filled in correctly and three fields only partially
then there would only be one error message. Or one field filled correctly
and three filled incorrectly, and one not done, then two error messages.

I catalogued all the strange combinations of error messages below in an
email to my instructor who has gone on vacation, so no answer.

So does this have to do with Perl's procedural treatment of not and
the number of loops involved. SICP says a perfect match can only
be done using "and" "or" to mathematical logic.

Or do I just missing something important in how this should be coded?

This has been bothering me, I would appreciate any insight as to why
Perl produces these results. I can't see a logical reason for it, so I
thought it might be a builtin procedural method.
(I realize I could have used just one zip field and one telephone field)

Regards
Stephen

email message to instuctor:
I have spent several hours trying to figure this out
and it is killing me. I tried to make my regular
expressions easy by making the zip code into
two fields (5 and 4) and the telephone into three
fields (3 and 3 and 4). But I guess this caused
a complication for the logic expression.

Here is the code you recommended and I added
the global "g's" because it seemed to work better.
(The ++ seemed to have no effect.)

@desired = ("zip","code","area","pre","local");
foreach $_ (@desired) {
    if  ($FORM{$_}++ ne  ""
 &&  $FORM{'zip'}  !~ /^[0-9]{5}$/g &&  $FORM{'code'} !~/^[0-9]{4}$/g
 &&  $FORM{'area'} !~ /^[0-9]{3}$/g &&  $FORM{'pre'}  !~ /^[0-9]{3}$/g
 &&  $FORM{'local'}  !~ /^[0-9]{4}$/g) {

So this worked really great for finding errors. It would print out five
error
messages if I had only one or two digits in each field. And if they were
all correctly filled out there was the "Mission Accomplished" message,
meaning it all worked right with no errors.

The problem came up when if three fields were correctly filled in
and two were filled in and with error it failed to give the error message.

If two fields were correctly filled in and two left blank and an error
was created in the fifth field, the code would not detect and it would
give the all ok message.

But if there were two correct fields and two errors and one field
left blank it would report just one error. And if two fields were
correct and two were wrong and one field blank, then there was
only one error message instead of  showing what should be two errors.

I thought it might be due to the "g" switch. Because the longest field
five (5) for the zip would create even stranger behavior without the
"g" switch. The "g" switch did not seem to have an effect on the other
fields and so I thought it best to leave them all as "g".

I am obsessing about this and have been reading tutorials on
control statements and logical and : or operators (don't they have
andor statements) and case statements which looks like andor to me.

I'll bet that code would have worked for just one zipcode field and
one telephone field according to other sources. It seems to me this
should work...maybe because there are two fields of 3, and 4 length?
Wouldn't you rather think about this than ride a bike in the sun? :-)

___________                    __________
|                     |                    |                  |
|__________ |                    |_________|
Zip                                     Code
_______                   _______                 _______
|            |                    |            |                 |
|
|______|                    |______|                 |_______|
Area                         Prefix                      Local


Resolution and Discovery,
Stephen








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

Date: 06 Aug 2001 15:56:03 GMT
From: trammell@bayazid.hypersloth.invalid (John J. Trammell)
Subject: Re: Perl Logical Knot Problem
Message-Id: <slrn9msto3.65g.trammell@haqq.hypersloth.net>

On Mon, 06 Aug 2001 15:36:50 GMT, Stephen Harris wrote:
[snip]
> The problem came up with the optional fields. I tried to set it up
> so that it would approve the form if they did not fill out the
> phone and zip code. But if they did fill it out then it would warn
> them of and incomplete field or not all digits used.
> 
> Two fields one for  zip: XXXX   and one for code: XXXX
> Three fields for area: ###  pre: ### and local: ####
> 
> Next I'll show the code I used for this filtering. What this produced
> is anomalous results. I'm wondering (I'm new) if the strange results
> were caused because procedural nots are not quite the same as
> mathematical nots(according to the online version of SICP/Scheme).
> 
> @desired = ("zip","code","area","pre","local");  # 1 below code
> foreach $i (@desired) {                                        # 2 below
> code
>     if  ($FORM{$i} ne  ""                                       # 3 below
> code
>  &&  $FORM{'zip'}  !~ /^[0-9]{5}$/g &&  $FORM{'code'} !~/^[0-9]{4}$/g
>  &&  $FORM{'area'} !~ /^[0-9]{3}$/g &&  $FORM{'pre'}  !~ /^[0-9]{3}$/g
>  &&  $FORM{'local'}  !~ /^[0-9]{4}$/g) {

What do you think that /g gains you?  I think the best thing
for you to do at this point is to keep hammering at the code,
and put in lots of print statements to figure out exactly what
it's doing.  You'll be a better coder after figuring this out
for yourself.



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

Date: Mon, 06 Aug 2001 16:16:32 GMT
From: "Brent Dax" <brentdax1@earthlink.net>
Subject: Re: Perl Logical Knot Problem
Message-Id: <Apzb7.496$t41.63537@newsread2.prod.itd.earthlink.net>


"Stephen Harris" <stephen.p.harris@worldnet.att.net> wrote in message
news:mQyb7.4536$1p1.402752@bgtnsc04-news.ops.worldnet.att.net...
 ...
> The problem came up with the optional fields. I tried to set it up
> so that it would approve the form if they did not fill out the
> phone and zip code. But if they did fill it out then it would warn
> them of and incomplete field or not all digits used.
>
> Two fields one for  zip: XXXX   and one for code: XXXX
> Three fields for area: ###  pre: ### and local: ####
>
> Next I'll show the code I used for this filtering. What this produced
> is anomalous results. I'm wondering (I'm new) if the strange results
> were caused because procedural nots are not quite the same as
> mathematical nots(according to the online version of SICP/Scheme).
>
> @desired = ("zip","code","area","pre","local");  # 1 below code
> foreach $i (@desired) {                                        # 2 below
> code
>     if  ($FORM{$i} ne  ""                                       # 3 below
> code
>  &&  $FORM{'zip'}  !~ /^[0-9]{5}$/g &&  $FORM{'code'} !~/^[0-9]{4}$/g
>  &&  $FORM{'area'} !~ /^[0-9]{3}$/g &&  $FORM{'pre'}  !~ /^[0-9]{3}$/g
>  &&  $FORM{'local'}  !~ /^[0-9]{4}$/g) {
 ...

Problem is, you're checking *all* the fields each time the if statement
executes.  What you need to do is something like this:

    @desired = ("zip","code","area","pre","local");
    %checkre{@desired} = (
        '^[0-9]{5}$',
        '^[0-9]{4}$',
        '^[0-9]{3}$',
        '^[0-9]{3}$',
        '^[0-9]{4}$'
    );                #build a hash of the regular expressions to validate
against

    for(@desired) {    #or use foreach
        if($FORM{$_} ne '' && $FORM{$_} !~ /$checkre{$_}/) {

Here, I'm building a hash of regular expressions keyed by field name and
matching the field against the regexp.  (If you're going to use %checkre
again and you're on Perl 5.6 or later, using qr// instead of '' would speed
things up considerably.)  The other way to do it is to do a switch
statement.  Damian Conway's Switch.pm, available from the CPAN, will allow
you to do that:

    use Switch 'fallthrough';
    @desired = qw(zip code area pre local);

    FIELDS: for(@desired) {
        next if $FORM{$_} eq '';
        switch($_) {
            case "zip"   { $form{zip}   !~ /^[0-9]{5}$/ or next FIELDS }
            case "code"  { $form{code}  !~ /^[0-9]{4}$/ or next FIELDS }
            case "area"  { $form{area}  !~ /^[0-9]{3}$/ or next FIELDS }
            case "pre"   { $form{pre}   !~ /^[0-9]{3}$/ or next FIELDS }
            case "local" { $form{local} !~ /^[0-9]{4}$/ or next FIELDS }
            #error handler here
        }
    }

Note that this code is all untested--it could be incorrect.  (That switch
statement looks particularly suspicious, but I can't see anything wrong with
it.)

HTH,
--Brent Dax
brentdax1@earthlink.net




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

Date: Mon, 06 Aug 2001 10:13:41 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Perl Logical Knot Problem
Message-Id: <3B6ED045.9FE67132@stomp.stomp.tokyo>

Stephen Harris wrote:

(snipped)

> The guestbook has three required fields
> (name, email and comment) which seemed
> to work OK.

Those fields and related code either work ok or
do not work ok. Your "seemed" is inappropriate.


> The problem came up with the optional fields. I tried to set it up
> so that it would approve the form if they did not fill out the
> phone and zip code. But if they did fill it out then it would warn
> them of and incomplete field or not all digits used.


Your code is quite illogical and most inefficient.

Add maximum length restrictions to your form action
to prevent entries longer than desired.

For my test code below my signature, you can check
both zip and phone combined, or with easy modification,
check zip and phone as independent units. As is, my
code checks zip and phone as a single unit. My Error
check sub-routine can be modified to do whatever you
like, such as checking the actual data within each field
and reporting a custom error message based on field
content or lack thereof.


Godzilla!
--

TEST SCRIPT:
____________

#!perl

$FORM{'zip'} = 12345;
$FORM{'code'} = 6789;
$FORM{'area'} = 123;
$FORM{'pre'} = 456;
$FORM{'local'} = 7891;

@desired = ("zip", "code", "area", "pre", "local");

for (@desired)
 {
  if (!($FORM{$_}))
   { $FORM{$_} = 1; }
  $count = $FORM{$_} =~ tr/0-9//;
  $check = "$check$count";
 }

if ($check == 54334)
 { print "Successful Check\n\n"; }
else
 { &Error; }

sub Error
 {
  if (substr ($check, 0, 1) != 5)
   { print "Five Digit Zip Code In Error\n"; }
  if (substr ($check, 1, 1) != 4)
   { print "Four Digit Zip Code In Error\n"; }
  if (substr ($check, 2, 1) != 3)
   { print "Three Digit Area Code In Error\n"; }
  if (substr ($check, 3, 1) != 3)
   { print "Three Digit Prefix Code In Error\n"; }
  if (substr ($check, 4, 1) != 4)
   { print "Four Digit Phone Number In Error\n"; }
 }

exit;


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

Date: Mon, 06 Aug 2001 16:33:17 GMT
From: "Brent Dax" <brentdax1@earthlink.net>
Subject: Re: Perl multithreading on WIN32 - Help needed
Message-Id: <hFzb7.354$nb4.63914@newsread1.prod.itd.earthlink.net>

<bhakami@4tv.net> wrote in message
news:YKwb7.288$NJ6.468@www.newsranger.com...
> I am running perl (5.6.0) on Windows NT (WIN32). Can anyone tell me if any
kind
> of multithreading implementation is available, and where I can find it.

If you don't need to share *anything* across threads, take a look at the
fork() function--it's implemented and it works well on 5.6.0/Win32.  If you
need too share stuff across threads, look at Thread.pm--it should ship with
your Perl distribution.  Note, however, that it's experimental, and probably
won't stay around in later versions.  I'm not sure if threads.pm (from the
CPAN) supports 5.6 or not, but if it does, this is the way to go--threads.pm
will be sticking around.

HTH,
--Brent Dax
brentdax1@earthlink.net




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

Date: 6 Aug 2001 14:04:43 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: Problems with the localtime function !!!!
Message-Id: <997106681.870104@elaine.furryape.com>

In article <9km51n$alt$1@s1.read.news.oleane.net>,
VIN <vincent_le_lyonnais@yahoo.fr> wrote:
>       LC_COLLATE = "fr_FR",
>       LANG = "fr"
>    are supported and installed on your system.
>perl: warning: Falling back to the standard locale ("C").
>
>What's the problem ???


Perl uses the system's localtime function, and in this case, 
you have set up the locale variables for French setttings. However
it looks like one or more of them is either not supported or not
installed - hence the error message. If you install these files
then you'll be ok.

In other words, you should be asking an mandrake expert, not a perl
group.


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

Date: 06 Aug 2001 11:00:10 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Regular Expression
Message-Id: <m3wv4hfab9.fsf@dhcp9-161.support.tivoli.com>

On 03 Aug 2001, trammell@bayazid.hypersloth.invalid wrote:

> On Fri, 03 Aug 2001 11:45:49 -0400, Jeremy Lavine jeopary-posted:
> [jeopardectomized]
>>> "Lee Osborne" wrote:
> [snip]
>>>> What is the regular expresssion to check whether a string
>>>> contains ONLY numbers?
>> 
>> if($inputLn =~ /^\d*$/) {print "digits only"}
>> else {print "not just digits"}
>> 
> 
> How about:
> 
>  if ($input =~ /\D/) {
>      print "matched a non-digit\n";
>  } else {
>      print "failed to match a non-digit\n";
>  }

This recommendation is often made, but I'm not sure why.  I think
there is an intuitive feel that searching for one bad character is
more efficient than verifying that all the characters are good.  But
both require the *exact* same checks.  If the string is valid, both
methods will have to examine the entire string to determine that.  If
the string is invalid, both methods will determine that at the
earliest possibility (/^\d*$/ because it is anchored and /\D/ because
that is a complete match.

A quick benchmark on my system found that /^\d*$/ is actually faster
than /\D/.  I expect this is due to some of the regex optimizations
for anchored patterns.

Here is a summary, followed by the script and actual result:

           Good         Bad @ beginning   Bad @ middle   Bad @ end

/\D/       85462.91/s   389282.72/s       127475.78/s    77312.43/s
/^\d*$/    92451.37/s   409717.23/s       158048.81/s    96383.85/s


#!/usr/bin/perl
use strict;
use warnings;
use Benchmark;

my $good    = "1" x 1000;
my $bad_beg = "d" . "1" x 999;
my $bad_mid = "1" x 499 . "d" . "1" x 500;
my $bad_end = "1" x 999 . "d";

timethese -5, {
  POS_GOOD    => sub { $good    =~ /^\d*$/ or  die },
  POS_BAD_BEG => sub { $bad_beg =~ /^\d*$/ and die },
  POS_BAD_MID => sub { $bad_mid =~ /^\d*$/ and die },
  POS_BAD_END => sub { $bad_end =~ /^\d*$/ and die },
  NEG_GOOD    => sub { $good    =~ /\D/    and die },
  NEG_BAD_BEG => sub { $bad_beg =~ /\D/    or  die },
  NEG_BAD_MID => sub { $bad_mid =~ /\D/    or  die },
  NEG_BAD_END => sub { $bad_end =~ /\D/    or  die },
}
__END__
Benchmark: running NEG_BAD_BEG, NEG_BAD_END, NEG_BAD_MID, NEG_GOOD, POS_BAD_BEG, POS_BAD_END, POS_BAD_MID, POS_GOOD, each for at least 5 CPU seconds...
NEG_BAD_BEG:  7 wallclock secs ( 5.04 usr +  0.39 sys =  5.43 CPU) @ 383688.03/s (n=2083426)
NEG_BAD_END:  5 wallclock secs ( 5.58 usr +  0.00 sys =  5.58 CPU) @ 74932.44/s (n=418123)
NEG_BAD_MID:  5 wallclock secs ( 5.52 usr +  0.01 sys =  5.53 CPU) @ 125824.77/s (n=695811)
  NEG_GOOD:  6 wallclock secs ( 5.12 usr +  0.18 sys =  5.30 CPU) @ 83531.89/s (n=442719)
POS_BAD_BEG:  5 wallclock secs ( 5.26 usr +  0.00 sys =  5.26 CPU) @ 420843.35/s (n=2213636)
POS_BAD_END:  5 wallclock secs ( 5.25 usr +  0.00 sys =  5.25 CPU) @ 97301.90/s (n=510835)
POS_BAD_MID:  4 wallclock secs ( 5.14 usr +  0.02 sys =  5.16 CPU) @ 152999.61/s (n=789478)
  POS_GOOD:  6 wallclock secs ( 5.16 usr +  0.00 sys =  5.16 CPU) @ 90314.73/s (n=466024)


-- 
Ren Maddox
ren@tivoli.com


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

Date: Mon, 06 Aug 2001 17:34:41 GMT
From: Jacqui.Caren@ig.co.uk (Jacqui caren)
Subject: Re: Reporting Questionable Programming Activity
Message-Id: <90F5BCDD8JacquiCarenigcouk@195.8.69.73>

mjcarman@home.com (Michael Carman) wrote in <3B6A9E43.46C55C@home.com>:

>Dave Stafford wrote:
>> 
>> "Smiley" <gurm@intrasof.com> wrote in message
>> >
>> > The company I'm working for purchased a Perl CGI Script that
>> > turns out to be seriously faulty - so much so that my boss asked
>> > me to investigate whether there's any international agency or
>> > organization set up that we can report this kind of thing to.
>>
>> In Europe (dunno about elsewhere) you have certain rights as a
>> consumer. When you buy a product it is expected to work, and if
>> it does not you can have the product replaced or your money
>> returned.
>> 
>> I would go back to the supplier and threaten to sue.
>
>Heh. Most software sold in the US contains disclaimers in the small
>print that says (cynically paraphrased) "This software is not guaranteed
>to be suitable for any purpose whatsoever, including (and especially)
>that for which it was marketed."  >:)

under UK law we have the fair trade act etc which means that
if unfair contractual terms are imposed upon your (or even if you
agreed to them) a court can ignore them and issue a judgement
as if they never existed.

Also in the Uk data belongs to the user so if a company say MS
decides to stop your machine you have a legal right to sue
them for all losses due to your inability to access your data.

ICL got hammered by a UK court for removing hardware used by
a council to access data they owned. Note that a paper copy
of the data would have sufficed for the court but because
they had removed all access to the data ICL lost big time.

So, just because you are in the US does not mean you are safe.
You could be sued by a UK or EU user under UK or EU law and
lose when you may have won in the US...


Also there have been cases in the UK where someone sued for
losses due to freeware provided by a consultant. He did not
state that the software provided was not limited liability and
the company won damages based upon thier use of this software
for what they deemed its intended purpose.

Basically even giving software away without constraining your
limitations is seriously dangerous in the UK.

Jacqui


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

Date: Mon, 06 Aug 2001 12:26:45 -0400
From: Ted Zlatanov <tzz@beld.net>
Subject: Re: searching hash with array values
Message-Id: <m3r8up2lyy.fsf@heechee.beld.net>

brian@remorse.dhs.org (brian) writes:

> Suppose that a file contains record of the type
> fruit:banana,apple,pear
> vegetable:cucumber,tomato
> ...
>
> I create a hash in which keys 'fruit' and 'vegetable' correspond to
> lists of the appropriate food items.  The user enters the name of a
> food item.  We want to know whether the food item is in our database,
> and, if so, what category of food it is.  I know that I can brutally
> search with a foreach keys(%food) and a foreach for the matching
> arrays, but I have the feeling that it isn't an elegant way. 

You are basically indexing by the wrong thing (unless you also need to
find items by food category).  The following should work for you.

#!/usr/bin/perl -w

use strict;
use Data::Dumper;

my %byitem;
foreach my $data (<DATA>)
{
 my @items = split /[:,]/, $data;
 my $category = shift @items;
 $byitem{$_} = $category foreach @items;
}

print Dumper \%byitem;

__DATA__
fruit:banana,apple,pear
vegetable:cucumber,tomato
bad input


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----==  Over 80,000 Newsgroups - 16 Different Servers! =-----


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

Date: 6 Aug 2001 08:41:37 -0700
From: isterin@hotmail.com (isterin)
Subject: Re: Translate VB-Script into Perl
Message-Id: <db67a7f3.0108060741.532bd708@posting.google.com>

You write a Perl equivalent.  If you are trying to have someone do
this for you I don't think this is going to fly, but maybe someone on
a college summer break will take a crack at it:)

Ilya

"Axel Wei? <axel.dieter.weiss@t-online.de> wrote in message news:<9klkcu$8s1$05$1@news.t-online.com>...
> I've to write a perl-programm that install printer on a W2K-Printserver. I
> use from the ResourceKit the PRNADMIN.DLL. There are a sample sourcecode
> (VisualBasic-Script) in the Doku to check the installed Printerdriver. I
> don't know how to translate this to perl, special the marked line.
> 
> dim oMaster
> dim oDriver
> Rem creating the PrintMaster object
> set oMaster = CreateObject("PrintMaster.PrintMaster.1")
> Rem the property that enumerates drivers take an optional parameter for
> server name
> Rem if it is missing, the drivers on the local computer will be enumerated
> for each oDriver in oMaster.Drivers("\\Servername")
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> Rem get the driver name
> wscript.echo "DriverName    : " & oDriver.ModelName
> Rem get a number as driver version
> wscript.echo "Version       : " & oDriver.Version
> Rem get a string description of the driver. Ex "Windows 2000"
>         wscript.echo "DriverVersion : " & oDriver.DriverVersion
> Rem get the path where the files are
>        wscript.echo "DriverPath    : " & oDriver.Path
> Rem environment of the driver ex: Windows NT x86
>         wscript.echo "Environment   : " & oDriver.Environment
> Rem architecture of the driver, ex Intel
>         wscript.echo "DriverEnv     : " & oDriver.DriverArchitecture
>  Rem monitor name, if any
>         wscript.echo "MonitorName   : " & oDriver.MonitorName
> next
> 
> Thanks Axel


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

Date: Mon, 06 Aug 2001 16:24:33 GMT
From: "Brent Dax" <brentdax1@earthlink.net>
Subject: Re: validate IP address
Message-Id: <5xzb7.339$nb4.62234@newsread1.prod.itd.earthlink.net>

"Jag Man" <a0197620@MailAndNews.com> wrote in message
news:3B91180F@MailAndNews.com...
> I have an IP variable with default value 000.000.000.000 I needs to verify
> that the input value for this variable is a valid IP address.
>
> Need a shortest possible subroutine.

If you mean valid as in "correct number of numbers", a short regular
expression will do the trick:

    $ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
    #make sure you have four digit sequences 1-3 numbers each, separated by
periods,
    #and that the IP takes up the entire variable

If you mean make sure the IP address exists, I don't know how to do that.

HTH,
--Brent Dax
brentdax1@earthlink.net




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

Date: Mon, 6 Aug 2001 11:04:09 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Xerces XML for Windows
Message-Id: <slrn9mtcf9.dmq.tadmc@tadmc26.august.net>

Mark Riehl <mark.riehl@agilecommunications.com> wrote:
>
>Is anyone using the Xerces Perl parser for Windows?  If so, are there any
>tricks I need to know about to get it to compile under Windows?


There is a mailing list for folks using Perl to process XML:

   http://listserv.ActiveState.com/mailman/listinfo/perl-xml


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


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

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


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