[25988] in Perl-Users-Digest
Perl-Users Digest, Issue: 8207 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 27 18:13:05 2005
Date: Mon, 27 Jun 2005 15:05:06 -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, 27 Jun 2005 Volume: 10 Number: 8207
Today's topics:
Re: chdir in parent shell: win32 <1usa@llenroc.ude.invalid>
Re: chdir in parent shell: win32 <pkent77tea@yahoo.com.tea>
Re: Checking IP addresses against lists of IPs, partial (Anno Siegel)
Re: perl script <tadmc@augustmail.com>
Re: regexp to sql wildcard conversion <pkent77tea@yahoo.com.tea>
Re: Simple Structure Question <tadmc@augustmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 27 Jun 2005 18:45:17 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: chdir in parent shell: win32
Message-Id: <Xns96829613F2F5Aasu1cornelledu@127.0.0.1>
"Shea Martin" <sam_squirrelnutz@hotmail.com> wrote in
news:TIXve.53438$Ph4.1528751@ursa-nb00s0.nbnet.nb.ca:
> I have a perl script which does a chdir() at the end. When I call
> this script (from windows console window, cmd.exe), I would like this
> dir to be the new working directory for the console.
You should consult the FAQ before posting:
perldoc -q env
I know the FAQ mentions Unix, but the principle is the same. Your Perl
script is running in a different process than the shell from which it
was invoked.
> *.cmd/*.com/*.bat files which 'cd' do this.
Sure, they run in the same process as the shell that launched them.
> Attachment decoded: untitled-2.txt
> ------=_NextPart_000_0004_01C57B2E.4E73A140
> <html xmlns:o="urn:schemas-microsoft-com:office:office"
> xmlns:w="urn:schemas-microsoft-com:office:word"
> xmlns="http://www.w3.org/TR/REC-html40">
Please do not post HTML.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Mon, 27 Jun 2005 20:12:14 +0100
From: pkent <pkent77tea@yahoo.com.tea>
Subject: Re: chdir in parent shell: win32
Message-Id: <pkent77tea-939265.20120627062005@ptn-nntp-reader01.plus.net>
In article <TIXve.53438$Ph4.1528751@ursa-nb00s0.nbnet.nb.ca>,
"Shea Martin" <sam_squirrelnutz@hotmail.com> wrote:
> I have a perl script which does a chdir() at the end. When I call this
> script (from windows console window, cmd.exe), I would like this dir to
> be the new working directory for the console.
...
> I have tried using chdir(), system(cd <path>), exec(cd <path>). But
> none of them are able to change the directory of the parent shell. I
Basically, it can't be done like that - not in Windows, not in Unix, but
I can't say for sure that that's the case in other OSes.
Your perl program is a new process, and its parent - the cmd.exe window
from which you started it by typing "perl C:\wherever\foo.pl" - doesn't
take much notice of the child. Specifically, changing the working
directory (or %ENV, for example) in the child has no effect on the
parent.
When you run a batch script it's read and executed by the cmd.exe you're
looking at, not by a child cmd.exe process. That's why your cmd.exe
responds to 'cd' commands in the batch script - it's reading and acting
on the .bat file, not forking off a copy of cmd.exe
You could try wrapping the perl script in a batch file - see pl2bat -
and manually add the chdir at the end. Or maybe there's some way of
sending a "change directory" message/event to the cmd.exe process itself
(with Win32::something)? Or you could even get perl to change to the
right directory and then it could start another copy of cmd.exe probably
using exec. I'm sure other people will think of even more answers :-)
Compare the situation on Unix if you had this script:
#!/usr/bin/bash
cd /
and you invoked it the following ways (assume your shell is bash):
./foo
bash ./foo
. ./foo
P
--
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply
------------------------------
Date: 27 Jun 2005 20:30:59 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Checking IP addresses against lists of IPs, partial IPs, and netmasks.
Message-Id: <d9pnm3$fre$2@mamenchi.zrz.TU-Berlin.DE>
Adam Funk <a24061@yahoo.com> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
>
> > Adam Funk <a24061@yahoo.com> wrote in comp.lang.perl.misc:
> >> I'm trying to write some Perl code to check an IP addresses against a
> >> list of strings containing IP address, partial IP addresses ending in
> >> ".", net/mask pairs and net/masklength pairs.
> >>
> >> In other words, I'd like ip_found("192.168.2.3") to return true if the
> >> test list contains any of the following:
> >> 192.168.2.3
> >> 192.168.
> >> 192.168.2.0/255.255.255.0
> >> 192.168.2.0/24
> >>
> >> I'm sure someone else has done this already -- any good code to recycle?
> >
> > So what have you tried? Which modules have you considered?
>
> I had started from scratch using regexps and some other string manipulation,
> but fortunately found Net::Netmask, which does a lot of the job for me.
>
> I can read the input file and for each netmask string, create a Net::Netmask
> and test with the Net::Netmask->match($ip) method, until it returns true or
> I run out of input.
>
> But I'm wondering if there is a more efficient way to do it.
Don't worry about efficiency at this point. Enjoy having found a
method that *works* and move on. When the program as a whole is too
slow, and if it turns out that the IP search is the culprit, then it's
time to think about a speed-up.
In any case, we have too little information about the way that search
is performed to come up with improvements. If you run many IPs against
a rarely changing set of network blocks the situation is different from
the other way 'round.
Anno
------------------------------
Date: Mon, 27 Jun 2005 16:00:24 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: perl script
Message-Id: <slrndc0q78.3gq.tadmc@magna.augustmail.com>
yo <> wrote:
> Subject: perl script
Please put the subject of your article in the Subject of your article.
> open(INFILE, "@ARGV[0]");
You should always enable warnings when developing Perl code!
You should always, yes *always*, check the return value from open().
open(INFILE, $ARGV[0] ) or die "could not open '$ARGV[0]' $!";
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 27 Jun 2005 20:37:54 +0100
From: pkent <pkent77tea@yahoo.com.tea>
Subject: Re: regexp to sql wildcard conversion
Message-Id: <pkent77tea-D8FEDD.20375427062005@ptn-nntp-reader01.plus.net>
In article <2d184bb4.0506270016.51fa2ad3@posting.google.com>,
neil.shadrach@corryn.com (Neil Shadrach) wrote:
> For example given the expression /^a (fatal|critical) error has
> occurred$/
> add "like 'a % error has occurred'" to the sql.
Interestingly (as I often say...) I've got some code at work that could
do with this kind of "best effort" regex->SQL conversion but doesn't yet
do it. I'm assuming your database doesn't support any kind of regexes,
and that it supports the % and _ wildcards.
My idea would be this sort of conversion (pseudocode):
if the first token is a '^'
remove that token
else
sql = '%'
end unless
if the last token is a '$'
remove that token
else
sqlend = '%'
end unless
foreach token in the regex
if the token is a constant character
sql .= escaped form of that character
else if the token represents exactly one unknown character
sql .= '_'
else
sql .= '%'
end if
end foreach
sql .= sqlend
Now, I haven't tested that at all but it looks like it would do the
right thing. The tricky bit is turning the regex into a string of tokens
- maybe this would be of use there:
http://search.cpan.org/~pinyan/Regexp-Parser-0.10/lib/Regexp/Parser.pm
(although you might not need to walk the whole regex tree, just to a
depth of one level, to determine what to do to each token?)
P
--
pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
Remove the tea to reply
------------------------------
Date: Mon, 27 Jun 2005 16:31:18 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Simple Structure Question
Message-Id: <slrndc0s16.3gq.tadmc@magna.augustmail.com>
one man army <newsAT@screenlightDOT.com> wrote:
> You know why All Five of you men are so cool, because You Read The
> Manual!
Thanks, now that we have affirmation from you, our lives are complete.
> I admit it, after 2 straight 15 hour plus research days, on a completely
> unrelated topic,
If it was unrelated, then why do you bring it up?
> That's why you guys are
> worth it, 'cause your language does work.
Yeah, right.
> But in the Beginners Perl Book I have, there is no discussion of this
> terse syntax I encountered,
I fail to see how a deficiency in the book you've chosen is relevant.
> The post that is really the indicator of them all I think is Tassilo's
> with the .sig that says "use bigint;
> $n=71423350343770280161397026330337371139054411854220053437565440;
> $m=-8,;;$_=$n&(0xff)<<$m,,$_>>=$m,,print+chr,,while(($m+=8)<=200);"
>
> I have worked as a C programmer for 15 years. I have written and shipped
> and rev'ed huge commercial applications.
Wow, you da man!
> You will never, ever, ever find
> code like that in any file, ever. It is considered Bad Practice, for
> good reasons.
You don't seem to be able to tell playing around from production code.
> But I don't have months to just study Perl.
That's fortunate, since a couple of hours would be enough to
accomplish your task.
> The post was
> hasty, I admit it.
Then why all the whining?
So long!
--
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 8207
***************************************