[17525] in Perl-Users-Digest
Perl-Users Digest, Issue: 4945 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 21 21:05:47 2000
Date: Tue, 21 Nov 2000 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: <974858711-v9-i4945@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 21 Nov 2000 Volume: 9 Number: 4945
Today's topics:
$x % 0 [was: Addition vs. concatenation] <iltzu@sci.invalid>
Re: A Small Problem Any Sugestions? (Tad McClellan)
Re: Addition vs. concatenation [was: Beginners Blues II <lincmad001@telecom-digest.zzn.com>
Binding Variables and DBI <mysangam@my-deja.com>
Re: Eurodate mysteries (Tom Christiansen)
Re: Eurodate mysteries <wd@denx.muc.de>
Re: Eurodate mysteries <flavell@mail.cern.ch>
Re: Eurodate mysteries <flavell@mail.cern.ch>
FAQ? <smokindave@smokindave.com>
Re: HELP! bring variables out of a subroutine? <atong@operamail.com>
Re: how do I delete initial and final spaces in a strin (Christopher Burke)
Launching Excel2000 or Internet Explorer from Perl <vigne@nhamp.net>
Re: Location Redirect (newbie help question) <dianne@dogmac.com>
Re: Memory limitation & memory leak <softcomp@home.com>
Re: Most easy way to get IP from a local NIC by device (Ilya Zakharevich)
Re: Most easy way to get IP from a local NIC by device (Martien Verbruggen)
Re: Naming variables with variables, how? <sumus@aut.dk>
Need a quick definition of PERL <bluman@claranews.com>
Re: Need a quick definition of PERL (Martien Verbruggen)
Re: OT:Re: Eurodate mysteries <gm@magpage.com>
Parsing name<->value data from html forms. (Bobby Bailey)
Re: Parsing name<->value data from html forms. (Tad McClellan)
Re: perl vs C style (Chris Fedde)
Re: perl vs C style (Tad McClellan)
Re: perl vs C style (Tad McClellan)
Re: REGEXP Help! Trying to parse funky time format... (Martien Verbruggen)
Re: REGEXP Help! Trying to parse funky time format... <friedman@math.utexas.edu>
Re: Sort strings before numbers (Tad McClellan)
Re: Sort strings before numbers <ddunham@redwood.taos.com>
Re: urgent, regular expression <bart.lateur@skynet.be>
Re: Weird question: has anyone used Perl to parse the S dack@visi.com
Re: Why are references useful? <ren.maddox@tivoli.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 21 Nov 2000 23:28:02 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: $x % 0 [was: Addition vs. concatenation]
Message-Id: <974848891.11347@itz.pp.sci.fi>
In article <8ve8so$1o6$1@lublin.zrz.tu-berlin.de>, Anno Siegel wrote:
>
>Treatment of singed operands by the mod operation varies wildly, and
>Perl hands down what it gets. All the while, there is a perfectly
>reasonable extension of the modulo operation x%y for all real x and y:
>Let x%y = x - y*floor(x/y) if y != 0, and let x%0 = x. The theory
>can be found in (where else) Knuth, _The Art..._ Vol 1, see index.
What's the logic behind that last definition? I would rather assume
that, were x%0 defined at all, the most reasonable value would be 0.
I'd look in the Knuth book, but I only have volume 2 in my bookshelf
and in any case the bookshelf isn't here.
>Long ago, when Perl 5 came out, I proposed a patch that implemented
>this. Of course it wasn't accepted, it breaks old code.
Grpmh. Code like that deserves to break..
(tongue only halfway in cheek)
--
Ilmari Karonen -- http://www.sci.fi/~iltzu/
"Get real! This is a discussion group, not a helpdesk. You post
something, we discuss its implications. If the discussion happens to
answer a question you've asked, that's incidental." -- nobull in clpm
------------------------------
Date: Tue, 21 Nov 2000 19:07:14 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: A Small Problem Any Sugestions?
Message-Id: <slrn91m3hi.jsb.tadmc@magna.metronet.com>
On Tue, 21 Nov 2000 13:46:25 -0600, Todd Anderson <todd@mrnoitall.com> wrote:
>
>
>nobull@mail.com wrote:
>
[ snip 45 lines of good advice ]
>Good grief...
>just use...
>$FORM{$name} =~ s/ //g;
For 1 line of bad advice.
Good grief, do the same thing only 10 times faster:
$FORM{$name} =~ tr/ //d;
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 21 Nov 2000 17:03:07 -0800
From: Linc Madison <lincmad001@telecom-digest.zzn.com>
Subject: Re: Addition vs. concatenation [was: Beginners Blues II]
Message-Id: <211120001703076565%lincmad001@telecom-digest.zzn.com>
In article <8ve0ve$hjm$1@soap.pipex.net>, Geoff Winkless
<geoff-at-farmline-dot-com@127.0.0.1> wrote:
> "Ilmari Karonen" <iltzu@sci.invalid> wrote in message
> news:974812727.2114@itz.pp.sci.fi...
> > In article <8vbjjb$alf$1@soap.pipex.net>, Geoff Winkless wrote:
> > >No. Addition of numbers is associative and commutative.
> >
> > ..and it would make sense to expect anything that is called addition,
> > or uses the addition operator "+", to follow those laws as well.
>
> Why? It's =patently= obvious that you _cannot_ have a (useful)
> addition function which follows those rules for strings. It is still
> clear what most people's perception of "adding two strings together"
> would be.
Take another example: multiplication. Multiplication of real (and
complex) numbers is commutative. Multiplication of matrices is not
commutative, but it's still called multiplication, and it's still
useful. Multiplication of quaternions is not commutative, but it's
still called multiplication, and it's quite useful. (Multiplication of
quaternions maps very nicely onto the cross product of 3-dimensional
vectors.)
Indeed, if you study number theory or advanced algebra, I'm sure you
can find some abstract realm in which it's not a given that addition is
commutative.
After all, if you think that addition is always commutative, try adding
water to acid. [Just in case anyone doesn't know what I'm talking
about, it is VERY DANGEROUS to add water to acid.]
------------------------------
Date: Wed, 22 Nov 2000 01:37:52 GMT
From: Sangam <mysangam@my-deja.com>
Subject: Binding Variables and DBI
Message-Id: <8vf81g$k3c$1@nnrp1.deja.com>
I am binding variable names using DBI with Oracle to call Stored
Procedure. For each variable I have to seperately name them.
Any idea how I can do the same thing using an array or hash.
I have tried simple thing, but it didn't work.
Thanks
--
.
.
.
Sangam
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 21 Nov 2000 16:30:55 -0700
From: tchrist@perl.com (Tom Christiansen)
Subject: Re: Eurodate mysteries
Message-Id: <3a1b05af@cs.colorado.edu>
In article <Pine.GHP.4.21.0011212207520.2132-100000@hpplus03.cern.ch>,
Alan J. Flavell <flavell@mail.cern.ch> wrote:
>OK, let's concede I misunderstood your intention of doing no more than
>to explain it, to be a tacit defence (or in your case, presumably
>defense) of the practice (or practise).
"I have no respect for a man who can only spell a word one way."
--Mark Twain
"It's a damn poor mind that can only think of one way to spell
a word." --Andrew Jackson
"Men get opinions as boys learn to spell, by reiteration chiefly."
--Elizabeth Barrett Browning
Be it for good or ill, we have in English no pontificating Royal
Academy to hand down imperious fiats, nor have we some National Academy
who from their marmoreal tombs to pass inane judgements contrary to the
collective will of the speakers of our language. And thank goodness for
that, for otherwise we, too, would be compelled to write such shameful
atrocities as "cédéron".
You might be surprised, Alan, to learn that I write those particular
words just as you would. For "defence", well, that's another story,
but with "practice/practise", I appreciate the distinction between
subject and verb, just as I do with licence/license and advice/advise.
So your "in my case" part does not precisely apply.
Just as with Perl programming, I in English excercise personal
choice on words that admit multiple spellings. And also as in Perl,
these are *deliberate* choices, not random glitches. I elect
spellings that are (largely) consistent with principles too abstruse
to detail here.
So while it might initially please you to note my personal preference
for writing "grey", "glamour", "analyse", "travelling", and
"knowledgeable", you would likely be far less delighted when you found
me also using the forms of "color", "recognize", "tire", "pajamas",
and "aging".
To someone else, the opposite alignment of felicity and lack thereof
would surely apply. Since I'm guaranteed to rankle someone no
matter what I do, I might as well choose a path through this that
makes some internal sense to me personally--which I have, in fact,
done.
On dates, it's clearly the case that in a computer, you want something
a computer can readily manipulate. The ISO format is good for that;
you can just pass in through sort(1).
I have myself long used dd/mm/yy, but have largeloy abandoned it
on public documents because I was sick and tired of having to
endlessly explain the matter to the infinite numbers of idiots who,
upon reading "13/5/88", become apoplectic as they try to figure out
what the thirteenth month must be. Did you know that in our
lovely electoral snafu down in Far North Cuba, some ballots were
almost discarded due to incredible ignorance?
http://www.iht.com/articles/1528.htm
Excerpted:
It seemed odd to one watcher that mail might have been erroneously
postmarked as being mailed in December--until the observer
recalled that some countries reverse the order of month and date
used in U.S. mail. Thus, a letter mailed Oct. 12 in France could
have the postmark 12-10-00. Some Florida vote-counters might
interpret that as Dec. 10.
It's amazing but true. So, of course, I got to explain to my kind
European cohorts of that particular day how "Americans could be so
stupid" as to (nearly) commit this kind of oversight, or so ignorant
as not to know how anything else works in the world.
One eventually grows tired of being called upon to justify the
ignorance of my fellows. Next time I go to Europe, I'm going to
bring a stack of pre-printed cards with little FAQs explaining the
myriad myths and misunderstandings that I am constantly expected
to address. And one of them is, "How come Americans write dates
wrong?" I then get to explain why it's not *wrong*, but rather,
is imply reflective of our speech.
I noted yesterday upon my repatriation, and not without some small
relish, that the American immigration forms ironically expected
dd/mm/yy, which my fellow passengers would chronically mess up.
I think I'm going to just go back to writing dates in Latin. "MM"
is easier than "2000", after all. But then we'll have to figure
out whether to include July and August. And then I get to explain
that the ides don't fall on the 15th of all possible months. Hm...
maybe I'll just use strftime() after all. :-)
--tom
------------------------------
Date: Tue, 21 Nov 2000 23:24:41 GMT
From: Wolfgang Denk <wd@denx.muc.de>
Subject: Re: Eurodate mysteries
Message-Id: <G4EED6.opM.7.denx@denx.muc.de>
Bart Lateur <bart.lateur@skynet.be> writes:
>Tom Christiansen wrote:
>What strikes me is that all of these "alternatives" use the European
>order: the month in the middle.
This seems perfectly natural to me (well, I'm from Germany, Europe :-)
because it is odered from smaller to bigger units (day-month-year) or
vice versa (year-month-time).
Writing 11/22/2000 gives me similar feelings like writing
426 = 2 * 10^1 + 6 * 10^0 + 4 * 10^2 - it's "not natural".
Wolfgang Denk
--
Software Engineering: Embedded and Realtime Systems, Embedded Linux
Phone: (+49)-8142-4596-87 Fax: (+49)-8142-4596-88 Web: www.denx.de
The software required `Windows 95 or better', so I installed Linux.
------------------------------
Date: Wed, 22 Nov 2000 01:49:46 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Eurodate mysteries
Message-Id: <Pine.GHP.4.21.0011220143040.27008-100000@hpplus03.cern.ch>
On 21 Nov 2000, Tom Christiansen wrote:
> I noted yesterday upon my repatriation, and not without some small
> relish, that the American immigration forms ironically expected
> dd/mm/yy, which my fellow passengers would chronically mess up.
Well,that's OK then. :-)
> I think I'm going to just go back to writing dates in Latin. "MM"
> is easier than "2000", after all
For heaven's sake don't write 2888 in Roman numbers, or you'll wake my
old friend Dr. John Stockton. (do a Deja search if you want to know
what that's all about. It seems to be one of the keys that he uses to
find pirate copies of his FAQ about dates).
Btw, there was a logical smiley with those multiple spellings of mine,
so I'm treating your reply as having one too. OK?
------------------------------
Date: Wed, 22 Nov 2000 01:51:54 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Eurodate mysteries
Message-Id: <Pine.GHP.4.21.0011220150210.27008-100000@hpplus03.cern.ch>
On Tue, 21 Nov 2000, Wolfgang Denk wrote:
> This seems perfectly natural to me (well, I'm from Germany, Europe :-)
warum dann z.B einhundertdreiundzwanzig?
;-)
------------------------------
Date: Tue, 21 Nov 2000 19:52:24 -0600
From: Smokin' Dave <smokindave@smokindave.com>
Subject: FAQ?
Message-Id: <6j9m1tc1jjm69bjnlrin0k23qnbv5k12b3@4ax.com>
Hi, I'm completely new to Perl, and was looking for this group's FAQ, in order to
avoid asking tired old questions. Can anybody point out a URL for this?
TIA
--
Smokin' Dave
Hell hath no coffee, no cigarettes.....
Smokin' Dave's Taxicab Diaries
http://www.smokindave.com
------------------------------
Date: Wed, 22 Nov 2000 08:45:09 +0800
From: "meow" <atong@operamail.com>
Subject: Re: HELP! bring variables out of a subroutine?
Message-Id: <8vf4ut$k2f@news.or.intel.com>
just use return("$your_variable") will do...
webbgroup@my-deja.com wrote in message <8vemlm$544$1@nnrp1.deja.com>...
>I have been able to use
>
>return 1;
>
>but how do I bring variables that I set within the subroutine out of
>it?? Doesn't using the return kill the subroutine after it is used??
>
>
>Sent via Deja.com http://www.deja.com/
>Before you buy.
------------------------------
Date: 21 Nov 2000 23:58:32 GMT
From: craznar@hotmail.com (Christopher Burke)
Subject: Re: how do I delete initial and final spaces in a string?
Message-Id: <8FF466688craznar@130.102.2.1>
uri@sysarch.com (Uri Guttman) wrote in <x71yw5dp55.fsf@home.sysarch.com>:
>>>>>> "CB" == Christopher Burke <craznar@hotmail.com> writes:
>
> CB> uri@sysarch.com (Uri Guttman) wrote in
> <x7hf52eh0j.fsf@home.sysarch.com>:
>
> >> \1 is a backreference and should only be used in the regex itself
> >> and not in the replacement string. it is supported but not proper.
> >> use $1 and brethren as that is what they are designed for.
>
> CB> You mean 'or even better supported' because the above DOES work.
>
>from perlre:
>
>
>WARNING on \1 vs $1
>
> Some people get too used to writing things like:
>
> $pattern =~ s/(\W)/\\\1/g;
>
> This is grandfathered for the RHS of a substitute to avoid
> shocking the sed addicts, but it's a dirty habit to get
> into. That's because in PerlThink, the righthand side of a
> s/// is a double-quoted string. \1 in the usual double-
> quoted string means a control-A. The customary Unix meaning
> of \1 is kludged in for s///. However, if you get into the
> habit of doing that, you get yourself into trouble if you
> then add an /e modifier.
>
> s/(\d+)/ \1 + 1 /eg; # causes warning under -w
>
> Or if you try to do
>
> s/(\d+)/\1000/;
>
> You can't disambiguate that by saying \{1}000, whereas you
> can fix it with ${1}000. Basically, the operation of
> interpolation should not be confused with the operation of
> matching a backreference. Certainly they mean two different
> things on the left side of the s///.
>
>
>that says it all. i would hope \1 in the RHS is dropped in perl6 (and it
>may be) as it is wrong.
Correction - unsupported....
------------------------------
Date: Tue, 21 Nov 2000 16:54:54 -0800
From: Stuart Vigne <vigne@nhamp.net>
Subject: Launching Excel2000 or Internet Explorer from Perl
Message-Id: <D65FF87A6AE54DAC.6BB1E2BE7FC711A2.37C0B82FFC012455@lp.airnews.net>
well after much work my Perl Tool is done, but I have one last feature
I want to include:
My final report is launching via Notepad, but I would like to change
that to Excel, and sometimes Internet Explorer. I run in Windows
2000, and this is the only platform my Perl script will ever run on.
Thanks in advance.
-Stuart V.
------------------------------
Date: Wed, 22 Nov 2000 00:44:35 GMT
From: Dianne van Dulken <dianne@dogmac.com>
Subject: Re: Location Redirect (newbie help question)
Message-Id: <8vf4tj$hm0$1@nnrp1.deja.com>
In article <Xns8FF397F90wyzelliyahoocom@203.39.3.131>,
wyzelli@yahoo.com (Wyzelli) wrote:
<snip>
Thanks a lot, Wyzelli
I had never heard of LWP before, as had none of my collegues. After a
morning of installing modules, it works like a dream.
Thankyou for keeping me from going mad (and repressing the evil slack
coder inside)
Cheers
Di
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 22 Nov 2000 00:55:10 GMT
From: "Jon" <softcomp@home.com>
Subject: Re: Memory limitation & memory leak
Message-Id: <OPES5.22645$15.5316415@news1.rdc1.az.home.com>
Michael,
I am sure the reference to the structure was not returned upon
exiting the function
and that's what was confusing to us. We track the memory usage by the script
via
"top" in Unix and we noticed that it crashes quite predictably when about
700MB of
memory was used. We also noticed that the memory usage grew considerably
after
we have exited the function and re-enter it the second time. We were
working out
of the assumption that the freed memory when the script exited the function
the first
time will be re-used when we hit the same function the second time. The
computer
has 4G of RAM so I don't think that is the problem since as a test case, we
pretty
much stopped all other programs. This is most puzzling.
Jon
"Michael Carman" <mjcarman@home.com> wrote in message
news:3A1A8EEF.8122C17D@home.com...
> Jon wrote:
> >
> > Does anyone here know if there is a limitation to the amount of
> > memory Perl can access - assuming that the physical RAM is not
> > the limiting factor?.
>
> IIRC, No. Perl will suck up every last byte your system has to offer.
>
> > If I have a localized (my) reference to a hash of hash to an array
> > within a function, does all the memory used to build this structure
> > gets freed and be made available when Perl exit the function?.
>
> Maybe -- it depends on what you do with that reference. Do you abandon
> it or return it to the caller? If something is still using that memory
> it won't be freed. Compare:
>
> sub foo {
> my $thing = [0 .. 10];
> # ...
> return;
> }
>
> sub bar {
> my $thing = [0 .. 10];
> # ...
> return $thing;
> }
>
> (Ignore for the moment the fact that both functions are silly and
> useless.) In foo() the array which $thing points to goes out of scope so
> its memory will be freed up for reuse. In bar() the reference is
> returned to the caller so something outside the function still knows
> about the array, it's reference count is non-zero, and it will *not* be
> freed upon leaving the sub. It will hang around occupying memory until
> everyone has forgotten about it.
>
> -mjc
------------------------------
Date: 21 Nov 2000 23:50:02 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Most easy way to get IP from a local NIC by device name (eth0,eth1...)
Message-Id: <8vf1na$316$1@charm.magnus.acs.ohio-state.edu>
[A complimentary Cc of this posting was NOT sent to Martien Verbruggen
<mgjv@tradingpost.com.au>],
who wrote in article <slrn91ls6v.r2.mgjv@verbruggen.comdyn.com.au>:
> But how do you know that that is eth1 or eth0? I think the question
> was to find the IP address that are tied to a specific interface.
> I took that to mean that given nothing else but the name of the
> interface, find its IP address. In other words, you don't know any
> network or host addresses. That's what you're trying to find out.
What is bad with netstat -i or -I? Is it not portable? Or does it
not work with eth0?
Ilya
------------------------------
Date: Wed, 22 Nov 2000 01:49:57 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Most easy way to get IP from a local NIC by device name (eth0,eth1...)
Message-Id: <slrn91m9h5.r2.mgjv@verbruggen.comdyn.com.au>
On 21 Nov 2000 23:50:02 GMT,
Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
> [A complimentary Cc of this posting was NOT sent to Martien Verbruggen
><mgjv@tradingpost.com.au>],
> who wrote in article <slrn91ls6v.r2.mgjv@verbruggen.comdyn.com.au>:
>> But how do you know that that is eth1 or eth0? I think the question
>> was to find the IP address that are tied to a specific interface.
>> I took that to mean that given nothing else but the name of the
>> interface, find its IP address. In other words, you don't know any
>> network or host addresses. That's what you're trying to find out.
>
> What is bad with netstat -i or -I? Is it not portable? Or does it
> not work with eth0?
the options to netstat are highly unportable, as is the output. On
linux netstat -i doesn't give you any addresses, and -I doesn't exist.
On Solaris -i gives you the addresses (as does -I, but limited to the
specified interface).
Of course, the output of ifconfig is platform specific as well, but at
least it's slightly easier to deal with, and will give you info you
need in any case.
There may be platforms (unices) where this doesn't work, but I don't
know of any.
Of course, you have to wrap anything in a sub anyway, and test for the
platform you're on. You're free to use ifconfig where appropriate,
netstat where that works, and anything else for the others (ipconfig
for NT?)
Martien
--
Martien Verbruggen |
Interactive Media Division | The four horsemen of the apocalypse
Commercial Dynamics Pty. Ltd. | are called Abort, Retry, Ignore and
NSW, Australia | Fail.
------------------------------
Date: 22 Nov 2000 01:26:46 +0100
From: Jakob Schmidt <sumus@aut.dk>
Subject: Re: Naming variables with variables, how?
Message-Id: <vgtgonqx.fsf@macforce.sumus.dk>
Ilmari Karonen <iltzu@sci.invalid> writes:
> In article <itpolxxq.fsf@macforce.sumus.dk>, Jakob Schmidt wrote:
> >
> >But don\t do it. There\s practically always a better way. Probably you
> >simply want an array or a hash. Believe me.
>
> I've no idea what made your apostrophes turn into backslashes, but I
> did spend a few seconds wondering why you'd use \s outside a regexp..
Sorry to have troubled you. The explanation is actually a little amusing
so here goes:
My good old Apple USB Keyboard died a while ago because it drank my coffee.
I told it not to but it wouldn't listen. A few days ago I finally bought
a replacement (iKey from Macally) - this is actually one of the reasons
why I'm back in c.l.p.m: I can now use my LinuxPPC again :-)
But a few keys in the new keyboard produced different codes than on the old
one - an so I had to alter my keymap to get thing back to normal.
But before I took the time to do so I simply couldn't find the apostrophe
on the keyboard. It gave me backslashes instead. After a while I decided
to post the message you're follow-up'ing as it was. It didn't occur to
me that compositions like \s might be confusing in i perl newsgroup.
And so: back on topic and out :-)
--
Jakob Schmidt
http://aut.dk/orqwood
etc.
------------------------------
Date: Wed, 22 Nov 2000 01:24:22 +0000
From: Blueman <bluman@claranews.com>
Subject: Need a quick definition of PERL
Message-Id: <9t7m1tgo1d0pv5fbicqcmrcpg4eqrpi225@4ax.com>
Keywords: *
I have to translate a small C++ routine to PERL. Is there a website
where I can get a basic definition of the language, and maybe a little
tutorial?
__________________________________________________________
What is your one purpose in life ... to explode of course.
------------------------------
Date: Wed, 22 Nov 2000 01:55:43 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Need a quick definition of PERL
Message-Id: <slrn91m9s0.r2.mgjv@verbruggen.comdyn.com.au>
On Wed, 22 Nov 2000 01:24:22 +0000,
Blueman <bluman@claranews.com> wrote:
> I have to translate a small C++ routine to PERL. Is there a website
> where I can get a basic definition of the language, and maybe a little
> tutorial?
http://finance.yahoo.com/quotes?symbols=PERL
The perl FAQ, section 1, has this entry:
What is Perl?
as well as this one:
What's the difference between "perl" and "Perl"?
And, surprise, surprise, www.perl.com and www.perl.org have loads of
other information. On the other hand, www.perl.net has nothing at all.
Maybe that's why you couldn't find it.
Martien
--
Martien Verbruggen |
Interactive Media Division | Hi, John here, what's the root
Commercial Dynamics Pty. Ltd. | password?
NSW, Australia |
------------------------------
Date: 22 Nov 2000 00:23:34 GMT
From: "~greg" <gm@magpage.com>
Subject: Re: OT:Re: Eurodate mysteries
Message-Id: <8vf3m6$vpg$0@216.155.32.36>
"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message news:slrn91luhs.r2.mgjv@verbruggen.comdyn.com.au...
> On 21 Nov 2000 20:02:54 GMT,
> ~greg <gm@magpage.com> wrote:
>
> > The idea was to match lines like: "Date: 09 Aug 1999 ..."
> > by /^Date: (\S+) (\S+) (\S+) /
>
> That won't match :). The number of spaces after the : get in the way.
>
> /^Date: +(\S+) +(\S+) +(\S+) /;
>
> > and then to use $3 . $Month{$2} . $Day{$1}
> > for sorting by date.
> >
> > Of course it didn't work -- because Perl converts string '01'
> > to numeric 1 and then back to string '1'. Easy enough to fix,
> > - once it's realized what was happening.
>
> No, it doesn't. It only does that if you use a string in a numeric
> context, and then in a string context again.
>
> $_ = "Date: 09 Aug 1999 ...";
> /^Date: +(\S+) +(\S+) +(\S+) /;
> print $1;
> my $foo = $1;
> print $foo;
> $foo += 0;
> print $foo;
>
> 09
> 09
> 9
>
> > I'm new to perl (or perl is new to me - depending on how you
> > read dates) - but it just makes it that much clearer why so much
> > thought was put into the problems of automatic casting
> > in C++.
>
> In Perl the idea is that it almost always does what you want or mean.
> Things stay strings until you use them as numbers or booleans. Then
> Perl converts. It's not really possible to convert perl's behaviour
> with anything that happens in C++. Automatic casting isn't the same
> thing as Perl's maghical handling of scalar values.
>
> Martien
Thank you.
I'm not certain where that numeric context was. What I thought was that
it must have occurred right at the start - in the construction of the the hash tables
- i.e. - that the '01', '02', etc must have been stored as numeric 1,2, ...-
- and then converted back to strings in the string context signaled by concatenation
- but as '1', '2', etc - so that e.g. what should have been '20000131' --for 31 Jan 2000
- wound up as '2000131' -- which was then sorted, as a string, after '20001231'
- i.e. 31 Dec 2000, instead of before it, - because that's what happened.
~Greg
------------------------------
Date: 21 Nov 2000 18:51:02 -0600
From: chilalin@dataflo.net (Bobby Bailey)
Subject: Parsing name<->value data from html forms.
Message-Id: <slrn91m5va.3c4.chilalin@devel.chil.org>
Greetings,
I'm looking for any pointers to a module that might help me do the following:
I am trying to connect to a specified URL and (assuming there is a form
contained on the page specified by the URL) run through the data on the page,
automatically grabbing the form elements and type, along with any list of
values provided (for select lists, etc). I then want to fill in those form
elements with data specified by the script. In essense, I'm looking to
automatically fill out the form and submit it back to the server. I know that
CGI.pm is used for parsing forms on the server side -- would the routines
there allow me to do the above, or is there a different module that might work
better?
Thanks,
--
Bobby Bailey | "The only source of knowledge is experience."
Linux Server Admin | -- Albert Eistein
MUD Programmer | DestinyMUD! Come play at telnet://destiny.nerp.net:1235
------------------------------
Date: Tue, 21 Nov 2000 19:18:54 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Parsing name<->value data from html forms.
Message-Id: <slrn91m47e.jv0.tadmc@magna.metronet.com>
On 21 Nov 2000 18:51:02 -0600, Bobby Bailey <chilalin@dataflo.net> wrote:
>I'm looking for any pointers to a module that might help me do the following:
>
>I am trying to connect to a specified URL and (assuming there is a form
>contained on the page specified by the URL)
use LWP::Simple;
$form_page = get 'http://www.perl.com';
>run through the data on the page,
>automatically grabbing the form elements and type, along with any list of
>values provided (for select lists, etc).
use HTML::Parser; (or other of similar ilk)
>I then want to fill in those form
>elements with data specified by the script. In essense, I'm looking to
>automatically fill out the form and submit it back to the server.
use LWP::UserAgent;
>or is there a different module that might work
>better?
The LWP is part of the libwww package on CPAN.
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 22 Nov 2000 00:04:14 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: perl vs C style
Message-Id: <24ES5.671$Bf7.189415936@news.frii.net>
In article <u7d7fpvxnm.fsf@benburb.tangent.com>,
joe mc cool <joe@benburb.demon.co.uk> wrote:
>
>can someone point me to sources on the differences between idioms in
>perl and c programming.
>
Look at the perlstyle manual page for some thoughts close to this topic.
perldsc, perllol, perlmodlib, and perltoot might also be reasonable to
examine. And don't forget to read other peoples code.
chris
--
This space intentionally left blank
------------------------------
Date: Tue, 21 Nov 2000 18:42:14 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: perl vs C style
Message-Id: <slrn91m22m.jsb.tadmc@magna.metronet.com>
On 21 Nov 2000 21:10:53 +0000, joe mc cool <joe@benburb.demon.co.uk> wrote:
>
>can someone point me to sources on the differences between idioms in
>perl and c programming.
Perl idioms are cool. C idioms suck.
(but ask in the C newsgroup too so the votes will cancel out...)
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 21 Nov 2000 19:11:13 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: perl vs C style
Message-Id: <slrn91m3p1.jv0.tadmc@magna.metronet.com>
On Wed, 22 Nov 2000 00:04:14 GMT, Chris Fedde
<cfedde@fedde.littleton.co.us> wrote:
>In article <u7d7fpvxnm.fsf@benburb.tangent.com>,
>joe mc cool <joe@benburb.demon.co.uk> wrote:
>>
>>can someone point me to sources on the differences between idioms in
>>perl and c programming.
>>
>
>Look at the perlstyle manual page for some thoughts close to this topic.
>perldsc, perllol, perlmodlib, and perltoot might also be reasonable to
>examine. And don't forget to read other peoples code.
And straight from the camel's mouth:
http://www.wall.org/~larry/natural.html
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 21 Nov 2000 23:10:36 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: REGEXP Help! Trying to parse funky time format...
Message-Id: <slrn91m06c.r2.mgjv@verbruggen.comdyn.com.au>
On Tue, 21 Nov 2000 14:04:13 -0800,
Liam Furniss <liam@nethelpnow.com> wrote:
> Hello Perlish Types,
>
> I have a some time data in the form XXd,XX:XX.XX (e.g. 5d,23:55.07), and I
> can't seem to craft a regexp the will extract just the numbers into
> variables that will be useful to me. Currently, I'm trying
Assumptions:
5d means 5 days. The number before the d can have more digits.
The thing after the comma is time in hours, minutes, second, and
always is composed of three two-digit pairs.
$_ = "5d,23:55.07";
my ($days, $hours, $minutes, $seconds) =
/^(\d+)d,(\d\d):(\d\d)\.(\d\d)$/;
> /(\d*d,)?(\d*:)?(\d*\.)?(\d*)?/, but it reports the minutes in $4 and $3 is
You're being too greedy and uncertain there. Just state what you want.
You're making too many things optional, which just confuses the issue.
> empty...The other problem of course is making it work when the no day or
> hour data (e.g. 5.23)...Anyone feel kind enough to work their regexp mojo
> for me? This script could help save a struggling dot com! Hehe.
That is indeed another problem. And I would really call that a data
format problem. Could you post a more complete set of all possible
data that can come in? You're being too vague here. A minimal set that
illustrates each possible variant of your input data will do. It may
very well be that you don't want to do this in a single regex, but in
three or more.
Oh, why not. Here's some stuff that probably does what you want. Adapt
to your needs.
One that tests bit by bit:
my ($days, $hours, $minutes, $seconds) = (0, 0, 0, 0);
if (@match = /^(\d+)d,(\d\d):(\d\d)\.(\d\d)$/)
{
($days, $hours, $minutes, $seconds) = ($1, $2, $3, $4);
}
elsif (@match = /^(\d\d):(\d\d)\.(\d\d)$/)
{
($hours, $minutes, $seconds) = @match;
}
elsif (@match = /^(\d\d)\.(\d\d)$/)
{
($minutes, $seconds) = @match;
}
If you insist on doing it with a single regex:
my ($days, $hours, $minutes, $seconds) =
/^(?:(\d+)d,)?(?:(\d\d):)?(\d\d)\.(\d\d)$/;
$hours = 0 unless defined $hours;
$days = 0 unless defined $days;
I suspect that the first one probably is faster, but I may be wrong.
Martien
--
Martien Verbruggen |
Interactive Media Division |
Commercial Dynamics Pty. Ltd. | "Mr Kaplan. Paging Mr Kaplan..."
NSW, Australia |
------------------------------
Date: Tue, 21 Nov 2000 19:47:41 -0600
From: Chas Friedman <friedman@math.utexas.edu>
Subject: Re: REGEXP Help! Trying to parse funky time format...
Message-Id: <3A1B25BC.87FDF444@math.utexas.edu>
I tried:
$_="5d,23:55.07";
@stuff=/(\d*d,)?(\d*:)?(\d*\.)?(\d*)?/;
print "@stuff\n";
print "\$3=$3\n";
and this produces the output:
5d, 23: 55. 07
$3=55.
so you must be doing something else wrong besides what Martien Verbruggen
indicated
(his solution covers various cases and eliminates the d , . and : from the
saved variables which seems to be
what you wanted, of course.)
Liam Furniss wrote:
........
> I have a some time data in the form XXd,XX:XX.XX (e.g. 5d,23:55.07), and I
> can't seem to craft a regexp the will extract just the numbers into
> variables that will be useful to me. Currently, I'm trying
> /(\d*d,)?(\d*:)?(\d*\.)?(\d*)?/, but it reports the minutes in $4 and $3 is
> empty.............
------------------------------
Date: Tue, 21 Nov 2000 18:39:11 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Sort strings before numbers
Message-Id: <slrn91m1sv.jsb.tadmc@magna.metronet.com>
On Tue, 21 Nov 2000 23:51:32 +0100, Holger <hbhb@gmx.de> wrote:
>On Mon, 20 Nov 2000 18:58:39 -0500, tadmc@metronet.com (Tad McClellan)
>wrote:
>>>In <perlfunc> I found an example for sort.
>>> } map { [$_, /=(\d+)/, uc($_)] } @old;
>>The last square brackets return a reference to an anonymous array.
>Yes, I meant the square ones.
perldoc perlreftut
>Is there a difference between an (anonymous)
>list and array (in perl, in C at least I know that there is)?
Whoa!
Let's start over.
Perl FAQ, part 4:
"What is the difference between a list and an array?"
Lists can never be named.
Arrays can be @named or [anonymous]
>In <perldata>
>I only found parentheses, that form a list.
I guess you were looking at the "List value constructors" section?
Note that it does not say what you just paraphrased above.
It says parens are only required where precedence requires them.
The classic example of 2 related points is Perl's push() function:
perldoc -f push
=item push ARRAY,LIST
First, we see that there must be a difference else it would be
"ARRAY, ARRAY" or "LIST, LIST". Perl needs to modify the first
one, so it must be an array, not a list.
Second, here's a list with no parenthesis:
push @array, 1, 2, 3, 4;
>>I doubt that the ST is a win for what you need to do anyway, just
>>split up the list of keys as above.
So don't use the ST. It won't help here.
>Initially, I also got warnings that some arguments aren't numeric in
>numeric comparison. That's why my original post has these expensive tests
>because I had to test for numeric value before comparing.
>One question to your example: Doesn't building up the "helping" array
>consume too much time (not to mention space)?
Splitting the keys into 2 arrays is O(n) (proportional to number
of keys).
Quick sort (that perl uses) is O(n log n).
If you let n (# of keys) get big enough, 2 arrays will begin to win.
>Btw, what does "ST" mean?
Schwartzian Transform
That's the name for the map/sort/map code snippet. It is in the
Perl FAQs about sorting. Surely you have already seen the Perl
FAQs about sorting, haven't you?
perldoc -q sort
--
Tad McClellan SGML consulting
tadmc@metronet.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 22 Nov 2000 01:31:34 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Re: Sort strings before numbers
Message-Id: <WlFS5.157$tH1.103273@news.pacbell.net>
Holger <hbhb@gmx.de> wrote:
> Yes, I meant the square ones. Is there a difference between an (anonymous)
> list and array (in perl, in C at least I know that there is)? In <perldata>
> I only found parentheses, that form a list.
Arrays can contain lists. Subroutines can return a list. A list is
not a variable. An array is a variable. There is no such thing as an
anonymous list.
An anonymous array doesn't (usually) have a name..
@a = (1,2,3);
"@a" is a name for an array that contains 1,2, and 3. The "(1,2,3)"
will return a list of values (in list context).
$ref = \@a;
A "reference" to @a has been taken and stored in $ref. We can now use
the ref to get to the elements of @a.
$ref->[1]
Is a way to access the second element of @a. Note that although we're
working with the @a array, we didn't use it's name at all. Because of
that, we can construct arrays that don't have a name in the first place.
$ref = [1,2,3];
We now have a reference to an array that again holds the elements 1, 2,
and 3, but this time, the array doesn't have a name of it's own.
Instead, we must use the reference to it.
--
Darren Dunham ddunham@taos.com
Unix System Administrator Taos - The SysAdmin Company
Got some Dr Pepper? San Francisco, CA bay area
< Please move on, ...nothing to see here, please disperse >
------------------------------
Date: Wed, 22 Nov 2000 00:20:52 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: urgent, regular expression
Message-Id: <k04m1tsakn8ntt13fdbsgmsn8nt7h7rb8g@4ax.com>
eastking@my-deja.com wrote:
>I need to write a regular expression to change my source code. So would
>you please help. Thanks in advance.
>
>This oringinal is as following:
>
> Vara = funcA(funcB(funC(something))) + funcA(funcB(funC(otherthing)))
>
>I want it be translated to
> Vara = funcA(funcB(funC(something),'para'),'para') + funcA(funcB(funC
>(otherthing),'para'),'para')
>
>As you can see, the funcA and funcB both add a parameter in it's
>parameter list.
That sounds more like it needs a grammar than a regular expression. So
let me pull in Parse::RecDescent.
use Parse::RecDescent;
my $grammar = <<'#EOT#';
statement: bareword '=' expr | <error>
expr: term op expr | term
term: number | bareword '(' arguments ')'
{ shift @item; splice @item, -1, 0, ", 'para'" if $item[0] eq 'funcA'
or $item[0] eq 'funcB'; join '', @item }
| bareword | <error>
number: /-?\d+\.?\d*/
bareword: /[a-zA-Z_]\w+/
op: '+' | '-' | '*' | '/' | '%'
arguments: argument ',' arguments | argument | ''
argument: expr
#EOT#
$::RD_AUTOACTION = q { shift @item; join '', @item };
my $parser = new Parse::RecDescent($grammar);
$line = "Vara = funcA(funcB(funC(something))) +
funcA(funcB(funC(otherthing)))";
print $parser->statement($line);
__END__
This prints, on one line:
Vara=funcA(funcB(funC(something), 'para'),
'para')+funcA(funcB(funC(otherthing), 'para'), 'para')
which sounds pretty much like what you want.
A snag is that it strips all whitespace.
--
Bart.
------------------------------
Date: Wed, 22 Nov 2000 00:27:06 GMT
From: dack@visi.com
Subject: Re: Weird question: has anyone used Perl to parse the Shoutcast XML feed for display to a browser?
Message-Id: <3a1b12bd.33093646@news.visi.com>
On Tue, 21 Nov 2000 07:40:44 GMT, "Lauren Smith"
<lauren_smith13@hotmail.com> wrote:
>
><dack@visi.com> wrote in message news:3a198bf3.19656414@news.visi.com...
>> Any insights or pointers are appreciated. Thanks.
>
>Here's an easy pointer. Put your question in the body of your message.
>It's easier to read and answer that way.
>
>Lauren
Hey, thanks a lot!
------------------------------
Date: 21 Nov 2000 17:39:36 -0600
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Why are references useful?
Message-Id: <m3wvdw7v47.fsf@dhcp11-177.support.tivoli.com>
Ron Grabowski <ronnie@catlover.com> writes:
> > This is one of those things that are hard to explain with simple examples.
>
> Suppose you have a large array that takes up 20mb of memory. If you to
> pass that array by value to a subroutine you now have to two instances
> of it ( the original one and the copy ). The data in the array is now
> taking up 40mb of space ( an extra 20mb of a copy that is being sent to
> the sub ). By passing the array by reference you are pointing the
> subroutine to the location in memory that the big array is stored at so
> you are using 20mb of memory instead of 40mb.
But this is a spurious argument for the use of references in Perl as
arguments are *always* passed by reference. It isn't until you decide
to make a copy within the subroutine that a copy occurs. To wit:
#!/usr/local/bin/perl
use strict;
use warnings;
sub modify_array {
s/old/new/ for @_;
}
my @array = qw/here is the old data/;
modify_array(@array);
print "@array\n";
__END__
Admittedly, this doesn't really *prove* that the array is passed by
reference, but it gives a pretty good hint that it is. Of course, if
the subroutine does something like
my @values = @_;
or
my $first = shift;
then a copy certainly occurs. But it is explicit, not implicit.
As for when references are useful, there are lots of examples. The
most memorable for me is thinking back to the way I just to handle
aggregate data in Perl4:
$name{ren} = 'Ren Maddox';
$email{ren} = 'ren@tivoli.com';
i.e., parallel structures. With references, you can use:
$people{ren}{name} = 'Ren Maddox';
$people{ren}{email} = 'ren@tivoli.com';
As to why this is better, I'll leave that as a homework
assignment... :)
--
Ren Maddox
ren@tivoli.com
------------------------------
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 V9 Issue 4945
**************************************