[26459] in Perl-Users-Digest
Perl-Users Digest, Issue: 8628 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 3 18:05:38 2005
Date: Thu, 3 Nov 2005 15:05:05 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 3 Nov 2005 Volume: 10 Number: 8628
Today's topics:
Re: FAQ 3.24 Can I write useful Perl programs on the co <1usa@llenroc.ude.invalid>
FAQ 9.19 How do I return the user's mail address? <comdog@pair.com>
Re: s///x <notvalid@email.com>
Re: s///x <rvtol+news@isolution.nl>
Re: s///x <someone@example.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 03 Nov 2005 22:59:53 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: FAQ 3.24 Can I write useful Perl programs on the command line?
Message-Id: <Xns9703B717A32F6asu1cornelledu@127.0.0.1>
John Bokma <john@castleamber.com> wrote in
news:Xns9703AB74F4C91castleamber@130.133.1.4:
> "A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote:
>
>> D:\> perl -e "print qq{my var$_;\n} for (1 .. 1_000_000)" > payme.pl
>
> Now why did you do that... :-( (j/k, I blame Ben Wa, and will tell so to
> his provider in a not nice way)
I had plonked him right after seeing his reply to the Emacs modules
message so I did not realize what he had done after that. I noticed it
when I checked the group later on my office machine.
I beg forgiveness, and I'll get in touch with Adelphia as well.
Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)
comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
------------------------------
Date: Thu, 3 Nov 2005 23:03:00 +0000 (UTC)
From: PerlFAQ Server <comdog@pair.com>
Subject: FAQ 9.19 How do I return the user's mail address?
Message-Id: <dke4v4$qpe$1@reader2.panix.com>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.
--------------------------------------------------------------------
9.19: How do I return the user's mail address?
On systems that support getpwuid, the $< variable, and the Sys::Hostname
module (which is part of the standard perl distribution), you can
probably try using something like this:
use Sys::Hostname;
$address = sprintf('%s@%s', scalar getpwuid($<), hostname);
Company policies on mail address can mean that this generates addresses
that the company's mail system will not accept, so you should ask for
users' mail addresses when this matters. Furthermore, not all systems on
which Perl runs are so forthcoming with this information as is Unix.
The Mail::Util module from CPAN (part of the MailTools package) provides
a mailaddress() function that tries to guess the mail address of the
user. It makes a more intelligent guess than the code above, using
information given when the module was installed, but it could still be
incorrect. Again, the best way is often just to ask the user.
--------------------------------------------------------------------
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-2002 Tom Christiansen and Nathan
Torkington, and other contributors as noted. All rights
reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
------------------------------
Date: Thu, 03 Nov 2005 20:32:35 GMT
From: Ala Qumsieh <notvalid@email.com>
Subject: Re: s///x
Message-Id: <Dtuaf.9142$q%.3486@newssvr12.news.prodigy.com>
Dr.Ruud wrote:
> OK. I am still trying to think up why it was chosen to not affect the
> replacement part. I have no doubt that there is a simple explanation why
> it is not feasible, but I just can't think it up (tired of working some
> very long days, but very satisfied with the results and very happy with
> Perl).
I don't think the reason is that it's not feasible, but rather that it's
not intuitive. Regular expressions can be messy, so having an option to
add comments, and 'beautify' them is a good idea. The replacement part
of an s/// is simply a string, and won't really benefit much from such
an option.
Moreover, you CAN add comments in the replacement part if you want to.
You just need to modify your code slightly, and use the /e modifier.
From your example:
$_ = "abc 123 def 123 ghi";
$x = s/ # Replace
1 # ONE
2 # TWO
3 # THREE
/ # by
4 . # FOUR
5 . # FIVE
6 # SIX
/gsex; # global sex
But, I think this can be less readable than the alternative if the
replacement part is a simple string.
--Ala
------------------------------
Date: Thu, 3 Nov 2005 22:42:59 +0100
From: "Dr.Ruud" <rvtol+news@isolution.nl>
Subject: Re: s///x
Message-Id: <dke4nr.100.1@news.isolution.nl>
Ala Qumsieh:
> Regular expressions can be messy, so having an
> option to add comments, and 'beautify' them is a good idea. The
> replacement part of an s/// is simply a string, and won't really
> benefit much from such an option.
I met this with some rather lengthy strings of \x{####} in both the
search and the replacement part.
> Moreover, you CAN add comments in the replacement part if you want to.
> You just need to modify your code slightly, and use the /e modifier.
> From your example:
>
> $_ = "abc 123 def 123 ghi";
>
> $x = s/ # Replace
> 1 # ONE
> 2 # TWO
> 3 # THREE
> / # by
> 4 . # FOUR
> 5 . # FIVE
> 6 # SIX
> /gsex; # global sex
Thanks, that looks workable. Will the o-modifier make up for any lost
performance? I'll test it.
> But, I think this can be less readable than the alternative if the
> replacement part is a simple string.
Yes, but in my case it often isn't. The algorithm needs to be checked by
linguists. They rather read the Unicode character names and such, so I
like to use the \N{name} format, but (without that e-modifier) that
would give very lengthy lines. I was going to store everything in
variables, but I'll test this format too.
Short example (without backreferences):
$x = s/(?<=\x{0020})
\x{0111}\x{0123}\x{0222}\x{02AA}\x{0123}\x{0223}\x{0221}\x{0241}\x{0247}
\x{02E2}\x{0223}(?=\x{0020})
/\x{0117}\x{000D}\x{0223}\x{02AA}\x{000D}\x{0223}\x{0221}\x{0221}\x{0223
}/gmsx;
(actual codes munged)
--
Affijn, Ruud
"Gewoon is een tijger."
------------------------------
Date: Thu, 03 Nov 2005 22:14:31 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: s///x
Message-Id: <bZvaf.101611$Io.43343@clgrps13>
Dr.Ruud wrote:
> Ala Qumsieh:
>
>>Moreover, you CAN add comments in the replacement part if you want to.
>>You just need to modify your code slightly, and use the /e modifier.
>> From your example:
>>
>> $_ = "abc 123 def 123 ghi";
>>
>> $x = s/ # Replace
>> 1 # ONE
>> 2 # TWO
>> 3 # THREE
>> / # by
>> 4 . # FOUR
>> 5 . # FIVE
>> 6 # SIX
>> /gsex; # global sex
>
> Thanks, that looks workable. Will the o-modifier make up for any lost
> performance?
Probably not.
perldoc -q /o
John
--
use Perl;
program
fulfillment
------------------------------
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 8628
***************************************