[12927] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 337 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 2 17:07:28 1999

Date: Mon, 2 Aug 1999 14: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           Mon, 2 Aug 1999     Volume: 9 Number: 337

Today's topics:
    Re: ANNOUNCE: Perl Conference papers <cassell@mail.cor.epa.gov>
    Re: binary data <aqumsieh@matrox.com>
    Re: BOOLEAN SEARCH (John Borwick)
    Re: Can anyone explain concepts of Perl Objects? <jdporter@min.net>
    Re: Can anyone explain concepts of Perl Objects? (Damian Conway)
    Re: cargo-cult programming (Tad McClellan)
    Re: CHMOD function <gt7202e@prism.gatech.edu>
    Re: Date incrementing <cassell@mail.cor.epa.gov>
    Re: Files exploding on me and I'm not sure why (John Borwick)
    Re: Getting the Win32::API module to work (Jan Dubois)
    Re: How do I pass arguments from one CGI script to anot <andrew@dmi.stevens-tech.edu>
    Re: How do I pass arguments from one CGI script to anot makarand_kulkarni@my-deja.com
    Re: How to access only last field of a split ? <sachin@sanskrit.lz.att.com>
    Re: How to compare two files and get the differences ? (Larry Rosler)
    Re: How to compare two files and get the differences ? <factory@factory.co.kr>
    Re: How to determine a date in the past <cassell@mail.cor.epa.gov>
    Re: IP Address validation <cassell@mail.cor.epa.gov>
    Re: IP Validation <dummkopf@debussy.ucsc.edu>
    Re: IP Validation (Larry Rosler)
    Re: Logical Construction makarand_kulkarni@my-deja.com
        Newbie question about hashes <nslatius@dds.nl>
    Re: parallel processing in perl makarand_kulkarni@my-deja.com
    Re: Perl and pws <kperrier@blkbox.com>
    Re: Printing lines BTW two strings in file (NOT!) <cassell@mail.cor.epa.gov>
        Problem reading forms with perl genelong@my-deja.com
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

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

Date: Mon, 02 Aug 1999 13:53:01 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: ANNOUNCE: Perl Conference papers
Message-Id: <37A6052D.51E0558F@mail.cor.epa.gov>

Stephen O. Lidie wrote:
[snip of most of Tom's post]
> > ()     http://conference.oreilly.com/perl3/conf_desc.html#papers
[snip of Abigail's header by Stephen]
> > Oh goodie. Now I can go off and sulk even more about the fact that I'm
> > not coming to TPC.
> 
> Think YAPC, Grasshopper.

Hmm, given the title of Damian Conway's second paper, I'm
not sure labeling someone an edible insect is a good idea.  :-)

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Mon, 2 Aug 1999 14:29:46 -0400 
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: binary data
Message-Id: <x3y672ynihz.fsf@tigre.matrox.com>


pacman@defiant.cqc.com (Alan Curry) writes:

> s///g is a very frequently useful thing. Worthy of being one of the first
> things you should learn in perl. s/// without the g, on the other hand, is
> weird and rarely useful. I don't blame anyone for reading over perlop(1) and
> choosing to remember only the more useful constructs.

huh?
What if you want to replace only the first occurrence of a string in a
substring?

	$str = 'I have 10 dollars and 20 cents';
	$str =~ s/(\d+)/$1 + 2/e;

A /g there would be a bug. There are other situations where a /g will
be useless, and will just add noise to your code.

It is extremely stupid to use features blindly. Why not use them
properly and learn something new in the process?

> Putting a /s on all your regexps basically eliminates one obscure matching
> rule, making it that much easier to write correct regexps. If you want [^\n],
> you can say so. If you can just remember to use s///gs all the time, that's
> two obscure rules you don't have to worry about. Sounds like a good policy.

A pretty good policy? The only thing you'll be doing is confusing any
person that even attempts to read your code. Adding noise to your code
is never a Good Thing. There are also certain cases when I don't want
my dots to match newlines. Ever thought of THAT possibility?

> >  while (<FILE>) {
> >    chomp;
> >    push @stopwords, $_;
> >  }
> >}
> >
> >that could be done with
> >	chomp( @stopwords = <FILE> ) ;
> 
> Whitespace doesn't win you perl golf. Or was there an actual point in this
> rewrite?

Why don't you benchmark it and see for yourself? What about readability?



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

Date: Mon, 2 Aug 1999 20:04:01 GMT
From: John.Borwick@sas.com (John Borwick)
Subject: Re: BOOLEAN SEARCH
Message-Id: <37a8f98f.28548290@newshost.unx.sas.com>

On Mon, 02 Aug 1999 18:26:09 GMT, inlandpac@my-deja.com wrote:

>You understood correctly and this is also what I came up with in part.

[cut all the extra lines that were totally unnecessary]

 *plonk*

-- 
John Borwick


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

Date: Mon, 02 Aug 1999 19:15:43 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Can anyone explain concepts of Perl Objects?
Message-Id: <7o4qol$2m7$1@nnrp1.deja.com>

In article <7ngseh$871$1@towncrier.cc.monash.edu.au>,
  damian@cs.monash.edu.au (Damian Conway) wrote:
> abigail@delanet.com (Abigail) writes:
>
> >IMO, Perl objects
> >suck, its main reason being how member data is dealt with.
>
> You need to read my book :-)
>
> There are at least three reasonable ways of creating objects with
> properly secured member data:
>
> 	* closures (a la perltoot),

Maybe you're forgetting who wrote OO::Closures.

--
John Porter
Since time is short, and you may lie,
I'm going to have to torture you.


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: 2 Aug 1999 19:49:20 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: Can anyone explain concepts of Perl Objects?
Message-Id: <7o4so0$38c$1@towncrier.cc.monash.edu.au>

John Porter <jdporter@min.net> writes:

>> There are at least three reasonable ways of creating objects with
>> properly secured member data:
>>
>> 	* closures (a la perltoot),

>Maybe you're forgetting who wrote OO::Closures.

And maybe sometimes grandma needs to be reminded how to suck eggs :-)

Actually, I *had* forgotten. But the info in perltoot is still useful
for young players who might confuse Abigail's dislike with Perl's disability.

Damian


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

Date: Mon, 2 Aug 1999 11:03:19 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: cargo-cult programming
Message-Id: <nvb4o7.g65.ln@magna.metronet.com>

Tom Christiansen (tchrist@mox.perl.com) wrote:
:      [courtesy cc of this posting mailed to cited author]

: In comp.lang.perl.misc, 
:     tadmc@metronet.com (Tad McClellan) writes:
: :: i do not know if this is cargo-cult ? whatever that means.
: :   It means:
: :      "Copied and used without any understanding of how it works"

: Got any lexicon entries for the http://language.perl.com/misc/geekspeak.html
: contest? :-)


   No. I am too busy reading questions that have already been 
   answered, questions about stuff other than Perl, and 25,000
   character replies to every newbie that posts here.

   I am stoopid!


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Mon, 02 Aug 1999 15:15:34 -0400
From: andy barfoot <gt7202e@prism.gatech.edu>
Subject: Re: CHMOD function
Message-Id: <37A5EE56.DA363938@prism.gatech.edu>

NightFever wrote:
> 
> I'm tring to make this work:
> 
> $OrignialLogFile = 'sample.txt';
> ..
> ..
> ..
> ..
> chmod (0770, $OrignialLogFile);
> 
> I'm tring to chmod a file to 770 (or any mode for that matter) and it
> won't change it.  It will change it if I put the exact file, but not a
> a variable like this example, can anyone help?


Maybe you're misspelling the variable.  (How should we know, anyway?)

Do this:
	chmod 0770, $OriginalLogFile or die "couldn't chmod because $!\n";




-- 
 andy barfoot


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

Date: Mon, 02 Aug 1999 13:15:20 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
To: paulm@dirigo.com
Subject: Re: Date incrementing
Message-Id: <37A5FC58.8403524B@mail.cor.epa.gov>

[courtesy cc e-mailed to poster]

Stone Cold wrote:
> 
> Yeah, I know.  But if I can figure out how to increment the date, I'll
> change the year to 4-digits.

Okay.  First, a little pedantry.  This newsgroup adheres 
religiously to usenet standards.  That includes putting your
responses after the bits to which you reply.  If you can do
that in future, the responders will be happier with you, and
you'll be happier that no one called you bad names for failing
to use Usenet posting style.

Now that I've done my part to live up to the c.l.p.misc
tradition of rudeness and pedantry, let me give you some
advice on your problem.  First, look at localtime().  In
list context, it will toss an array of date/time variables
back at you.  So

    my ($mon, $year) = (localtime)[4,5];

will give you a month offset and a year offset.  $mon
goes from 0 to 11, since it is the *offset* from the first
month.  This means, among other things, that you can
feed this directly into an array to get the month abbrevi-
ation you want.

    my @mon_name=qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct
                     Nov Dec Jan Feb Mar Apr );
    my @mon_list=@mon_name[$mon .. ($mon+4)];

Now print out the contents of @mon_list, and you'll see
you have your desired list, even when your starting month
is toward the end of the calendar.

When you switch to a 4-digit year [not required when it's
clear you're printing *current* months], you'll want to
recall that $year is an offset from 1900.  Add 1900 to the
number you get, and you'll be Y2K-compliant.

Remembering to change the year part of your date when the
months wrap over to the next year is an exercise left to
the reader.  ;-)

HTH,
David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Mon, 2 Aug 1999 19:45:17 GMT
From: John.Borwick@sas.com (John Borwick)
Subject: Re: Files exploding on me and I'm not sure why
Message-Id: <37a7f30e.26882925@newshost.unx.sas.com>

On Mon, 02 Aug 1999 15:47:59 GMT, vertigotwo@my-deja.com wrote:

[ snip explanation ]
>sub savedata{
> open(FILE, ">ff/playerindex") || IllegalRefresh("PlayerIndex file
>cannot be opened - $!");
> flock(FILE, 2) || IllegalRefresh("PlayerIndex cannot be flocked - $!");
> seek (FILE, 0, 2) || IllegalRefresh("PlayerIndex cannot be seeked -
>$!");

	Why do you open for writing '>' instead of appending '>>'?  Your
seek could then be removed.


> foreach $elem (keys(%person)){
>  $money{$elem}= int($money{$elem} * 100) /100;

isn't int($money{$elem} * 100)/100; the same as int($money{$elem}) ?

>  print FILE "---\n";
>  print FILE "$person{$elem}\n";
>  print FILE "$password{$elem}\n";
>  print FILE "$lastplay{$elem}\n";
>  print FILE "$points{$elem}\n";
>  print FILE "$money{$elem}\n";
>  print FILE "$inventory{$elem}\n";
>  print FILE "$playnum{$elem}\n";
>  print FILE "$mailbool{$elem}\n";
>  print FILE "$address{$elem}\n";
>  print FILE "$hoursbtw{$elem}\n";
>  print FILE "$mailday{$elem}\n";
>  print FILE "$awards{$elem}\n";
>  print FILE "$penalties{$elem}\n";
>  print FILE "$salary{$elem}\n";
>  print FILE "$lastsignon{$elem}\n";
>  print FILE "$karma{$elem}\n";
>  print FILE "$imps{$elem}\n";
>  print FILE "$bonusp{$elem}\n";

I'm sure it's a bad idea, but this particular code makes me want to
suggest symbolic references to reduce typing.

So unless the append helps out on the files, i guess this doesn't help
too much.  however maybe the code review is good for business or
whatever.

-- 
John Borwick


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

Date: Mon, 02 Aug 1999 22:35:59 +0200
From: jan.dubois@ibm.net (Jan Dubois)
Subject: Re: Getting the Win32::API module to work
Message-Id: <37a7fbfc.4000482@news3.ibm.net>

[mailed & posted]

rurban@xarch.tu-graz.ac.at (Reini Urban) wrote:

>"Sam Weatherhead" <sweather@fastenal.com> wrote:
>>Any Suggestions are appreciated.
>
>Get Aldi and some other Win32 module writers to provide Makemaker
>install scripts. This would solve most of our problems with Win32.

It contains standard MakeMaker support.  You can easily build it yourself.
I guess people are thrown off by the fact that the distribution also
contains prebuild binaries for the *old* ActiveWare "Perl for Win32 build
3xx" versions.  These are completely useless for the current ActivePerl.

But the easiest way to install it is through ppm:

   ppm install Win32-API

and you are all set.

-Jan


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

Date: Mon, 02 Aug 1999 15:31:38 -0700
From: Mariusz A Tuliszewski <andrew@dmi.stevens-tech.edu>
Subject: Re: How do I pass arguments from one CGI script to another?
Message-Id: <37A61C4A.95077A52@dmi.stevens-tech.edu>

Justin Development wrote:

> I have an HTML file (my.html) that passes a username and password to a CGI
> script (let's call it my1.cgi), the  my1.cgi script then passes name,
> address, phone number to another CGI script (my2.cgi) which prints it out to
> a file.
>
> How do I pass the username and password from my.html to my2.cgi so I can
> print it to a file? my1.cgi knows about the username and password but
> my2.cgi doesn't. I know it has something to do with the scope of the
> namespace but I don't know how?
>
> Thanks

You have two options.  You can call the second cgi and pass it the parameters.

A trick is just to do something like this...  When your first cgi is done
processing, have it generate an html page that simply changes the location of
the current page.  But what you have to do is pass the parameters at the end.

my1.cgi:
 ..
some stuff going on here
 ..
finished processing
 ..
print "content-type: text/html"
print "<html><head><title></title></head><body>"
print "<script language=\"javascript\">
print "location.href=my2.cgi&username=$username+password=$password....etc"
print "</script></body></html>"

It's also a good idea to escape the parameters just in case

Hope that helps

Andrew




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

Date: Mon, 02 Aug 1999 19:44:31 GMT
From: makarand_kulkarni@my-deja.com
Subject: Re: How do I pass arguments from one CGI script to another?
Message-Id: <7o4ser$3vg$1@nnrp1.deja.com>

==
I am assuming that you have a form in my.html that
submits values to my1.cgi. After my1.cgi is invoked
I can see two scenarios possible.

* Either my1.cgi is dynamically generating a form
that later invokes my2.cgi. In this case
you can pass values using hidden variables.

* If my1.cgi wants to call my2.cgi directly then
do a GET directly using LWP::UserAgent.

==
> script (let's call it my1.cgi), the  my1.cgi script then passes name,
> address, phone number to another CGI script (my2.cgi) which prints it
out to
> a file.
>
> How do I pass the username and password from my.html to my2.cgi so I
can
>
>


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Mon, 02 Aug 1999 16:27:40 -0400
From: Sawant Sachin <sachin@sanskrit.lz.att.com>
Subject: Re: How to access only last field of a split ?
Message-Id: <37A5FF3C.7999B457@sanskrit.lz.att.com>

Hi,
 $line = "word.10.word.20.30.40.50";
 $scalar = ( reverse split '[.]',$line)[0]; # last element of split line

Above will work !!

Regards,
Sachin.

Larry Rosler wrote:

> In article <37A5656F.D109EB85@Mark.Com> on Mon, 02 Aug 1999 10:31:28
> +0100, Mark <Mark@Mark.Com> says...
> > Try:
> > $line = "word.10.word.20.30.40.50";
> > $scalar = ( reverse split '.',$line)[0]; # last element of split line
>
> Before suggesting to someone that they try something, you ought to try
> it yourself.  ALWAYS!
>
> Hint: '.' is a regex metacharacter.
>
> --
> (Just Another Larry) Rosler
> Hewlett-Packard Laboratories
> http://www.hpl.hp.com/personal/Larry_Rosler/
> lr@hpl.hp.com



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

Date: Mon, 2 Aug 1999 12:30:36 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: How to compare two files and get the differences ?
Message-Id: <MPG.120f91bb1bdc90a8989d9c@nntp.hpl.hp.com>

In article <7o3hav$162$1@news1.kornet.net> on Mon, 2 Aug 1999 16:38:11 
+0900, Yeong Mo/Director Hana co. <factory@factory.co.kr> says...
> Larry Rosler ÀÌ(°¡) ¸Þ½ÃÁö¿¡¼­ ÀÛ¼ºÇÏ¿´½À´Ï´Ù...
                       Who dat?
 ...
> >perlfaq4: "How do I compute the difference of two arrays? How do I
> >compute the intersection of two arrays?"
> 
> About perlfaq4.
> Then is this right to get the differences if there is following 2 arrays ?
> @array1=(1,2,3,4,5);
> @array2=(0,2,3,4);
>     @union = @intersection = @difference = ();
>     %count = ();
>     foreach $element (@array1, @array2) { $count{$element}++ }
>     foreach $element (keys %count) {
>         push @union, $element;
>         push @{ $count{$element} > 1 ? \@intersection : \@difference },
> $element;
>     }
> print "$element\n";

Well, no.  Didn't you try it before posting?  'Computer science' is both 
a theoretical science and an experimental science (if it is a science at 
all :-).

As $element is undefined at the end of the loop, that won't do anything 
useful.

  print "@difference\n";

would print the symmetric difference of the two arrays (elements in one 
or the other, but not in both).

But that is not what you asked for -- you wanted the set difference: 
elements in one but not in the other.  Read the thread that I referred 
to, which you cut out of your response.  The techniques are similar; the 
result is not.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Tue, 3 Aug 1999 06:12:37 +0900
From: "Yeong Mo/Director Hana co." <factory@factory.co.kr>
Subject: Re: How to compare two files and get the differences ?
Message-Id: <7o5128$cp5$1@news1.kornet.net>

With your solution, it going to be work.
However, I have no idea hwo to handle the two lines.
my $all = "?????";
my $takeout = "?????";
Would you please give me more directions ?
Thank you in advance.

The following code is what I am trying;
open(FILE, "$page_dir/link/data/categories.backup") || die "I can't open
that file of $dbdata\n";
flock (FILE,1) or die "can't lock index file\n";
  @lines = <FILE>;
  close(FILE);
  $sizelines = @lines;
  for ($i=0;$i<$sizelines;$i++) {
   ($f1, $categorybackup, $f2, $f3, $f4, $f5, $f6, $f7) = split ('\|',
$lines[$i]);
$catall= "$categorybackup,";
}

open(FILE, "$page_dir/link/data/categories.db") || die "I can't open that
file of $dbdata\n";
flock (FILE,1) or die "can't lock index file\n";
  @lines = <FILE>;
  close(FILE);
  $sizelines = @lines;
  for ($i=0;$i<$sizelines;$i++) {
 ($f1, $category, $f2, $f3, $f4, $f5, $f6, $f7) = split ('\|', $lines[$i]);
$cattakeout= "$category,";
 }

use strict;

my $all = "";
my $takeout = "";

my %takeout;
@takeout{split /,\s*/ => $takeout} = ();
my $remain = join ', ' => grep !exists $takeout{$_} =>
    split /,\s*/ => $all;
print "$remain\n";



Larry Rosler ÀÌ(°¡) ¸Þ½ÃÁö¿¡¼­ ÀÛ¼ºÇÏ¿´½À´Ï´Ù...
>In article <7o3hav$162$1@news1.kornet.net> on Mon, 2 Aug 1999 16:38:11
>+0900, Yeong Mo/Director Hana co. <factory@factory.co.kr> says...
>> Larry Rosler ÀÌ(°¡) ¸Þ½ÃÁö¿¡¼­ ÀÛ¼ºÇÏ¿´½À´Ï´Ù...
>                       Who dat?
>...
>> >perlfaq4: "How do I compute the difference of two arrays? How do I
>> >compute the intersection of two arrays?"
>>
>> About perlfaq4.
>> Then is this right to get the differences if there is following 2 arrays
?
>> @array1=(1,2,3,4,5);
>> @array2=(0,2,3,4);
>>     @union = @intersection = @difference = ();
>>     %count = ();
>>     foreach $element (@array1, @array2) { $count{$element}++ }
>>     foreach $element (keys %count) {
>>         push @union, $element;
>>         push @{ $count{$element} > 1 ? \@intersection : \@difference },
>> $element;
>>     }
>> print "$element\n";
>
>Well, no.  Didn't you try it before posting?  'Computer science' is both
>a theoretical science and an experimental science (if it is a science at
>all :-).
>
>As $element is undefined at the end of the loop, that won't do anything
>useful.
>
>  print "@difference\n";
>
>would print the symmetric difference of the two arrays (elements in one
>or the other, but not in both).
>
>But that is not what you asked for -- you wanted the set difference:
>elements in one but not in the other.  Read the thread that I referred
>to, which you cut out of your response.  The techniques are similar; the
>result is not.
>
>--
>(Just Another Larry) Rosler
>Hewlett-Packard Laboratories
>http://www.hpl.hp.com/personal/Larry_Rosler/
>lr@hpl.hp.com




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

Date: Mon, 02 Aug 1999 13:31:12 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: How to determine a date in the past
Message-Id: <37A60010.2410B4DD@mail.cor.epa.gov>

Phil R Lawrence wrote:
[snip]
> sub today {
>     use Date::Calc qw/Today Add_Delta_Days Month_to_Text/;
>     my $self = shift;
> 
>     my $offset = (@_) ? shift() : 0;
>     $self->dielog("Non-integer offset!") unless ($offset =~ /^-?\d+$/);
>     # Steffen Beyer kindly provided the next 2 lines...
>     my ($year, $month, $day) = Add_Delta_Days(Today(), $offset);
>     my $date = uc sprintf("%02d-%.3s-%d", $day, Month_to_Text($month), $year);
                             ^^^^ ^^^^ ^^   ----  -------------

>     return $date;
> }
> This gives MM-DD-YYYY...

Are you sure?  It looks to me like it gives DD-mmm-YYYY, where 'mmm'
is a string for the month.

Which should relieve Alan to no end.  :-)

[Like Steffen Beyer is going to provide an America-centric date 
string.  Leave that to us 'Murkins to muck up.]
 
David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Mon, 02 Aug 1999 13:21:05 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: IP Address validation
Message-Id: <37A5FDB1.82D71145@mail.cor.epa.gov>

Malcolm Ray wrote:
[a very nice post which I am ruthlessly eliding]

Malcolm didn't try to write a complete coverage of the topic,
since this isn't the newsgroup for that.  But.. you might also
want to verify that the IP address is *not* 0.0.0.0 [or some
variant with more zeroes and/or fewer periods].  A regex is not
the ideal way to tackle that either.

And in some cases you may want to verify that the submitter
didn't toss you the ol' loopback address.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Mon, 02 Aug 1999 12:07:18 -0700
From: Helmut Katzgraber <dummkopf@debussy.ucsc.edu>
Subject: Re: IP Validation
Message-Id: <37A5EC66.647FC95D@debussy.ucsc.edu>


that is still not good enough. look into the o'reilly book "mastering
regular expressions". there they make an elaborate example on how to do
it right. your regex should look like this:

([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$

quiet a monster, but it will only match valid IPs.

cheers, h.

-- 
-----------------------------------------------------------------
Helmut G. Katzgraber		mail:	dummkopf@debussy.ucsc.edu
Physics Department, Kerr Hall	http://debussy.ucsc.edu/~dummkopf
University of California	Phone:	(+1) 831-459-4762
Santa Cruz, CA 95064, USA	Fax:    (+1) 831-459-3043
-----------------------------------------------------------------


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

Date: Mon, 2 Aug 1999 12:43:38 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: IP Validation
Message-Id: <MPG.120f94c04b88263989d9d@nntp.hpl.hp.com>

In article <37A5EC66.647FC95D@debussy.ucsc.edu> on Mon, 02 Aug 1999 
12:07:18 -0700, Helmut Katzgraber <dummkopf@debussy.ucsc.edu> says...
> 
> that is still not good enough. look into the o'reilly book "mastering
> regular expressions". there they make an elaborate example on how to do
> it right. your regex should look like this:
> 
> ([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])\.([01]?\d\d?|2[0-4]\d|25[0-5])$
> 
> quiet a monster, but it will only match valid IPs.

This just demonstrates the inanity of using regexes -- which are fine 
for checking syntax -- to check semantics.  A simple capture:

  my @b = $ip_addr =~ /(\d+)\.(\d+)\.(\d+)\.(\d+)/;

Followed by a few checks:

  print "valid\n" if @b && !grep $_ > 255 => @b;

makes a lot more sense.

There may be more rules than you have shown, such as which fields may 
not be 0.  I'm sure the Socket function inet_aton gets it right, as well 
as getting the fewer-than-four-fields forms discussed by Malcolm Ray in 
the other thread.

The original poster sent it twice, so now there are two threads going.  
Yuck!

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Mon, 02 Aug 1999 19:28:35 GMT
From: makarand_kulkarni@my-deja.com
Subject: Re: Logical Construction
Message-Id: <7o4rgm$361$1@nnrp1.deja.com>

--
I think what you want to do is

foreach $item ( items of your complex data struct )
{
   # do your stuff here.
   Process(x) ;
}

whereas in calling sub X() inside while() will
always return the same value ( the first item).

---
>
> while(more X){
>
>  PROCESS  the value returned by X;
> }
>
> sub X{
>
>     foreach (1..10){
>
>       return ONE_AT_A_TIME $_;
>     }
> }
>


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Mon, 02 Aug 1999 22:44:33 +0200
From: Niek Slatius <nslatius@dds.nl>
Subject: Newbie question about hashes
Message-Id: <37A60330.43A938C@dds.nl>

Hi people,

I've been playing with this for a while and tried to put some things
together from what I've found in the perlfaq. I thought I almost found
my answer in a previous thread (thread: Hey that's pretty neat!) but
that didn't fully satisfy me eather. Here's the deal:

In my script I've a hash called %FORM. This thread implements all names
from my HTML form with it's corresponding values.
So for instance: $FORM{'name'} is John. What I want to do is lowercase
all values of this hash.

I started of trying this code:

foreach values %FORM{
    $FORM{$a} = lc $FORM{$a};
}

No good :'-(

I've tried this code:

foreach values %FORM ($value){
    $value = lc $value;
}

That didn't work either :'-(

What a'm I missing here? Don't tell me I need to put the values of %FORM
in an array first, then lowercase those values and then put 'em back in
a hash again please (except of course if that's the only solution) ;-)

Thanx in advance for any support.
BTW if it is in the FAQ (but not in clear simple English) please
redirect me if you would. My native language is not English you see ;-)
so I sometimes have trouble figuring out what words mean (like
'iteration'... although I have a clue as to what it probably means).

Thanx again,

Niek Slatius
nslatius@NO_SPAM.dds.nl (you know the drill)
http://huizen.dds.nl/~nslatius




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

Date: Mon, 02 Aug 1999 20:29:14 GMT
From: makarand_kulkarni@my-deja.com
Subject: Re: parallel processing in perl
Message-Id: <7o4v2d$659$1@nnrp1.deja.com>



Do you mean that you have scripts that fetch data
from Oracle database tables and puts this data into
flat files ? If yes then you can have separate
scripts reading and dumping from these tables. Maybe,
pass the table-name on the command line. Very soon
Perl will have threads and then you can have a
multithreaded program to do this.

==
Makarand Kulkarni

>
> I have a perl script that fetches data from an Oracle database in flat
> files.
>
>


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: 02 Aug 1999 14:55:15 -0500
From: Kent Perrier <kperrier@blkbox.com>
Subject: Re: Perl and pws
Message-Id: <4BBD3872A975FBB5.69AA152635F408FA.3E5170929E7F67A4@lp.airnews.net>

"Andy" <andy@webfx3.freeserve.co.uk> writes:

> Hi
> 
> I have a   simple question . I am using PWS and win98 + perl (for
> windows)when
> i try to   run a script from pws it tries to download it not run it???? What
> is wrong.
> I know this  is in an FAQ somewhere but  i cant find it
> 
> Any Ideas

Yeah, who don't you:

a) read the documentation for your server software and the perl 
distribution that you are using
b) take a look at deja.com and see that this has been asked-and-flamed 
at least once a week for the last month?
and
c) get a better news reader.  The way yours line breaks sucks.

Kent


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

Date: Mon, 02 Aug 1999 12:55:07 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Printing lines BTW two strings in file (NOT!)
Message-Id: <37A5F79B.3879FECF@mail.cor.epa.gov>

Philip 'Yes, that's my address' Newton wrote:
> 
> Tad McClellan wrote:
> 
> [stuff comparing efficiency of xxxx and x{4}; Philip had claimed xxxx
> was more efficient]
> 
> >    Or what were you thinking of?
> 
> Just parroting something I (thought I) read in _Mastering Regular
> Expressions_. Never actually compared the speed myself.

Been there, done that, had the t-shirt chewed right off my back.
:-)

I read the same book, and found that some of the stuff I learned
wasn't true after 5.003 .  Hmmm.  The nerve of some people,
learning by experience and improving the product based on 
enlightened feedback.  I think Ilya bit me twice in a month
about that book.  But I still recommend it to people who want
to learn about regexen in general, even though Perl is not the
only language/tool in the book which has been improved since 
it was published.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Mon, 02 Aug 1999 20:30:38 GMT
From: genelong@my-deja.com
Subject: Problem reading forms with perl
Message-Id: <7o4v5f$685$1@nnrp1.deja.com>

I have a problem I would appreciate help on.  I have an html form with
an input text field that I am reading with a perl program.  I read the
data and then write it out to a file, like this:

open (FILE,">$wholefile") || die "Cannot open $wholefile: $!\n";
$text = $FORM{'text'};
print FILE "$text";
close(FILE);

The problem is that when a user enters "<" in the text area, the
following text does not make it to the file.  So if the user
types "a<b>c", the file winds up with "ac" written to it.

Obviously something is interpreting the "<" as an html command, but I
can't find a way around it.  I have tried

$text =~ s/</xxx/g

but it doesn't seem to find anything to do the substitution.

Can anyone suggest a way of stopping the translation of data, and
simply getting character-for-character data from the input field to a
perl variable?  Many thanks.

Gene Long


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 1 Jul 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.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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


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