[32829] in Perl-Users-Digest
Perl-Users Digest, Issue: 4094 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Dec 14 05:17:39 2013
Date: Sat, 14 Dec 2013 02:17:08 -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 Sat, 14 Dec 2013 Volume: 11 Number: 4094
Today's topics:
"Use of assignment to $[ is deprecated" means I will ne jidanni@jidanni.org
Re: "Use of assignment to $[ is deprecated" means I wil <peter@makholm.net>
Re: "Use of assignment to $[ is deprecated" means I wil <jurgenex@hotmail.com>
Re: "Use of assignment to $[ is deprecated" means I wil jidanni@jidanni.org
Re: "Use of assignment to $[ is deprecated" means I wil <rweikusat@mobileactivedefense.com>
Re: "Use of assignment to $[ is deprecated" means I wil <ben@morrow.me.uk>
Re: "Use of assignment to $[ is deprecated" means I wil <gamo@telecable.es>
Re: anything like cassandra or riak in perl? <visphatesjava@gmail.com>
Re: anything like cassandra or riak in perl? <Huge@nowhere.much.invalid>
Re: anything like cassandra or riak in perl? <cwilbur@chromatico.net>
Re: anything like cassandra or riak in perl? <visphatesjava@gmail.com>
Re: Extract sample (w/o replacement) <bugbear@trim_papermule.co.uk_trim>
Re: Extract sample (w/o replacement) <gamo@telecable.es>
Re: Extract sample (w/o replacement) <rweikusat@mobileactivedefense.com>
Perl Modules and packages nraju531@gmail.com
what are some huge sites with cataalyst? what are bigge <visphatesjava@gmail.com>
Re: Why is this sub removing newlines?? <rvtol+usenet@xs4all.nl>
Re: Why is this sub removing newlines?? <jblack@nospam.com>
Re: Why is this sub removing newlines?? <rweikusat@mobileactivedefense.com>
Re: Why is this sub removing newlines?? <derykus@gmail.com>
Re: Why is this sub removing newlines?? <rweikusat@mobileactivedefense.com>
Re: Why is this sub removing newlines?? <ben@morrow.me.uk>
Re: Why is this sub removing newlines?? <rweikusat@mobileactivedefense.com>
Re: Why is this sub removing newlines?? <derykus@gmail.com>
Re: Why is this sub removing newlines?? <ben@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 12 Dec 2013 20:58:46 +0800
From: jidanni@jidanni.org
Subject: "Use of assignment to $[ is deprecated" means I will need to spend all night to update my program
Message-Id: <87r49ip6nt.fsf@jidanni.org>
http://jidanni.org/astro/programs/jupmoons
produces "Use of assignment to $[ is deprecated".
Which means I need to delicately adjust various array indexes all over
my program.
And there is no "p2p" (like "a2p", "s2p") program to do it for me!
------------------------------
Date: Thu, 12 Dec 2013 15:59:45 +0100
From: Peter Makholm <peter@makholm.net>
Subject: Re: "Use of assignment to $[ is deprecated" means I will need to spend all night to update my program
Message-Id: <877gbaqfmm.fsf@vps1.hacking.dk>
jidanni@jidanni.org writes:
> http://jidanni.org/astro/programs/jupmoons
> produces "Use of assignment to $[ is deprecated".
>
> Which means I need to delicately adjust various array indexes all over
> my program.
In the given code you use array subscripts 5 times (lines 80, 85, 88, 91,
and 94) every time with index = 0 before setting $[.
That should not take all night to update...
//Makholm
------------------------------
Date: Thu, 12 Dec 2013 08:48:03 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: "Use of assignment to $[ is deprecated" means I will need to spend all night to update my program
Message-Id: <oqpja99l68shifk90trq3b4i3c4hldjbr2@4ax.com>
jidanni@jidanni.org wrote:
>http://jidanni.org/astro/programs/jupmoons
>produces "Use of assignment to $[ is deprecated".
>
>Which means I need to delicately adjust various array indexes all over
>my program.
Welcome to the 21st century.
$[: "As of release 5 of Perl[...] Its use is highly
discouraged."
Perl 5 was released almost 20 years ago (October 1994). If you still
have to maintain programs that are over 20 years old then maybe it is
indeed time to update them.
jue
------------------------------
Date: Fri, 13 Dec 2013 07:54:29 +0800
From: jidanni@jidanni.org
Subject: Re: "Use of assignment to $[ is deprecated" means I will need to spend all night to update my program
Message-Id: <87haadmxqi.fsf@jidanni.org>
OK I see it didn't affect my program at all and have now chucked it. Hmmm.
------------------------------
Date: Fri, 13 Dec 2013 20:04:41 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: "Use of assignment to $[ is deprecated" means I will need to spend all night to update my program
Message-Id: <87wqj8h606.fsf@sable.mobileactivedefense.com>
gamo <gamo@telecable.es> writes:
> El 13/12/13 00:54, jidanni@jidanni.org escribió:
>> OK I see it didn't affect my program at all and have now chucked it. Hmmm.
>>
> If you yet removed the $]=1, there are still bugs like
> $somevar = @str[0], which should look like $var = $str[0]
>
> It's better to put a #!/usr/bin/perl -W
> to print warnings about.
-W is documented as
-W Enables all warnings regardless of "no warnings" or $^W. See
perllexwarn.
When dealing with 'trusted' code (ie, all 'no warnings' where purposely
but in place by the person who wrote the code who is also the person
running the script) this is probably not terribly useful. There's also
the question whether it is appropriate for production code to print
warnings and/or whether
$1 // '' # I enabled this warning, however, it's actually harmful
and similar constructs should be put into code solely to work around
some misbehaviour which could have been left disabled in the first
place.
In my opinion, the sensible answer to both question is 'no': Warnings in
debugged code are not useful to people running this code (but possibly
harmful, eg, if they keep getting written to a file until there's no
more space for more warnings) and code which serves no useful purpose
except hacking around warnings is dead weight insofer the function of a
program is concerned. I'm also decidedly not of the opinion that
Perl programmers cannot be bothered with silly things like
compiling. "Tweak, Run, Tweak, Run" is our way of life.
[http://search.cpan.org/~sisyphus/Inline-0.53/Inline.pod]
When I'm dealing with something more complicated than an isolated
(small) file, I usually use a Makefile target looking somewhat like
this:
$(TMP)/syn.%: $(MES)/%
$(CPERL) $< && touch $@
with
CPERL := perl -cw -Mstrict
so that I can run the perl compiler with warnings and strict enabled on
all changed files by typing 'make'. This is especially useful when
doing stuff like 'building Debian packages from Perl sources' and when
the packaged program can't be tested without first installing it in a
suitable location: For as long as the code doesn't even pass the
'test' included above, there's no use bothering with moving it into an
execution environment.
------------------------------
Date: Sat, 14 Dec 2013 00:58:31 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: "Use of assignment to $[ is deprecated" means I will need to spend all night to update my program
Message-Id: <n2nsna-prq.ln1@anubis.morrow.me.uk>
Quoth Rainer Weikusat <rweikusat@mobileactivedefense.com>:
> gamo <gamo@telecable.es> writes:
> >
> > It's better to put a #!/usr/bin/perl -W
> > to print warnings about.
>
> -W is documented as
>
> -W Enables all warnings regardless of "no warnings" or $^W. See
> perllexwarn.
>
> When dealing with 'trusted' code (ie, all 'no warnings' where purposely
> but in place by the person who wrote the code who is also the person
> running the script) this is probably not terribly useful.
I think -W was intended to be 'lint-for-Perl', and like lint, to be only
be used occasionally, from the command line, rather than put on a #!
line. In practice, I don't believe it's ever useful.
Ben
------------------------------
Date: Fri, 13 Dec 2013 09:58:29 +0100
From: gamo <gamo@telecable.es>
Subject: Re: "Use of assignment to $[ is deprecated" means I will need to spend all night to update my program
Message-Id: <l8ei7n$eje$1@speranza.aioe.org>
El 13/12/13 00:54, jidanni@jidanni.org escribió:
> OK I see it didn't affect my program at all and have now chucked it. Hmmm.
>
If you yet removed the $]=1, there are still bugs like
$somevar = @str[0], which should look like $var = $str[0]
It's better to put a #!/usr/bin/perl -W
to print warnings about.
------------------------------
Date: Fri, 13 Dec 2013 02:53:29 -0800 (PST)
From: johannes falcone <visphatesjava@gmail.com>
Subject: Re: anything like cassandra or riak in perl?
Message-Id: <237dd576-708b-4167-b33b-b65393d7ee44@googlegroups.com>
whats astroturfing?
a good idea is a good idea eh?
------------------------------
Date: 13 Dec 2013 11:14:37 GMT
From: Huge <Huge@nowhere.much.invalid>
Subject: Re: anything like cassandra or riak in perl?
Message-Id: <bh08gtFp5rhU1@mid.individual.net>
On 2013-12-13, johannes falcone <visphatesjava@gmail.com> wrote:
> whats astroturfing?
>
> a good idea is a good idea eh?
http://en.wikipedia.org/wiki/Astroturfing
--
Today is Boomtime, the 55th day of The Aftermath in the YOLD 3179
Human being; a spacesuit for a fish
------------------------------
Date: Fri, 13 Dec 2013 13:30:55 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: anything like cassandra or riak in perl?
Message-Id: <871u1g8uxs.fsf@new.chromatico.net>
>>>>> "j" == johannes falcone <visphatesjava@gmail.com> writes:
j> a good idea is a good idea eh?
Indeed, and tautologically so.
Charlton
--
Charlton Wilbur
cwilbur@chromatico.net
------------------------------
Date: Sat, 14 Dec 2013 00:50:40 -0800 (PST)
From: johannes falcone <visphatesjava@gmail.com>
Subject: Re: anything like cassandra or riak in perl?
Message-Id: <f44ed9be-1d00-4591-a005-c99dc5aba231@googlegroups.com>
On Friday, December 13, 2013 10:30:55 AM UTC-8, Charlton Wilbur wrote:
> >>>>> "j" == johannes falcone <visphatesjava@gmail.com> writes:
>
>
>
> j> a good idea is a good idea eh?
>
>
>
> Indeed, and tautologically so.
>
>
>
> Charlton
>
>
>
>
>
> --
>
> Charlton Wilbur
>
> cwilbur@chromatico.net
prevayler seems where the computing industry must go sooner or later
------------------------------
Date: Wed, 11 Dec 2013 11:07:56 +0000
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: Extract sample (w/o replacement)
Message-Id: <OrWdnXxR14YR2jXPnZ2dnUVZ8gKdnZ2d@brightview.co.uk>
gamo wrote:
>
> It's a better way to do this?
>
> my @matrix = 1..10_000_000;
>
>
> sub extract{
> my $ind = int rand ($#matrix+1);
> ($matrix[$ind],$matrix[-1]) = ($matrix[-1],$matrix[$ind]);
> return pop @matrix;
> }
>
> The goal is to extact random elements without using shuffle, and
> ever removing them from the original list.
Depending on how important the performance of this is,
and what other operations are performed on the array,
a data structure more sophisticated than a plain (huge)
array might be indicated.
BugBear
------------------------------
Date: Wed, 11 Dec 2013 12:20:00 +0100
From: gamo <gamo@telecable.es>
Subject: Re: Extract sample (w/o replacement)
Message-Id: <l89hov$lq5$1@speranza.aioe.org>
El 11/12/13 12:07, bugbear escribió:
> a data structure more sophisticated than a plain (huge)
> array might be indicated.
>
> BugBear
Interesting. Can you be more specific?
Thanks
------------------------------
Date: Wed, 11 Dec 2013 12:58:30 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Extract sample (w/o replacement)
Message-Id: <87sitzsfwp.fsf@sable.mobileactivedefense.com>
bugbear <bugbear@trim_papermule.co.uk_trim> writes:
> gamo wrote:
>>
>> It's a better way to do this?
>>
>> my @matrix = 1..10_000_000;
>>
>>
>> sub extract{
>> my $ind = int rand ($#matrix+1);
>> ($matrix[$ind],$matrix[-1]) = ($matrix[-1],$matrix[$ind]);
>> return pop @matrix;
>> }
>>
>> The goal is to extact random elements without using shuffle, and
>> ever removing them from the original list.
>
> Depending on how important the performance of this is,
> and what other operations are performed on the array,
> a data structure more sophisticated than a plain (huge)
> array might be indicated.
Certainly not for this particular task. There's also the problem that
algorithms implemented in Perl tend to be a lot slower ('have bigger
constants', [can I credit this to Robert Pike in English in some sane
way?]) than algorithms implemented in C which implies that Perl arrays
are more often a good choice for Perl code than C arrays would be for
C[*].
[*] No, that's not because memory management in C is soo complicated ...
------------------------------
Date: Sat, 14 Dec 2013 00:38:09 -0800 (PST)
From: nraju531@gmail.com
Subject: Perl Modules and packages
Message-Id: <0d144114-f3e2-40c4-982d-d8cbb45605fd@googlegroups.com>
Hi,
I am new to perl scripting i want to know the were the perl modules and packages are in perl scripting language.
Regards,
Nagaraju
------------------------------
Date: Sat, 14 Dec 2013 01:18:23 -0800 (PST)
From: johannes falcone <visphatesjava@gmail.com>
Subject: what are some huge sites with cataalyst? what are biggest perl powered sites in general?
Message-Id: <80894721-5160-4c1a-96ad-cebd535561b3@googlegroups.com>
can someone kik me down this info?
------------------------------
Date: Wed, 11 Dec 2013 14:10:06 +0100
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: Why is this sub removing newlines??
Message-Id: <52a8642e$0$2951$e4fe514c@news2.news.xs4all.nl>
On 2013-12-05 22:56, John Black wrote:
> I've been using \s as a shortcut for spaces or tabs.
See also perlrecharclass, look for [[:blank:]] and \h.
--
Ruud
------------------------------
Date: Wed, 11 Dec 2013 14:24:37 -0600
From: John Black <jblack@nospam.com>
Subject: Re: Why is this sub removing newlines??
Message-Id: <MPG.2d1285cfe58b397f9897a3@news.eternal-september.org>
In article <52a8642e$0$2951$e4fe514c@news2.news.xs4all.nl>, rvtol+usenet@xs4all.nl says...
>
> On 2013-12-05 22:56, John Black wrote:
>
> > I've been using \s as a shortcut for spaces or tabs.
>
> See also perlrecharclass, look for [[:blank:]] and \h.
Thanks. Looks like what I really wanted in most cases was \h. [[:black:]] sounds like it
would work too but its just too bulky to put into regexs since it can be easily avoided with
\h.
John Black
------------------------------
Date: Thu, 12 Dec 2013 13:11:10 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Why is this sub removing newlines??
Message-Id: <87txee6wpd.fsf@sable.mobileactivedefense.com>
Rainer Weikusat <rweikusat@mobileactivedefense.com> writes:
> Rainer Weikusat <rweikusat@mobileactivedefense.com> writes:
>> Charles DeRykus <derykus@gmail.com> writes:
[remove whitespace at end of string but keep \n if it is there]
>>> $string =~ s/ ^\s+ | \s+(?=\n)$ | \s*[^\n\S]+$ //gx;
[this also deal with whitespace at the beginning]
> s/\s*?(?=\n)?$//;
Maybe logically simpler:
s/\s*?(\n)?$/$1/;
(this will likely a result in a warning when there's no newline at the
end of the line and runtime warnings are enabled).
------------------------------
Date: Thu, 12 Dec 2013 19:36:44 -0800
From: Charles DeRykus <derykus@gmail.com>
Subject: Re: Why is this sub removing newlines??
Message-Id: <l8dvcv$9ai$1@speranza.aioe.org>
On 12/12/2013 5:11 AM, Rainer Weikusat wrote:
> Rainer Weikusat <rweikusat@mobileactivedefense.com> writes:
>> Rainer Weikusat <rweikusat@mobileactivedefense.com> writes:
>>> Charles DeRykus <derykus@gmail.com> writes:
>
> [remove whitespace at end of string but keep \n if it is there]
>
>>>> $string =~ s/ ^\s+ | \s+(?=\n)$ | \s*[^\n\S]+$ //gx;
>
> [this also deal with whitespace at the beginning]
>
>> s/\s*?(?=\n)?$//;
>
> Maybe logically simpler:
>
> s/\s*?(\n)?$/$1/;
>
> (this will likely a result in a warning when there's no newline at the
> end of the line and runtime warnings are enabled).
Hm, as you note though, doesn't handle initial w/s and coughs an
'uninitialized" warning if no ending \n. However, you could take a cough
suppressant:
s{\s*?(\n)?$}{$1 // ''}e;
But, more significantly, doesn't handle multiple ending newlines, eg,
"foo \n\n\n"
[which of course may not be an issue for the OP]
--
Charles DeRykus
------------------------------
Date: Fri, 13 Dec 2013 15:26:27 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Why is this sub removing newlines??
Message-Id: <8738lwkc0s.fsf@sable.mobileactivedefense.com>
Charles DeRykus <derykus@gmail.com> writes:
> On 12/12/2013 5:11 AM, Rainer Weikusat wrote:
>> Rainer Weikusat <rweikusat@mobileactivedefense.com> writes:
>>> Rainer Weikusat <rweikusat@mobileactivedefense.com> writes:
>>>> Charles DeRykus <derykus@gmail.com> writes:
>>
>> [remove whitespace at end of string but keep \n if it is there]
>>
>>>>> $string =~ s/ ^\s+ | \s+(?=\n)$ | \s*[^\n\S]+$ //gx;
>>
>> [this also deal with whitespace at the beginning]
>>
>>> s/\s*?(?=\n)?$//;
>>
>> Maybe logically simpler:
>>
>> s/\s*?(\n)?$/$1/;
>>
>> (this will likely a result in a warning when there's no newline at the
>> end of the line and runtime warnings are enabled).
>
>
> Hm, as you note though, doesn't handle initial w/s and coughs an
> uninitialized" warning if no ending \n. However, you could take a
> cough suppressant:
>
> s{\s*?(\n)?$}{$1 // ''}e;
It wasn't supposed to handle initial whitespace because that's not
really related to the \n-issue (also true for the first) ...
> But, more significantly, doesn't handle multiple ending newlines, eg,
> "foo \n\n\n"
> [which of course may not be an issue for the OP]
... and it certainly wasn't supposed to do that, either: When processing
something line-by-line which I assumed to be the case here, "foo \n\n\n"
will be the three lines
"foo \n"
"\n"
"\n"
and assuming that handling "foo \n bla\n \n" should result in
"foo\n blah\n \n", ie the purpose is to remove leading whitespace at
the beginning of a multi-line text but not leading whitespace on the
individual lines seems rather bizarre to me. Or that processing
"a \n " should remove the \n given that newlines are not supposed to
be removed. And what about " a b \n bbb\n\n c \n"?
------------------------------
Date: Fri, 13 Dec 2013 15:38:20 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Why is this sub removing newlines??
Message-Id: <c8mrna-7gn.ln1@anubis.morrow.me.uk>
Quoth Rainer Weikusat <rweikusat@mobileactivedefense.com>:
> Rainer Weikusat <rweikusat@mobileactivedefense.com> writes:
> > Rainer Weikusat <rweikusat@mobileactivedefense.com> writes:
> >> Charles DeRykus <derykus@gmail.com> writes:
>
> [remove whitespace at end of string but keep \n if it is there]
>
> >>> $string =~ s/ ^\s+ | \s+(?=\n)$ | \s*[^\n\S]+$ //gx;
>
> [this also deal with whitespace at the beginning]
>
> > s/\s*?(?=\n)?$//;
>
> Maybe logically simpler:
>
> s/\s*?(\n)?$/$1/;
If you're willing to rely on \s*? finding all the whitespace (it does,
because the 'start earlier in the string' rule trumps the 'match
minimally' rule, but IMHO it's confusing), you just need
s/\s*?$//
Ben
------------------------------
Date: Fri, 13 Dec 2013 16:35:19 +0000
From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
Subject: Re: Why is this sub removing newlines??
Message-Id: <87d2l0iu9k.fsf@sable.mobileactivedefense.com>
Ben Morrow <ben@morrow.me.uk> writes:
> Quoth Rainer Weikusat <rweikusat@mobileactivedefense.com>:
>> Rainer Weikusat <rweikusat@mobileactivedefense.com> writes:
>> > Rainer Weikusat <rweikusat@mobileactivedefense.com> writes:
>> >> Charles DeRykus <derykus@gmail.com> writes:
>>
>> [remove whitespace at end of string but keep \n if it is there]
>>
>> >>> $string =~ s/ ^\s+ | \s+(?=\n)$ | \s*[^\n\S]+$ //gx;
>>
>> [this also deal with whitespace at the beginning]
>>
>> > s/\s*?(?=\n)?$//;
>>
>> Maybe logically simpler:
>>
>> s/\s*?(\n)?$/$1/;
>
> If you're willing to rely on \s*? finding all the whitespace (it does,
> because the 'start earlier in the string' rule trumps the 'match
> minimally' rule, but IMHO it's confusing), you just need
>
> s/\s*?$//
What's confusing here is that $ matches two different things depending
on the context: Apparently, if it is preceded by \s*?, it matches
immediately before \n at the end of the line and if that is \s*, it
matches after the \n. But that's certainly good to know.
------------------------------
Date: Fri, 13 Dec 2013 12:29:01 -0800
From: Charles DeRykus <derykus@gmail.com>
Subject: Re: Why is this sub removing newlines??
Message-Id: <l8fqmu$qag$1@speranza.aioe.org>
On 12/13/2013 7:26 AM, Rainer Weikusat wrote:
> Charles DeRykus <derykus@gmail.com> writes:
>> On 12/12/2013 5:11 AM, Rainer Weikusat wrote:
>>> Rainer Weikusat <rweikusat@mobileactivedefense.com> writes:
>>>> Rainer Weikusat <rweikusat@mobileactivedefense.com> writes:
>>>>> Charles DeRykus <derykus@gmail.com> writes:
>>>
>>> [remove whitespace at end of string but keep \n if it is there]
>>>
>>>>>> $string =~ s/ ^\s+ | \s+(?=\n)$ | \s*[^\n\S]+$ //gx;
>>>
> ...
>
> It wasn't supposed to handle initial whitespace because that's not
> really related to the \n-issue (also true for the first) ...
>
Yes, I was over-generalizing. But, imo, a one-liner handles both goals
without being rocket science[1].
>> But, more significantly, doresn't handle multiple ending newlines, eg,
>> "foo \n\n\n"
>> [which of course may not be an issue for the OP]
>
> ... and it certainly wasn't supposed to do that, either: When processing
> something line-by-line which I assumed to be the case here, "foo \n\n\n"
> will be the three lines
>
That wasn't really specified though. The goal was to remove trailing
whitespace from the beginning and end of "strings" [rather than just
well-behaved lines] without clobbering a trailing newline.
> "foo \n"
> "\n"
> "\n"
>
> and assuming that handling "foo \n bla\n \n" should result in
> "foo\n blah\n \n", ie the purpose is to remove leading whitespace at
> the beginning of a multi-line text but not leading whitespace on the
> individual lines seems rather bizarre to me. Or that processing
> "a \n " should remove the \n given that newlines are not supposed to
> be removed. And what about " a b \n bbb\n\n c \n"?
>
Yes, agreed. Without more certainty about original intent, it becomes
bizarre. But less bizarrely, a string might easily have multiple
newlines on the end with the reasonable goal of removing all but the
final one.
--
Charles DeRykus
------------------------------
Date: Sat, 14 Dec 2013 00:53:39 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Why is this sub removing newlines??
Message-Id: <jpmsna-prq.ln1@anubis.morrow.me.uk>
Quoth Rainer Weikusat <rweikusat@mobileactivedefense.com>:
> Ben Morrow <ben@morrow.me.uk> writes:
> >
> > If you're willing to rely on \s*? finding all the whitespace (it does,
> > because the 'start earlier in the string' rule trumps the 'match
> > minimally' rule, but IMHO it's confusing), you just need
> >
> > s/\s*?$//
>
> What's confusing here is that $ matches two different things depending
> on the context: Apparently, if it is preceded by \s*?, it matches
> immediately before \n at the end of the line and if that is \s*, it
> matches after the \n. But that's certainly good to know.
It's not context-dependent: /$/ is equivalent to /\n?\z/; that is, it
matches the end of the string, or a newline before the end of the
string. This is, indeed, well worth remembering; in situations where it
matters, /\z/ should be used instead of /$/.
This is all historical in origin: when processing line-by-line without
autochomp (say, with -n but without -l) this is more useful than having
/$/ just match end-of-line. Still, IMHO it would have been better design
for <> and -n to always autochomp, and for -p to always set $\ = $/.
Ben
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 V11 Issue 4094
***************************************