[26412] in Perl-Users-Digest
Perl-Users Digest, Issue: 8583 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 28 11:05:30 2005
Date: Fri, 28 Oct 2005 08:05:05 -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 Fri, 28 Oct 2005 Volume: 10 Number: 8583
Today's topics:
Re: FAQ 7.15 How do I create a static variable? <thundergnat@hotmail.com>
Re: Moving data structure around better than globals? (Anno Siegel)
Re: search & relplace question (Anno Siegel)
Re: search & relplace question <someone@example.com>
Re: search & relplace question (Anno Siegel)
Re: Timelocal input, post good Date filters (from - to) (Anno Siegel)
Re: Timelocal input, post good Date filters (from - to) <1usa@llenroc.ude.invalid>
Re: Unintuitive expression evaluation (Anno Siegel)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 28 Oct 2005 08:52:20 -0400
From: thundergnat <thundergnat@hotmail.com>
Subject: Re: FAQ 7.15 How do I create a static variable?
Message-Id: <IvadnQrucb2Zgv_eRVn-hg@rcn.net>
PerlFAQ Server wrote:
> You can fake a static variable by using a lexical variable which goes of
> scope.
Extremely minor error. I think that should be:
variable which goes out of scope.
^^^
------------------------------
Date: 28 Oct 2005 13:35:15 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Moving data structure around better than globals?
Message-Id: <djt9ej$nrg$1@mamenchi.zrz.TU-Berlin.DE>
Tad McClellan <tadmc@augustmail.com> wrote in comp.lang.perl.misc:
> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> > I have accepted that package globals as well as file scoped lexicals
> > should be avoided if possible,
>
>
> I'd say "if practicable" rather than "if possible".
>
> It is the _abuse_ of global variables that is often warned against,
> they do have their place.
>
> My personal red flag is when there are "many" (over 10?) globals.
It isn't only the number of globals but also the complexity (or sheer
size) of the code that potentially uses (and changes) them. In a big
file a single file global can be one too many. It's the number of
variables times code size that should raise the red flag.
> When I see that developing, I recast them to a single global hash.
I must admit I wonder what that really gains. The root of the evil
of globals is that they are fully exposed to all code that follows.
So is a global hash. So how is a global hash with n keys better than
n global variables? Serious question.
When I get worried about globals, I put them into one or (usually) more
bare blocks and add the necessary accessor routines. Other code must
go through those. That way I get real access restriction and can also
compartmentalize (is that really a word?) the mess of globals. The
bare blocks form lexical islands that can be designed like objects,
since they combine a set of data with a set of routines to manipulate
them.
Admittedly, the method is quite heavy on programmer time. But then,
the point when you have to do something about your globals is usually
a point where a program has outgrown its original framework and some
re-organization is due anyway. Organizing your globals into this
kind of poor man's objects can be part of the process.
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
Date: 28 Oct 2005 10:23:55 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: search & relplace question
Message-Id: <djsu7r$ess$1@mamenchi.zrz.TU-Berlin.DE>
Ashwin <Ashwin@DoNot@Email.com> wrote in comp.lang.perl.misc:
> Hi,
> I am not able to understand why
> my @result =map ((s/BBI_DIR/BBI_DIR\\RBI/), @BBY); modifies the @BBY
> array,
> what I expected was that @result should get updated with replaced lines,
> but it only updated with value 1 , which is what search function
> returns on success
>
> if I try
>
> my @result =map ((s/BBI_DIR/BBI_DIR\\RBI/,$_), @BBY);
> @results and @BBY get the same value , but @result also gets those line
> which are replaces appended with 1,
> what I need is only @result to get updated
You're almost there. Use another map to de-couple the original array:
my @result = map { s/BBI_DIR/BBI_DIR\\RBI/; $_ } map "$_", @BBY;
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
Date: Fri, 28 Oct 2005 11:21:43 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: search & relplace question
Message-Id: <bRn8f.60515$S4.15244@edtnps84>
Tassilo v. Parseval wrote:
> Also sprach Ashwin:
>
>>I am not able to understand why
>>my @result =map ((s/BBI_DIR/BBI_DIR\\RBI/), @BBY); modifies the @BBY
>>array,
>>what I expected was that @result should get updated with replaced lines,
>>but it only updated with value 1 , which is what search function
>>returns on success
>
> Precisely.
>
>>if I try
>>
>>my @result =map ((s/BBI_DIR/BBI_DIR\\RBI/,$_), @BBY);
>>@results and @BBY get the same value , but @result also gets those line
>>which are replaces appended with 1,
>>what I need is only @result to get updated
>
> You can make a copy of $_ in the map block and apply s/// to that. Or
> you use List::MoreUtils::apply() (courtesy of Brian McCauley) which is
> just like map() only that it wont alter the input elements:
>
> use List::MoreUtils qw/apply/;
>
> my @result = apply { s/BBI_DIR/BBI_DIR\\RBI/ } @BBY;
Another way to do it:
s/BBI_DIR/BBI_DIR\\RBI/ for my @result = @BBY;
John
--
use Perl;
program
fulfillment
------------------------------
Date: 28 Oct 2005 11:37:24 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: search & relplace question
Message-Id: <djt2hk$ess$6@mamenchi.zrz.TU-Berlin.DE>
John W. Krahn <krahnj@telus.net> wrote in comp.lang.perl.misc:
> Tassilo v. Parseval wrote:
> > Also sprach Ashwin:
> >
> >>I am not able to understand why
> >>my @result =map ((s/BBI_DIR/BBI_DIR\\RBI/), @BBY); modifies the @BBY
> >>array,
> >>what I expected was that @result should get updated with replaced lines,
> >>but it only updated with value 1 , which is what search function
> >>returns on success
> >
> > Precisely.
> >
> >>if I try
> >>
> >>my @result =map ((s/BBI_DIR/BBI_DIR\\RBI/,$_), @BBY);
> >>@results and @BBY get the same value , but @result also gets those line
> >>which are replaces appended with 1,
> >>what I need is only @result to get updated
> >
> > You can make a copy of $_ in the map block and apply s/// to that. Or
> > you use List::MoreUtils::apply() (courtesy of Brian McCauley) which is
> > just like map() only that it wont alter the input elements:
> >
> > use List::MoreUtils qw/apply/;
> >
> > my @result = apply { s/BBI_DIR/BBI_DIR\\RBI/ } @BBY;
>
> Another way to do it:
>
> s/BBI_DIR/BBI_DIR\\RBI/ for my @result = @BBY;
Ah... very nice. That's the array version of the scalar idiom
( my $result = $RBY) =~ s/.../.../;
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
Date: 28 Oct 2005 10:42:59 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Timelocal input, post good Date filters (from - to)
Message-Id: <djsvbj$ess$3@mamenchi.zrz.TU-Berlin.DE>
<robic0@yahoo.com> wrote in comp.lang.perl.misc:
> About the __DATA__ thing, I thought it was a flag to ignore below as
> comments, but thats where I put the output. Whats the right way
> to do it?
Bell's ringing. Off to the docs!
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
Date: Fri, 28 Oct 2005 10:56:47 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Timelocal input, post good Date filters (from - to)
Message-Id: <Xns96FD46AE82B9Casu1cornelledu@127.0.0.1>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in news:djsvbj$ess$3
@mamenchi.zrz.TU-Berlin.DE:
> <robic0@yahoo.com> wrote in comp.lang.perl.misc:
>
>> About the __DATA__ thing, I thought it was a flag to ignore below as
>> comments, but thats where I put the output. Whats the right way
>> to do it?
>
> Bell's ringing. Off to the docs!
Indeed.
The OP can start by reading the posting guidelines:
Also provide example input data for your program. If you
need to show file input, use the __DATA__ token (perldata.pod)
to provide the file contents inside of your Perl program.
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: 28 Oct 2005 12:30:52 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Unintuitive expression evaluation
Message-Id: <djt5ls$ess$8@mamenchi.zrz.TU-Berlin.DE>
Tassilo v. Parseval <tassilo.von.parseval@rwth-aachen.de> wrote in comp.lang.perl.misc:
> Also sprach A. Sinan Unur:
> > Bill Davidsen <davidsen@deathstar.prodigy.com> wrote in
> > news:mNa8f.3023$Y61.1523@newssvr33.news.prodigy.com:
> I think the left-shift operator could be made smarter so that it always
> works up to 2**64 - 1, even on 32bit machines.
...but only if the bit pattern can be preserved. It wouldn't do to return
the numeric equivalent as a float. So there must be support for 64 bit
integers, either in hardware or in software. I don't think Perl supplies
that if the native C doesn't.
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
------------------------------
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 8583
***************************************