[24106] in Perl-Users-Digest
Perl-Users Digest, Issue: 6300 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 25 09:05:55 2004
Date: Thu, 25 Mar 2004 06:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 25 Mar 2004 Volume: 10 Number: 6300
Today's topics:
Re: Accessing OS Message Loop (Phil Jacobson)
Re: Accessing OS Message Loop chris-usenet@roaima.co.uk
check for unix wildcards in filename (Rex Gustavus Adolphus)
Re: check for unix wildcards in filename (Anno Siegel)
Re: check for unix wildcards in filename <nobull@mail.com>
Re: check for unix wildcards in filename (Anno Siegel)
Declaring variables outside subroutines <anon@ics.mq.edu.au>
Re: Declaring variables outside subroutines (Anno Siegel)
Re: dollar sign and spaces from a string <jwillmore@remove.adelphia.net>
Re: dollar sign and spaces from a string <mr@sandman.net>
Re: File traversing <bmb@ginger.libs.uga.edu>
Re: File traversing (Malcolm Dew-Jones)
I want to scanf, dammit! <mitia.nospam@northwestern.edu.invalid>
Re: I want to scanf, dammit! <m@lteubl.de>
Re: I want to scanf, dammit! (Anno Siegel)
Re: need help with array searching <bmb@ginger.libs.uga.edu>
parsing config file (Simon Lee)
Re: parsing config file (Anno Siegel)
Re: Per Script Beginner Advice (SWREG) <Joe.Smith@inwap.com>
Re: Per Script Beginner Advice (SWREG) <jwillmore@remove.adelphia.net>
Re: Per Script Beginner Advice (SWREG) <jwillmore@remove.adelphia.net>
Perl automation of Mozilla <rbell01824@earthlink.net>
Re: Perl upgraded = problem resurfacing <nobull@mail.com>
Puzzling Socket::inet_ntoa problem axel@white-eagle.co.uk
Re: Puzzling Socket::inet_ntoa problem (Anno Siegel)
Re: Removing folders recursively <Joe.Smith@inwap.com>
Re: SOAP::Lite <tadmc@augustmail.com>
Re: SOAP::Lite <postmaster@castleamber.com>
Re: The "value" of a block in 'map' (Anno Siegel)
Re: The "value" of a block in 'map' <uri.guttman@fmr.com>
Re: The "value" of a block in 'map' <bernie@fantasyfarm.com>
Re: The "value" of a block in 'map' <bernie@fantasyfarm.com>
Re: The "value" of a block in 'map' <bernie@fantasyfarm.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 24 Mar 2004 18:34:53 -0800
From: p_jacobson@hotmail.com (Phil Jacobson)
Subject: Re: Accessing OS Message Loop
Message-Id: <2453019.0403241834.10e55fe9@posting.google.com>
> What is it you're really hoping to achieve?
One of the things I'd like to do is point perl at a file and say
"under no circumstances are you to let this file be modified, copied
over or deleted." And while I was thinking about if I could achieve
this, I began to explore the main Windows message loop as an option.
Could it even be possible to allow perl to read the message loop and,
if it sees an instruction regarding a particular file, prevent that
instruction from taking place.
Phil Jacobson
------------------------------
Date: Thu, 25 Mar 2004 13:00:50 +0000
From: chris-usenet@roaima.co.uk
Subject: Re: Accessing OS Message Loop
Message-Id: <2p1bj1-1co.ln1@moldev.cmagroup.co.uk>
Phil Jacobson <p_jacobson@hotmail.com> wrote:
> One of the things I'd like to do is point perl at a file and say
> "under no circumstances are you to let this file be modified, copied
> over or deleted."
It seems to me that the easiest way of solving this is to use a filesystem
that provides user based permissions, and lock down the file that
way. Since you're on Windows, NTFS would be a reasonable choice.
Chris
------------------------------
Date: 25 Mar 2004 02:58:20 -0800
From: uffesterner@spamhole.com (Rex Gustavus Adolphus)
Subject: check for unix wildcards in filename
Message-Id: <c70a85ff.0403250258.7d39cee4@posting.google.com>
Hi
I need to check if a variable containing a filename
has any (non-escaped) unix wildcards in it.
I guess a nice regex would do the trick,
could any of you regex-gurus publish _the_ regex for it?
Tia
------------------------------
Date: 25 Mar 2004 11:20:45 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: check for unix wildcards in filename
Message-Id: <c3ufad$ktk$1@mamenchi.zrz.TU-Berlin.DE>
Rex Gustavus Adolphus <uffesterner@spamhole.com> wrote in comp.lang.perl.misc:
> Hi
>
> I need to check if a variable containing a filename
> has any (non-escaped) unix wildcards in it.
Define "unix wildcard" and "escaped", then we can talk.
> I guess a nice regex would do the trick,
> could any of you regex-gurus publish _the_ regex for it?
Defining "wildcard" as one of "*" and "?" and defining "escape" as
a prepended backslash, try /(?<!\\)[*?]/.
Anno
------------------------------
Date: 25 Mar 2004 12:10:40 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: check for unix wildcards in filename
Message-Id: <u9brmlf7pb.fsf@wcl-l.bham.ac.uk>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
> Rex Gustavus Adolphus <uffesterner@spamhole.com> wrote in comp.lang.perl.misc:
> > I need to check if a variable containing a filename
> > has any (non-escaped) unix wildcards in it.
Why do you think that you need to do that? Usually it's simplest to
always assume the variable may, the time saving of not doing a glob()
is minimal.
> Define "unix wildcard" and "escaped", then we can talk.
Yeah, verily.
If you are really talking about shell meta-characters your reason is
something to do with security then you are almost certainly
misguided.
> > I guess a nice regex would do the trick,
> > could any of you regex-gurus publish _the_ regex for it?
>
> Defining "wildcard" as one of "*" and "?" and defining "escape" as
> a prepended backslash, try /(?<!\\)[*?]/.
That is wrong, it will not match \\*
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 25 Mar 2004 12:44:35 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: check for unix wildcards in filename
Message-Id: <c3uk7j$o5g$1@mamenchi.zrz.TU-Berlin.DE>
Brian McCauley <nobull@mail.com> wrote in comp.lang.perl.misc:
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
>
> > Rex Gustavus Adolphus <uffesterner@spamhole.com> wrote in comp.lang.perl.misc:
>
> > > I need to check if a variable containing a filename
> > > has any (non-escaped) unix wildcards in it.
>
> Why do you think that you need to do that? Usually it's simplest to
> always assume the variable may, the time saving of not doing a glob()
> is minimal.
>
> > Define "unix wildcard" and "escaped", then we can talk.
>
> Yeah, verily.
>
> If you are really talking about shell meta-characters your reason is
> something to do with security then you are almost certainly
> misguided.
>
> > > I guess a nice regex would do the trick,
> > > could any of you regex-gurus publish _the_ regex for it?
> >
> > Defining "wildcard" as one of "*" and "?" and defining "escape" as
> > a prepended backslash, try /(?<!\\)[*?]/.
>
> That is wrong, it will not match \\*
True. It also doesn't deal with character classes that most shells accept
as a kind of "wildcard". It's not trivial. Perhaps String::ShellQuote
has something helpful.
Anno
------------------------------
Date: Thu, 25 Mar 2004 20:33:34 +1100
From: "Appoooh" <anon@ics.mq.edu.au>
Subject: Declaring variables outside subroutines
Message-Id: <c3u91e$ha8$1@sunb.ocs.mq.edu.au>
I'm no guru, and I haven't been programming professionally for long, but I
can't help finding it disturbing that in the code below, $var is in scope
within the subroutine foo. This is a bit eccentric compared to C++ or Java
... do perl hackers just accept this? Is it considered good programming
practice to declare as few variables as possible outside of any function
given that they'll effectively be global? I'm tempted to place variables
like these in a naked block and pass them around using parameters, but I've
never seen perl code that does this. What is best practice?
Cheers,
David
use strict;
use warnings;
my $var;
sub foo {
my $var2 = $var;
...
...
$var2;
}
------------------------------
Date: 25 Mar 2004 10:02:31 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Declaring variables outside subroutines
Message-Id: <c3uann$i1g$1@mamenchi.zrz.TU-Berlin.DE>
Appoooh <anon@ics.mq.edu.au> wrote in comp.lang.perl.misc:
> I'm no guru, and I haven't been programming professionally for long, but I
> can't help finding it disturbing that in the code below, $var is in scope
> within the subroutine foo. This is a bit eccentric compared to C++ or Java
> ... do perl hackers just accept this?
Accept what? That a variable in an outer block can be accessed from
block nested inside? That is standard for block-scoped languages since
Algol.
> Is it considered good programming
> practice to declare as few variables as possible outside of any function
> given that they'll effectively be global?
Yes, that's standard practice. "Declare (lexical) variables in the
smallest possible scope" is the rule.
> I'm tempted to place variables
> like these in a naked block and pass them around using parameters, but I've
> never seen perl code that does this. What is best practice?
The normal case is to pass everything a sub needs as a parameter.
A sub that accesses lexical variables outside its own scope is a
special case, also known as a closure. You do this when a sub needs
to keep a persistent value from call to call, or when two or more
subs need to access a common set of variables. (There are more
uses for closures. Their real domain is that of anonymous
subroutines, and some restrict the term "closure" to that case.)
Enclosing such subs and the variables they need in a bare block is
common practice in Perl, but it's only done when there is an actual
reason to keep the variables outside the subs.
Anno
------------------------------
Date: Thu, 25 Mar 2004 00:12:19 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: dollar sign and spaces from a string
Message-Id: <pan.2004.03.25.05.12.16.454303@remove.adelphia.net>
On Wed, 24 Mar 2004 22:13:01 +0100, Sandman wrote:
> In article <c3rkdn$prg$1@mamenchi.zrz.TU-Berlin.DE>,
> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
Okay. Someone was kind enough to post when a thread was getting out of
hand for me ... so I'm returning the favor :-)
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
There is a Massachusetts law requiring all dogs to have their
hind legs tied during the month of April.
------------------------------
Date: Thu, 25 Mar 2004 10:40:47 +0100
From: Sandman <mr@sandman.net>
Subject: Re: dollar sign and spaces from a string
Message-Id: <mr-4ABB9F.10404625032004@news.fu-berlin.de>
In article <pan.2004.03.25.05.12.16.454303@remove.adelphia.net>,
James Willmore <jwillmore@remove.adelphia.net> wrote:
> On Wed, 24 Mar 2004 22:13:01 +0100, Sandman wrote:
>
> > In article <c3rkdn$prg$1@mamenchi.zrz.TU-Berlin.DE>,
> > anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
>
> Okay. Someone was kind enough to post when a thread was getting out of
> hand for me ... so I'm returning the favor :-)
I don't understand...?
--
Sandman[.net]
------------------------------
Date: Wed, 24 Mar 2004 18:26:06 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: File traversing
Message-Id: <Pine.A41.4.58.0403241824260.11768@ginger.libs.uga.edu>
On Wed, 24 Mar 2004, George Kinley wrote:
> Hello
> I am trying to write some statement to a file, then I want to go back to the
> start of line, how can I do that, I know this is trivial one,
> but :o)
>
This is perhaps not an exact answer to your question, but you might want
to investigate the module, Tie::File.
Regards,
Brad
------------------------------
Date: 24 Mar 2004 15:48:52 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: File traversing
Message-Id: <40621e64@news.victoria.tc.ca>
George Kinley (georgekinley@hotmail.com) wrote:
: Hello
: I am trying to write some statement to a file, then I want to go back to the
: start of line, how can I do that, I know this is trivial one,
: but :o)
perldoc -f tell
perldoc -f seek
either save the position (tell) before writing and then seek back to it,
or seek backwards the length of the line you just wrote.
------------------------------
Date: 25 Mar 2004 07:41:13 GMT
From: Dmitry Epstein <mitia.nospam@northwestern.edu.invalid>
Subject: I want to scanf, dammit!
Message-Id: <Xns94B712A16EB9Dmitianorthwesternedu@63.218.45.21>
I know this has been asked before, mostly by novice percolytes (is
that what you call Perl adherents?), but the sages just replied:
scanf sucks, we don't need it. Well, here is a real-life situation
that I have to deal with quite frequently. See if you can suggest
an acceptable solution using the all-mighty pattern search.
I have a file with floats separated by spaces and newlines. There
can be several numbers per line, but I don't know and don't care
about exactly how they are written because that has no relation to
the logic of the problem. Suppose the file contains 2500 numbers
and I need to read the first 500, or better yet, read just the
number #500. This number can be in the middle of a line, for all I
know.
Using something like scanf or the C++ stream input operator, the
solution is ludicrously simple: just read the requisite number of
times in a loop using a single statement. But with Perl I just
don't see a simple way to do it that does not involve slurping the
entire file into memory first (and then possibly duplicating it
while applying split). Oh sure, I could read line by line, split
each line, and count the number of words read. But that's not
nearly as simple, and besides, if I have to continue working with
the file, then the issue of having read more numbers than was
needed may come up (remember, that target number may have been in
the middle of a line).
So there.
--
Dmitry Epstein
Northwestern University, Evanston, IL. USA
mitia(at)northwestern(dot)edu
------------------------------
Date: Thu, 25 Mar 2004 09:11:56 +0100
From: Malte Ubl <m@lteubl.de>
Subject: Re: I want to scanf, dammit!
Message-Id: <c3u793$76k$1@news.dtag.de>
Dmitry Epstein wrote:
> Using something like scanf or the C++ stream input operator, the
> solution is ludicrously simple:
> So there.
http://search.cpan.org/search?query=scanf&mode=all
Does that help?
If it doesnt, just use Inline::C.
malte
------------------------------
Date: 25 Mar 2004 08:33:27 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: I want to scanf, dammit!
Message-Id: <c3u5gn$elj$1@mamenchi.zrz.TU-Berlin.DE>
Dmitry Epstein <mitia.nospam@northwestern.edu.invalid> wrote in comp.lang.perl.misc:
> I know this has been asked before, mostly by novice percolytes (is
> that what you call Perl adherents?), but the sages just replied:
> scanf sucks, we don't need it. Well, here is a real-life situation
> that I have to deal with quite frequently. See if you can suggest
> an acceptable solution using the all-mighty pattern search.
>
> I have a file with floats separated by spaces and newlines. There
> can be several numbers per line, but I don't know and don't care
> about exactly how they are written because that has no relation to
> the logic of the problem. Suppose the file contains 2500 numbers
> and I need to read the first 500, or better yet, read just the
> number #500. This number can be in the middle of a line, for all I
> know.
>
> Using something like scanf or the C++ stream input operator, the
> solution is ludicrously simple: just read the requisite number of
> times in a loop using a single statement. But with Perl I just
> don't see a simple way to do it that does not involve slurping the
> entire file into memory first (and then possibly duplicating it
> while applying split). Oh sure, I could read line by line, split
> each line, and count the number of words read. But that's not
> nearly as simple, and besides, if I have to continue working with
> the file, then the issue of having read more numbers than was
> needed may come up (remember, that target number may have been in
> the middle of a line).
>
> So there.
my $n = 500;
my @line;
while ( <DATA> ) { last if ( $n -= @line = split) < 0 }
print "$line[ $n]\n";
So there :)
Anno
------------------------------
Date: Wed, 24 Mar 2004 18:52:26 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: need help with array searching
Message-Id: <Pine.A41.4.58.0403241851040.11768@ginger.libs.uga.edu>
On Tue, 23 Mar 2004, Dave Smith wrote:
> I have an array of data and I need to search for duplicate fields.
>
> The array looks like this:
>
> [0] NAME, ACCOUNT NUMBER, PHONE
> [1] JOHN, 12345,509-555-1212
> [2] MATT, 98376,509-555-1212
>
> I want to find the duplicate phone numbers and print them out in a list.
> Suggestions?
Are you sure you don't really have a _file_ of such data? :-)
Regards,
Brad
------------------------------
Date: 25 Mar 2004 00:34:09 -0800
From: Simon.Lee@asia.ing.com (Simon Lee)
Subject: parsing config file
Message-Id: <fdab9c3d.0403250034.c76daf3@posting.google.com>
Hi all,
I'd like to parse a config file like this (match pattern I want in log
files, and just want to send warning msgs to "adderss3" & "address4"):
/tmp/a.a {
DEFAULT_MAIL_ADDR "addr1
MATCH "[eE]rror" {
MAIL "address1", "address2"
EXCEPT "No [Ee]rror" ## comments here
}
MATCH "[Ww]arn" {
MAIL "address3", "address4"
}
}
I guess "Parse::RecDescent" can do this but does anyone show me some
sample code ?
Thanks in advance,
Simon
------------------------------
Date: 25 Mar 2004 09:43:35 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: parsing config file
Message-Id: <c3u9k7$hce$1@mamenchi.zrz.TU-Berlin.DE>
Simon Lee <Simon.Lee@asia.ing.com> wrote in comp.lang.perl.misc:
> Hi all,
>
>
> I'd like to parse a config file like this (match pattern I want in log
> files, and just want to send warning msgs to "adderss3" & "address4"):
>
> /tmp/a.a {
> DEFAULT_MAIL_ADDR "addr1
> MATCH "[eE]rror" {
> MAIL "address1", "address2"
> EXCEPT "No [Ee]rror" ## comments here
> }
> MATCH "[Ww]arn" {
> MAIL "address3", "address4"
> }
> }
>
>
> I guess "Parse::RecDescent" can do this but does anyone show me some
> sample code ?
What have you tried so far?
To parse a structure like the above, you need a formal description
of the structure. That cannot be derived from a single example,
not to mention that your example seems to be incorrect -- there's
a quote missing at the end of the second line.
Parse::RecDescent has examples of such formal descriptions in terms
of rules and terminal symbols. Study them and come up with a similar
description for the content of your config files. The translation
into a grammar that Parse::RecDescent can use is mostly a mechanical
process.
Anno
------------------------------
Date: Thu, 25 Mar 2004 12:53:09 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Per Script Beginner Advice (SWREG)
Message-Id: <VCA8c.6157$w54.53757@attbi_s01>
James Willmore wrote:
> On Wed, 24 Mar 2004 00:44:34 -0800, Richard Fairbairn wrote:
>>How do I protect the keygen script from being read by anyone (besides
>>SWREG) who wants to just hack my software?
>
> Google is your firend :-)
>
> This has been asked and answered before. Use the keywords
> 'comp.land.perl.misc protect' to get started. If nothing else, it will
> give a preview of what this thread will look like :-)
The OP was not asking "how can I provide a perl program to a customer
and not have them see the source". The answer to his question is
"Put it in a password-protected directory on your web server and
give the password out to SWREG only". The details for which he'll
have to check with his web hosting provider's documentation.
-Joe
------------------------------
Date: Thu, 25 Mar 2004 08:49:03 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Per Script Beginner Advice (SWREG)
Message-Id: <pan.2004.03.25.13.49.01.625988@remove.adelphia.net>
On Thu, 25 Mar 2004 12:53:09 +0000, Joe Smith wrote:
> James Willmore wrote:
>
>> On Wed, 24 Mar 2004 00:44:34 -0800, Richard Fairbairn wrote:
>>>How do I protect the keygen script from being read by anyone (besides
>>>SWREG) who wants to just hack my software?
>>
>> Google is your firend :-)
>>
>> This has been asked and answered before. Use the keywords
>> 'comp.land.perl.misc protect' to get started. If nothing else, it will
>> give a preview of what this thread will look like :-)
>
> The OP was not asking "how can I provide a perl program to a customer
> and not have them see the source". The answer to his question is
> "Put it in a password-protected directory on your web server and
> give the password out to SWREG only". The details for which he'll
> have to check with his web hosting provider's documentation.
> -Joe
Which has also been asked and answered :-) The threads for this question
are not quite as long, but still available through your local Google.
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
Is it possible that software is not like anything else, that it
<is meant to be discarded: that the whole point is to always see
it as a soap bubble?
------------------------------
Date: Thu, 25 Mar 2004 09:04:55 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Per Script Beginner Advice (SWREG)
Message-Id: <pan.2004.03.25.14.04.53.4864@remove.adelphia.net>
On Thu, 25 Mar 2004 08:49:03 -0500, James Willmore wrote:
> On Thu, 25 Mar 2004 12:53:09 +0000, Joe Smith wrote:
>
>> James Willmore wrote:
>>
>>> On Wed, 24 Mar 2004 00:44:34 -0800, Richard Fairbairn wrote:
>>>>How do I protect the keygen script from being read by anyone (besides
>>>>SWREG) who wants to just hack my software?
>>>
>>> Google is your firend :-)
>>>
>>> This has been asked and answered before. Use the keywords
>>> 'comp.land.perl.misc protect' to get started. If nothing else, it will
>>> give a preview of what this thread will look like :-)
>>
>> The OP was not asking "how can I provide a perl program to a customer
>> and not have them see the source". The answer to his question is
>> "Put it in a password-protected directory on your web server and
>> give the password out to SWREG only". The details for which he'll
>> have to check with his web hosting provider's documentation.
>> -Joe
>
> Which has also been asked and answered :-) The threads for this question
> are not quite as long, but still available through your local Google.
Just an aside, this link *may* be helpful for the OP:
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=e0160815.0210261950.e9fa592%40posting.google.com
Someone did share how to make the link shorter, but for the life of me I
don't remember where I put that helpful hint :-(
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
All bridge hands are equally likely, but some are more equally likely than
others. -- Alan Truscott
------------------------------
Date: Thu, 25 Mar 2004 12:42:28 GMT
From: Richard Bell <rbell01824@earthlink.net>
Subject: Perl automation of Mozilla
Message-Id: <9qk5609ovb81f1l5ko2o1ggtbg2u3hbt6r@4ax.com>
I'm moving an application from XP to Linux.
The XP version of the application uses com automation to instantiate
an instance of IE6 and then drive it to various web sites. These are
generally fairly sophisticated with content driven by scripts, involve
frames, etc. I need to measure the time between the start of
navigation and its completion, reference the DOM to extract certain
data from the page, possibly save the page (not just the HTML, but
exactly what you would get by manually doing a SAVEAS), etc. Because
of the sophistication of the pages LWP is not a viable answer (no
support to scripts or frames as I understand). Likewise wget. It
appears that I'll need to automate a real browser (Mozilla?) under
Linux.
I'd like to do this using Perl and Mozilla but am unsure how to
approach the problem. Is it possible? What is the general approach?
Are there any examples of Perl/Mozilla applications or interfaces?
I'm generally aware of PLXPCOMP and XPCOMP but unclear of how to use
them to attack this task.
Thanks for any clues.
R
------------------------------
Date: 25 Mar 2004 12:20:22 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Perl upgraded = problem resurfacing
Message-Id: <u97jx9f795.fsf@wcl-l.bham.ac.uk>
Tad McClellan <tadmc@augustmail.com> writes:
> Grant <emailgrant123@yahoo.com> wrote:
>
> > One more thing: The "<?xml" characters will always be at the very
> > beginning of the response. Is there a better way to write:
> >
> > if ($response =~ /^<\?xml/ ) {
> >
> > knowing that?
>
>
> Regexes are not the Right Tool for constant strings:
>
> if ( index($response, '<?xml') == 0 ) {
Sometimes the Right Tool is the one that is in your hand.
Also rember that readability is usually more important than speed.
While I know that the index() approach works it doesn't pass the 'just
read it aloud' test. ("Response starts with <?xml").
I often use RE to find constant strings e.g.
$^O =~ /Win32/
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Thu, 25 Mar 2004 13:21:04 GMT
From: axel@white-eagle.co.uk
Subject: Puzzling Socket::inet_ntoa problem
Message-Id: <41B8c.14509$1x2.2755@news-binary.blueyonder.co.uk>
I am having a puzzling problem with Socket::inet_ntoa - the following
piece of code:
#!/usr/bin/perl
use Socket;
$ip = "www.yahoo.com";
$temp = gethostbyname($ip);
$temp = inet_ntoa($temp);
print $temp, "\n";
$temp = inet_ntoa(gethostbyname($ip));
print $temp, "\n";
# End of code
gives the following result:
216.109.118.77
Usage: Socket::inet_ntoa(ip_address_sv) at ./l1.pl line 10.
I am trying to figure out why saving the result of gethostbyname in a
variable and then using inet_ntoa on that variable works fine, whereas
trying to pass the result directly to inet_ntoa bombs out. I can't find
anything in the documentation.
Any clues/help appreciated.
Thanks
Axel
------------------------------
Date: 25 Mar 2004 13:32:42 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Puzzling Socket::inet_ntoa problem
Message-Id: <c3un1q$qai$1@mamenchi.zrz.TU-Berlin.DE>
<axel@white-eagle.co.uk> wrote in comp.lang.perl.misc:
> I am having a puzzling problem with Socket::inet_ntoa - the following
> piece of code:
>
> #!/usr/bin/perl
>
> use Socket;
>
> $ip = "www.yahoo.com";
> $temp = gethostbyname($ip);
> $temp = inet_ntoa($temp);
> print $temp, "\n";
>
> $temp = inet_ntoa(gethostbyname($ip));
> print $temp, "\n";
>
> # End of code
>
> gives the following result:
>
> 216.109.118.77
> Usage: Socket::inet_ntoa(ip_address_sv) at ./l1.pl line 10.
>
> I am trying to figure out why saving the result of gethostbyname in a
> variable and then using inet_ntoa on that variable works fine, whereas
> trying to pass the result directly to inet_ntoa bombs out. I can't find
> anything in the documentation.
Context. The get* functions return different results in list and scalar
context, as the doc clearly states. Try (untested)
inet_ntoa(scalar gethostbyname($ip))
Anno
------------------------------
Date: Thu, 25 Mar 2004 12:47:04 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Removing folders recursively
Message-Id: <cxA8c.93677$po.719961@attbi_s52>
Shabam wrote:
> I'm currently using the following function to delete entire directories
> including all content in it. However it often fails out on me when
> files/folders that begin with a dot appear. I am running this in the comand
> line and would like to prevent tainted input such as "../../../root", hence
> not allowing the dot in front.
You need to check for "../" and other bad stuff in $direc, not in readdir().
> opendir(DIR,$direc);
> @dirs = grep {!(/^\./) && -d "$direc/$_" } readdir(DIR);
opendir(DIR,$direc) or die "Cannot read directory $direc - $!\n";
foreach (readdir DIR) {
next if $_ eq '.' or $_ eq '..';
my $dirent = "$direc/$_";
if (-d $dirent) { push @dirs,$dirent } else { push @files,$dirent }
}; closedir DIR;
------------------------------
Date: Wed, 24 Mar 2004 18:10:11 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: SOAP::Lite
Message-Id: <slrnc648r3.jsg.tadmc@magna.augustmail.com>
Michael Hill <hillmw@ram.lmtas.lmco.com> wrote:
> I found that:
>
> my $self = $shift;
>
> should have been:
>
> my $self = shift;
"use strict" might have caught that problem in microseconds.
You should enable it in all of your Perl programs.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 24 Mar 2004 18:45:38 -0600
From: John Bokma <postmaster@castleamber.com>
Subject: Re: SOAP::Lite
Message-Id: <40622c00$0$24356$58c7af7e@news.kabelfoon.nl>
Tad McClellan wrote:
> Michael Hill <hillmw@ram.lmtas.lmco.com> wrote:
>
>
>>I found that:
>>
>> my $self = $shift;
>>
>>should have been:
>>
>> my $self = shift;
>
> "use strict" might have caught that problem in microseconds.
>
> You should enable it in all of your Perl programs.
I recommend even to use my ($self) = @_;
itīs even shorter, and when you need to add an additional parameter,
it's just add it to the ().
--
John personal page: http://johnbokma.com/
Freelance Perl / Java developer available - http://castleamber.com/
------------------------------
Date: 24 Mar 2004 23:14:17 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: The "value" of a block in 'map'
Message-Id: <c3t4o9$q5j$2@mamenchi.zrz.TU-Berlin.DE>
Bernie Cosell <bernie@fantasyfarm.com> wrote in comp.lang.perl.misc:
> Is there any way, other than "the last expression evaluated" to set the
> 'value' of a BLOCK done in a map {BLOCK} list; ? I note that it doesn't
> even say in the docs for map [nor for grep] what the value of BLOCK *IS*,
> but it is easy enough to guess that it is at least the value of the last
> expression. But I'm finding that a bit limiting. In 'eval' it *DOES*
> specify the value:
>
> >>> In both forms, the value returned is the value of
> >>> the last expression evaluated inside the mini-pro
> >>> gram; a return statement may be also used, just as
> >>> with subroutines.
>
> but that doesn't work for map: I tried map {stuff; return something if
> BADNESS; more stuff} and for my trouble got
>
> Can't return outside a subroutine at ...
>
> Short of doing:
> map { eval { my block with returns} }
>
> is there any other way for map [probably also grep, etc] to provide a value
> other than the very last statement in the block?
If you want to return something, turn the block into a sub block:
map sub { stuff; return something if BADNESS; more stuff }->(), ...;
In the sub, use $_ as you would in an ordinary map block. Formally, the
block is now executed in a sub call, so the whole thing is an expression
and a comma is needed after it.
If you want to return nothing (just ignore any BADNESS) you can use "last"
to finish prematurely like so:
map do {{ stuff; last if BADNESS; more stuff }}, ...;
Again, "do" turns the block into a statement. The inner block is needed
to provide a (formal) loop block to "last" out of.
Anno
------------------------------
Date: 24 Mar 2004 15:40:04 -0500
From: Uri Guttman <uri.guttman@fmr.com>
Subject: Re: The "value" of a block in 'map'
Message-Id: <siscad26x9ln.fsf@tripoli.fmr.com>
>>>>> "BC" == Bernie Cosell <bernie@fantasyfarm.com> writes:
BC> Is there any way, other than "the last expression evaluated" to set the
BC> 'value' of a BLOCK done in a map {BLOCK} list; ? I note that it doesn't
BC> even say in the docs for map [nor for grep] what the value of BLOCK *IS*,
BC> but it is easy enough to guess that it is at least the value of the last
BC> expression. But I'm finding that a bit limiting. In 'eval' it *DOES*
BC> specify the value:
>>>> In both forms, the value returned is the value of
>>>> the last expression evaluated inside the mini-pro
>>>> gram; a return statement may be also used, just as
>>>> with subroutines.
BC> but that doesn't work for map: I tried map {stuff; return something if
BC> BADNESS; more stuff} and for my trouble got
map/grep BLOCK is like do BLOCK in this respect:
do BLOCK
Not really a function. Returns the value of the last command in
the sequence of commands indicated by BLOCK.
BC> Short of doing:
BC> map { eval { my block with returns} }
BC> is there any other way for map [probably also grep, etc] to
BC> provide a value other than the very last statement in the block?
it isn't a sub or an eval so the last expression/statement is the value
of the block. it is also like a sub with no explicit return. the map doc
should state that explicitly like do BLOCK does.
>>>> open(FOO) or die "Can't open $FOO: $!"; # FOO or bust!
>>>> open(FOO) ? 'hi mom' : die "Can't open $FOO: $!";
>>>> # a bit exotic, that last one
>>>>
BC> Isn't "that last one" not only exotic, but incorrect??? [in fact,
BC> won't it *always* 'die' regardless of whether the open works or
BC> not?]
how do you expect it to die if open succeeds? open will return true and
the left clause of ?: will execute and the die clause will not. beyond
exotic, it is stupid. a good rule is to never use ?: for flow control,
only for conditional values.
uri
------------------------------
Date: Thu, 25 Mar 2004 08:39:33 -0500
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Re: The "value" of a block in 'map'
Message-Id: <emn5605q9kp8ksh9spbv8hg146eh8b3ms4@library.airnews.net>
Uri Guttman <uri.guttman@fmr.com> wrote:
} >>>>> "BC" == Bernie Cosell <bernie@fantasyfarm.com> writes:
}
} >>>> open(FOO) or die "Can't open $FOO: $!"; # FOO or bust!
} >>>> open(FOO) ? 'hi mom' : die "Can't open $FOO: $!";
} >>>> # a bit exotic, that last one
} >>>>
}
} BC> Isn't "that last one" not only exotic, but incorrect??? [in fact,
} BC> won't it *always* 'die' regardless of whether the open works or
} BC> not?]
}
} how do you expect it to die if open succeeds? open will return true and
} the left clause of ?: will execute and the die clause will not. beyond
} exotic, it is stupid. a good rule is to never use ?: for flow control,
} only for conditional values.
I misunderstood [and mistyped my test where I verified it]... sigh... it
doesn't actually *SAY* in perlop that ?: short circuits... but it actually
does as my not-mistypted little test demonstrated
>>> $ perl -we 'open(N, "/dev/null")? warn "yes": warn "no"'
>>> Name "main::N" used only once: possible typo at -e line 1.
>>> yes at -e line 1.
sorry about that... I'm not sure how I got it into my head that ?: does
_not_ short circuit but I clearly got confused...
/Bernie\
--
Bernie Cosell Fantasy Farm Fibers
bernie@fantasyfarm.com Pearisburg, VA
--> Too many people, too few sheep <--
------------------------------
Date: Thu, 25 Mar 2004 08:48:40 -0500
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Re: The "value" of a block in 'map'
Message-Id: <ljo5601kf1f0vg77m6jo648b9b6qoqtvu7@library.airnews.net>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote:
} Bernie Cosell <bernie@fantasyfarm.com> wrote in comp.lang.perl.misc:
} > Is there any way, other than "the last expression evaluated" to set the
} > 'value' of a BLOCK done in a map {BLOCK} list; ?...
} > is there any other way for map [probably also grep, etc] to provide a value
} > other than the very last statement in the block?
}
} If you want to return something, turn the block into a sub block:
}
} map sub { stuff; return something if BADNESS; more stuff }->(), ...;
Thanks for all the replies. Along the line of the suggestion above,
wouldn't it work OK for me just to go to the 'expression' form of map,
instead of the BLOCK form and just use an eval? that is:
map eval {stuff, return(whatever) for badness, do whatever I want},LIST
Basically the same as your suggestion, with one level of indirection
removed...
/Bernie\
--
Bernie Cosell Fantasy Farm Fibers
bernie@fantasyfarm.com Pearisburg, VA
--> Too many people, too few sheep <--
------------------------------
Date: Thu, 25 Mar 2004 08:48:48 -0500
From: Bernie Cosell <bernie@fantasyfarm.com>
Subject: Re: The "value" of a block in 'map'
Message-Id: <u9o56012pks8on0e77n3h7gk85i6bkgb5f@library.airnews.net>
"A. Sinan Unur" <1usa@llenroc.ude> wrote:
} Bernie Cosell <bernie@fantasyfarm.com> wrote in
} news:fap360pvsc9vrrbua3361fue9hcffa3omf@library.airnews.net:
}
} > Is there any way, other than "the last expression evaluated" to set
} > the 'value' of a BLOCK done in a map {BLOCK} list; ?
} > I note that it doesn't even say in the docs for map [nor for grep]
} > what the value of BLOCK *IS*, but it is easy enough to guess that
} > it is at least the value of the last expression.
}
} perldoc -f map
}
} map BLOCK LIST
} map EXPR,LIST
} Evaluates the BLOCK or EXPR for each element of LIST (locally
} setting $_ to each element) ....
}
} If that explanation is not enough,you'll need to post an example of what
} you are trying to achieve.
The problem is that it doesn't say what the *VALUE* of the block is. It is
said explicitly in most other places that the value of a block is the last
expression evaluated it in but it doesn't actually say here, and I'd hoped
that the BLOCK here was more eval-like than do-like.
I had a simple 'map' but it got more complicated, and instead of moving the
complexity out to a subroutine [which would've worked fine] I tried to use
the BLOCK form to put the mess in-line, and so I had:
map { my ($vars) = bunth of stuff;
bunch of tests on $_, with bailouts to returned assorted
canned values
processing of $_
VALUE;
}
<LIST>
Obviously, VALUE was what I had previously and I'd tried to put the
sanity-testing stuff ahead of it.
/Bernie\
--
Bernie Cosell Fantasy Farm Fibers
bernie@fantasyfarm.com Pearisburg, VA
--> Too many people, too few sheep <--
------------------------------
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 6300
***************************************