[25053] in Perl-Users-Digest
Perl-Users Digest, Issue: 7303 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Oct 25 14:10:42 2004
Date: Mon, 25 Oct 2004 11:10:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 25 Oct 2004 Volume: 10 Number: 7303
Today's topics:
list vs scalar context for localtime? <scobloke2@infotop.co.uk>
Re: list vs scalar context for localtime? <pinyaj@rpi.edu>
Re: list vs scalar context for localtime? <tadmc@augustmail.com>
Re: list vs scalar context for localtime? <perl@my-header.org>
Re: MAIL recommendation <cwilbur@mithril.chromatico.net>
Re: MAIL recommendation <nospam@nospam.com>
Re: MAIL recommendation <sbryce@scottbryce.com>
Re: MAIL recommendation <nospam@nospam.com>
Re: measure time (hopefully in milliseconds) (dan baker)
Re: open-perl-ide qustion <nospam@nospam.com>
Re: Optimize Perl.. ctcgag@hotmail.com
Re: perl optimazation guide/book ctcgag@hotmail.com
Re: Practical Extraction Recording Language <1usa@llenroc.ude.invalid>
Re: Practical Extraction Recording Language <bik.mido@tiscalinet.it>
Re: Problem with useless use error message <1usa@llenroc.ude.invalid>
Re: Regular expressions to find the presence of special <jurgenex@hotmail.com>
Re: What's the seed? ctcgag@hotmail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 25 Oct 2004 14:48:12 +0000 (UTC)
From: Ian Wilson <scobloke2@infotop.co.uk>
Subject: list vs scalar context for localtime?
Message-Id: <clj3nc$c7c$1@hercules.btinternet.com>
Which X and Y in `perldoc -X Y` will explain why we need parentheses
around localtime in
#!/usr/bin/perl
use strict;
use warnings;
my ($d,$m,$y) = (localtime)[3,4,5];
printf (" Today is %02d/%02d/%04d\n", $d, $m+1, $y+1900);
AFAIK Perl uses parentheses for list context and for precedence, I think
they are used here to force a list context?
In the assignment statement, since the LHS is a list, I'd have thought
it would supply a list context to the RHS anyway.
Also, it superficially appears to me that the [3,4,5] ought to be a hint
that the thing to the left ought not to be interpreted in a scalar context.
I've read perldoc -f localtime and perused my blue Camel.
Clearly I'm missing something fundamental :-(
------------------------------
Date: Mon, 25 Oct 2004 11:59:50 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
Subject: Re: list vs scalar context for localtime?
Message-Id: <Pine.SOL.3.96.1041025115619.23848A-100000@vcmr-86.server.rpi.edu>
On Mon, 25 Oct 2004, Ian Wilson wrote:
>Which X and Y in `perldoc -X Y` will explain why we need parentheses
>around localtime in
>
> #!/usr/bin/perl
> use strict;
> use warnings;
> my ($d,$m,$y) = (localtime)[3,4,5];
> printf (" Today is %02d/%02d/%04d\n", $d, $m+1, $y+1900);
>
>AFAIK Perl uses parentheses for list context and for precedence, I think
>they are used here to force a list context?
The () are necessary for the [3,4,5] to be a subscript of a list.
Consider the function localtime(), which takes an optional argument, the
number of seconds for which to calculate the date. If you did:
my @stuff = localtime [3,4,5];
you would be passing an array reference to localtime(), and you'd get
unexpected values.
The () in (localtime)[3,4,5] don't *make* a list, they *contain* the list.
I would guess perldata would discuss this issue.
--
Jeff "japhy" Pinyan % How can we ever be the sold short or
RPI Acacia Brother #734 % the cheated, we who for every service
Senior Dean, Fall 2004 % have long ago been overpaid?
RPI Corporation Secretary %
http://japhy.perlmonk.org/ % -- Meister Eckhart
------------------------------
Date: Mon, 25 Oct 2004 11:04:24 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: list vs scalar context for localtime?
Message-Id: <slrncnq908.k4d.tadmc@magna.augustmail.com>
Ian Wilson <scobloke2@infotop.co.uk> wrote:
> Subject: list vs scalar context for localtime?
Your question does not have anything to do with context.
> Which X and Y in `perldoc -X Y` will explain why we need parentheses
> around localtime in
> my ($d,$m,$y) = (localtime)[3,4,5];
perldoc perldata
See the "Slices" section.
> AFAIK Perl uses parentheses for list context and for precedence, I think
> they are used here to force a list context?
No, because...
> In the assignment statement, since the LHS is a list, I'd have thought
> it would supply a list context to the RHS anyway.
It is the assignment operator that supplies the context for its RHS.
> I've read perldoc -f localtime and perused my blue Camel.
Yes, because a list slice can be used with _any_ list, not just
the list returned by localtime.
> Clearly I'm missing something fundamental :-(
"list slices" are the fundamental that you are missing.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 25 Oct 2004 18:11:00 +0200
From: Matija Papec <perl@my-header.org>
Subject: Re: list vs scalar context for localtime?
Message-Id: <pm8qn05me7dn9mt0rjqsl1acpd37vbqp45@4ax.com>
X-Ftn-To: Ian Wilson
Ian Wilson <scobloke2@infotop.co.uk> wrote:
>Which X and Y in `perldoc -X Y` will explain why we need parentheses
>around localtime in
>
> #!/usr/bin/perl
> use strict;
> use warnings;
> my ($d,$m,$y) = (localtime)[3,4,5];
> printf (" Today is %02d/%02d/%04d\n", $d, $m+1, $y+1900);
>
>AFAIK Perl uses parentheses for list context and for precedence, I think
>they are used here to force a list context?
>
>In the assignment statement, since the LHS is a list, I'd have thought
>it would supply a list context to the RHS anyway.
>
>Also, it superficially appears to me that the [3,4,5] ought to be a hint
>that the thing to the left ought not to be interpreted in a scalar context.
No, left side clearly tells to localtime that it wants list context. (see
perldoc -f wantarray) You need braces around localtime so you can pick
particular list elements => 3,4,5
You can also write this like
my (undef, undef, undef, $d,$m,$y) = localtime;
and you'll be again ignoring everything but 3,4, and 5th element from list.
--
Matija
------------------------------
Date: Mon, 25 Oct 2004 16:16:33 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: MAIL recommendation
Message-Id: <87acuan5na.fsf@mithril.chromatico.net>
>>>>> "dk" == daniel kaplan <nospam@nospam.com> writes:
>> Have you *still* not read the Posting Guidelines?
dk> charlton,
dk> rather than jump on the bandwagon, re-read my post, but here
dk> it is again...read what i am asking. i did not ask HOW DO YOU
dk> SEND MAIL....i already am....what i asked for was
dk> recommendations as to what people felt were BETTER email
dk> handling module ones...if this isn;t the place to ask for
dk> recommendations (as i did when searhcing for a decent IDE)
dk> then just say that.
This isn't the place to ask questions that are answered in the FAQ.
This is one of the places where FAQ questions are discussed and
improved, and so the questions in the FAQ are pretty much the same as
you'd get if you asked the same question here. That's why you get
pointed to the FAQ every time you ask a question that is in the FAQ:
we've already put effort into answering that question correctly, and
you're ignoring that effort.
dk> but really now you're just being nasty to be nasty it seems...
No, I'm pointing out just how fucking rude you're being, and how it's
hurting you in the long run.
We have posting guidelines for a reason. They explain the proper
standards of behavior in comp.lang.perl.misc. They explain how to get
help. Ignoring them (have you even read them yet?) is essentially
saying, "I don't care what you all think, you're going to do things my
way or not at all."
We have a FAQ for a reason. If you have a question, you should check
to see if it's in the FAQ, because we've already put effort into
answering it. It is extremely unlikely that you'll get a different
answer in clpm than you get in the FAQ, because clpm is made up
largely of the people who *wrote* the FAQ. By not even consulting the
FAQ before you ask yet another question in it, you're ignoring the
effort that went into creating it and demanding special treatment.
Finally, here's a clue. You've annoyed enough of the knowledgeable
regulars in this group by doing inane things like *repeatedly* asking
FAQs that, if you ever *do* have a real problem, you'll have burned up
all your tolerance. You've already burned up a good bit of it.
If you consider pointing this out "nasty," well, good luck. Two or
three more weeks of this and the only ones not being "nasty" to you
will be idiots and trolls. Pointing this out is not "nasty," it is
charitable -- but I suppose there are none so blind as those who will
not see.
Charlton
--
cwilbur at chromatico dot net
cwilbur at mac dot com
------------------------------
Date: Mon, 25 Oct 2004 12:46:46 -0400
From: "daniel kaplan" <nospam@nospam.com>
Subject: Re: MAIL recommendation
Message-Id: <1098722861.80955@nntp.acecape.com>
> This isn't the place to ask questions that are answered in the FAQ.
> This is one of the places where FAQ questions are discussed and
well then how about this charlton, are you telling me that asking people's
opinions about which module they PREFER is a faq question?
------------------------------
Date: Mon, 25 Oct 2004 11:33:53 -0600
From: Scott Bryce <sbryce@scottbryce.com>
Subject: Re: MAIL recommendation
Message-Id: <10nqe7vr9l6a89@corp.supernews.com>
daniel kaplan wrote:
> well then how about this charlton, are you telling me that asking people's
> opinions about which module they PREFER is a faq question?
Had you bothered to read the FAQ, you would have found this answer:
<quoting from the FAQ>
This answer is extracted directly from the MIME::Lite documentation.
Create a multipart message (i.e., one with attachments).
use MIME::Lite;
### Create a new multipart message:
$msg = MIME::Lite->new(
From =>'me@myhost.com',
To =>'you@yourhost.com',
Cc =>'some@other.com, some@more.com',
Subject =>'A message with 2 parts...',
Type =>'multipart/mixed'
);
### Add parts (each "attach" has same arguments as "new"):
$msg->attach(Type =>'TEXT',
Data =>"Here's the GIF file you wanted"
);
$msg->attach(Type =>'image/gif',
Path =>'aaa000123.gif',
Filename =>'logo.gif'
);
$text = $msg->as_string;
MIME::Lite also includes a method for sending these things.
$msg->send;
This defaults to using sendmail but can be customized to use SMTP via
the Net::SMTP manpage.
<End of quote>
You won't get a better answer than that here. We aren't here to read the
FAQ to you. We assume that if you can code, you can also read.
------------------------------
Date: Mon, 25 Oct 2004 13:53:55 -0400
From: "daniel kaplan" <nospam@nospam.com>
Subject: Re: MAIL recommendation
Message-Id: <1098726891.330365@nntp.acecape.com>
> Had you bothered to read the FAQ, you would have found this answer:
> This answer is extracted directly from the MIME::Lite documentation.
> Create a multipart message (i.e., one with attachments).
wow, this is almost ridiculous.
there are many different modules i can use to take care of email (sending
and receiving), correct?
if the answer is NO, please say so.
but since i am pretty sure that the answer is YES, i am trying to see
people's preferences, that's all...i ask this now, before i get to heavy
into one particualr module, because since i am new to perl, i jumped into
Date::Manip, which i found out later was sort of lumbersome, especially for
the minimal date tasks i was doing. so had i researched it better BEFORE
hand, i would have picked a different module.
i can't type or spell well, but don;t tell me that i didn't make it clear
what i was looking for....
------------------------------
Date: 25 Oct 2004 07:58:04 -0700
From: botfood@yahoo.com (dan baker)
Subject: Re: measure time (hopefully in milliseconds)
Message-Id: <13685ef8.0410250658.1c42bf3e@posting.google.com>
"Takashi Yamauchi" <takashiyyy@yahoo.com> wrote in message news:<cli018$674$1@news.tamu.edu>...
> I am a novice perl learner. If this question is one of FAQ, please direct
> me to the web site where I can get an answer.
> ...
> Could anyone show me how to measure time in miliseconds (or better than
> seconds)?
> ------------------------------
in your local perl documentation, look up the module Time::HiRes
a good place to start with questions is your locally installed FAQs,
then search this newsgroup for old postings, maybe check CPAN.org then
post a question.
d
------------------------------
Date: Mon, 25 Oct 2004 10:46:25 -0400
From: "daniel kaplan" <nospam@nospam.com>
Subject: Re: open-perl-ide qustion
Message-Id: <1098715641.574393@nntp.acecape.com>
> I have been using Open-Perl-IDE for 2 1/2 years and am very happy with
> it. I have created 2 very large enterprise pTk apps with it (over
> 800,000 lines) and it has fit the bill. I highly recommend it, but
> this is my personal view - an IDE is a very much a personal decision.
> Go try them all and see which works best for the way you work.
this one fits the bill....although it could use one very simple
feature...Upload to Server
>>every option under the sun and always come back to Open-Perl-IDE or vi.
vi? is this another one i can try?
thanks ahead
------------------------------
Date: 25 Oct 2004 17:11:00 GMT
From: ctcgag@hotmail.com
Subject: Re: Optimize Perl..
Message-Id: <20041025131100.337$da@newsreader.com>
Matija Papec <perl@my-header.org> wrote:
> http://www-106.ibm.com/developerworks/library/l-optperl.html?ca=dgr-lnxw0
> 6OptPerl
>
> Usually they have good articles but this one isn't nearly there, and I
> doubt that author is just making jokes in it?
I fully expect that, in the next few days, I will be forwarded this article
by someone in senior management, who will demand to know how many of these
"best practises" I implement.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 25 Oct 2004 17:14:59 GMT
From: ctcgag@hotmail.com
Subject: Re: perl optimazation guide/book
Message-Id: <20041025131459.476$C8@newsreader.com>
bulk88@hotmail.com (buildmorelines) wrote:
> Are there any books or guide to Perl function and operator and syntax
> (not algorithem) optimzation? like a guide that says what function or
> way of doing something is faster than another.
I rather suspect that such things exists, but I rather doubt they are
worthwhile.
> Two of them I discovered were scalar(@array) is faster than $#array,
> and pop(@array) is faster than $array[-1]. Are there any more of those
> kinds of optimzations?
Well, in neither case do the alternatives you present do the same thing.
If you don't care whether you get the right answer, you can get
extreme optimization by replacing all of your code with:
print rand();
exit;
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 25 Oct 2004 13:37:39 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Practical Extraction Recording Language
Message-Id: <Xns958D61F0214F7asu1cornelledu@132.236.56.8>
"Peter Wyzl" <wyzelli@yahoo.com> wrote in
news:S_5fd.38800$5O5.8193@news-server.bigpond.net.au:
> "A. Sinan Unur" <usa1@llenroc.ude.invalid> wrote in message
> news:Xns958CE837A2D0asu1cornelledu@132.236.56.8...
>> Just for laughs:
>>
>> http://www.unc.edu/~husted/Work/PerlReference.htm#anchor8
>
> Since the tutorial has been critiqued widely, perhaps some of her code
> too...
Why not try it yourself. At each line, ask if ther is a better way to do
it.
> #Generate a random number
> print "Enter a seed number: ";
> $seed = <STDIN>;
> chomp $seed;
> srand($seed ^ time);
Since the user cannot reproduce the same password even when she knows the
seed, what is the use of asking the user to enter the seed. Either the
seed should be used unmodified (as a forgotten password retrieval
mechanism, maybe?) or the default seed should be used. See Abigail's
responses in http://tinyurl.com/6npm6.
So, the script needs to start with:
use strict;
use warnings;
> #Set up a list of consonants and vowels
> @consonants= split(/ */, "bcdfghjklmnpqrstvwxyz");
There is no point to this, really.
my @consonants= qw'b c d f g h j k l m n p q r s t v w x y z';
On the other hand, if one just has to use split, say what you mean:
my @consonants= split //, 'bcdfghjklmnpqrstvwxyz';
> @vowels= split (/ */, "\@310u");
Same deal.
my @vowels= qw'@ 3 1 0 u';
> #Loop through the generation of a password
> for ($i=1; $i<=4; $i +=1) {
> print $consonants[int(rand(21))],
> $vowels[int(rand(5))];
> }
Since the loop index is not used at all, this can be written as:
print $consonants[int(rand(21))], $vowels[int(rand(5))] for (1 .. 4);
However, 'z' will never be picked in this scheme.
Sinan.
------------------------------
Date: Mon, 25 Oct 2004 16:36:16 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Practical Extraction Recording Language
Message-Id: <fsrpn09mkqoq5vtms565u2a4f8c06r6rpe@4ax.com>
On 24 Oct 2004 11:00:52 -0700, el_roachmeister@yahoo.com wrote:
>As someone who has been programming in perl for several years, I found
>the site useful. It was simple and well organized and I picked up
>several new tips to add to my "arsenal". Yeah, it may not be 100%
>accurate, but perl is about getting the job done, not about splitting
>hairs.
Huh?!? You're joking, aren't you?
Tell the truth: she's your girlfriend... eh?
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 25 Oct 2004 13:18:35 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Problem with useless use error message
Message-Id: <Xns958D5EB486ACFasu1cornelledu@132.236.56.8>
djcameron60616@yahoo.com (delfuego) wrote in
news:6b28e43f.0410242225.47d226f2@posting.google.com:
> Tad McClellan <tadmc@augustmail.com> wrote in message
> news:<slrncnodsa.g1i.tadmc@magna.augustmail.com>...
>> delfuego <djcameron60616@yahoo.com> wrote:
>>
>> > I am trying to write a simple Perl program to do the following:
>> > Open /etc/passwd for read, create an output file in cwd for append,
>> > cut the fields 1,3-4,6 from /etc/passwd and redirect that output to
>> > the output file password, then close the two file handles for the
>> > input and output files.
>>
>>
>> Here is a complete Perl program that does that:
>>
>> perl -lne 'print join ":", (split /:/)[0,2,3,5]' /etc/passwd
>> >>password
> Tad -- thanks! It worked.
> I still need to learn a lot more Perl and scour your brain as well as
> Sinan's in the futuer for answers probably.
To get more information about command line options, type
perl -h
For detailed information, consult perldoc perlrun.
Sinan.
------------------------------
Date: Mon, 25 Oct 2004 14:24:13 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Regular expressions to find the presence of special characters
Message-Id: <h08fd.1807$C_6.504@trnddc04>
[Please do not top post!]
[Tried to rearrange text into chronological sequence]
[Please do not blindly fullquote but trim the quotation to the amount needed
to provide context]
Vertica Garg wrote:
> "Jürgen Exner" <jurgenex@hotmail.com> wrote in message
>> Vertica Garg wrote:
>>> I am trying to validate that the string contains characters [A-Z a-z
>>> 0-9 / . -] only. If there is any other charcter in the string, I
>>> have to print the error message. No special characters like *, &, $
>>> etc should be allowed.
>>
>> Ask the negated question: You got an error condition if your string
>> contain any character _not_ in that class.
>>
>> [^A-Z a-z0-9 / . -]
>
> But unfortunately, this does not work in all the cases.
> e.g., if
>
> $code="@KK.L";
What does the array @KK contain?
Or did you mean
$code='@KK.L';
or
$code="\@KK.L";
jue
------------------------------
Date: 25 Oct 2004 17:34:59 GMT
From: ctcgag@hotmail.com
Subject: Re: What's the seed?
Message-Id: <20041025133459.864$m1@newsreader.com>
Derek Fountain <nospam@example.com> wrote:
> In any recent version of Perl, the seed for the random number generator
> is set at the first time rand() is called. Can I find out what that seed
> is so I can subsequently reproduce the random sequence?
>
> At present I'm setting my own seed using "time ^ ($$ + ($$ << 15))", but
> my program is being run repeatedly over and over, and only takes a
> fraction of a second to do its job. That means time is often the same for
> several runs, and $$ tends to go up in small, sometimes single, steps. I
> have my suspicions about the quality of my seed!
I think this would be generally adequate, but you don't say what you are
using this for. If you are concerned, and you think that perl's default
srand is better than what you are doing, I would do something like this:
my $x=int rand(~0); #Cause srand to be invoked "naturally"
srand($x);
warn "using $x as seed"; #record seed
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 7303
***************************************