[24520] in Perl-Users-Digest
Perl-Users Digest, Issue: 6700 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 17 09:05:47 2004
Date: Thu, 17 Jun 2004 06:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 17 Jun 2004 Volume: 10 Number: 6700
Today's topics:
Re: 'my' doesn't totally isolate (John Brock)
Re: 'my' doesn't totally isolate (Anno Siegel)
download a webpage <anonymous@disneyland.com>
Re: download a webpage <ittyspam@yahoo.com>
Re: download a webpage <tore@aursand.no>
Re: filehandles (Sam Holden)
Het zal toch niet zijn wie ik denk dat het is? <noem@il.com>
Re: How to launch VFP from perl (zeke)
Re: I need help with an 'if statement' in perl (Sam)
Re: I need help with an 'if statement' in perl <usenet@morrow.me.uk>
Re: instance of class into sub? <98734@mail.muni.cz>
Re: instance of class into sub? (Anno Siegel)
Re: instance of class into sub? <ittyspam@yahoo.com>
Re: instance of class into sub? <ebohlman@omsdev.com>
Re: instance of class into sub? <ittyspam@yahoo.com>
Memory limitation for Perl <markus.mohr@mazimoi.de>
Re: Memory limitation for Perl (Anno Siegel)
Re: Memory limitation for Perl <markus.mohr@mazimoi.de>
Re: parsing a text file (Anno Siegel)
Re: random underslashes and single regex <wherrera@lynxview.com>
Re: random underslashes and single regex <noreply@gunnar.cc>
SMS using perl - how? <timeless_illusion@yahoo.com>
Re: SMS using perl - how? <me@privacy.net>
Re: sorting text <postmaster@castleamber.com>
Re: sorting text <postmaster@castleamber.com>
Re: SSH and Math::Pari prereq on AIX5.1 (W. Van Hooste)
SSH problem (Dianne van Dulken)
What does $$ mean? (Anne-Marte)
Re: What does $$ mean? (Anno Siegel)
Re: What does $$ mean? <vetro@online.no>
Re: What does $$ mean? <jurgenex@hotmail.com>
Win32::OLE->GetObject doesn't work on WinXP? (Goh, Yong Kwang)
Re: Win32::OLE->GetObject doesn't work on WinXP? <ThomasKratz@REMOVEwebCAPS.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 17 Jun 2004 01:44:55 -0400
From: jbrock@panix.com (John Brock)
Subject: Re: 'my' doesn't totally isolate
Message-Id: <carb4n$8et$1@panix2.panix.com>
In article <10cl1kt6ep6ai9c@corp.supernews.com>,
Scott Bryce <sbryce@scottbryce.com> wrote:
>Uri Guttman wrote:
>> you still haven't explained a real use for this.
>I don't think the OP had a "real use" for this. I think he was just
>exploring the nuances of the language and came across something that
>behaved differently than he expected it to.
Actually I did have a real and perfectly sensible reason for testing
an array using defined(), but when I realized that defined() didn't
do what I thought it did I solved the problem another way, using
an additional flag variable. I did get some very helpful responses
here, but I have to say I didn't appreciate the demands that I
explain my need for this feature. No Mr. Guttman, I was not having
an "XY problem". I didn't bother explaining my need for the feature
because the code I was using it in was trivial, the fix was trivial,
and neither was worth posting. My concern was understanding. I
have been coding Perl for a long time, and it bothered me that
defined() wasn't working the way I thought it should. Randal
Schwartz pretty much cleared it up for me: for performance reasons
defined() is not defined for aggregates.
Okay. However while the 3rd edition of Programming Perl does say
that the use of defined() on aggregates is "deprecated", when I go
back to the *2nd* edition I am explicitly told it is okay. (pp.
155: "You may also check to see whether arrays, hashes, or subroutines
exist."). Clearly this is where I got the idea that doing this
was kosher, and I have to say I am a bit ticked off about it, since
I know I have done this elsewhere (although under this is the first
time it has caused a problem). So, did the behavior of Perl change
at some point, or was the documentation changed because someone
noticed that the behavior was unreliable?
And I am still interested in learning whether
my @aaa;
undef(@aaa);
...
defined(@aaa);
will always return FALSE, which would mean that I could still use
the test as a flag. In my code it does, but if defined(@aaa) is
truly "undefined" then I guess I shouldn't count on it.
--
John Brock
jbrock@panix.com
------------------------------
Date: 17 Jun 2004 09:21:08 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: 'my' doesn't totally isolate
Message-Id: <carnq4$h6g$1@mamenchi.zrz.TU-Berlin.DE>
John Brock <jbrock@panix.com> wrote in comp.lang.perl.misc:
> In article <10cl1kt6ep6ai9c@corp.supernews.com>,
> Scott Bryce <sbryce@scottbryce.com> wrote:
> >Uri Guttman wrote:
>
> >> you still haven't explained a real use for this.
>
> >I don't think the OP had a "real use" for this. I think he was just
> >exploring the nuances of the language and came across something that
> >behaved differently than he expected it to.
>
> Actually I did have a real and perfectly sensible reason for testing
> an array using defined(), but when I realized that defined() didn't
> do what I thought it did I solved the problem another way, using
> an additional flag variable. I did get some very helpful responses
> here, but I have to say I didn't appreciate the demands that I
> explain my need for this feature.
So we're supposed to answer your questions, but not ask questions
back? I don't think you quite understand how this Usenet thing works.
> No Mr. Guttman, I was not having
> an "XY problem".
Problem X: I want to associate a "pristine" state with an aggregate.
Non-solution Y: use defined() on the aggregate. Your original question
was entirely about Y, no mention of X. That is what we call an XY
problem here.
> I didn't bother explaining my need for the feature
> because the code I was using it in was trivial, the fix was trivial,
> and neither was worth posting.
Trivial or not, if you keep parts of the problem to yourself, expect
questions.
> My concern was understanding. I
> have been coding Perl for a long time, and it bothered me that
> defined() wasn't working the way I thought it should. Randal
> Schwartz pretty much cleared it up for me: for performance reasons
> defined() is not defined for aggregates.
>
> Okay. However while the 3rd edition of Programming Perl does say
> that the use of defined() on aggregates is "deprecated", when I go
> back to the *2nd* edition I am explicitly told it is okay. (pp.
> 155: "You may also check to see whether arrays, hashes, or subroutines
> exist."). Clearly this is where I got the idea that doing this
> was kosher, and I have to say I am a bit ticked off about it, since
> I know I have done this elsewhere (although under this is the first
> time it has caused a problem).
You are ticked off easily.
Perl is a fast-moving target, and printed documentation is bound to
be out of date at some time. Use the online documentation that
comes with your version of Perl. "perldoc -f defined".
> So, did the behavior of Perl change
> at some point, or was the documentation changed because someone
> noticed that the behavior was unreliable?
AFAIK the change happened with Perl 5 when lexicals were introduced.
Whether the introduction of lexicals was the reason for the change,
I don't know, but I suspect so.
> And I am still interested in learning whether
>
> my @aaa;
> undef(@aaa);
> ...
> defined(@aaa);
>
> will always return FALSE, which would mean that I could still use
> the test as a flag. In my code it does, but if defined(@aaa) is
> truly "undefined" then I guess I shouldn't count on it.
"defined(@aaa)" is deprecated, unreliable, non-portable and subject
to change without notice. Okay? Okay.
Anno
------------------------------
Date: Thu, 17 Jun 2004 10:24:59 GMT
From: "luc" <anonymous@disneyland.com>
Subject: download a webpage
Message-Id: <%jeAc.158373$kB7.7925895@phobos.telenet-ops.be>
How can you download a webpage to some text file in a local directory?
------------------------------
Date: Thu, 17 Jun 2004 06:55:36 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: download a webpage
Message-Id: <20040617065439.N20623@dishwasher.cs.rpi.edu>
On Thu, 17 Jun 2004, luc wrote:
> How can you download a webpage to some text file in a local directory?
Assuming you mean to have "using Perl" added to the end of this question,
you should read the documentation for LWP and LWP::Simple
perldoc LWP
perldoc LWP::Simple
They contain examples on doing just that.
Paul Lalli
------------------------------
Date: Thu, 17 Jun 2004 14:03:45 +0200
From: Tore Aursand <tore@aursand.no>
Subject: Re: download a webpage
Message-Id: <pan.2004.06.17.10.52.07.979446@aursand.no>
On Thu, 17 Jun 2004 10:24:59 +0000, luc wrote:
> How can you download a webpage to some text file in a local directory?
perldoc LWP::Simple
--
Tore Aursand <tore@aursand.no>
"What we do is never understood, but only praised and blamed."
(Friedrich Nietzsche)
------------------------------
Date: 16 Jun 2004 23:06:25 GMT
From: sholden@flexal.cs.usyd.edu.au (Sam Holden)
Subject: Re: filehandles
Message-Id: <slrncd1kjh.l7g.sholden@flexal.cs.usyd.edu.au>
On Wed, 16 Jun 2004 09:46:37 -0400, Brad Baxter <bmb@ginger.libs.uga.edu> wrote:
> On Tue, 16 Jun 2004, Sam Holden wrote:
>
>> On Tue, 15 Jun 2004 22:10:22 -0400, Brad Baxter <bmb@ginger.libs.uga.edu> wrote:
>> >
>> > Sorry, but param() doesn't return open filehandles. I guess you just need
>> > to open them yourself.
>>
>> Yes it does. I guess you need to read the documentation.
>>
>> Of course using upload() instead of param() is a far wiser choice.
>
> Sunny beaches. I stand corrected--just never used that feature, and
> didn't recall reading about it. Thanks.
This is the main reason upload() is to be prefered (in my opinion, anyway)
it documents that the thing is a file handle and not just a piece of text.
It also makes error checking easier (for people who send garbage to the
script, such that the file upload field isn't a file upload) - but for me
the documentation aspect is the reason to use it (though grepping
some code, I see I didn't always...)
--
Sam Holden
------------------------------
Date: Thu, 17 Jun 2004 00:49:48 +0200
From: Arjen Jongeling<noem@il.com>
Subject: Het zal toch niet zijn wie ik denk dat het is?
Message-Id: <40d0ce8e_3@127.0.0.1>
Is het die Ear Youth weer? Nee, het is Arjen Jongeling!
Het is een kwestie van geduld
voor heel usenet Hollands lult
------------------------------
Date: 17 Jun 2004 03:31:37 -0700
From: mfzarno@nsa.gov (zeke)
Subject: Re: How to launch VFP from perl
Message-Id: <e1810acf.0406170231.3e1ce0ec@posting.google.com>
Bill <wherrera@lynxview.com> wrote in message news:<HaidnTSsMY-HWlLdRVn-sA@adelphia.com>...
> zeke wrote:
> > I have a VisualFoxPro program (.fxp extension) that I wish my perl
> > script to launch. In addition I need to pass an argument from perl to
> > the VFP program, and lastly receive back from the VFP program an
> > argument (successful vs error condition at end of VFP program). I can
> > do this in Mac environment, but am now required to do same in
> > Windows2000PRO
>
> If you would post the part of the script that is Mac-specific in its
> call of VFP, we could probably help you port it.
OK. I have a VFP program called "TEST01.FXP" in directory
/Volumes/INWORK. I have a crontab entry to call "TEST1.PL" at 6 A.M.
daily. The "TEST1.PL" script is:
#! /usr/bin/perl
`open "/Volumes/INWORK/TEST01.FXP"`;
This works in Mac OSX environment flawlessly. But I am having to
migrate to Windows2000PRO environment. I'll work passing the argument
later - for now I just need to get the VFP to launch... Hope this
assists - and thanks in advance for any help!
Zeke
------------------------------
Date: 16 Jun 2004 22:16:22 -0700
From: samuelvange@cox.net (Sam)
Subject: Re: I need help with an 'if statement' in perl
Message-Id: <dae5ebbf.0406162116.7a2a25f1@posting.google.com>
Thanks Ben,
This is the only time I will need to display the name of the
collection. Is this solution buggy. Why is it a very bad idea.
Thanks again
Sam
Ben Morrow <usenet@morrow.me.uk> wrote in message news:<cao96b$ra2$2@wisteria.csv.warwick.ac.uk>...
> Quoth samuelvange@cox.net (Sam):
> >
> > I have a list of items categorized by collection. One of these is
> > simply called 'collection' (where as the others have names like
> > 'ceramic collection', 'glassware collection', etc.).
> >
> > *What I need to do is have the drop down menu list all of these
> > categories, and for the group that is simply called 'collection', I'd
> > like it to display 'Ken Edwards collection'.
> >
> > @collections=&get_collections;
>
> You don't need the '&' on that sub call; in fact, it may do things
> you're not expecting.
>
> > foreach $collection (@collections) {print
> > "<option>$collection</option>";}
>
> print '<option>',
> (/^collection$/i ? 'Ken Edwards collection' : $_),
> '</option>'
> for @collections;
>
> Note that this is a Very Bad Idea: the right answer is to fix whatever
> is causing this collection to have the wrong name in the first place.
>
> Ben
------------------------------
Date: Thu, 17 Jun 2004 06:36:59 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: I need help with an 'if statement' in perl
Message-Id: <care6b$683$1@wisteria.csv.warwick.ac.uk>
[please quote properly]
Quoth samuelvange@cox.net (Sam):
> Ben Morrow <usenet@morrow.me.uk> wrote in message news:<cao96b$ra2$2@wisteria.csv.warwick.ac.uk>...
> > Quoth samuelvange@cox.net (Sam):
> > >
> > > I have a list of items categorized by collection. One of these is
> > > simply called 'collection' (where as the others have names like
> > > 'ceramic collection', 'glassware collection', etc.).
> > >
> > > *What I need to do is have the drop down menu list all of these
> > > categories, and for the group that is simply called 'collection', I'd
> > > like it to display 'Ken Edwards collection'.
> > >
> > > @collections=&get_collections;
> >
> > You don't need the '&' on that sub call; in fact, it may do things
> > you're not expecting.
> >
> > > foreach $collection (@collections) {print
> > > "<option>$collection</option>";}
> >
> > print '<option>',
> > (/^collection$/i ? 'Ken Edwards collection' : $_),
> > '</option>'
> > for @collections;
> >
> > Note that this is a Very Bad Idea: the right answer is to fix whatever
> > is causing this collection to have the wrong name in the first place.
>
> This is the only time I will need to display the name of the
> collection. Is this solution buggy. Why is it a very bad idea.
It is a bad idea because it is not maintainable: if you're not careful
you'll end up with hundreds of these special-case replacements all over
the code, and you'll have no idea which values come from where. You say
this is the only place you need the name; you cannot be certain there
will not be others in the future. As I said, the right answer is to
change get_collections to return the correct data.
Ben
--
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/' # ben@morrow.me.uk
------------------------------
Date: Thu, 17 Jun 2004 10:00:07 GMT
From: gep <98734@mail.muni.cz>
Subject: Re: instance of class into sub?
Message-Id: <HzG6G7.FKp@news.muni.cz>
Gunnar Hjalmarsson wrote:
> Paul Lalli wrote in comp.lang.perl.misc:
>
>> Please read the posting guidelines that are posted to this group
>> once a week. They will tell you to post complete but short scripts
>> that illustrate your problem, and to copy and paste your code,
>> rather than retype it.
>
>
> And to not multi-post.
>
I sent it to 2 different newsgroups, it's ok, i think. No, i know it.
------------------------------
Date: 17 Jun 2004 10:43:55 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: instance of class into sub?
Message-Id: <carslb$j95$3@mamenchi.zrz.TU-Berlin.DE>
gep <98734@mail.muni.cz> wrote in comp.lang.perl.misc:
> Gunnar Hjalmarsson wrote:
> > Paul Lalli wrote in comp.lang.perl.misc:
> >
> >> Please read the posting guidelines that are posted to this group
> >> once a week. They will tell you to post complete but short scripts
> >> that illustrate your problem, and to copy and paste your code,
> >> rather than retype it.
> >
> >
> > And to not multi-post.
> >
> I sent it to 2 different newsgroups, it's ok, i think. No, i know it.
No, you don't. It's not about the number of newsgroups (that is a
concern too, if they're many), it's about the way newsreaders treat
your posting.
Is there a reason why everybody who has read your posting in one of
the groups *must* also see it in the other? If not, multi-posting
is wrong and crossposting is right.
Anno
------------------------------
Date: Thu, 17 Jun 2004 06:54:10 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: instance of class into sub?
Message-Id: <20040617065025.W20623@dishwasher.cs.rpi.edu>
On Thu, 17 Jun 2004, gep wrote:
> Gunnar Hjalmarsson wrote:
> > Paul Lalli wrote in comp.lang.perl.misc:
> >
> >> Please read the posting guidelines that are posted to this group
> >> once a week. They will tell you to post complete but short scripts
> >> that illustrate your problem, and to copy and paste your code,
> >> rather than retype it.
> >
> >
> > And to not multi-post.
> >
> I sent it to 2 different newsgroups, it's ok, i think. No, i know it.
>
No one's complaining that you sent to 2 different newsgroups. They're
complaining about the *method* in which you did so. The method you used
is called "multi-posting". This means sending one message to one group,
and then sending a copy of that message to another group. This is
considered rude. The reason is that many people use mail readers which
download messages from multiple groups at a time. Because of what you
did, they saw your message twice for no reason.
The correct method is called "cross-posting". This means sending one
message to both groups. This is usually done by specifiying both groups
on the "Newsgrps:" header (analagous to To: in emails), separated by
commas. Using this method, your message will be sent to both groups, with
the same message id. Mail readers will recognize the same id, and only
download the message once. This saves time, bandwidth, and effort on all
concerned.
Please do a google search for "multipost crosspost" and you'll see several
references to the topic. Please also check out the posting guidelines I
mentioned previously.
Thank you,
Paul Lalli
------------------------------
Date: 17 Jun 2004 12:02:51 GMT
From: Eric Bohlman <ebohlman@omsdev.com>
Subject: Re: instance of class into sub?
Message-Id: <Xns950B4863DF828ebohlmanomsdevcom@130.133.1.4>
Paul Lalli <ittyspam@yahoo.com> wrote in
news:20040617065025.W20623@dishwasher.cs.rpi.edu:
> No one's complaining that you sent to 2 different newsgroups. They're
> complaining about the *method* in which you did so. The method you
> used is called "multi-posting". This means sending one message to one
> group, and then sending a copy of that message to another group. This
> is considered rude. The reason is that many people use mail readers
> which download messages from multiple groups at a time. Because of
> what you did, they saw your message twice for no reason.
Actually, that's one of the smaller parts of the reason. The biggest part
of the reason is that someone reading the followups to a multi-posted
message has to read several groups, not just one, in order to see them all.
If, say, a message is multi-posted to comp.lang.perl.misc and
comp.lang.perl.modules (as the original was), then someone reading
c.l.p.misc won't see any of the responses in c.l.p.modules, at least not
until he reads the latter group (if he in fact does).
Why is that rude? Because the person reading c.l.p.misc might very well
take the time to post a response and then, upon going to c.l.p.modules,
discover that someone else posted essentially the same response there. So
the first person has wasted his time answering a question that's already
been answered. If the message had been crossposted, he'd have quickly seen
that the question had already been answered and not bothered to post a
redundant response.
Multi-posting fragments threads that should be kept together, leading to
duplication of effort and in many cases inadequate peer review of
responses.
------------------------------
Date: Thu, 17 Jun 2004 08:38:38 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: instance of class into sub?
Message-Id: <20040617083802.W20623@dishwasher.cs.rpi.edu>
On Thu, 17 Jun 2004, Eric Bohlman wrote:
> Paul Lalli <ittyspam@yahoo.com> wrote in
> news:20040617065025.W20623@dishwasher.cs.rpi.edu:
>
> > No one's complaining that you sent to 2 different newsgroups. They're
> > complaining about the *method* in which you did so. The method you
> > used is called "multi-posting". This means sending one message to one
> > group, and then sending a copy of that message to another group. This
> > is considered rude. The reason is that many people use mail readers
> > which download messages from multiple groups at a time. Because of
> > what you did, they saw your message twice for no reason.
>
> Actually, that's one of the smaller parts of the reason. The biggest part
> of the reason is that someone reading the followups to a multi-posted
> message has to read several groups, not just one, in order to see them all.
> If, say, a message is multi-posted to comp.lang.perl.misc and
> comp.lang.perl.modules (as the original was), then someone reading
> c.l.p.misc won't see any of the responses in c.l.p.modules, at least not
> until he reads the latter group (if he in fact does).
I stand better informed. Much obliged.
Paul Lalli
------------------------------
Date: Thu, 17 Jun 2004 13:27:56 +0200
From: Markus Mohr <markus.mohr@mazimoi.de>
Subject: Memory limitation for Perl
Message-Id: <sqv2d0dnsient0gkibmqddr4c9jlev2ohu@4ax.com>
Hello,
I have built a Perl/Tk-based program in a client-server-interacting
mode which is composed of about 15 separate modules.
For one special task, the parsing of a XML string containing an image
object in its CDATA section, I want to limit the usable memory to a
certain amount. This is necessary since otherwise the process takes as
much memory as possible and could lead to system breakdowns.
Is there a method do realize such a memory usage limitation?
And if so, does it have to be integrated in the XML parsing process,
or can I sort of integrate this statement in my main *.pl file?
Hope I made everything clear enough.
Sincerely
Markus Mohr
------------------------------
Date: 17 Jun 2004 11:47:33 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Memory limitation for Perl
Message-Id: <cas0cl$j95$4@mamenchi.zrz.TU-Berlin.DE>
Markus Mohr <markus.mohr@mazimoi.de> wrote in comp.lang.perl.misc:
> Hello,
>
> I have built a Perl/Tk-based program in a client-server-interacting
> mode which is composed of about 15 separate modules.
> For one special task, the parsing of a XML string containing an image
> object in its CDATA section, I want to limit the usable memory to a
> certain amount. This is necessary since otherwise the process takes as
> much memory as possible and could lead to system breakdowns.
>
> Is there a method do realize such a memory usage limitation?
Not in Perl, but perhaps in your OS. Under Unix, type "man ulimit"
and see what it says.
> And if so, does it have to be integrated in the XML parsing process,
> or can I sort of integrate this statement in my main *.pl file?
Ulimit restricts the resources for an entire process.
Anno
------------------------------
Date: Thu, 17 Jun 2004 13:49:36 +0200
From: Markus Mohr <markus.mohr@mazimoi.de>
Subject: Re: Memory limitation for Perl
Message-Id: <0913d0l87qo3ltribfgio3qtlc6kesepud@4ax.com>
On 17 Jun 2004 11:47:33 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno
Siegel) wrote:
>Markus Mohr <markus.mohr@mazimoi.de> wrote in comp.lang.perl.misc:
>> Hello,
>>
>> I have built a Perl/Tk-based program in a client-server-interacting
>> mode which is composed of about 15 separate modules.
>> For one special task, the parsing of a XML string containing an image
>> object in its CDATA section, I want to limit the usable memory to a
>> certain amount. This is necessary since otherwise the process takes as
>> much memory as possible and could lead to system breakdowns.
>>
>> Is there a method do realize such a memory usage limitation?
>
>Not in Perl, but perhaps in your OS. Under Unix, type "man ulimit"
>and see what it says.
Thank you, I know that about Linux, but I have to compile it under
Windows, and therefore it should be integral part of the code.
Sincerely
Markus Mohr
------------------------------
Date: 17 Jun 2004 10:36:43 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: parsing a text file
Message-Id: <cars7r$j95$2@mamenchi.zrz.TU-Berlin.DE>
Suresh <gsuresh@rogers.com> wrote in comp.lang.perl.misc:
> Hi,
>
> I have a file in the following format.
>
>
> Title 223
> Version 2324
> protocol src: 172.30.39.3
> data
>
> 0000 94 93 32 43 f3 h3
> 1223 23 k3 j3 3k k3 2k
> 9232 92 k3 92 k2 92 l2
>
> Title 3434
> Version 233
> ........ keeps on gooing in the same format.
>
> I want to write a script that grep/parse Title,src, and the data part(all
> the data).
> The format is same all the time. The data always start with 0000 and two
> spaces. After that
> the data follow the same pattern.
>
> What I want is that i have to go to a specific(user input) src and parse the
> data for that specific src.
>
> I was able to go the src but don't know how to iterate one line at a time,
> from 0000 to the end of the data.
>
> while(<>) {
> if(src=$user input)
> print .....
>
> if(/^0000\s\s .. /end../
> ....
>
> I wanna way to iterate each line once it entered into a loop.
You could use paragraph mode and read two blocks of data each time
through a read loop. Use the first block to see if you want to
look at the data (in the second block) at all. If you do, split
the second block on newline and loop through the lines. Here is how:
my $given_src = '172.30.39.3';
$/ = ''; # paragraph mode (localize in a real program)
while ( <DATA> ) {
my $data = <DATA>;
next unless /protocol src: \Q$given_src/;
for ( split /\n/, $data ) {
# work with each data line in $_ here
print "$_\n";
}
}
Anno
------------------------------
Date: Wed, 16 Jun 2004 22:27:45 -0600
From: Bill <wherrera@lynxview.com>
Subject: Re: random underslashes and single regex
Message-Id: <XICdnRTR4JlfgEzdRVn-gg@adelphia.com>
Gunnar Hjalmarsson wrote:
> Bill wrote:
>
>> Anyone know of a _single regex_ for the following:
>>
>> Match a string which has a single '_' character placed at random
>> within it. The string without the '_' is known, the position of the
>> '_' is not known.
>>
>> I know one can strip out the '_' and then match, but I'd like to do
>> it with one m// statement.
>
>
> Why?? Please explain.
>
> Without having seen the regex, I suppose that character classes is the
> key.
>
It is for a mail filter: a spammer mutates the From by moving a _
character at random.
------------------------------
Date: Thu, 17 Jun 2004 07:41:23 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: random underslashes and single regex
Message-Id: <2jcp83Fvb6bpU1@uni-berlin.de>
Bill wrote:
> Gunnar Hjalmarsson wrote:
>> Bill wrote:
>>> I know one can strip out the '_' and then match, but I'd like
>>> to do it with one m// statement.
>>
>> Why?? Please explain.
>
> It is for a mail filter: a spammer mutates the From by moving a _
> character at random.
Aha, thanks, but I meant why are you anxious to do it in one
statement? To me, using tr/// to remove it seems both more straight
forward and more efficient.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Thu, 17 Jun 2004 11:02:03 -0700
From: "Neo" <timeless_illusion@yahoo.com>
Subject: SMS using perl - how?
Message-Id: <2jco1uF109n1nU1@uni-berlin.de>
Hi,
How can I send an SMS message to my mobile phone using perl???
Is there any FREE gateway for sending SMS?
Thnx!
-Neo
------------------------------
Date: Thu, 17 Jun 2004 20:02:18 +1200
From: "Tintin" <me@privacy.net>
Subject: Re: SMS using perl - how?
Message-Id: <2jd1knF10502oU1@uni-berlin.de>
"Neo" <timeless_illusion@yahoo.com> wrote in message
news:2jco1uF109n1nU1@uni-berlin.de...
> Hi,
>
> How can I send an SMS message to my mobile phone using perl???
> Is there any FREE gateway for sending SMS?
See http://search.cpan.org/~eim/WWW-SMS-0.09/lib/WWW/SMS.pm
------------------------------
Date: Wed, 16 Jun 2004 21:04:53 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: sorting text
Message-Id: <40d0fc45$0$205$58c7af7e@news.kabelfoon.nl>
Jeff 'japhy' Pinyan wrote:
> On Wed, 16 Jun 2004, John Bokma wrote:
>
>
>>Web Surfer wrote:
>>
>>
>>> if ( 2 < @fields ) { # Ignore if less than 3 fields
>>
>>silly, the OP never specified that could happen. It are 4 fields btw, so
>>I would test for inequality, not less than..
>
>
> Because it was the *third* field that contained the string the OP is
> searching for. Thus, skip any line that doesn't have enough fields.
Was there ever in the specification that there could be less than 4
fields? No.
>>Don't see any point in putting the constant to the left, btw. Silly C
>>coding convention IIRC.
>
> There's nothing wrong with it. It's not "silly". There is a point to it.
> It stops you from accidentally writing = instead of == if you mean to do a
> comparison. Compare:
>
> if ($foo = 2) { ... }
Found = in conditional, should be ==
> The coder *meant* to write ==, but only did =. The first one is not an
> error, and the if block is reached all the time. The second one IS an
> error.
No, it's and error if your compiler, interpreter, etc doesn't *WARN*
you. And a programmer turning of those warnings is silly.
Most C, C++ compilers do warn, as does Perl (with use strict, use
warnings). It is IMNSHO a stupid coding convention, illogical,
unreadable, weird. Especially with *inequalities* as the prev post used.
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: Wed, 16 Jun 2004 21:06:06 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Re: sorting text
Message-Id: <40d0fc8e$0$205$58c7af7e@news.kabelfoon.nl>
Gunnar Hjalmarsson wrote:
> John Bokma wrote:
> No, it can't. If the string is not found in $_, index() returns -1
> which is a true value.
Arrgh, stupid of me.
--
John MexIT: http://johnbokma.com/mexit/
personal page: http://johnbokma.com/
Experienced Perl programmer available: http://castleamber.com/
Happy Customers: http://castleamber.com/testimonials.html
------------------------------
Date: 16 Jun 2004 23:48:22 -0700
From: wvanhooste@yahoo.com (W. Van Hooste)
Subject: Re: SSH and Math::Pari prereq on AIX5.1
Message-Id: <495823bb.0406162248.1ed57dad@posting.google.com>
wvanhooste@yahoo.com (W. Van Hooste) wrote in message news:<495823bb.0406150153.5d7a5342@posting.google.com>...
> problem
> I try to install Net::SSH::Perl (instead of Net::SSH). And have lots
> of problems with the compilation of prereq Math::Pari and GP/PARI...
I decided NOT to use Net::SSH::Perl; to mutch: prereq's, broken
packages, unsupported systems and not flexible enough. I wanted to
provide the password interactive (1 time only) and run stuff using SCP
and SSH on abouth 100 systems (all AIX). Net::SSH::Perl makes it
possible to provide that password via a scalar. My current (and
second) choice => Bundle::Expect handles this nicely...
------------------------------
Date: 16 Jun 2004 19:02:37 -0700
From: dianne@dogmac.com (Dianne van Dulken)
Subject: SSH problem
Message-Id: <923a879d.0406161802.40fc3ec6@posting.google.com>
Hi,
I'm having some trouble connecting to a third site via both SSleay and
UserAgent. I think it might have something to do with the
certificates, but I can't work out exactly what. I keep on getting a
500 error, when I am expecting a Location moved response.
Would someone mind having a quick look over my code and seeing if
there is something blatently obviously wrong that I'm missing.
Thank you very much
Dianne
!/usr/bin/perl
use strict;
use Net::SSLeay;
use LWP::Debug qw(+);
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
$ENV{HTTPS_DEBUG} = 1;
$ENV{HTTPS_VERSION} = 3;
$Net::SSLeay::trace = 2;
$ENV{HTTPS_CERT_FILE} = 'certs/oilolig.pem';
$ENV{HTTPS_KEY_FILE} = 'certs/oilolig.pem';
sub connectto {
my ($thisurl, $method) = @_;
print "CONNECTING to $thisurl via $method \n";
my $location;
my $cookie;
if (($method eq 'post') ||($method eq 'get')) {
my ($page, $response, @headers);
my ($url1, $sub_url1) = &spliturls($thisurl);
print "split urls are $url1 and $sub_url1 \n";
if ($method eq 'post') {
print "attempting to connect via post \n";
($page, $response, @headers) =
Net::SSLeay::post_https($url1, 443, $sub_url1, '');
}
if ($method eq 'get') {
print "attempting to connect via get \n";
($page, $response, @headers) =
Net::SSLeay::get_https($url1, 443, $sub_url1, '');
}
for (my $i = 0; $i < $#headers; $i+=2) {
print "header $i : $headers[$i] = " . $headers[$i+1] . "\n";
if ($headers[$i] eq "LOCATION") { $location = $headers[$i+1];}
if ($headers[$i] eq "COOKIE") {$cookie = $headers[$i+1];}
}
return ($location, $cookie);
} else {
# otherwise, we want to connect via useragent
print "UA connect \n\n";
my $ua = LWP::UserAgent -> new();
my $cookie_jar = HTTP::Cookies->new(
file => "lwp_cookies.dat",
autosave => 1,
);
$ua->cookie_jar( $cookie_jar );
my $request = HTTP::Request->new(GET => $thisurl);
my $res = $ua->request($request);
my $location = $res->header('LOCATION');
my $cookie = $res->header('COOKIE');
print "location is $location \n cookie is $cookie \n";
if ($res->is_success) {
print "Connection to UA is ok\n";
}
else {
print "Connection to UA gives " . $res->status_line . "\n";
}
return "res is $res \n";
}
}
sub spliturls {
my ($url1) = @_;
print "SPLITURLS url1 is $url1 \n";
my ($junk, $url2, $sub_url2);
($junk, $url2) = split('//', $url1);
($url2, $sub_url2) = split('/', $url2, 2);
return ($url2, '/'.$sub_url2);
}
my $url1 = 'https://shopfront3.telstra.com.au/LOLOSTGCb2b/services/ProductCreateImmService';
my ($url2, $cookie) = &connectto($url1, 'post');
print "url2 : $url2 \n";
my ($url3, $cookie2) = &connectto($url2, 'ua');
print "url3 : $url3 \n";
------------------------------
Date: 17 Jun 2004 02:28:02 -0700
From: mkrogsru@online.no (Anne-Marte)
Subject: What does $$ mean?
Message-Id: <5a429986.0406170128.6c938690@posting.google.com>
Hello
What does $$ mean? What does the numbers i get stand for?
Anne-M. K.
------------------------------
Date: 17 Jun 2004 09:31:36 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: What does $$ mean?
Message-Id: <carodo$h6g$2@mamenchi.zrz.TU-Berlin.DE>
Anne-Marte <mkrogsru@online.no> wrote in comp.lang.perl.misc:
> Hello
> What does $$ mean? What does the numbers i get stand for?
perldoc perlvar
Anno
------------------------------
Date: Thu, 17 Jun 2004 11:36:26 +0200
From: "Vetle Roeim" <vetro@online.no>
Subject: Re: What does $$ mean?
Message-Id: <opr9qfm0ad3hk3cf@quickfix.opera.com>
On 17 Jun 2004 02:28:02 -0700, Anne-Marte <mkrogsru@online.no> wrote:
> Hello
> What does $$ mean? What does the numbers i get stand for?
Try reading the documentation by typing 'perldoc perlvar' on
the command line, or going here:
<URL: http://www.perldoc.com/perl5.8.4/pod/perlvar.html>
Heres a quote from that page:
$$ The process number of the Perl running this script. You should
consider this variable read-only, although it will be altered
across fork() calls. (Mnemonic: same as shells.)
--
Touch eyeballs to screen for cheap laser surgery!
------------------------------
Date: Thu, 17 Jun 2004 09:36:47 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: What does $$ mean?
Message-Id: <PCdAc.37145$tA6.9474@nwrddc03.gnilink.net>
Anne-Marte wrote:
> What does $$ mean? What does the numbers i get stand for?
Please see The Fine Manual: "perldoc perlvar", section "$$"
jue
------------------------------
Date: 16 Jun 2004 23:36:35 -0700
From: gohyongkwang@hotmail.com (Goh, Yong Kwang)
Subject: Win32::OLE->GetObject doesn't work on WinXP?
Message-Id: <354933d6.0406162236.71167499@posting.google.com>
Hi.
I copied the code fragment from
http://www.wellho.net/solutions/1480965085.html to extract text from
Microsoft Word document.
---
use Win32::OLE;
use Win32::OLE::Enum;
print "Opening $ARGV[1]\n";
$document = Win32::OLE->GetObject("$ARGV[1]");
if(!defined $document){
die "Document still not defined!";
}
print "Opening $ARGV[0]\n";
open (FH,">$ARGV[0]");
print "Extracting Text ...\n";
$paragraphs = $document->Paragraphs();
$enumerate = new Win32::OLE::Enum($paragraphs);
while(defined($paragraph = $enumerate->Next()))
{
$style = $paragraph->{Style}->{NameLocal};
print FH "+$style\n";
$text = $paragraph->{Range}->{Text};
$text =~ s/[\n\r]//g;
$text =~ s/\x0b/\n/g;
print FH "=$text\n";
}
--
When I run it, the program keeps crashing with $document being
undefined and trying to call Paragraphs method.
So I added a check to determine if $document is defined before trying
to call the Paragraphs method. Somehow, when I run it: perl doc2txt.pl
test.txt test.doc, somehow the Win32::OLE->GetObject method always
fails to work and return a proper handle to the Word document. Thus
causing it to be undefined and crashing when Paragraphs method is
called.
Why is this so?
------------------------------
Date: Thu, 17 Jun 2004 11:28:01 +0200
From: Thomas Kratz <ThomasKratz@REMOVEwebCAPS.de>
Subject: Re: Win32::OLE->GetObject doesn't work on WinXP?
Message-Id: <40d16421$0$14521$bb690d87@news.main-rheiner.de>
Goh, Yong Kwang wrote:
> Hi.
>
> I copied the code fragment from
> http://www.wellho.net/solutions/1480965085.html to extract text from
> Microsoft Word document.
>
> ---
>
> use Win32::OLE;
> use Win32::OLE::Enum;
>
> print "Opening $ARGV[1]\n";
> $document = Win32::OLE->GetObject("$ARGV[1]");
>
> if(!defined $document){
> die "Document still not defined!";
> }
>
> print "Opening $ARGV[0]\n";
> open (FH,">$ARGV[0]");
>
> print "Extracting Text ...\n";
>
> $paragraphs = $document->Paragraphs();
> $enumerate = new Win32::OLE::Enum($paragraphs);
> while(defined($paragraph = $enumerate->Next()))
> {
> $style = $paragraph->{Style}->{NameLocal};
> print FH "+$style\n";
> $text = $paragraph->{Range}->{Text};
> $text =~ s/[\n\r]//g;
> $text =~ s/\x0b/\n/g;
> print FH "=$text\n";
> }
>
> --
> When I run it, the program keeps crashing with $document being
> undefined and trying to call Paragraphs method.
>
> So I added a check to determine if $document is defined before trying
> to call the Paragraphs method. Somehow, when I run it: perl doc2txt.pl
> test.txt test.doc, somehow the Win32::OLE->GetObject method always
> fails to work and return a proper handle to the Word document. Thus
> causing it to be undefined and crashing when Paragraphs method is
> called.
>
> Why is this so?
Yep, got that too with a relative path name. Supply a complete pathname as
second argument. You are talking to Word via OLE. It doesn't have a clue,
where the document is supposed to be.
Adding a few checks (check every call to OLE objects, and 'open'!) and
using 'strict' and 'warnings' is strongly recommended, as usual.
Thomas
--
open STDIN,"<&DATA";$=+=14;$%=50;while($_=(seek( #J~.> a>n~>>e~.......>r.
STDIN,$:*$=+$,+$%,0),getc)){/\./&&last;/\w| /&&( #.u.t.^..oP..r.>h>a~.e..
print,$_=$~);/~/&&++$:;/\^/&&--$:;/>/&&++$,;/</ #.>s^~h<t< ..~. ...c.^..
&&--$,;$:%=4;$,%=23;$~=$_;++$i==1?++$,:_;}__END__#....>>e>r^..>l^...>k^..
------------------------------
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 6700
***************************************