[17914] in Perl-Users-Digest
Perl-Users Digest, Issue: 74 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 16 21:05:33 2001
Date: Tue, 16 Jan 2001 18:05:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <979697111-v10-i74@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 16 Jan 2001 Volume: 10 Number: 74
Today's topics:
Re: ApacheModulePerl.dll <randy@theory.uwinnipeg.ca>
Re: bidirectional communication using sockets <bart.lateur@skynet.be>
Re: Can't associate .PL files in Win98 <glburton@mindspring.com>
Re: Can't associate .PL files in Win98 <glburton@mindspring.com>
Re: Can't associate .PL files in Win98 <glburton@mindspring.com>
Defining global variables with an installer script <ans@_nospam_x64.net>
Re: Fetching server's hard-disk with Perl <ans@_nospam_x64.net>
Finite Automata with Output using PerlRE? <pcj@Stanford.EDU>
Re: Finite Automata with Output using PerlRE? <kstep@pepsdesign.com>
Fork, IPC:Open2, Windows? jmwjr@my-deja.com
grepmail 4.45 released <newspost@coppit.org>
Re: How to convert a double-spaced file to single space <mischief@velma.motion.net>
Re: How to convert a double-spaced file to single space (Ben Okopnik)
Re: More questions about pattern matching <mischief@velma.motion.net>
Re: More questions about pattern matching pyro3k@my-deja.com
Re: Newbie question: hash tables and dbm files; what am <nospam-abuse@[127.0.0.1]>
Newbie Sytax Question <sean@customautotrim.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 16 Jan 2001 19:29:42 -0600
From: "Randy Kobes" <randy@theory.uwinnipeg.ca>
Subject: Re: ApacheModulePerl.dll
Message-Id: <942std$3dt$1@canopus.cc.umanitoba.ca>
"Rob" <a565a87@my-deja.com> wrote in
message news:9414ed$8aj$1@nnrp1.deja.com...
> I nmade 5.6.0 from the CPAN source distribution, and the root sits on
> my C drive. I'm using the very latest Win32 1.3.14 binary distr. of
> Apache.
[ ... ]
> The httpd.conf DSO line reads:
> LoadModule perl_module modules/ApacheModulePerl.dll
>
> ---
> Running Apache from the console, not a service. I get the following:
>
> R:\Program Files\Apache Group\Apache>apache
> Syntax error on line 205 of r:/program files/apache
> group/apache/http.conf:
> Cannot load r:/program files/apache
> group/apache/modules/ApacheModulePerl.dll into server:
> Note the errors or messages above, and press the <Esc> key to exit.
> R:\Program Files\Apache Group\Apache>apache
>
> The ApacheModulePerl.dll is a binary that I obtained
> from .../authors/Jeffrey_Baker. The file is dated 10/28/98. (It's the
> one that isn't supposed to work with the ActiveState perl.) I'm not
> using an ActiveState distribution.
[ ... ]
That ApacheModulePerl.dll is relatively old, and most likely
isn't binary compatible with your perl. You'll have to compile
mod_perl yourself, with the same compiler that you built
perl with (this probably has to be VC++, to be compatible
with the apache binary). The cvs mod_perl sources are at
http://perl.apache.org/from-cvs/modperl/ - see
INSTALL.win32 for directions for compiling on Win32.
best regards,
randy kobes
------------------------------
Date: Wed, 17 Jan 2001 01:16:59 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: bidirectional communication using sockets
Message-Id: <ois96tcmqhvk1feg02bp6usenh2j353rl6@4ax.com>
John Boy Walton wrote:
>> I am trying to write a PERL program using sockets. One side ( which
>> we call client ) is communicating with the listener ( which we call
>> server)
>The server serves and the client 'listens', you have them around the wrong
>way.
Really? Hmmm... the client is the one that initiates communication, a
server is the one that responds to it.
--
Bart.
------------------------------
Date: Tue, 16 Jan 2001 16:58:43 -0800
From: Gary Burton <glburton@mindspring.com>
Subject: Re: Can't associate .PL files in Win98
Message-Id: <3A64EE43.633D6FC3@mindspring.com>
Steve:
Your problem and mine are much different. Although I am the one most confused here, I believe I have the answer to YOUR question. It seems that you just need to put ";c:\perl\bin\" at the end of your path.
Now, if I were only that smart when it comes to MY question.
shiloam@pacbell.net wrote:
> >
>
> Ok, I think everyone is making this just a little bit too complicated.
> Yes the perl %1 is what the registry says, and yes, I too have win98
> and am running ActivePerl and it runs just fine. However when I enter
> an MS-Dos Prompt and type something like myscript.pl it says 'bad
> command or filename'. This is because the Perl.exe can't
> be 'associated' in DOS. DOS doesn't know what an 'association' is. If I
> type 'c:\perl\bin\perl.exe myscript.pl' however, I get satisfactory
> results.
>
> Now if you are double-clicking an Icon somewhere in windows, the
> association should work, do like the previous engineer said and put
> something like;
>
> <STDIN>;
>
> at the end of ALL your scripts until you get the hang of it. <STDIN>
> just waits for user input. Good Luck.
>
> Steve Tilden
> Instant Perl Fan
>
> Sent via Deja.com
> http://www.deja.com/
------------------------------
Date: Tue, 16 Jan 2001 17:15:49 -0800
From: Gary Burton <glburton@mindspring.com>
Subject: Re: Can't associate .PL files in Win98
Message-Id: <3A64F245.8021DB94@mindspring.com>
What you say is true if the path to the script file does not have any spaces in it, but falls apart if it does. However, it seems that you are correct about the fact that you can't associate to the DOS shell. None of the other suggestions I have gotten are working.
My "batch file" solution seems to be the best option at this point. Anyway, you taught me something new.
Duncan Murdoch wrote:
>
> On Mon, 15 Jan 2001 19:01:49 -0600, David Efflandt <efflandt@xnet.com>
> wrote:
>
> >While the file association does not work from the DOS shell, it does work
> >from Windows Explorer (see below). From the DOS shell you either run the
> >script as a commandline parameter to Perl, or use pl2bat to convert it to
> >a .bat file.
>
> File associations *do* work from the DOS shell, but you need to use
> the "start" program to access them. That is, if you've associated
> *.pl with Perl, then
>
> start prog.pl
>
> will run "Perl prog.pl". It saves a bit of typing if Perl isn't on
> the current path. (If you want to save typing even when Perl is on
> the path, you could rename start.exe to s.exe...)
>
> Not Perl related, but "start ." is a quick way to open an Explorer
> view of the current directory.
>
> Duncan Murdoch
------------------------------
Date: Tue, 16 Jan 2001 17:51:11 -0800
From: Gary Burton <glburton@mindspring.com>
To: David Efflandt <efflandt@xnet.com>
Subject: Re: Can't associate .PL files in Win98
Message-Id: <3A64FA8F.87EB7937@mindspring.com>
It seems you are correct about the association. I have not been able to make anyone else's suggestions work.
Rather than using pl2bat, why not do what I suggested in my posting of the 14th? That is create one batch file to launch all perl programs and associate that batch file with the .pl extension? In my posting, I complained about that solution and said I don't like it much. However, it is looking pretty good at this point.
David Efflandt wrote:
>
> On Sun, 14 Jan 2001, Gary Burton wrote:
>
> > The association still would not work in Windows 98. An opinion on one
> > of the discussion groups was that it can't be done for shell
> > (DOS) programs in Win95 or Win98, although it works fine in Windows
> > NT. Unfortunately, that seems to be correct because I carefully
> > reviewed the instructions in ActiveState's perlwin32faq4 FAQ called "How
> > do I associate Perl scripts with Perl?" and followed them precisely.
>
> While the file association does not work from the DOS shell, it does work
> from Windows Explorer (see below). From the DOS shell you either run the
> script as a commandline parameter to Perl, or use pl2bat to convert it to
> a .bat file. This requires that Perl and pl2bat are in your PATH (usually
> C:\PERL\BIN). The pl2bat worked for me.
>
------------------------------
Date: Wed, 17 Jan 2001 00:32:04 GMT
From: "Anson Parker" <ans@_nospam_x64.net>
Subject: Defining global variables with an installer script
Message-Id: <8K596.65892$xW4.516790@news-server.bigpond.net.au>
Does anyone have some advice on writing an installer to install a
bunch of perl scripts? The key issue is I'd like the installer to write
some user-defined variables into a Perl file such as, for example,
where to write the log file to.
e.g. file "config.pl"
$LOGFILE = '/var/log/mylog.txt';
Basically I have one file which stores a bunch of these globals variables
such as the above example and is used by the other Perl scripts (I guess
like a header file in C) - is this sort of requirement fulfilled by
something
like ExtUtils::MakeMaker?
------------------------------
Date: Wed, 17 Jan 2001 00:56:41 GMT
From: "Anson Parker" <ans@_nospam_x64.net>
Subject: Re: Fetching server's hard-disk with Perl
Message-Id: <d5696.65909$xW4.516982@news-server.bigpond.net.au>
You cannot index the entire server's hard disk (well, unless the
server is some kind of web-based filesystem) through a web
browser. What you can do is index all files (html, gif, jpg, etc.)
linked from the first html page of the web server (including
subsequent html pages which link to others and so on).
Essentially, you'd be writing a web robot to crawl through a
specified website - if you're not careful (and have enough bandwidth)
you can inadvertantly write a DoS attack - you should read
"A Standard for Robot Exclusion" at
http://www.hirschle.ch/html-kurs/robots/robots.html to get
an idea of how to make your robot well behaved.
Otherwise check out the Perl modules at CPAN:
WWW::Robot - Web traversal engine for robots & agents
WWW::RobotRules - Parse /robots.txt file
Anson.
<-nancy-@libero.it> wrote in message news:3a64681f.17002689@news.tin.it...
> Hi
>
> I'm trying to write a perl script
> who indexes the content of a web server's hard disk
> simply by typing an URL.
>
> The script has to list all the files on the server's hard disk
> on which that URL is hosted.
>
> Is it possible to do so ? If so, do I have to use LWP ?
>
> Please give me directions, thanks
>
> Joseph
>
------------------------------
Date: 16 Jan 2001 23:18:03 GMT
From: Paul Cody Johnston <pcj@Stanford.EDU>
Subject: Finite Automata with Output using PerlRE?
Message-Id: <942krb$c6f$1@nntp.Stanford.EDU>
I'd like to be able to automata with output, like a lexer might.
Therefore in a regular expression having several alternatives ( '|' ), I'd
like to be able to know which alternative was successful. I'd also like
to be able to associate an identifier (or a number) with each alternative
in the definition of the regex.
This would involve extending the regular expression syntax and possibly
the addition of another special variable.
For example if I have the regular expression:
$animal =~ m/ cat | dog | mouse /x;
I want to know what kind of animal it is. Preferably, I would have
something like:
my $DOG = 10;
my $CAT = 20;
my $MOUSE = 30;
$animal = m/ (?~$DOG dog ) | (?~$CAT cat ) | (?~$MOUSE mouse ) /x;
use English;
my $animal_id = $MATCH_OUTPUT;
So in this example I made up some hypothetical new regex syntax where the
(?~ ) group means "Associate the value after the tilde with the enclosing
alternative. If the alternative is successfully matched, set the special
variable "MATCH_OUTPUT" to that value".
Finally, I have two questions:
(1) can I do this now in Perl?
(2) if not, what do you think of the idea?
Thanks,
Paul
------------------------------
Date: Tue, 16 Jan 2001 20:44:07 -0500
From: "Kurt Stephens" <kstep@pepsdesign.com>
Subject: Re: Finite Automata with Output using PerlRE?
Message-Id: <942t97$4va$1@slb6.atl.mindspring.net>
"Paul Cody Johnston" <pcj@Stanford.EDU> wrote in message
news:942krb$c6f$1@nntp.Stanford.EDU...
> I'd like to be able to automata with output, like a lexer might.
> Therefore in a regular expression having several alternatives ( '|' ), I'd
> like to be able to know which alternative was successful. I'd also like
> to be able to associate an identifier (or a number) with each alternative
> in the definition of the regex.
If you are looking for a lexer, check out the Parse::Lex bundle on CPAN.
The bundle contains several modules that allow you to specify an action that
is executed when the associated regex matches. These lexers work either by
modifying the pos() pointer in the source string or by consuming tokens from
the string. The actions are simple code references, and may do as little as
returning the token itself.
> This would involve extending the regular expression syntax and possibly
> the addition of another special variable.
>
> For example if I have the regular expression:
>
> $animal =~ m/ cat | dog | mouse /x;
>
> I want to know what kind of animal it is. Preferably, I would have
> something like:
>
> my $DOG = 10;
> my $CAT = 20;
> my $MOUSE = 30;
>
> $animal = m/ (?~$DOG dog ) | (?~$CAT cat ) | (?~$MOUSE mouse ) /x;
> use English;
> my $animal_id = $MATCH_OUTPUT;
I don't see a need for a new regex syntax here. By examining the capture
variables $1, etc. you can determine which part of the regex matches.
<<start code>>
my ($text, $animal);
$text = 'Eeek, a mouse!';
if ($text =~ m/\b(cat|dog|mouse)\b/) {
$animal = uc($1);
print $animal;
}
<<end code>>
If you wanted to associate a numerical value with the token, you could use a
hash: The example below also shows how to generate the regex on the fly.
<<start code>>
my %tokens = (
CAT => 1,
DOG => 2,
MOUSE => 3,
);
my $temp = join '|', keys %tokens;
my $regex = qr{\b($temp)\b}i;
my $text = 'Eeek, a mouse!';
if ($text =~ m/$regex/) {
print "$1 => ", $tokens{uc($1)}, "\n";
}
<<end code>>
Finally, a lexer that demonstrates lex like behavior. The lexer sub
consumes tokens from the global scalar ref $LLTEXT. The behavior is quite
similar to the lexers generated by Parse::Lex.
<<start code>>
use strict;
use warnings;
my @animals = qw(
aardvark bison cat
dog emu frog
);
my @regexen = map { qr{\b$_\b}i } @animals;
my $text = "I saw a gnu, emu, cat and bison";
my $LLTEXT = \$text;
while (1) {
my ($type, $token) = lexer();
last unless $type;
print "$type: '$token'\n";
}
sub lexer {
# Dummy foreach loop coerces $$LLTEXT into $_
foreach ($$LLTEXT) {
# Strip whitespace
s/^\s+// and redo;
# Test each regex
foreach my $regex (@regexen) {
s/^($regex)// and return (uc($1), $1);
}
# Capture other tokens
s/^(\w+)// and return ('WORD', $1);
s/^(\S+)// and return ('OTHER', $1);
s/^(.+)// and return ('UNKNOWN', $1);
}
return (undef, undef); # Done
}
<<end code>>
HTH,
Kurt Stephens
------------------------------
Date: Wed, 17 Jan 2001 01:19:57 GMT
From: jmwjr@my-deja.com
Subject: Fork, IPC:Open2, Windows?
Message-Id: <942rvl$p95$1@nnrp1.deja.com>
I have a client/server perl app that spawns another executable for each
client using IPC::Open2. If I run the server on a Solaris box it works
great, but when I try the server on a win(NT or 2000) box it doesnt
work well.
After teting for a while it seems to me that the combination of Win,
IPC::Open2 and fork is what is giving me problems. I have test scripts
which I have used to try to isolate the problem. I have wrote echo.pl
to simulate the executable. All it does is send the data it receives
from STDIN to STDOUT preceding it with "DONE".
I know open2 does a fork, is this possible causing some problems?
I have tried to narrow the problem down, but might have missed
something. Has anyone had problems porting to windows with forks.
Thanks Mike.
#
# echo.pl
#
select STDOUT; $| = 1;
while (<>) {
$i++;
print "DONE $i $_";
}
#######################################################################
Using IPC::Open2 without forking, but having two open2's running to the
echo.pl works.
#
# test_nfork.pl
#
use IPC::Open2;
$|++;
$id=$$;
print "$pid\n";
open (TMP1, ">tmp1.txt");
select TMP1; $|++;
select STDOUT;
select TMP2; $|++;
select STDOUT;
open (TMP2, ">tmp2.txt");
print TMP1 "The Parent $$ $pid\n";
print TMP2 "The Child $$ $pid\n";
print TMP1 "The BEG1\n";
print TMP2 "The BEG2\n";
$openid1=open2(\*READ1, \*WRITE1, 'perl ./echo.pl -');
$openid2=open2(\*READ2, \*WRITE2, 'perl ./echo.pl -');
print TMP1 "Parent OpenId $openid1\n";
print WRITE1 "Help Me\n";
print TMP2 "Child OpenId $openid2\n";
print WRITE2 "Help Me Toooo\n";
$line1 = <READ1>;
$line2 = <READ2>;
print TMP1 "Rec1: $line1";
print TMP2 "Rec2 $line2";
close (READ1); close (WRITE1);
close (READ2); close (WRITE2);
print TMP1 "The END1\n";
close TMP1;
print TMP2 "The END2\n";
close TMP2;
#####################################################################
But when I combine a fork to one child process, and run the open2 in
both the parent and child, the parent sends and receives data
correctly, but the child never gets anything form the echo.pl.
#
# test_fork.pl
#
use IPC::Open2;
$|++;
$id=$$;
print "$pid\n";
$pid = fork();
if (!($pid == 0)) {
open (TMP1, ">tmp1.txt");
select TMP1; $|++;
select STDOUT;
print TMP1 "The Parent $$ $pid\n";
print TMP1 "The BEG1\n";
$openid1=open2(\*READ1, \*WRITE1, 'perl ./echo.pl -');
print TMP1 "Parent OpenId $openid1\n";
print WRITE1 "Help Me\n";
$line1 = <READ1>;
print TMP1 "Rec1: $line1";
close (READ1); close (WRITE1);
print TMP1 "The END1\n";
close TMP1;
}
else {
open (TMP2, ">tmp2.txt");
select TMP2; $|++;
select STDOUT;
print TMP2 "The Child $$ $pid\n";
print TMP2 "The BEG2\n";
$openid2=open2(\*READ2, \*WRITE2, 'perl ./echo.pl -');
print TMP2 "Child OpenId $openid2\n";
print WRITE2 "Help Me Toooo\n";
$line2 = <READ2>;
print TMP2 "Rec2 $line2";
close (READ2); close (WRITE2);
print TMP2 "The END2\n";
close TMP2;
}
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Tue, 16 Jan 2001 18:08:54 -0500
From: David Coppit <newspost@coppit.org>
Subject: grepmail 4.45 released
Message-Id: <t69lbihfrhvn83@corp.supernews.com>
Description:
- grepmail is a Perl program that searches a normal or compressed mailbox
(gzip, bzip2, or tzip) for a given regular expression and returns those
emails that match the query. It also supports searches constrained by date
and size.
Download:
- You can download grepmail 4.45 from CPAN:
http://www.cpan.org/authors/id/D/DC/DCOPPIT/grepmail-4.45.tar.gz
- Until the file propagates to the mirrors, you can use the following URL:
http://download.sourceforge.net/grepmail/grepmail-4.45.tar.gz
Changes:
- Added -n and -V to usage message.
- Added workarounds to prevent warnings resulting from a bug in Perl 5.6
- A blank line before the start of an email is not required now. This
allows broken folders created by Netscape to be read.
A complete change log is at:
- ftp://grepmail.sourceforge.net/pub/grepmail/CHANGES
David
------------------------------
Date: Tue, 16 Jan 2001 23:36:58 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: How to convert a double-spaced file to single spaced?
Message-Id: <t69moqnesj1t73@corp.supernews.com>
Abigail <abigail@foad.org> wrote:
> Colin Watson (cjw44@flatline.org.uk) wrote on MMDCXCV September MCMXCIII
> in <URL:news:9426pv$ssq$1@riva.ucam.org>:
> __ Terrence Brannon <brannon@lnc.usc.edu> wrote:
> __ >How can I do this as a Perl one-liner? I get very confused when I try
> __ >to understand the -n -p -l -e options of perl, but I am sure I can do
> __ >this in one line if I could figure them out.
> __
> __ Either of these, depending on which way round your spacing is:
> __
> __ perl -ne 'print if $i = !$i'
> __ perl -ne 'print unless $i = !$i'
Colin's response works if the data is uniformly double-spaced, but
I hate choosing based on the ordering of the lines. It loses nonblank
data if the data is not uniformly double-spaced, too.
> Or just:
> $ perl -lp00e0 in > out
Abigail's solution works to get rid of all blank lines just like the
following:
$ perl -ne 'print if(!/^$/)'
or
$ perl -ne 'print unless(/^$/)'
Of course, Abigail's solution is, as usual, shorter than mine to
do the same thing.
For some cases of doublespace to singlespace conversion, this is
exactly what needs to be done. However, if there are supposed to
be some blank lines left, such as changing example 1a to example
1b below, ( I'll use visible \n to signify the newlines for visual
clarity ):
###----- 1a:
line\n
\n
another line\n
\n
\n
\n
line after a blank line\n
###----- end of 1a
###----- 1b:
line\n
another line\n
\n
line after a blank line\n
###----- end of 1b
The following one-liner will get rid of blank lines between two
otherwise contiguous lines, but will leave every second blank
line in a series of blank lines. This may be a better solution
in cases where some blank lines should be maintained. I'm not
sure if this is an issue for the OP or not, but I thought I'd
mention it just in case anyone really needs this behavior.
perl -p0e 's/(.*)?\n\n(.*)?/$1\n$2/g' in > out
--
Christopher E. Stith
Disclaimer: Actual product may not resemble picture in ad in any way.
------------------------------
Date: 17 Jan 2001 00:53:34 GMT
From: ben-fuzzybear@geocities.com (Ben Okopnik)
Subject: Re: How to convert a double-spaced file to single spaced?
Message-Id: <slrn969rc8.1a6.ben-fuzzybear@Odin.Thor>
The ancient archives of Tue, 16 Jan 2001 23:36:58 -0000 showed
Chris Stith of comp.lang.perl.misc speaking thus:
>Abigail <abigail@foad.org> wrote:
>
>> Or just:
>
>> $ perl -lp00e0 in > out
<Laugh> Awesome. As usual. This time, I even know what she did. Hanging
around this group is having a positive effect on my Perl knowledge -
amazing. :)
>The following one-liner will get rid of blank lines between two
>otherwise contiguous lines, but will leave every second blank
>line in a series of blank lines. This may be a better solution
>in cases where some blank lines should be maintained. I'm not
>sure if this is an issue for the OP or not, but I thought I'd
>mention it just in case anyone really needs this behavior.
>
>perl -p0e 's/(.*)?\n\n(.*)?/$1\n$2/g' in > out
In that case, I'll risk sticking my oar in - is there anything wrong with
the following?
perl -pi~ -wp0e's/\n\n/\n/g' in
I wrote an 'awk' version of it a couple of years ago, and have been using
it to "undoublespace" files ever since. It's not something that comes up
very often, but it has come in useful.
Ben Okopnik
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
perl -we '$perl=0;JsP $perl "perl"; $perl->perl(0)'\
2>&1|perl -ne '{print ((split//)[19,29,20,4,5,1,2,
15,13,14,12,52,5,21,12,52,8,5,14,1,6,37,12,52,75])}'
------------------------------
Date: Wed, 17 Jan 2001 00:31:25 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: More questions about pattern matching
Message-Id: <t69putcfi4ni0a@corp.supernews.com>
Mike McPherson <hafateltec@hotmail.com> wrote:
> First I think that there should be a newsgroup just for perl re alone :) I
> think it would get the traffic LOL
> #!/usr/bin/perl -w
> print "\nPlease input a ip address in xxx.xxx.xxx.xxx format --->";
> $validip = <STDIN>;
> unless ($validip =~
> /^[0-2][0-5]{2}.[0-2][0-5]{2}.[0-2][0-5]{2}.[0-2][0-5]{2}/) {
> chomp($validip);
> print "\n$validip: Not a valid ip\n";
> }else{
> chomp($validip);
> print "\n$validip is valid\n";
> }
What are you trying to do? Valid IPs can contain up to 9 when written
in decimal. Just because 255 is the largest allowed doesn't mean that
99 is not allowed. 99.99.99.99 is a perfectly valid IP address.
> As I read I am seeing more and more on how to do this regexp but there are
> still some things that I am not sure on.
> For example the above will validate a number such as 111.111.111.111 yet it
> will not validate 249.249.249.249 ::
Of course not. You're disallowing anything that isn't three characters
per section, with only 0 through 5 for the second two characters. BTW,
012.012.012.012 on some systems is entirely different from 12.12.12.12
as an IP address. By not allowing a section shorter than three characters,
you'd be making your program technically incorrect even if it matched
the right ranges.
> So now you can see some of my frustration. Unfortunatly my "Mastering
> Regular Expressions by Jeffrey Friedl" is still 3 days away from getting
> here and I need to figure this out earlier than that so all help is
> appriciated.
Treating this as a regular expression alone is part of your problem.
You could validate an address via a regex, but it would be far more
complex than splitting the sections and doing numeric comparisons.
The following code has been tested at the bounds and at a few spots
within the range, and seems to work. Don't be afraid to build a
regex from variables if you must use a regex for something this
complex. Do be afraid to use a regex that is this complex in the
first place unless you know what you are doing.
######################################################
#!/usr/bin/perl -w
use strict;
my $section = '(?:(?:[0-2]?[0-5]{2})|(?:[0-9]{0,2}))';
my $dot = '\.';
while(<>) {
if( /(?:$section$dot){3}$section/o ) {
print "Valid IP: $_\n";
} else {
print "Invalid IP: $_\n";
}
}
######################################################
The following splits sections at '.' and checks the section
against the minimum value of 0 and the maximum value of 255.
It may have more lines, but the logic is simpler and it might
even be faster, although I haven't benchmarked the two.
######################################################
#!/usr/bin/perl -w
use strict;
while(<>) {
chomp;
my @section = split(/\./);
my $good_ip = 1;
for( @section ) {
if( $_ > 255 ) {
$good_ip = 0;
last;
} elsif( $_ < 0 ) {
$good_ip = 0;
last;
} else {
# no change
}
}
if( $good_ip ) {
print "Valid IP: $_\n";
} else {
print "Invalid IP: $_\n";
}
}
#######################################################
HTH,
Chris
--
Christopher E. Stith
Product shown enlarged to make you think you're getting more.
------------------------------
Date: Wed, 17 Jan 2001 01:46:09 GMT
From: pyro3k@my-deja.com
Subject: Re: More questions about pattern matching
Message-Id: <942tgv$qgb$1@nnrp1.deja.com>
In article <t69putcfi4ni0a@corp.supernews.com>,
Chris Stith <mischief@velma.motion.net> wrote:
> ######################################################
>
> The following splits sections at '.' and checks the section
> against the minimum value of 0 and the maximum value of 255.
> It may have more lines, but the logic is simpler and it might
> even be faster, although I haven't benchmarked the two.
>
> ######################################################
> #!/usr/bin/perl -w
> use strict;
>
> while(<>) {
> chomp;
> my @section = split(/\./);
> my $good_ip = 1;
> for( @section ) {
> if( $_ > 255 ) {
> $good_ip = 0;
> last;
> } elsif( $_ < 0 ) {
> $good_ip = 0;
> last;
> } else {
> # no change
> }
> }
> if( $good_ip ) {
> print "Valid IP: $_\n";
> } else {
> print "Invalid IP: $_\n";
> }
> }
> #######################################################
>
> HTH,
> Chris
This works beautifully %99.999999. Returns Valid if input is 1...
Sent via Deja.com
http://www.deja.com/
------------------------------
Date: Tue, 16 Jan 2001 20:29:17 -0500
From: "James Kauzlarich" <nospam-abuse@[127.0.0.1]>
Subject: Re: Newbie question: hash tables and dbm files; what am I doing wrong?
Message-Id: <kz696.3131$d25.20940@newsfeed.slurp.net>
----- Original Message -----
From: Garry Williams <garry@zvolve.com>
Newsgroups: comp.lang.perl.misc
Sent: Tuesday, January 16, 2001 10:15 AM
Subject: Re: Newbie question: hash tables and dbm files; what am I doing
wrong?
> The remedy is to serialize your data structure before storing it as
> the value in a dbm record.
>
> --
> Garry Williams
I don't know what you mean by that.
I was hoping to be able to do it without relying on modules. I'm not using
my own machine, and my ISP does not have many modules installed. In fact,
they may have none. And they have not been inclined to install any. I
asked if they could install the CGI module, and they asked 1) What was it.
2) Where could it be gotten from, and 3) If it was a standard part of perl.
Then they said no. That was before they yanked shell access from all the
users. So I wrote my own routines to decode and encode URL's.
I guess I'm gonna have to move it to another server. ::sigh:: Oh well, I
found a neat free one. Shell access, ftp, cgi-bin, SSI and MySQL (I'll
probably end up doing it in that). The only drawback is it's in Russia and
the support documents don't really survive the Bablefish process (grin)
Oh well, I thank everybody for their input.
jmk
--
do NOT remove the nospam from the repy to address above,
instead send email to o1tech(at)skyenet(dot)net
------------------------------
Date: Tue, 16 Jan 2001 16:03:20 -0800
From: sean <sean@customautotrim.com>
Subject: Newbie Sytax Question
Message-Id: <3A64E148.BBDE7865@customautotrim.com>
I'm having a problem using the Perl print statement (print "Set-Cookie:
cookie1=ezine; \n";) to send a cookie that works for IE, the snippet
below works just fine for Netscape but it won't set a cookie in IE. Can
anyone point me in the right direction on this?
#!/usr/bin/perl
print "Set-Cookie: cookie1=ezine; \n";
print "Content-type: text/html\n\n";
print <<"HTML code";
<html>
<head>
<title>Untitled</title>
<body>
<p>Cookie has been set.</p>
</body>
</html>
HTML code
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 74
*************************************