[14074] in Perl-Users-Digest
Perl-Users Digest, Issue: 1484 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 24 21:05:33 1999
Date: Wed, 24 Nov 1999 18:05:15 -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: <943495515-v9-i1484@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 24 Nov 1999 Volume: 9 Number: 1484
Today's topics:
Re: '/usr/bin/file' function in bash for perl??? <cassell@mail.cor.epa.gov>
Almost ready: ????::TNEF.pm (Douglas Wilson)
Re: Assigning an element of n associat. array to a scal <pullen@one.net.au>
Re: Best book on Perl <cassell@mail.cor.epa.gov>
Re: Change password via cgi script (Abigail)
Re: compare a string to values in an array? (Martien Verbruggen)
Re: cookies <cassell@mail.cor.epa.gov>
Re: dynamically created filehandles. Help!! jkosowan@my-deja.com
Re: getlogin() <cassell@mail.cor.epa.gov>
Re: How to send a bitmap as part of an HTML mail messag <dukat@flash.net>
Re: Learning LWP (Alastair)
Re: mirror : y2k compliance <cassell@mail.cor.epa.gov>
mySQL + Perl - SELECT results binding ambassador_black@my-deja.com
Re: mySQL + Perl - SELECT results binding <lr@hpl.hp.com>
Re: Net::Ping <cassell@mail.cor.epa.gov>
Re: New dialect of perl: xperl (or reinventing perl, or (Martien Verbruggen)
passing scalars by reference as fast as passing by valu <ff@creative.net>
Re: passing scalars by reference as fast as passing by <lr@hpl.hp.com>
Re: passing scalars by reference as fast as passing by <cassell@mail.cor.epa.gov>
Re: Perl interact with Unix command <dchristensen@california.com>
Re: recipe 1.11 in Cookbook Where? Here documents <cassell@mail.cor.epa.gov>
Re: reg expr question (Martien Verbruggen)
Re: sprintf help <skilchen@swissonline.ch>
Re: sprintf help <cassell@mail.cor.epa.gov>
Re: sprintf help <cassell@mail.cor.epa.gov>
Re: sprintf help <lr@hpl.hp.com>
Re: stupid user Q (Yanick Champoux)
Re: Test for eval() without using eval() ?? (Martien Verbruggen)
Re: Threads and memory leaks <dan@tuatha.sidhe.org>
Using C functions in PErl sumengen@my-deja.com
Re: using regex to extract data (Martien Verbruggen)
Re: variable scoping (Martien Verbruggen)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 24 Nov 1999 15:56:08 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: '/usr/bin/file' function in bash for perl???
Message-Id: <383C7B18.8919CB13@mail.cor.epa.gov>
support@wildapache.net wrote:
>
> Hello,
Howdy,
> Does anyone know if there is a perl function to get the same results
> as the 'file' function in bash?
See the Perl Power Tools for an implementation of 'file'.
http:/language.perl.com/ppt/
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Thu, 25 Nov 1999 00:56:58 GMT
From: dwilson@gtemail.net (Douglas Wilson)
Subject: Almost ready: ????::TNEF.pm
Message-Id: <383b7e9c.1625149@news>
Brief history:
I email myself something with an attachment FROM
a unix system TO a windoze system. The attachment
is just Base64 encoded text.
I use Net::POP3 or Mail::POP3Client along with
MIME::Parser to get the attachment, and I find out
my simple attachment has become a Base64
encoded TNEF (Transport
Network Encapsulated File) file ( Arrgh! ).
Thus, TNEF.pm was born. The question is, where
to put it? Should it be MIME::xxx, or Net:xxx or
File::xxx or Mail::xxx or what?
The file is already MIME encoded as Base64 and
then needs further decoding, so I'm not sure it
belongs under MIME::, and I think it has too many options
for MIME::Parser to automatically handle the functions.
Its usually going to be used on email files so maybe it should be
under Mail::...
TNEF has 'Net'work in the name so maybe it should
go under 'Net::' :) This is the least likely choice I know :)
I just need to decide where it goes, document it ( Like all
good programmers do ;-) , and upload it. Also need to
make it installable like most other modules are, I haven't done
this and am reading the perldocs on this, but some direction
(where should I be paying attention) would be helpful.
TIA,
Douglas Wilson
------------------------------
Date: Thu, 25 Nov 1999 12:01:21 +1100
From: "Andrew Bleakley" <pullen@one.net.au>
Subject: Re: Assigning an element of n associat. array to a scalar variable
Message-Id: <383c89a7@pink.one.net.au>
The solution was to add the keyword my. That is my $user_name=$in{name}.
That's for all the help and suggestions - I am re-writing it to use the
CGI.pm.
Thank you, Andrew
------------------------------
Date: Wed, 24 Nov 1999 15:40:47 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Best book on Perl
Message-Id: <383C777F.949FF0C@mail.cor.epa.gov>
Arved Sandstrom wrote:
>
> In article <383B36A6.AEABAA33@mail.cor.epa.gov>, David Cassell
> <cassell@mail.cor.epa.gov> wrote:
>
> > Do *not* buy any book with the word 'dummies', 'unleashed',
> > or 'idiot' if you really want to learn some Perl.
> >
> So "Idiots Unleashed on Perl, Vol.2: Mastering Perl CGI for Dummies, with
> foreword by Jorge Soares, author of 'Reminiscences of the Ice Blink:
> Portuguese Whaling Songs of the Labrador Sea'" would be a bad idea?
That's PERL/CGI . Lots of visitors here insist that Perl is
all caps, and that it is the same as CGI. They can't all be
wrong, can they? :-)
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: 24 Nov 1999 17:16:29 -0600
From: abigail@delanet.com (Abigail)
Subject: Re: Change password via cgi script
Message-Id: <slrn83oskf.m2v.abigail@alexandra.delanet.com>
Tim Bornholtz (tbornhol@prioritytech.com) wrote on MMCCLXXV September
MCMXCIII in <URL:news:86470D334C82EF52.53AF987B531374D2.678CD5F89EF64C8E@lp.airnews.net>:
//
// sub ChangePassword {
//
// my ($userid, $password) = @_;
So... are you doing any authentication, or can anyone change anyone's
password?
// #If Password is empty, the user will be removed!!!!!
//
// my ($PasswordFile, $NewFile, $BackupFile);
// my (@saltchars, $salt, $passwdcrypt);
//
// $PasswordFile = ".htpasswd";
// $NewFile = "$PasswordFile.tmp.$$";
// $BackupFile = "$PasswordFile.bak";
//
// # encrypt the password
// srand($$|time);
That's about the worst choice you can make. Remove the call to srand
entirely, unless you are using an old version of Perl. But those have
security holes, and shouldn't be used anyway.
// @saltchars=(a..z,A..Z,0..9,'.','/');
// $salt=$saltchars[int(rand($#saltchars+1))];
// $salt.=$saltchars[int(rand($#saltchars+1))];
Why not @saltchars instead of $#saltchars + 1?
// $passwdcrypt = crypt($password,$salt);
//
// if (! open(CURRENT, "< $PasswordFile")) {
// return "Unable to open file $PasswordFile, password was NOT changed";
// }
// if(! open(NEW, "> $NewFile")) {
// return "Unable to open file $NewFile, password was NOT changed";
At this moment, you still have an open file - with a global handle, so
it's not being closed.
// }
//
// while(<CURRENT>) {
// if (/^$userid/) {
// # If the password is blank, delete the user
// if(length($password) > 0) {
No real need for the > 0.
// print NEW "$userid:$passwdcrypt\n";
// }
// } else {
// print NEW $_;
// }
// }
//
// close(CURRENT);
// close(NEW);
//
// rename( $PasswordFile, $BackupFile);
// rename( $NewFile, $PasswordFile);
//
// return "Password successfully changed for $userid<br>\n";
Really? You're doing 2 renames without checking their return value.
How would you _know_ it was done succesfully?
// }
Abigail
--
perl -MNet::Dict -we '(Net::Dict -> new (server => "dict.org")
-> define ("foldoc", "perl")) [0] -> print'
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Wed, 24 Nov 1999 23:51:59 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: compare a string to values in an array?
Message-Id: <zS__3.118$Ua2.2308@nsw.nnrp.telstra.net>
On Wed, 24 Nov 1999 20:27:18 GMT,
Scott McMahan <scott@aravis.softbase.com> wrote:
> geetago@my-deja.com wrote:
> > Is there a way to compare a string to values in an array to see if
> > there is a match without looping through each value in the array?
>
> You could use join() and a regex, but I don't think this would
> be faster than a loop.
\begin{pedantry}
And you'd have to be absolutely sure that the combination of the thing
you join with and one or two of the elements are not going to produce
the thing you're looking for. Maybe valid for specific cases, but
hardly possible to make it valid in a general case.
And you do realise that the join loops as well? And that a loop that
terminates as soon as a match is found on average only has to examine
half of the array elements? And that a large array could generate a
monstrous string?
Just trying to say that avoiding a loop is not necessarily a good
thing.
\end{pedantry}
If all they want is to not have to write the loop themselves, and the
arrays are not monstrous enough to warrant saving time by bailing out
of the loop on a match, then probably grep is the most natural choice.
Martien
--
Martien Verbruggen |
Interactive Media Division | In the fight between you and the
Commercial Dynamics Pty. Ltd. | world, back the world - Franz Kafka
NSW, Australia |
------------------------------
Date: Wed, 24 Nov 1999 17:41:24 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: cookies
Message-Id: <383C93C4.58C0F50@mail.cor.epa.gov>
Darryl Dyck wrote:
[snip of parts I'm not complaining about]
> For cookie scripts: http://www.worldwidemart.com/scripts/cookielib.shtml
Ick. I *never* recommend anything from Matt's Script Archive.
Matt Wright wrote these things as a teenager teaching him-
self Perl. I also don't recommend programs *I* wrote when
I was teaching myself Perl.
> http://www.scriptsearch.com/pages/l9c3c15.shtml
Yuck.
> or use CGI.pm
Yes! CGI.pm does this correctly, without hideous glitches
which may bite you someday.
And one more nit to pick: please please please, place your
reply *after* the [properly-trimmed] text - it makes
threads like these so much easier to read and participate
in.
TIA,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Wed, 24 Nov 1999 23:38:57 GMT
From: jkosowan@my-deja.com
Subject: Re: dynamically created filehandles. Help!!
Message-Id: <81hsuh$j9s$1@nnrp1.deja.com>
Thanks!
-----------
J
> That's what you should do. See perlfaq5 for example:
>
> How can I use a filehandle indirectly?
>
> ...
>
> In the examples above, we assigned the filehandle to a
> scalar variable before using it. That is because only
> simple scalar variables, not expressions or subscripts
> into hashes or arrays, can be used with built-ins like
> `print', `printf', or the diamond operator.
>
> > >I have a hack that will work, namely putting $handlelist[0] into a
> >separate variable then calling the <>:
> >
> >my $temp = $handlelist[0];
> >$date_stamp = <$temp>;
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 24 Nov 1999 15:39:46 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: getlogin()
Message-Id: <383C7742.643A0984@mail.cor.epa.gov>
Paul Walker wrote:
>
> "Brett W. McCoy" wrote:
>
> > >Quick question - getlogin() is limited to returning 8 characters for a
> > >username. Is that because the OS only returns 8 characters, or just a
> > >limitation for some other reason?
> > Where does it say that it is limited 8 characters, and on what OS?
>
> The copy of "Teach yourself perl" that I'm using (since it's the closest
> thing we have to a handy reference!). Doesn't specify what OS, but we're
> using Solaris. If someone could check how many it returns under NT, that
> would be much appreciated. :-)
Just a bit of advice: the docs which come with Perl are a
much better manual. So is any book with an animal on the
cover [llama, camel, ram, ...]. I haven't heard any good
reviews of "Teach Yourself Perl [in K Days?]" so you may
want to consider using another source.
> (Must get around to adding a .sig)
Why? I find this refreshingly short and sweet. It's miles
better than the 28-lines-plus-vcard junk I so often see.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Thu, 25 Nov 1999 01:40:43 GMT
From: Eric Miller <dukat@flash.net>
Subject: Re: How to send a bitmap as part of an HTML mail message?
Message-Id: <383C9256.3DEFA415@flash.net>
Jack Alexander wrote:
>
> I'm using Windows NT4 SP6 and Perl 5.004.
> My Perl program creates an HTML formatted mail message and sends it using
> the SMTP package.
> I'd like to add a bitmap image to the mail content, but I don't know how to
> do this.
> Could someone give me a pointer where to look?
MIME::Base64 (comes with Perl)
Use that to create the message parts for the image file.
http://www.mindspring.com/~mgrand/mime.html
Find out how to create a MIME message.
------------------------------
Date: Thu, 25 Nov 1999 00:07:17 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: Learning LWP
Message-Id: <943488437.24587.0.nnrp-01.9e98c215@news.demon.co.uk>
Pradeep Kalyan <pradeep.kalyan@nwa.com> wrote:
>Could anybody suggest resources on web to learn LWP modules of PERL. I
>appreciate your reply.
I don't know if this is much (and haven't explicitly searched), but
there is an article at ;
http://www.webreference.com/perl/
(XML and Perl)
that has code to grab a file via HTTP using LWP. See the code for
xml-fetch.pl ;
http://www.webreference.com/perl/tutorial/1/xml-fetch.pl
Hope that helps a bit.
--
Alastair
work : alastair_sherringham@avid.com
home : alastair@calliope.demon.co.uk
------------------------------
Date: Wed, 24 Nov 1999 15:48:04 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: mirror : y2k compliance
Message-Id: <383C7934.90144A7D@mail.cor.epa.gov>
xtof wrote:
>
> Hi,
Howdy,
> I was told that the perl mirroring script "mirror" is not y2k compliant. But
You should figure that most freeware written by hacker-wannabe's
could have bugs in it.
> i can't find a clue about it except this post :
> http://x22.deja.com/getdoc.xp?AN=540069037&CONTEXT=943458544.687734862&hitnu
> m=0
> which seems to be a very special case to me.
Here's the key point:
if( $year < 70 ){
$year += 2000;
}
else {
$year += 1900;
}
If $year is taken out of localtime(), it will never again
be less than 70. It is the current year MINUS 1900, so
it is currently 99 and next year will be 100 . It looks
to me like this code accidentally gets a correct result
here. But if this is how the author handles a year, I
would have no confidence whatsoever in his/her ability
to handle other programming tasks properly. Lots of
luck. You'll probably need it.
> Might there be any perl 4 y2k compliance ? Then running mirror with perl 5
> should be ok !?
Perl 4 is not the problem. The bad code of the author of the
script is the problem.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Wed, 24 Nov 1999 23:15:48 GMT
From: ambassador_black@my-deja.com
Subject: mySQL + Perl - SELECT results binding
Message-Id: <81hrj1$ifc$1@nnrp1.deja.com>
Hi,
Looking for a little help with a piece of Perl. Probably very simple
for someone who knows what they are doing :)
Reading a mySQL database, prepare + execute etc (everything works
fine). I want to bind the results of the select
( @row=$sth->fetchrow_array; ) into an associative array without the
need to know the field names. The intended results would be something
like
$atable{'afield1'}
$atable{'afield2'}
$atable{'afield3'} etc.
I used the following code to try and do the job (yes .. not pretty but
I'm still new to the language!)
$count = 0;
while ($count<($sth->{NUM_OF_FIELDS}))
{
$sth->bind_col($count+1, \$atable{'$sth->{NAME}->[$count]'});
$count = $count + 1;
}
What do I get ? Nothing !! Not only does it not bind but it also seems
to destroy the use of @row[n] etc. What am I doing wrong? Can someone
help please?
And yes ... I have now found fetchrow_hashref. It could use it but this
piece of code is now "bugging" me now :)
Thanks
CB
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 24 Nov 1999 16:44:43 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: mySQL + Perl - SELECT results binding
Message-Id: <MPG.12a62656440d17e398a27c@nntp.hpl.hp.com>
In article <81hrj1$ifc$1@nnrp1.deja.com> on Wed, 24 Nov 1999 23:15:48
GMT, ambassador_black@my-deja.com <ambassador_black@my-deja.com> says...
...
> $count = 0;
> while ($count<($sth->{NUM_OF_FIELDS}))
> {
> $sth->bind_col($count+1, \$atable{'$sth->{NAME}->[$count]'});
> $count = $count + 1;
> }
The single-quotes in your hash key are suppressing interpolation of the
variable. Leave them off and things will work better. Whether that is
the whole problem with your code, I cannot say.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 24 Nov 1999 15:42:43 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Net::Ping
Message-Id: <383C77F3.89DF8297@mail.cor.epa.gov>
Bas van Gils wrote:
>
> Hello Guru's ;-)
Sorry, all you get today is me. :-)
[snip]
> bad arg length for Socket::unpack_sockaddr_in, length is 0, should be 16 at
> /usr=/lib/perl5/site_perl/i386-linux/Socket.pm line 236.
Offhand, I would say that your constants in Socket.pm are wrong.
Perhaps you need to re-install Perl.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Thu, 25 Nov 1999 00:01:34 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: New dialect of perl: xperl (or reinventing perl, or perl-izing jpython)
Message-Id: <y%__3.121$Ua2.2308@nsw.nnrp.telstra.net>
On 24 Nov 1999 11:58:56 -0600,
Abigail <abigail@delanet.com> wrote:
> Chris Durbin (durbin@cig.mot.com) wrote on MMCCLXXVI September MCMXCIII
> in <URL:news:Pine.GSO.4.21.9911241047250.19723-100000@ballad>:
> __ B) What are your thoughts on design patterns: Useful programming
> __ tools, or over-generic crutches for lazy programmers?
>
> What do you mean with "design patterns"?
I think he means those things that sell so many books. It's old
fashioned programmer common-sense given official names :)
fly-weight, factory, builder, singleton, proxy, immutable and all those
things.A They're good things IMO, but only when used discriminately.
Implementing things according to a 'pattern' just because you can is
silly. Of course, if you define enough patterns, everything falls
under that chapter.
Martien
--
Martien Verbruggen |
Interactive Media Division |
Commercial Dynamics Pty. Ltd. | What's another word for Thesaurus?
NSW, Australia |
------------------------------
Date: Thu, 25 Nov 1999 00:14:01 +0000
From: Farhad Farzaneh <ff@creative.net>
Subject: passing scalars by reference as fast as passing by value?
Message-Id: <383C7F49.FB107456@creative.net>
Hi,
I was suprised that passing a very long string (3MB) by reference is not
really faster than passing it by value. I don't understand why this is
the case. Here's the code. Any responses appreciated.
----------------------------------------
a#!/bin/perl
use Benchmark;
open F,"/var/log/kernel";
$/ = undef;
my $in = <F>;
close F;
print "length= ", length($in),"\n";
timethese(100,{'ref'=>sub { stripAppend(\$in) },
'value'=>sub { stripAppend($in)} });
sub stripAppend {
if ( ref($_[0]) ) {
# print "Value passed by reference $_[0]\n";
${$_[0]} =~ s!\n*\s*-- At \d{2}/\d{2}/\d{2} \d{2}:\d{2} \w+
adds:\s*\n*$!!s ;
} else {
# print "Value passed by value ",substr($_[0],0,40),"\n";
$_[0] =~ s!\n*\s*-- At \d{2}/\d{2}/\d{2} \d{2}:\d{2} \w+
adds:\s*\n*$!!s ;
$_[0];
}
}
----------------------------------------
and here are the results:
length= 3911239
Benchmark: timing 100 iterations of ref, value...
ref: 4 wallclock secs ( 4.46 usr + 0.00 sys = 4.46 CPU)
value: 5 wallclock secs ( 4.45 usr + 0.00 sys = 4.45 CPU)
Thanks,
Farhad
------------------------------
Date: Wed, 24 Nov 1999 16:57:34 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: passing scalars by reference as fast as passing by value?
Message-Id: <MPG.12a62955c41b3e6b98a27d@nntp.hpl.hp.com>
In article <383C7F49.FB107456@creative.net> on Thu, 25 Nov 1999 00:14:01
+0000, Farhad Farzaneh <ff@creative.net> says...
> I was suprised that passing a very long string (3MB) by reference is not
> really faster than passing it by value. I don't understand why this is
> the case.
Methinks I smell a C programmer! In C, arguments are passed by value,
so a scalar argument is copied into the memory named by the
corresponding parameter in the called function.
In Perl, arguments are passed by reference. Thus,
f($x);
sub f { $_[0] ...
$_[0] is a reference to (an alias for) $x. No copying takes place.
So whether you pass $x and use it as $_[0], or you pass \$x and use it
as ${$_[0]}, the value of $x isn't copied anywhere during the call. The
only difference in accessing it within the subroutine is one level of
indirection, which would hardly be noticed in your benchmark.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Wed, 24 Nov 1999 17:44:03 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: passing scalars by reference as fast as passing by value?
Message-Id: <383C9463.F53568BA@mail.cor.epa.gov>
Farhad Farzaneh wrote:
>
> Hi,
>
> I was suprised that passing a very long string (3MB) by reference is not
> really faster than passing it by value. I don't understand why this is
> the case. Here's the code. Any responses appreciated.
Since The Other Larry has already answered your main point,
I'll just add this:
Is this an adequate Benchmark? Think it over. You have no
control cases. You have no way of seeing based on what you
showed here whether there is a noticeable difference, or if
the time taken to do the regex totally swamped all relevant
timings.
Proper benchmarking is hard. Most benchmarks only show
anecdotal evidence, instead of substantiation.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Wed, 24 Nov 1999 15:48:58 -0800
From: "David Christensen" <dchristensen@california.com>
Subject: Re: Perl interact with Unix command
Message-Id: <383c7919$1_1@news5.newsfeeds.com>
Scootty:
Take a look at "Re: changing password in perl (chpasswd)" by Alan Curry
10/24/99.
BTW check out http://www.deja.com/home_ps.shtml -- I've found answers to
many questions this way.
--
David Christensen
dchristensen@california.com
-----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
http://www.newsfeeds.com The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including Dedicated Binaries Servers ==-----
------------------------------
Date: Wed, 24 Nov 1999 17:34:45 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: recipe 1.11 in Cookbook Where? Here documents
Message-Id: <383C9235.B1D32AB0@mail.cor.epa.gov>
Tom Kralidis wrote:
[snip]
> This works, but the problem is what I'm here documenting is flushed out
> indented, even if the code looks better and clearer. I've attached a
> simple example and output:
[snip]
> ($var = print <<' HERE_TARGET') =~ s/^\s+//gm;
> my text
> goes here
> HERE_TARGET
Where do you think the substitution takes place above?
Try this:
#!/usr/bin/perl -w
use strict;
my $var;
($var = print <<' HERE_TARGET') =~ s/^\s+//gm;
my text
goes here
HERE_TARGET
($var = <<' HERE_TARGET') =~ s/^\s+//gm;
my text
goes here
HERE_TARGET
print $var,"\n";
#############################
Here's the output:
my text
goes here
my text
goes here
The first substitution only transforms the LHS of your
parenthized expression. $var has the \s+ stripped off
the front of the lines. The print() statement still
has the spaces. Note the difference with my version.
HTH,
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Thu, 25 Nov 1999 00:04:09 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: reg expr question
Message-Id: <Z1%_3.124$Ua2.2308@nsw.nnrp.telstra.net>
On Wed, 24 Nov 1999 13:22:34 -0600,
Tom Briles <sariq@texas.net> wrote:
> I'm not sure when \z was introduced. But:
5.005
Martien
--
Martien Verbruggen |
Interactive Media Division | The world is complex; sendmail.cf
Commercial Dynamics Pty. Ltd. | reflects this.
NSW, Australia |
------------------------------
Date: Thu, 25 Nov 1999 00:36:34 +0100
From: "Samuel Kilchenmann" <skilchen@swissonline.ch>
Subject: Re: sprintf help
Message-Id: <81hsr0$1s1oi$1@fu-berlin.de>
Simon Cozens <simon@brecon.co.uk> wrote in message
news:slrn83oq4b.e4n.simon@othersideofthe.earth.li...
> Samuel Kilchenmann (comp.lang.perl.misc):
> >I know, but this is not one of the best FAQ entries. How could
> >somebody who doesn't know already what floor and ceil do, guess
> >that these functions may be used to round up or down?
>
> You wanted to round a number with sprintf. The FAQ says:
>
No he wanted to round a number _up_ and this is simply not possible
with (s)printf.
And i keep lamenting about the bad advice to use (s)printf to round
numbers:
a) the rounding behavior is system dependent ("round half to even" on
*nixish systems, "round half away from zero" on win32 systems)
b) this dependency is undocumented (and many of the *nix weenies
are not aware of this rounding mode: just take a look at a
Perl book as prominent as the Cookbook where the description
is simply wrong: see what's written on page 47.)
c) its complete overkill to use the huge machinery of a string
formatting sublanguage implemented in (s)printf for a task as
"simple" as rounding.
d) nobody knows why you need to stringify a number if you want to
round it.
e) there is already a usable round() in the perlxstut manpage and i
don't understand why this round() isn't a builtin.
------------------------------
Date: Wed, 24 Nov 1999 15:50:34 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: sprintf help
Message-Id: <383C79CA.BE661368@mail.cor.epa.gov>
Larry Rosler wrote:
>
> In article <81h4u5$1b9$1@nnrp1.deja.com> on Wed, 24 Nov 1999 16:49:10
> GMT, Samuel Kilchenmann <skilchen@swissonline.ch> says...
[snip]
> > Please, please, please: Show me, how you do round up with sprintf or
> > anything else mentioned in the FAQ ...
>
> Er, umm, you read the FAQ. The clue is even in the title. Here's how
> the FAQ begins:
>
> Does Perl have a round() function? What about ceil() and floor()? Trig
> functions?
Larry, Samuel does know that part. He's pulling an Abigail.
The key word in his sentence is 'up'. sprintf is used to
round 'off', as you know. BTW, if you check deja.com you'll
see that round-off issues are a particular hot button for
Samuel, and that he has written some Perl code on the subject.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Wed, 24 Nov 1999 15:53:54 -0800
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: sprintf help
Message-Id: <383C7A92.5935BB63@mail.cor.epa.gov>
Tom Briles wrote:
>
> Samuel Kilchenmann wrote:
[snip]
> > Please, please, please: Show me, how you do round up with sprintf or
> > anything else mentioned in the FAQ ...
>
> Ummm...
>
> perlfaq4: 'Does Perl have a round() function? What about ceil() and
> floor()? Trig functions?'
See my comment to Larry. You're missing the salient point
of Samuel's plaint. He not only knows about this, he is
concerned enough about roundoff to write his own code to do
it consistently across platforms.
David
--
David Cassell, OAO cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician
------------------------------
Date: Wed, 24 Nov 1999 16:38:32 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: sprintf help
Message-Id: <MPG.12a624e1f08f5da498a27b@nntp.hpl.hp.com>
In article <383C79CA.BE661368@mail.cor.epa.gov> on Wed, 24 Nov 1999
15:50:34 -0800, David Cassell <cassell@mail.cor.epa.gov> says...
> Larry Rosler wrote:
> >
> > In article <81h4u5$1b9$1@nnrp1.deja.com> on Wed, 24 Nov 1999 16:49:10
> > GMT, Samuel Kilchenmann <skilchen@swissonline.ch> says...
> [snip]
> > > Please, please, please: Show me, how you do round up with sprintf or
> > > anything else mentioned in the FAQ ...
> >
> > Er, umm, you read the FAQ. The clue is even in the title. Here's how
> > the FAQ begins:
> >
> > Does Perl have a round() function? What about ceil() and floor()? Trig
> > functions?
>
> Larry, Samuel does know that part. He's pulling an Abigail.
> The key word in his sentence is 'up'. sprintf is used to
> round 'off', as you know. BTW, if you check deja.com you'll
> see that round-off issues are a particular hot button for
> Samuel, and that he has written some Perl code on the subject.
Yes, I know all that. But tagging a polemic on rounding-off to a
question about rounding-up is diversive. The Subject being 'sprintf
help' is also diversionary, but no excuse.
The FAQ refers to POSIX::ceil; Alex Rhomberg showed a tiny two-liner for
ceil:
$_++ unless $_ < 0 || $_ == int;
$_ = int;
And that's all that this particular post warranted, not all this barrage
about rounding via sprintf.
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Thu, 25 Nov 1999 00:05:33 GMT
From: yanick1@sympatico.ca (Yanick Champoux)
Subject: Re: stupid user Q
Message-Id: <h3%_3.65157$up3.100958@news21.bellglobal.com>
[Posted and mailed]
In article <383b8243_1@news1.prserv.net>,
<tavi367@attglobal.net> writes:
> I key the following in at the prompt, and it works just fine.
> ------------------------------------------------------------
> walter} rmail -tw tavi@ussenterprise.com
> Subject: this is a test
> cc: tavi@earthling.net
>
> this should be in the body
> .
> ------------------------------------------------------------
> I then tried this in Perl...
> ------------------------------------------------------------
> #!/usr/bin/perl -w
>
> my $testMess = 'rmail -tw tavi@ussenterprise.com
>
> Subject: this is a test
> cc: tavi@earthling.net
>
> this should be in the body
> .';
>
> my $myResult = `$testMess`;
>
> print $myResult;
>
> #eof
> ------------------------------------------------------------
>
> The screen just sits there until I do a Cntrl-C.
>
> What obvious thing am I missing here?
Simple:
In the shell, you invoque 'rmail' with '-tw ...' as an
argument, and then you write your message on its stdin.
In the perl script, you invoque 'rmail' with everything
as an argument. The poor program, that *wants* some stdin attention,
will wait, and wait, and wait for data that will never come.
The solution?
#!/usr/bin/perl -w
open RMAIL, "| rmail -tw tavi@ussenterprise.com"
or die "Can't open rmail: $!\n";
print RMAIL <<EOT
Subject: this is a test
cc: tavi@earthling.net
this should be in the body
EOT
__END__
Joy,
Yanick
--
"Maybe we're a Bliss of another kind..." -Tori Amos
------------------------------
Date: Thu, 25 Nov 1999 00:38:32 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Test for eval() without using eval() ??
Message-Id: <cy%_3.5$Ye2.415@nsw.nnrp.telstra.net>
On Wed, 24 Nov 1999 12:24:03 -0600,
Matt Kruse <mkruse@rens.com> wrote:
> Abigail <abigail@delanet.com> wrote
> > Simon Cozens (simon@brecon.co.uk) wrote
> > __ >I've found that you cannot depend on CGI.pm being installed on a
> target web
> > __ >server.
> > __ It's part of the core now, and has been for quite some time, I'm led to
> > __ believe.
> > You don't have to believe. Just download Perl and check for yourself.
>
> That does _NOT_ mean that everyone has it installed. Not everyone is using
> the latest build. Hell, there are even ISP's who still link /usr/bin/perl to
> Perl4.
From one of your other posts in this thread:
> In case you did actually miss my point... My goal is to write the
> script so that it runs on any OS, any web server, any version of
> perl 5, and without using any modules that may or may not be on the
> machine.
CGI.pm is part of perl5. I do not believe that asking people to have
at least the _standard_ version of Perl available is too much to ask.
If you want to cater for every possible perversion of the standard
installation out there, that is your choice. We are merely pointing
out that we do not think it is a wise choice.
> It sounds like some of you have never written scripts to be used by the
> general population. It would be nice if everyone had the latest version of
> Perl installed with all the modules that are now part of the core, but
> that's just not the case. Then factor in that you want to support scripts
> running on Win9x, NT, and Mac without multiple versions. You either require
> lots of things and limit your audience, or write scripts to be as general as
> possible to work for the greatest number of people.
>
> I find the second option to be more interesting, more challenging, and more
> rewarding.
Fair enough. Most of us find it no more than normal that a standard
version of perl is available. You tend to allow any change to the core
functionality of perl. You'll have a hard job keeping up with all
possible permutations of installations out there, but that's what you
seem to want. But now the task of reinventing all the wheels, and
checking every single thing is your responsibility. And that means
everything. Someone hacking the code to disable eval, might have done
other nasties to the code, wittingly, or unwittingly. Are you going to
try to capture all that too? Are you going to wrap each open, close,
seek, stat, unlink, reanme and -X operator in evals (or anything
else).
The message you should be getting from all this is that most of us
believe that you've embarked on a long, tedious, bug-prone journey,
which can be easily avoided by asking people to have at least a
_standard_ version of perl available. If they have a sysadmin who
doesn't want that, then they should probably fire them, or go to
another ISP.
But I really expect that the original question was not the right one.
I can't actually see any admin hacking the perl code to get rid of
eval. I suspect the problem is something else. And you should probably
get your user to get that information from the local admin.
Martien
--
Martien Verbruggen |
Interactive Media Division | In a world without fences, who needs
Commercial Dynamics Pty. Ltd. | Gates?
NSW, Australia |
------------------------------
Date: Wed, 24 Nov 1999 23:21:57 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: Threads and memory leaks
Message-Id: <pq__3.6192$Pj3.13833@news.rdc1.ct.home.com>
Martin H. Sluka <martin@sluka.de> wrote:
> As it came to testing recently, we discovered that these applications
> all seemed to have the same memory leak, consuming some MBs per day,
> growing steadily.
> At first I feared that the problem would be hard to track, as each of
> my scripts uses more than a dozen of modules; however, one thing they
> had in common was, that they used threads and especially that they
> spawned a new one each 30 seconds (for handling a TCP connection).
Yep. Threads leak, and trigger an odd refcounting problem that leaks even
more. (It's possible to trigger it without threads, but it takes an awful
lot of work)
> I am of course aware that threads are still concerned a beta feature,
s/beta/experimental/
> and searching on <http://www.deja.com/>, I then indeed found some ar-
> ticles that state there is indeed a memory leak in conjunction with
> creating them. However, I really can't believe that if it's _that_
> obvious, it wouldn't have been fixed long since.
Why? The current thread code's not gotten that much attention. There are a
few bugs with it that are much nastier than this
> So am I getting something completely wrong here?
Nope.
> As I'm afraid I don't, is there any workaround for this kind of prob-
> lem apart from redisigning my applications not to periodically create
> new threads?
Nope.
> Or can I rely on this bug being fixed with the next release?
> (And when is this supposed to be?)
Don't count on the current thread model living much longer. It's likely to
die soon, possibly as early as the 5.6 release.
Dan
------------------------------
Date: Thu, 25 Nov 1999 01:11:32 GMT
From: sumengen@my-deja.com
Subject: Using C functions in PErl
Message-Id: <81i2c2$muq$1@nnrp1.deja.com>
Could anybody give me some pointers about this topic.
I have my C functions written already. How do I call them inside the
perl program.
What is the best (and simplest) way to do this,
Thanks,
Baris Sumengen.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 25 Nov 1999 00:48:41 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: using regex to extract data
Message-Id: <JH%_3.7$Ye2.415@nsw.nnrp.telstra.net>
On 24 Nov 1999 07:32:56 -0600,
Abigail <abigail@delanet.com> wrote:
> Martien Verbruggen (mgjv@comdyn.com.au) wrote on MMCCLXXVI September
> MCMXCIII in <URL:news:O5L_3.529$6Y1.6324@nsw.nnrp.telstra.net>:
> ~~
> ~~ You could use the flipflop operator:
> ~~
> ~~ my @d;
> ~~ while(<DATA>)
> ~~ {
> ~~ next unless (/^Date and Time: Thu Oct 14 08:12:00 1999/ .. 0);
> ~~ push @d, (/^Description\s+:\s(.+)$/);
> ~~ }
>
> Yeah, but that's suboptimal because you keep doing the test, even after
> it became false.
Yes, but the test I'm doing is basically equivalent to a
if (0) { #change flipflop status }
which should be reasonably fast :)
Martien
--
Martien Verbruggen |
Interactive Media Division | We are born naked, wet and hungry.
Commercial Dynamics Pty. Ltd. | Then things get worse.
NSW, Australia |
------------------------------
Date: Wed, 24 Nov 1999 23:45:59 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: variable scoping
Message-Id: <XM__3.116$Ua2.2308@nsw.nnrp.telstra.net>
On Wed, 24 Nov 1999 12:38:25 -0800,
Helmut Messerer <helmut@cancon.com> wrote:
> Tad McClellan wrote:
> > Using Symbolic References is a very very bad idea, you know.
> > They are all _global_ variables.
> >
> > Global variables are bad.
> sorry about the confusion, let me try again...
> I played around a little more with the following results:
>
> [--1--]
> #!/usr/bin/perl -w
> {
> $i1='';
> my $i="i1";
> $$i='TEST';
> print "i1=".$i1."/".${i1}."/".${'i1'}."/".${"i1"}."\n";
> }
>
> produces
> i1=TEST/TEST/TEST/TEST
>
> [--2--]
> #!/usr/bin/perl -w
> {
> my $i1='';
> my $i="i1";
> $$i='TEST';
> print "i1=".$i1."/".${i1}."/".${'i1'}."/".${"i1"}."\n";
> }
>
> that's how the whole thing got started, I had to remove the 'my' to get
> the code to work...
> I now tested it with 'local' instead of 'my' and this seems to work as
> well. What I want to know though is why this is, so that I can avoid it
> in the future.
Lexically scoped variables are not accessible with a symbolic
reference.
Listen to Tad: Do not use symbolic references. If you're not clear
about the difference between my and local (and why are you not using
the strict pragma?) you shouldn't consider playing with symbolic
references.
# perldoc perlref
You should be using real references instead. Or if you must use
'strings' as variable names, use a hash to store them.
You might also be interested in
# perldoc -f my
# perldoc -f local
# perldoc -q 'local.*my' | grep =head
=head1 Found in /usr/local/lib/perl5/5.00502/pod/perlfaq7.pod
=head2 What's the difference between dynamic and lexical (static)
scoping? Between local() and my()?
Martien
--
Martien Verbruggen |
Interactive Media Division |
Commercial Dynamics Pty. Ltd. | "Mr Kaplan. Paging Mr Kaplan..."
NSW, Australia |
------------------------------
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 1484
**************************************