[16921] in Perl-Users-Digest
Perl-Users Digest, Issue: 4333 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 15 11:11:00 2000
Date: Fri, 15 Sep 2000 08:10:15 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <969030615-v9-i4333@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 15 Sep 2000 Volume: 9 Number: 4333
Today's topics:
Regular Expression for matching with email addresses <james_adams@yahoo.com>
Re: Req.: The perfect Perl Editor? (Smylers)
Re: Shortest code for Fibonacci? <ren.maddox@tivoli.com>
Re: Shortest code for Fibonacci? <ren.maddox@tivoli.com>
Re: Shortest code for Fibonacci? (Gwyn Judd)
Re: Shortest code for Fibonacci? (Gwyn Judd)
Substitution <jluongonospam@draper.com>
Re: Text manipulation: translating several token at onc <tm@kernelconsult.com>
Re: Text manipulation: translating several token at onc <tm@kernelconsult.com>
Re: Text manipulation: translating several token at onc <ren.maddox@tivoli.com>
Re: Text manipulation: translating several token at onc <ren.maddox@tivoli.com>
URL Submission Perl CGI Script? (Mick Beeby)
Re: Web Client multipart-data POST tebrusca@my-deja.com
Re: Were to get a sendmail for a Win98 SE ? <cublai@earthlink.net>
Re: Working with IP addresses (hymie!)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 15 Sep 2000 14:53:11 GMT
From: James Adams <james_adams@yahoo.com>
Subject: Regular Expression for matching with email addresses
Message-Id: <8ptd4b$t1q$1@nnrp1.deja.com>
I want to verify that strings conform to a typical email address
format. I have some code which can use Perl regular expressions as
verification masks, but I'm not the world's best at Perl regular
expressions so I'm hoping that someone can provide me with some example
Perl regular expressions that I could use for this verification mask.
I want to match with something like
my.address_is-ugly@some.place.com (dashes, underscores, and digits are
ok, only one @ sign, etc.)
and fail to match with garbage such as this: bad%*)addres@isp@isp2.it
Many thanks in advance for any suggestions.
-James
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 15 Sep 2000 13:00:25 +0100 (BST)
From: Smylers-usenet@stripey.com (Smylers)
Subject: Re: Req.: The perfect Perl Editor?
Message-Id: <2000Sep15.120025.22248@leeds.ac.uk>
Tim Hammerquist <tim@degree.ath.cx> uttered something along the lines
of:
> Andreas Leiberger <andreas@gispi-sport.de> wrote:
>
> > Is there a software for creating perl scripts that includes an
> > excellent help documentation. I'm a fan of the mark+F1 technique. I
> > kind of miss that in Notepad. :-)
> > Can you recommend any programm in this context.
>
> Oblivious as to the "mark+F1" comment.
I think it's a reference to some (Microsoft) IDE's where highlighting
some code then pressing <F1> brings up the page of the help file deemed
to be most relevant to that code.
> vim ( http://www.vim.org )
In `Vim' you can do something similar with:
:set keywordprg=perldoc\ -f
then when the cursor is on a function name, pressing K will display the
documentation for that function.
Follow-ups set.
Smylers
------------------------------
Date: 15 Sep 2000 00:13:39 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Shortest code for Fibonacci?
Message-Id: <m3og1qck58.fsf@dhcp11-177.support.tivoli.com>
tjla@guvfybir.qlaqaf.bet (Gwyn Judd) writes:
> I was shocked! How could Clint Mario Cleetus <cmc77@pantheon.yale.edu>
> say such a terrible thing:
> >Hi,
> >
> >I am looking for a concise and elegant way to calculate the Fibonacci
> >Number corresponding to a given number. But it should also avoid recursion
> >in order to be efficient. I wrote a standard subroutine for this:
>
> <snip>
>
> >But this seems to be like any other standard C subroutine. Please let me
> >know if you have one-liners or atleast a much more elegant solution for
> >this.
>
> perl -le 'print length while ($ / =~ s|(.*)|s ,. *,$ /,ex, $ / . $ &|e)'
>
> Concise: Check
> Elegant: ummm
> Avoids Recursion: Check
> Efficient: Define "Efficient"
> Standard: Nope
> One-Line: Check
> Obfuscated: I hope so :)
Correct: Apparently not...
1
3
7
15
31
63
127
^C
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 15 Sep 2000 00:08:51 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Shortest code for Fibonacci?
Message-Id: <m3r96mckd8.fsf@dhcp11-177.support.tivoli.com>
Clint Mario Cleetus <cmc77@pantheon.yale.edu> writes:
> Hi,
>
> I am looking for a concise and elegant way to calculate the Fibonacci
> Number corresponding to a given number. But it should also avoid recursion
> in order to be efficient. I wrote a standard subroutine for this:
>
> sub Fib
> {
> $num = shift;
>
> return 1 if $num < 2;
>
> $f1 = $f2 = 1;
> for ($i = 1; $i < $num; $i++)
> {
> $f = $f1 + $f2;
> $f1 = $f2;
> $f2 = $f;
> }
> return $f;
> }
>
> But this seems to be like any other standard C subroutine. Please let me
> know if you have one-liners or atleast a much more elegant solution for
> this.
Well, despite your request, this uses recursion. However, because it
saves all previous results, the recursion cost isn't really an issue.
In fact, you can pay the entire cost as part of startup by
uncommenting the line near the end.
{
my @fib = (1, 1);
sub fib {
$_[0]<2 ? 1 : ($fib[$_[0]] or $fib[$_[0]] = fib($_[0]-1)+fib($_[0]-2));
}
# fib(1000); # pre-fill the array up to some "max" expected value
}
Calling this routine once is certainly slower than yours, but every
time it is called with a number lower than the maximum value that it
has already been called with, it returns almost instantly. Of course,
calling it with a really large number uses a sizeable chunk of memory.
Memoization rocks!
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Fri, 15 Sep 2000 14:38:42 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Shortest code for Fibonacci?
Message-Id: <slrn8s4d3e.8q2.tjla@thislove.dyndns.org>
I was shocked! How could Ren Maddox <ren.maddox@tivoli.com>
say such a terrible thing:
>tjla@guvfybir.qlaqaf.bet (Gwyn Judd) writes:
>
>> I was shocked! How could Clint Mario Cleetus <cmc77@pantheon.yale.edu>
>> say such a terrible thing:
>> >Hi,
>> >
>> >I am looking for a concise and elegant way to calculate the Fibonacci
>> >Number corresponding to a given number. But it should also avoid recursion
>> >in order to be efficient. I wrote a standard subroutine for this:
>>
>> perl -le 'print length while ($ / =~ s|(.*)|s ,. *,$ /,ex, $ / . $ &|e)'
>
> Correct: Apparently not...
The curse of the was working, changed but insufficiently tested code
strikes again :) How does this grab you?
perl -le 'print length while ($" =~ s|(.*)|s c. *c$ "cex, $ ". $ &|e)
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
It's all magic. :-)
-- Larry Wall in <7282@jpl-devvax.JPL.NASA.GOV>
------------------------------
Date: Fri, 15 Sep 2000 14:42:18 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Shortest code for Fibonacci?
Message-Id: <slrn8s4da6.8q2.tjla@thislove.dyndns.org>
I was shocked! How could Mark-Jason Dominus <mjd@plover.com>
say such a terrible thing:
>In article <Pine.GSO.4.10.10009142301000.15482-100000@morpheus.cis.yale.edu>,
>Clint Mario Cleetus <cmc77@pantheon.yale.edu> wrote:
>>I am looking for a concise and elegant way to calculate the Fibonacci
>>Number corresponding to a given number. But it should also avoid recursion
>>in order to be efficient.
>If you want to compute, say, fib(1000000000), this is definitely the
>way to go. If I were you I would translate it to C before optimizing
>it any further.
Way Off Topic: Wouldn't it be better to translate it to a language that
can handle numbers as large as fib(1000000000) such as I don't know
lisp? No doubt some spoil sport will jump in and say that there are
bignum libraries for C :)
--
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Gauls! We have nothing to fear; except perhaps that the sky may fall on
our heads tomorrow. But as we all know, tomorrow never comes!
-"Adventures of Asterix"
------------------------------
Date: Fri, 15 Sep 2000 08:51:22 -0400
From: "James M. Luongo" <jluongonospam@draper.com>
Subject: Substitution
Message-Id: <39C21B4A.A11C6FEB@draper.com>
In Windows, I would like to replace the full pathname of a file with
just the filename.
for instance
$dir = ARGV[0]; # a directory is sent
@files = glob ("$dir\\*.*"); # get all the files in $dir
foreach $file (@files) {
$file =~ s/$dir\\//; # take out $dir and replace with nothing
print "$file\n";
}
Yet, this doesn't work. $dir\\ is not matched. Why? And how can I do
this better?
--
------------------------
James M. Luongo x1427
Draper Laboratory Room 4207
------------------------
------------------------------
Date: Fri, 15 Sep 2000 15:21:52 +0200
From: TM <tm@kernelconsult.com>
To: Philip Garrett <philipg@atl.mediaone.net>
Subject: Re: Text manipulation: translating several token at once
Message-Id: <39C22270.46F280C@kernelconsult.com>
Philip Garrett a écrit :
> TM <tm@kernelconsult.com> wrote in message
> news:39C1A6A2.863E4040@kernelconsult.com...
> > Hello,
> >
> > here's the question let's take a text or even a line of text. with
> > let's say many atoms symbols from the periodic chart of elements. And
> > now we whant to translate each of them into their full name.
> > The brutal way would be to make a loop over the line and trying all of
> > the symbol one at a time:
> >
> > But I guess there must be a more elegant trick.
> >
> > TM
>
> my %elements = ( H => 'Hydrogen', O => 'Oxygen', N => 'Nitrogen' );
> my $text = 'H O N';
>
> $text =~ s/(\w)/$elements{$1}/g;
> print "$text\n";
>
> hth,
> Philip
That's great
------------------------------
Date: Fri, 15 Sep 2000 15:22:11 +0200
From: TM <tm@kernelconsult.com>
To: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Text manipulation: translating several token at once
Message-Id: <39C22283.62369A5A@kernelconsult.com>
Larry Rosler a écrit :
> In article <JRhw5.1682$jC4.274850@typhoon.southeast.rr.com>,
> philipg@atl.mediaone.net says...
> > TM <tm@kernelconsult.com> wrote in message
> > news:39C1A6A2.863E4040@kernelconsult.com...
>
> ...
>
> > > here's the question let's take a text or even a line of text. with
> > > let's say many atoms symbols from the periodic chart of elements. And
> > > now we whant to translate each of them into their full name.
> > > The brutal way would be to make a loop over the line and trying all of
> > > the symbol one at a time:
> > >
> > > But I guess there must be a more elegant trick.
>
> ...
>
> > my %elements = ( H => 'Hydrogen', O => 'Oxygen', N => 'Nitrogen' );
> > my $text = 'H O N';
> >
> > $text =~ s/(\w)/$elements{$1}/g;
> > print "$text\n";
>
> my %elements =
> ( H => 'Hydrogen', O => 'Oxygen', N => 'Nitrogen', Ne => 'Neon', );
> my $text = 'H2O N Ne Foo';
>
> $text =~ s/([A-Za-z]+)/$elements{$1} || $1/eg;
> print "$text\n";
>
> --
> (Just Another Larry) Rosler
> Hewlett-Packard Laboratories
> http://www.hpl.hp.com/personal/Larry_Rosler/
> lr@hpl.hp.com
That's even better!!
------------------------------
Date: 14 Sep 2000 23:45:45 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Text manipulation: translating several token at once
Message-Id: <m3u2biclfq.fsf@dhcp11-177.support.tivoli.com>
TM <tm@kernelconsult.com> writes:
> Hello,
>
> here's the question let's take a text or even a line of text. with
> let's say many atoms symbols from the periodic chart of elements. And
> now we whant to translate each of them into their full name.
> The brutal way would be to make a loop over the line and trying all of
> the symbol one at a time:
>
> But I guess there must be a more elegant trick.
Need to nail down the format a little more. Can anything else be in
the string, or is it simply a list of atomic symbols? Are they
space-separated?
Assuming you have something like "Ag He H Au Hg", then it is
straight-forward. Simply build a hash of all the symbols and their
names, then apply that hash to each token:
# assume %elements is already initialized
$_ = "Ag He H Au Hg";
s/(\w+)/$elements{$1}/g;
and that's it. Of course, if the data format is more complicated,
then the solution will be as well. But the basic idea of keying a
hash off of the atomic symbol is probably the fundamental portion of
the solution.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 15 Sep 2000 00:15:54 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: Text manipulation: translating several token at once
Message-Id: <m3lmwuck1h.fsf@dhcp11-177.support.tivoli.com>
"Philip Garrett" <philipg@atl.mediaone.net> writes:
> my %elements = ( H => 'Hydrogen', O => 'Oxygen', N => 'Nitrogen' );
> my $text = 'H O N';
>
> $text =~ s/(\w)/$elements{$1}/g;
> print "$text\n";
Which is fine until you add, say, Hg => 'Mercury', at which point you
need a "+" on that "\w".
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Fri, 15 Sep 2000 18:56:17 GMT
From: mick.beeby@mjb-is.co.uk (Mick Beeby)
Subject: URL Submission Perl CGI Script?
Message-Id: <39c2702a.70557236@news.freeserve.net>
Does anyone know where I can get a good, easy to use URL submission
script?
I have seen one on several differnet sites that submits to 300 sites
with a popup progress window but I can not find the actual script
itself anywhere.
I am not particularly worried about the amount of sites submitted to.
I'm primarily concerned with the major search engines.
I would appreciate it if anyone could point me in the right direction.
It needs to be able to run on NT IIS4.0 with Perl 5 Interpreter.
I'd appreciate any replies cross-mailed to me at
mick.beeby@mjb-is.co.uk
Thanks
Mick
------------------------------
Date: Fri, 15 Sep 2000 13:35:20 GMT
From: tebrusca@my-deja.com
Subject: Re: Web Client multipart-data POST
Message-Id: <8pt8in$n4l$1@nnrp1.deja.com>
In article <9shw5.47046$QW4.546759@news1.rdc1.mi.home.com>,
"Bill Hess" <billhess2000@home.com> wrote:
> I am trying to write a web client to upload files to a web server (in
Perl)-
> I know the CGI side on the server works, because I can upload
successfully
> using a web browser. But I cannot seem to get the headers correct.
Here is
> what I think the headers should look like - Am I missing
something??? I am
> trying to reverse engineer what IE is doing...
I'm working on exactly the same problem. What's in your error.log?
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Fri, 15 Sep 2000 12:07:45 GMT
From: "Captain Ahab" <cublai@earthlink.net>
Subject: Re: Were to get a sendmail for a Win98 SE ?
Message-Id: <liow5.12175$%p2.515105@newsread03.prod.itd.earthlink.net>
> >Can someone tell me were to get a sendmail for Win32?
I use Mail::Sendmail, which you can get on CPAN
http://www.perl.com/CPAN-local/modules/01modules.index.html, on Win98/NT.
------------------------------
Date: 15 Sep 2000 15:21:18 GMT
From: hymie@lactose.smart.net (hymie!)
Subject: Re: Working with IP addresses
Message-Id: <8ptepe$2ps$1@news.smart.net>
*whimper*
In our last episode, the evil Dr. Lacto had captured our hero,
Larry Rosler <lr@hpl.hp.com>, who said:
>In article <8pqrgf$qn0$1@news.smart.net> on 14 Sep 2000 15:39:59 GMT,
>hymie! <hymie@lactose.smart.net> says...
>
>...
>
>> Convert the two IP addresses from base-256 numbers into base-10 numbers.
>> Then, as you iterate between your starting and ending point, convert
>> the base-10 numbers back to base-256 IP addresses.
>>
>> $base10=unpack("L",join '',map chr,reverse split(/\./,$ip));
>>
>> $ip = join '.',unpack("C*",reverse pack ("L",$base10));
>
>You are seriously deluded to think that those are 'base-10' numbers.
I'm sorry. I was using "base-10" as a shorthand for "a single integer
that has the property of being sequential (and thus can be iterated over
with a simple $x++ construct) and can be easily manipulated by base-10-
thinking programmers. [ for ($i=$lownumber, $i <= $highnumber, $i++) ]"
As opposed to "a set of four integers that need to be operated on
individually and yet with respect to each other."
>But it is seriously flawed by the use of the endian-dependent 'L'
>conversion, instead of always big-endian 'Network' order.
Ah. Thank you. Now I understand what "A long in 'network' (big-endian)
order" means.
hymie! http://www.smart.net/~hymowitz hymie@lactose.smart.net
===============================================================================
Seems I'm not alone at being alone -
A hundred billion castaways looking for a home. --Sting
===============================================================================
------------------------------
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 4333
**************************************