[26016] in Perl-Users-Digest
Perl-Users Digest, Issue: 8232 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 8 16:21:23 2005
Date: Thu, 7 Jul 2005 00:05:06 -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 Thu, 7 Jul 2005 Volume: 10 Number: 8232
Today's topics:
Re: How to take acton upon a pattern of nth occurrence? <sherm@dot-app.org>
Re: How to take acton upon a pattern of nth occurrence? <jwkenne@attglobal.net>
Is there a name for secondary or derived properties? <BLOCKSPAMfishfry@your-mailbox.com>
Re: making alternation clearer in regular expressions <ebohlman@omsdev.com>
Re: making alternation clearer in regular expressions <skuo@psi.nsc.com>
sorting <bbrunno3000@yahoo.con>
Re: sorting <noreply@gunnar.cc>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 06 Jul 2005 17:19:35 -0400
From: Sherm Pendley <sherm@dot-app.org>
Subject: Re: How to take acton upon a pattern of nth occurrence?
Message-Id: <87ekabfx94.fsf@dot-app.org>
"A. Sinan Unur" <1usa@llenroc.ude.invalid> writes:
> Sherm Pendley <sherm@dot-app.org> wrote in
> news:87u0j7fzie.fsf@dot-app.org:
>
>> $foo += $bar;
>>
>> Back in the day of straightforward, non-optimizing C compilers, the
>> short form was an optimization.
>
> IMHO, it is a cognitive optimization for the programmer as well. Once
> one gets used to the notation, the difference between "Add $bar to $foo
> and store the result in $foo" and "add $bar to $foo, and store the
> result somewhere else" becomes easier to see, helping (at least me) with
> comprehension.
I agree, but that's something that was discovered later, when C became more
widely adopted and used. That's why it's still in common use today, now that
optimizing compilers and cheap hardware have made the original purpose moot.
sherm--
--
Due to the amount of unreadable gibberish being posted from Google Groups,
I seldom read messages posted from there.
Cocoa/Perl: http://camelbones.sf.net Hire Me: http://www.dot-app.org
------------------------------
Date: Wed, 06 Jul 2005 19:40:49 -0400
From: "John W. Kennedy" <jwkenne@attglobal.net>
Subject: Re: How to take acton upon a pattern of nth occurrence?
Message-Id: <6_Zye.88156$mx5.62989@fe08.lga>
Sherm Pendley wrote:
> "A. Sinan Unur" <1usa@llenroc.ude.invalid> writes:
>
>
>>Sherm Pendley <sherm@dot-app.org> wrote in
>>news:87u0j7fzie.fsf@dot-app.org:
>>
>>
>>> $foo += $bar;
>>>
>>>Back in the day of straightforward, non-optimizing C compilers, the
>>>short form was an optimization.
>>
>>IMHO, it is a cognitive optimization for the programmer as well. Once
>>one gets used to the notation, the difference between "Add $bar to $foo
>>and store the result in $foo" and "add $bar to $foo, and store the
>>result somewhere else" becomes easier to see, helping (at least me) with
>>comprehension.
>
>
> I agree, but that's something that was discovered later, when C became more
> widely adopted and used. That's why it's still in common use today, now that
> optimizing compilers and cheap hardware have made the original purpose moot.
It also has a semantic function:
$a[function-call()] = $a[function-call()] + $b;
and
$a[function-call()] += $b;
have different results if "function-call()" is not idempotent.
--
John W. Kennedy
"You can, if you wish, class all science-fiction together; but it is
about as perceptive as classing the works of Ballantyne, Conrad and W.
W. Jacobs together as the 'sea-story' and then criticizing _that_."
-- C. S. Lewis. "An Experiment in Criticism"
------------------------------
Date: Wed, 06 Jul 2005 22:33:25 -0700
From: fishfry <BLOCKSPAMfishfry@your-mailbox.com>
Subject: Is there a name for secondary or derived properties?
Message-Id: <BLOCKSPAMfishfry-32F54E.22332506072005@comcast.dca.giganews.com>
This question came up in my mind recently as I'm working with the XMLTV
package, which retrieves an XML document representing a television
schedule. To work with it I've created a Program object, which has
attributes such as "start_time" and "channel" and "title" and so forth.
In addition, I'd like to know which programs are movies, so I have an
attribute called isMovie. However, isMovie is not a fundamental
attribute of the program data as given to me by the XML. Instead, I
determine whether a program is a movie based on other criteria, in
particular whether it has a star_rating defined (like "*" or "**" etc.)
As I was coding this, I thought of a theoretical question. I have
accessor methods such as start_time() and channel() that get and set the
start_time and channel attributes. I also have an isMovie() method that
computes whether the program is a movie or not and returns a boolean.
I was noticing that isMovie() is conceptually different than accessors
that hide "primary" attributes, if you want to call them that. For
example, if a user calls isMovie() on a program object whose star-rating
has not been set yet, then isMovie() will return false, which is an
inaccurate result. In fact, at that moment the Program object is really
in an "incomplete" state, and the result of isMovie() is really
indeterminate.
To do this correctly, the documentation should inform the caller that
isMovie() must not be called until the Program object is completely
initialized ... but how would they know when that is? Perhaps isMovie()
should return true, false, or undefined and the documentation should
explain what that means. And if you were implementing this concept in a
language like C that does not have a concept of "undefined," you'd have
to return -1, 0, and 1 and document that.
I was wondering if there is some computer science term for this concept
of primary versus derived attribute of an object, and if there is a
recommended way to handle it.
By the way this is how I implemented my code:
In sub new:
$self = bless {
_start_time => '',
_starRating => undef,
<other stuff>,
_isMovie => sub {return defined($self->{'_starRating'});},
}, $class;
and later ...
sub isMovie {
my($self) = shift;
return $self->{'_isMovie'}->();
}
Is this a reasonable way to do this kind of thing? I don't think I've
ever felt the need to use an anonmous subroutine before, but in this
instance it felt natural.
Thanks for all input.
------------------------------
Date: 7 Jul 2005 00:58:56 GMT
From: Eric Bohlman <ebohlman@omsdev.com>
Subject: Re: making alternation clearer in regular expressions
Message-Id: <Xns968BCCD6C40A5ebohlmanomsdevcom@130.133.1.4>
joe <joe@example.com> wrote in news:joSdneRyE40LZFffRVn-uQ@rcn.net:
> #!perl -w
>
> $_ = 'acd';
> sub matched($) {return "pattern @{[shift]} matched\n" }
>
> print matched(1) if /^(?:ab|cd)$/;
> print matched(2) if /^(?:ab|cd)/;
[snip]
> It doesn't appear so obvious why the first two patterns do not match,
> but 3 and 4 do. There is an 'a' at the beginning of the string to
> which the pattern is tested against, followed by a 'b' or 'c',
> followed by a 'd', and finally, the end of string. I know what the
> documentation says; but how *you* would explain why the first two
> patterns do not work and the others do not?
Precedence: in regular expressions concatenation binds tighter than
alternation, so "ab|cd" parses as "(ab)|(cd)" rather than "a(b|c)d" (in
mathematical regular expression theory, concatenation behaves a lot like
multiplication and alternation behaves a lot like addition, so the
standard arithmetic precedence conventions are used).
------------------------------
Date: Wed, 6 Jul 2005 18:16:59 -0700
From: Steven Kuo <skuo@psi.nsc.com>
Subject: Re: making alternation clearer in regular expressions
Message-Id: <Pine.LNX.4.60.0507061808560.21839@psi.nsc.com>
On Tue, 5 Jul 2005, joe wrote:
> #!perl -w
>
> $_ = 'acd';
> sub matched($) {return "pattern @{[shift]} matched\n" }
>
> print matched(1) if /^(?:ab|cd)$/;
> print matched(2) if /^(?:ab|cd)/;
(snipped)
>
> It doesn't appear so obvious why the first two patterns do not match,
> but 3 and 4 do. There is an 'a' at the beginning of the string to which
> the pattern is tested against, followed by a 'b' or 'c', followed by a
> 'd', and finally, the end of string. I know what the documentation
> says; but how *you* would explain why the first two patterns do not work
> and the others do not?
>
> -J
You can ask *perl* to explain its attempts at matching the pattern
against target string if you use 're':
use re 'debug'; # or 'debugcolor'
for ("acd")
{
print "matched 1\n" if /^(?:ab|cd)$/;
}
__END__
Compiling REx `^(?:ab|cd)$'
size 10 Got 84 bytes for offset annotations.
first at 2
rarest char
at 0
1: BOL(2)
2: BRANCH(5)
3: EXACT <ab>(9)
5: BRANCH(8)
6: EXACT <cd>(9)
8: TAIL(9)
9: EOL(10)
10: END(0)
anchored `'$ at 2 anchored(BOL) minlen 2
Offsets: [10]
1[1] 4[1] 5[2] 0[0] 7[1] 8[2] 0[0] 9[0] 11[1] 12[0]
Omitting $` $& $' support.
EXECUTING...
Matching REx `^(?:ab|cd)$' against `acd'
Setting an EVAL scope, savestack=9
0 <> <acd> | 1: BOL
0 <> <acd> | 2: BRANCH
Setting an EVAL scope, savestack=19
0 <> <acd> | 3: EXACT <ab>
failed...
0 <> <acd> | 6: EXACT <cd>
failed...
Clearing an EVAL scope, savestack=9..19
Match failed
Freeing REx: `"^(?:ab|cd)$"'
The output may be a bit cryptic, but one eventually figures out that
BOL is Beginning-Of-Line, EOL is End-Of-Line, and that neither
the EXACT sequence 'ab' nor 'cd' appears immediately after BOL...
--
Hope this helps,
Steven
------------------------------
Date: Thu, 07 Jul 2005 05:04:29 GMT
From: "Luthor" <bbrunno3000@yahoo.con>
Subject: sorting
Message-Id: <xJ2ze.8561$3o4.7030@tornado.socal.rr.com>
Hi,
I have the following hash:
%hash
$hash->{value1}->{value2}
how can I sort the hash based on value2?
Thanks
------------------------------
Date: Thu, 07 Jul 2005 07:17:57 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: sorting
Message-Id: <3j3s86Fo27s7U1@individual.net>
Luthor wrote:
> I have the following hash:
>
> %hash
> $hash->{value1}->{value2}
>
> how can I sort the hash based on value2?
What have you done to find out?
perldoc -q "sort a hash"
"How do I sort a hash (optionally by value instead of key)?"
What have you tried?
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
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 8232
***************************************