[30527] in Perl-Users-Digest
Perl-Users Digest, Issue: 1770 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 5 14:09:54 2008
Date: Tue, 5 Aug 2008 11:09:13 -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 Tue, 5 Aug 2008 Volume: 11 Number: 1770
Today's topics:
a reference to an element of an array or hash, how to c <arifsaha@yahoo.com>
Re: a reference to an element of an array or hash, how xhoster@gmail.com
Re: a reference to an element of an array or hash, how <someone@example.com>
Re: a reference to an element of an array or hash, how (Zak B. Elep)
Re: a reference to an element of an array or hash, how <arifsaha@yahoo.com>
Re: bidding advice for a contract <Peter@PSDT.com>
Re: bidding advice for a contract <cartercc@gmail.com>
Re: bidding advice for a contract wes.tibular@yahoo.com
Re: bidding advice for a contract <cartercc@gmail.com>
Re: CLPM - a help group? <justin.0805@purestblue.com>
Re: CLPM - a help group? <bugbear@trim_papermule.co.uk_trim>
Expression Parsing Help Needed <merridian74@gmail.com>
Re: Expression Parsing Help Needed <bugbear@trim_papermule.co.uk_trim>
Re: Expression Parsing Help Needed <ben@morrow.me.uk>
Re: Expression Parsing Help Needed <jimsgibson@gmail.com>
Re: Expression Parsing Help Needed <RedGrittyBrick@SpamWeary.foo>
Re: FAQ 4.61 How can I always keep my hash sorted? <ben@morrow.me.uk>
Re: highly restrictive sub-classing <Peter@PSDT.com>
Re: Sort using reference to subroutine name? <ben@morrow.me.uk>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 5 Aug 2008 09:55:21 -0400
From: S P Arif Sahari Wibowo <arifsaha@yahoo.com>
Subject: a reference to an element of an array or hash, how to create?
Message-Id: <alpine.OSX.1.10.0808050919180.440@imac2006.local>
Hi!
Do you know how to create a reference to an element of an array
or hash? For instance I have an array @a, and I like $a2r
contains a reference to $a[2]. Anyway to do it in perl?
Keep in mind this is not the case where $a[2] contain a
reference and $a2r contains the same reference, but instead $a2r
contain a reference to the scalar stored in $a[2].
Let me explain more using the pseudo code below, RefTo represent
the mechanism in question:
my @a= (1, 2, 3, 4);
my $p= RefTo $a[2];
$$p= 9;
print join(",", @a) # should print 1,2,9,4
So, any idea wether there is such mechanism as RefTo in Perl?
Thanks!
--
(stephan paul) Arif Sahari Wibowo
_____ _____ _____ _____
/____ /____/ /____/ /____
_____/ / / / _____/ http://www.arifsaha.com/
------------------------------
Date: 05 Aug 2008 14:07:43 GMT
From: xhoster@gmail.com
Subject: Re: a reference to an element of an array or hash, how to create?
Message-Id: <20080805100744.232$cz@newsreader.com>
S P Arif Sahari Wibowo <arifsaha@yahoo.com> wrote:
> Hi!
>
> Do you know how to create a reference to an element of an array
> or hash? For instance I have an array @a, and I like $a2r
> contains a reference to $a[2]. Anyway to do it in perl?
The Perl "reference to" operator is the backslash.
>
> my @a= (1, 2, 3, 4);
>
> my $p= RefTo $a[2];
>
> $$p= 9;
>
> print join(",", @a) # should print 1,2,9,4
perl -le 'my @x=(1..4); my $p=\$x[2]; $$p=9; print "@x"'
1 2 9 4
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Tue, 05 Aug 2008 14:10:47 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: a reference to an element of an array or hash, how to create?
Message-Id: <HbZlk.58440$nD.3728@pd7urf1no>
S P Arif Sahari Wibowo wrote:
>
> Do you know how to create a reference to an element of an array or hash?
> For instance I have an array @a, and I like $a2r contains a reference to
> $a[2]. Anyway to do it in perl?
>
> Keep in mind this is not the case where $a[2] contain a reference and
> $a2r contains the same reference, but instead $a2r contain a reference
> to the scalar stored in $a[2].
>
> Let me explain more using the pseudo code below, RefTo represent the
> mechanism in question:
>
> my @a= (1, 2, 3, 4);
>
> my $p= RefTo $a[2];
>
> $$p= 9;
>
> print join(",", @a) # should print 1,2,9,4
$ perl -le'my @a = ( 1, 2, 3, 4 ); my $p = \$a[ 2 ]; $$p = 9; print join
",", @a'
1,2,9,4
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
------------------------------
Date: Tue, 05 Aug 2008 22:25:01 +0800
From: zakame@zakame.net (Zak B. Elep)
Subject: Re: a reference to an element of an array or hash, how to create?
Message-Id: <m2wsivh742.fsf@zakame.net>
S P Arif Sahari Wibowo <arifsaha@yahoo.com> writes:
> Do you know how to create a reference to an element of an array or hash?
> For instance I have an array @a, and I like $a2r contains a reference to
> $a[2]. Anyway to do it in perl?
,----[ perl -de 0 ]
| alteran:~ zakame$ perl -de 0
|
| Loading DB routines from perl5db.pl version 1.28
| Editor support available.
|
| Enter h or `h h' for help, or `man perldebug' for more help.
|
| main::(-e:1): 0
| DB<1> @a = ( 1, 2, 3 )
|
| DB<2> $a2r = \$a[2]
|
| DB<3> x $a2r
| 0 SCALAR(0x190fe24)
| -> 3
| DB<4> x $$a2r
| 0 3
`----
--
I like the idea of 256 bits, though: 32 for the (Unicode) character leaves
room for 224 Bucky bits, which ought to be enough for anyone.
-- Roland Hutchinson, in alt.folklore.computers
------------------------------
Date: Tue, 5 Aug 2008 11:37:41 -0400
From: S P Arif Sahari Wibowo <arifsaha@yahoo.com>
Subject: Re: a reference to an element of an array or hash, how to create?
Message-Id: <alpine.OSX.1.10.0808051108240.440@imac2006.local>
On Tue, 5 Aug 2008, xhoster@gmail.com wrote:
> perl -le 'my @x=(1..4); my $p=\$x[2]; $$p=9; print "@x"'
On Tue, 5 Aug 2008, John W. Krahn wrote:
> $ perl -le'my @a = ( 1, 2, 3, 4 ); my $p = \$a[ 2 ]; $$p = 9; print join ",", @a'
Duh! I should try it first, didn't think it will be that easy
before.
Thanks everyone!
--
(stephan paul) Arif Sahari Wibowo
_____ _____ _____ _____
/____ /____/ /____/ /____
_____/ / / / _____/ http://www.arifsaha.com/
------------------------------
Date: Tue, 05 Aug 2008 13:14:18 GMT
From: Peter Scott <Peter@PSDT.com>
Subject: Re: bidding advice for a contract
Message-Id: <pan.2008.08.05.13.14.18.142101@PSDT.com>
On Mon, 04 Aug 2008 14:36:32 -0700, cartercc wrote:
> This is a big player in a small but critical industry. There aren't
> many who build electronics to put into aircraft, missles, spacecraft,
> and bombs, which is why I don't want to mention names.
If this company really is 'big' in that industry then they most certainly
are used to issuing time and materials contracts, and the person who told
you otherwise is either a rank newcomer or trying to play you. Either
way, don't show them that *you* are a rank newcomer to the supplier side.
How can you possibly agree to a six week task when the specifications are
so loose that it might be a six month task? I don't know what you're
hoping to get out of this when the way you're going about it, they may
not only not pay you but claim damages for non-performance by the time the
dust settles.
--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/
------------------------------
Date: Tue, 5 Aug 2008 07:20:50 -0700 (PDT)
From: cartercc <cartercc@gmail.com>
Subject: Re: bidding advice for a contract
Message-Id: <ac8bd263-7961-4280-a99f-e84374be56a2@f63g2000hsf.googlegroups.com>
On Aug 5, 9:14 am, Peter Scott <Pe...@PSDT.com> wrote:
> If this company really is 'big' in that industry then they most certainly
> are used to issuing time and materials contracts, and the person who told
> you otherwise is either a rank newcomer or trying to play you. Either
> way, don't show them that *you* are a rank newcomer to the supplier side.
I've been there and talked to the management staff. I've seen what
they do. They are focused on their product but their record keeping is
mostly manual. The literally keep track of inventory and purchases on
yellow pads. The use Excel to track testing data but have no security
or logging, so they can't tell who made what entry. They have a real
need and they know it. The problem is that they are trying to do the
requirements engineering themselves and they don't have the backgroud,
despite their expertise and talents in other areas.
> How can you possibly agree to a six week task when the specifications are
> so loose that it might be a six month task? I don't know what you're
> hoping to get out of this when the way you're going about it, they may
> not only not pay you but claim damages for non-performance by the time the
> dust settles.
I'm hoping to do a good job and be paid for it. You and I both know
that the initial plans will change after the first week, but they are
convinced that they can waterfall their way to success. I want the
contract but I'm going to have to present something that will attract
the client while at the same time protect myself.
Besides, if they have a problem, others might have the same problem,
and I might be able to leverage a good solution for this client into
work for others. I've asked them what their competitors do, and
apparently this industry is so specialized that they all mostly use
manual methods or the standard Office applications. Seemlingly there
is no COTS solution available to them. It would be nice to be able to
do the work one time and get paid for it multiple times.
CC
------------------------------
Date: Tue, 5 Aug 2008 08:24:30 -0700 (PDT)
From: wes.tibular@yahoo.com
Subject: Re: bidding advice for a contract
Message-Id: <b1f5834b-29ad-41cb-bc54-fcb726fdad35@a21g2000prf.googlegroups.com>
On Aug 4, 11:48=A0am, cartercc <carte...@gmail.com> wrote:
>
> They have specified a database to track (1) purchasing, (2)
> manufacturing, (3) inventory control, (4) user specified enhancements,
> and (5) full documentation, and have specified a contract end date of
> September 24, 2008 by whch all work would be finished and the project
> would be delivered. They will not have their requirements
> specification until August 13, and based on my previous conversations,
> their requirements documents will probably be less than a page in
> length with very general, ambiguous specifications.
>
>
> Is there a better way to handle this? I really would like the work,
> but I don't want to lock myself in to an impossible position. Does
> anyone have a form contract that I could look at that provides
> appropriate protections?
>
> Thanks, CC.
As others have said, you might want to walk away from this. The last
time I saw this sort of situation (generalized requirements, short
timeframe for the features listed, lack of defined infrastructure), it
was put out to bid because the company had already chosen who they
wanted for the work, and their by-laws or some other constraint
required competitive bids.
Not saying that is what is happening here, as you say they have a good
reputation, but it is always a possibility and something you might
consider.
Further, even though the dates they indicate show a 6 week project,
they may skid on those requirements, and will not be likely to allow
you to skid on the deliverable. Each week you spend in development
might require a similar amount of time in documentation (Fully
documented is a red-flag term unless better defined in the
requirements), so this might be a rather ambitious project timeline
unless you already have a lot of experience in developing just what
they are looking for, and already have something on tap that you can
modify for their purposes.
------------------------------
Date: Tue, 5 Aug 2008 09:29:12 -0700 (PDT)
From: cartercc <cartercc@gmail.com>
Subject: Re: bidding advice for a contract
Message-Id: <95fd3f35-bafd-48da-8796-43428ffe144f@f36g2000hsa.googlegroups.com>
On Aug 5, 11:24 am, wes.tibu...@yahoo.com wrote:
> As others have said, you might want to walk away from this. The last
> time I saw this sort of situation (generalized requirements, short
> timeframe for the features listed, lack of defined infrastructure), it
> was put out to bid because the company had already chosen who they
> wanted for the work, and their by-laws or some other constraint
> required competitive bids.
Thanks for your input.
I know the other two guys bidding on the contract. The 'requirements'
were sent by email with copies to everyone, including those who
expressed an interest in bidding. To me, this is an indicator of the
inexperience of the client which facilitates collusion among the
bidders. I'm satisfied that this is a legitimate process to address a
serious problem.
> Not saying that is what is happening here, as you say they have a good
> reputation, but it is always a possibility and something you might
> consider.
After reading these comments and talking with some other people, I'm
beginning to see some politics. The owner of the company is currently
on vacation during this process, and this effort is being headed up by
(essentially) third tier management, so I'm guessing he gave
instructions before he left and the instructees are making a valient
effort to complete the instructions before he returns. Hence the lack
of detailed requirements.
> Further, even though the dates they indicate show a 6 week project,
> they may skid on those requirements, and will not be likely to allow
> you to skid on the deliverable. Each week you spend in development
> might require a similar amount of time in documentation (Fully
> documented is a red-flag term unless better defined in the
> requirements), so this might be a rather ambitious project timeline
> unless you already have a lot of experience in developing just what
> they are looking for, and already have something on tap that you can
> modify for their purposes.
I do this sort of thing for a living, already having a full time job,
so I have a substantial code base already. It's not like I'll be
writing this from scratch. Still, it's my experience that a project
like this will stretch over a period of years. The last project I did
similar to this one was in development for over two years, always in a
state of flux due to changing requirements, even though the first cut
was fully functional a week or two after I started.
If you want a prebuilt solution, use something like Access,
Quickbooks, etc. Buy it and adapt your business processes to the needs
of the software. You will have a working solution immediately. If you
want a custom solution that you can adapt to meet your business needs,
don't expect to have an immediate solution. One problem here might be
the desire to combine the benefits of a pre-built solution (immediacy)
with the benefits of a custom solution (customizability).
Remember? Good, fast, cheap: choose any two.
CC
------------------------------
Date: Tue, 05 Aug 2008 11:01:40 -0000
From: Justin C <justin.0805@purestblue.com>
Subject: Re: CLPM - a help group?
Message-Id: <23b6.48983314.df390@zem>
On 2008-08-04, sln@netherlands.com <sln@netherlands.com> wrote:
>
> This seems like the perfect place for me.
> I will use this group as a repository to dump large scale code into.
>
> How far back are the posts saved?
I think your first step would be to go and find out what usenet is, it
doesn't seem that you are quite sure. Until you know, I don't know how
you can be sure that this newsgroup is the place to 'dump large scale
code'.
Justin.
--
Justin C, by the sea.
------------------------------
Date: Tue, 05 Aug 2008 13:16:22 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: CLPM - a help group?
Message-Id: <t5qdncHzZYs62QXVnZ2dnUVZ8trinZ2d@posted.plusnet>
cartercc wrote:
> On Aug 2, 7:09 pm, brian d foy <brian.d....@gmail.com> wrote:
>> People post the thoughtful stuff in blogs now, so you don't see much of
>> that in usenet anymore.
>
> I've had the bad experience several times now of seeing news groups
> trashed and driving people away. It seems like a good idea to have a
> general discussion area for topics, but there seems to be a Gresham's
> law for usenet -- over time the bad posters kill the group.
>
> The reason I don't like blogs is because I haven't found a way to do a
> centralized search. You can find a blog anywhere, or not.
Indeed; and if there are (e.g.) 5 wise people
you need to search 5 blogs.
BugBear
------------------------------
Date: Tue, 5 Aug 2008 07:15:43 -0700 (PDT)
From: Theresa <merridian74@gmail.com>
Subject: Expression Parsing Help Needed
Message-Id: <e704a86f-28c2-4925-b33a-5f03d4094dc2@y21g2000hsf.googlegroups.com>
I think this is close, but I don't quite understand this well enough
to build the expression I need to build. It is something I ran across
in existing code, need to modify, but have had no prior experience
doing. I found and have been using the following documentation to
help me experiment. http://support.alphasoftware.com/alphafivehelp/Xbasic/O=
verview_of_Regular_Expressions_marketing.htm
Here's the senario...
Let=92s say I have the following input strings:
"ACCT Gold-P4 Mainframe - Germany Europe/Middle"
"ACCT Gold-P1 Unix-AIX-Linux - France Europe/Middle"
"ACCT Silver-P4 Database Infra Support client system - Germany Europe/
Middle"
I want to grab the portion of the string beginning after the P1/P4 and
ending with =93 =96 =93. More specifically, I need to grab:
"Mainframe"
"Unix-AIX-Linux"
"Database Infra Support client system"
(There are thousands of other potential values, but these 3
demonstrate the basic diversity I could expect.)
This is how I parsed everything up to and including P4/P1 (no problems
with this part):
"[^ ]* [^-]*-[^ ]*=85
But being new at this, I am unable to come up with a parsing
expression that successfully grabs those 3 different phrase
possibilities. This is the closest I've come (though I've tried many
other possibilities):
"[^ ]* [^-]*-[^ ]* ([^(?: - )*]*)(?: - )*.*"
Note: The =93(?: - )=94 portion is using =93non-marking parenthesis=94 so t=
hat
it doesn=92t spit out another sub-expression. Is that necessary? I'm
not sure, I just know it didn't work if I used parenthesis that
weren't non-marking. But, this returns:
=93Mainframe=94 great!
=93Unix-AIX-Linux=94 great!
=93Database=94 BAD!!! Truncates value "Database Infra Support
client system"
I have tinkered and tinkered, but without a thorough understanding of
the expression parsing syntax (the documentation tells what but not
why - and the "why" of it all is important for me to grasp it fully),
I'm unable to complete the parsing expression properly.
Any help would be greatly appreciated,
Theresa
------------------------------
Date: Tue, 05 Aug 2008 17:12:11 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: Expression Parsing Help Needed
Message-Id: <pPidnWzow7lG5gXVnZ2dnUVZ8qGdnZ2d@posted.plusnet>
Theresa wrote:
> I think this is close, but I don't quite understand this well enough
> to build the expression I need to build. It is something I ran across
> in existing code, need to modify, but have had no prior experience
> doing. I found and have been using the following documentation to
> help me experiment. http://support.alphasoftware.com/alphafivehelp/Xbasic/Overview_of_Regular_Expressions_marketing.htm
>
> Here's the senario...
> Let’s say I have the following input strings:
>
> "ACCT Gold-P4 Mainframe - Germany Europe/Middle"
> "ACCT Gold-P1 Unix-AIX-Linux - France Europe/Middle"
> "ACCT Silver-P4 Database Infra Support client system - Germany Europe/
> Middle"
>
> I want to grab the portion of the string beginning after the P1/P4 and
> ending with “ – “. More specifically, I need to grab:
Good spec.
/(P1|P4)(.*)( - )/
$2 should have what you want. $1 and $3 are uninteresting.
BugBear
------------------------------
Date: Tue, 5 Aug 2008 17:16:14 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Expression Parsing Help Needed
Message-Id: <evamm5-qd5.ln1@osiris.mauzo.dyndns.org>
Quoth Theresa <merridian74@gmail.com>:
> I think this is close, but I don't quite understand this well enough
> to build the expression I need to build. It is something I ran across
> in existing code, need to modify, but have had no prior experience
> doing. I found and have been using the following documentation to
> help me experiment. http://support.alphasoftware.com/alphafivehelp/Xbasic/O=
> verview_of_Regular_Expressions_marketing.htm
If you're using Perl's regular expressions, you would be better off
reading Perl's documentation (start with perldoc perlretut). (If you're
not using Perl, why are you asing here?)
> Here's the senario...
> Let=92s say I have the following input strings:
Please don't post quoted-printable content here. Stick to ASCII or (if
you must) un-encoded UTF8.
> "ACCT Gold-P4 Mainframe - Germany Europe/Middle"
> "ACCT Gold-P1 Unix-AIX-Linux - France Europe/Middle"
> "ACCT Silver-P4 Database Infra Support client system - Germany Europe/
> Middle"
>
> I want to grab the portion of the string beginning after the P1/P4 and
> ending with =93 =96 =93. More specifically, I need to grab:
> "Mainframe"
> "Unix-AIX-Linux"
> "Database Infra Support client system"
> (There are thousands of other potential values, but these 3
> demonstrate the basic diversity I could expect.)
>
> This is how I parsed everything up to and including P4/P1 (no problems
> with this part):
> "[^ ]* [^-]*-[^ ]*=85
>
> But being new at this, I am unable to come up with a parsing
> expression that successfully grabs those 3 different phrase
> possibilities. This is the closest I've come (though I've tried many
> other possibilities):
> "[^ ]* [^-]*-[^ ]* ([^(?: - )*]*)(?: - )*.*"
^^^^^^^
This is not valid (or rather, it doesn't mean what you think). Character
classes *only* contain a list of characters (with special meanings for
'^' and '-'), not general expressions. You seem to be trying to use [^ ]
as a general 'don't match this' operator: that's not how it works.
I would write /-P\d+ (.*?) - / unless the 'P4' isn't necessarily a 'P',
in which case I would write /\w+-\w+ (.*?) - /. The ? on the end of .*?
is important: it says 'match as little as possible, provided the next
bit of the pattern will match'.
Ben
--
I touch the fire and it freezes me, [ben@morrow.me.uk]
I look into it and it's black.
Why can't I feel? My skin should crack and peel---
I want the fire back... BtVS, 'Once More With Feeling'
------------------------------
Date: Tue, 05 Aug 2008 09:35:11 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: Expression Parsing Help Needed
Message-Id: <050820080935118026%jimsgibson@gmail.com>
In article
<e704a86f-28c2-4925-b33a-5f03d4094dc2@y21g2000hsf.googlegroups.com>,
Theresa <merridian74@gmail.com> wrote:
> I think this is close, but I don't quite understand this well enough
> to build the expression I need to build. It is something I ran across
> in existing code, need to modify, but have had no prior experience
> doing. I found and have been using the following documentation to
> help me experiment.
> http://support.alphasoftware.com/alphafivehelp/Xbasic/Overview_of_Regular_Expr
> essions_marketing.htm
>
> Here's the senario...
> Let’s say I have the following input strings:
>
> "ACCT Gold-P4 Mainframe - Germany Europe/Middle"
> "ACCT Gold-P1 Unix-AIX-Linux - France Europe/Middle"
> "ACCT Silver-P4 Database Infra Support client system - Germany Europe/
> Middle"
>
> I want to grab the portion of the string beginning after the P1/P4 and
> ending with “ – “. More specifically, I need to grab:
> "Mainframe"
> "Unix-AIX-Linux"
> "Database Infra Support client system"
> (There are thousands of other potential values, but these 3
> demonstrate the basic diversity I could expect.)
Try this:
if( $string =~ m{ \A ACCT \s+ (?:Gold|Silver) - P\d \s+ (.*) \s+ - }x
) {
# process what is in $1
}
--
Jim Gibson
------------------------------
Date: Tue, 05 Aug 2008 17:39:34 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: Expression Parsing Help Needed
Message-Id: <48988246$0$2918$fa0fcedb@news.zen.co.uk>
bugbear wrote:
> Theresa wrote:
>> I think this is close, but I don't quite understand this well enough
>> to build the expression I need to build. It is something I ran across
>> in existing code, need to modify, but have had no prior experience
>> doing. I found and have been using the following documentation to
>> help me experiment.
>> http://support.alphasoftware.com/alphafivehelp/Xbasic/Overview_of_Regular_Expressions_marketing.htm
>>
>>
>> Here's the senario...
>> Let’s say I have the following input strings:
>>
>> "ACCT Gold-P4 Mainframe - Germany Europe/Middle"
>> "ACCT Gold-P1 Unix-AIX-Linux - France Europe/Middle"
>> "ACCT Silver-P4 Database Infra Support client system - Germany Europe/
>> Middle"
>>
>> I want to grab the portion of the string beginning after the P1/P4 and
>> ending with “ – “. More specifically, I need to grab:
>
> Good spec.
>
> /(P1|P4)(.*)( - )/
>
> $2 should have what you want. $1 and $3 are uninteresting.
>
Why capture 1 and 3?
/P[14](.*) - /
Just my ¤0.02 worth.
--
RGB
------------------------------
Date: Tue, 5 Aug 2008 16:54:49 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: FAQ 4.61 How can I always keep my hash sorted?
Message-Id: <9n9mm5-7k3.ln1@osiris.mauzo.dyndns.org>
Quoth xhoster@gmail.com:
> Ben Morrow <ben@morrow.me.uk> wrote:
> >
> > 'tie' is provided so you can create a hash that is built any way you
> > like, and with the appropriate application of XS and magic you can even
> > make it as efficient as the builtin hashes.
>
> Are there working examples of this? I've thought it would be nice to have
> perl's own hash implementation copied from the guts and put into a tie able
> XS module, for playing around purposes.
Well, you can look at the source for threads::shared (which is where I
learned the idea), but be prepared to run away screaming :).
Basically: magic SVs have a vtable associated with them, which contains
functions that are called on get, set, &c. In older versions of perl,
there were a fixed list of possible vtables, denoted by 'magic type':
these are more-or-less equivalent to 'classes' in OO terms. So there was
a 'tainting' vtable, that did taint checks, a '%ENV' vtable, that looked
up values in %ENV, a 'tied' vtable, that called the tie mathods, and so
on.
With 5.8, it is possible to specify your own vtable, so you can have
'tie' magic that doesn't actually call the tie methods at all, and just
makes a direct call into your C implementation instead of using the perl
hash function. Unfortunately, there aren't slots in the vtable for the
hash and array methods (FIRSTKEY, NEXTKEY, PUSH, POP, &c.) and the
functions in hv.c and av.c call the methods directly, so those
operations still have to be done with (XS, if you like) methods.
Ben
--
If you put all the prophets, | You'd have so much more reason
Mystics and saints | Than ever was born
In one room together, | Out of all of the conflicts of time.
ben@morrow.me.uk The Levellers, 'Believers'
------------------------------
Date: Tue, 05 Aug 2008 12:59:06 GMT
From: Peter Scott <Peter@PSDT.com>
Subject: Re: highly restrictive sub-classing
Message-Id: <pan.2008.08.05.12.59.05.826522@PSDT.com>
On Mon, 04 Aug 2008 16:56:29 +0000, xhoster wrote:
> I have a lot of scripts that use a memory-hungry module, but most of them
> use only a small subset of that module's features, and it should be
> possible to implement that subset in a more memory efficient way.
>
> I want to "subclass" the memory hungry module. Many of the methods, ones
> which are rarely used and can't be made memory efficient, will not be
> implemented in the subclass.
Sounds like a job for AutoSplit/AutoLoader.
--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/
------------------------------
Date: Tue, 5 Aug 2008 16:30:20 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Sort using reference to subroutine name?
Message-Id: <c98mm5-7q2.ln1@osiris.mauzo.dyndns.org>
Quoth "Hein, Nashua NH" <heinvandenheuvel@gmail.com>:
> On Aug 4, 11:49 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> > Quoth "Hein, Nashua NH" <heinvandenheu...@gmail.com>:
> >
> > > I have function which I'd like to call telling it how to sort some arrays.
> :
> > > my $sort_function = $_[0]->();
>
> > Why are you doing this? (What did you think it would do for you?) I'm
> > fairly sure you just want
> >
> > my $sort_function = $_[0];
>
> I tried that first, but it didn't work for me.
> So I check some pod pages and googles around to find that suggestion
> in:
> http://www.perlmonks.org/index.pl?node_id=680130
Hmm, there's some *seriously* bad advice on that page :). I think what
you're not understanding is that $_[0]->() calls the function once,
before you even start sorting: that's not what you want to do. You want
to call the function *during* the sort, for each comparison, so you need
to pass the actual function into sort somehow, not its return value.
> > foreach (sort $sort_function keys %some_array) {
>
> > {$sort_function} will attempt to sort with a sub that returns
> > $sort_function every time, which is unlikely to be successful.
>
> Yeah, that is probably critical, but I'm not sure I entirely undestand
> that.
> I had tried putting a debug "print qq(in sort $a $b\n)" withing the
> function indeed showed undefs for $a and $b :-(
If you call sort with a block, like
sort { STATEMENTS } LIST;
then the STATEMENTS are compiled into a new anonymous sub. It's almost
exactly the same as
my $sub = sub { STATEMENTS };
sort $sub LIST;
or even
sub sort_sub { STATEMENTS }
sort sort_sub LIST;
except that sort blocks are very slightly more efficient than ordinary
anon subs. What you had,
my $sub = sub { STATEMENTS };
sort { $sub } LIST;
is then trying to sort using a sub which returns the same subref for
every comparison: $sub is never even called, so your carefully
constructed comparison subs become useless :). You could write a sort
block that explicitly calls the sub:
my $sub = sub { STATEMENTS };
sort { $sub->() } LIST;
but that's really just a waste of time: if all your sort sub is going to
do is call another function, you might as well pass that function to
sort directly.
> > Note that the sort function will need to be compiled into the package
> > that is current when 'sort' is called (or you could use the
> > ($$)-prototyped variant, but that's both slow and obscure) as otherwise
> > $a and $b won't work.
>
> That sounds like my problem.
No, it doesn't. I was talking about the case where you have
package Foo;
my $sub = sub { $a <=> $b };
package Bar;
my @list = sort $sub 2, 3, 1;
in which case sort is setting $Bar::a and $Bar::b, while the sub is
looking at $Foo::a and $Foo::b, so no useful comparisons get done (but
for a different reason from before). This would only be a problem if you
were passing in sort subs from a different package, which your example
code wasn't doing.
> > I'm not quite sure why you're doing this: why not just pass a ref to the
> > hash to sort by, and then use something like
>
> Because I was thinking of various other sort funtions, not just
> varying by hash.
OK, that makes sense.
> > Don't call subs with & unless you know what it does, and what it does is
> > what you want (hint: it probably isn't).
>
> I more or less know that, but got carried away in trying almost random
> solutions for my sort challenge, as reasoned (flawed reasoning :-)
> solutions did not work.
When you're lost, randomly trying things is *very* rarely helpful.
Re-reading the docs, adding 'warn' statements so you can see what is
actually going on, and (eventually) posting to Usenet are much more
likely to produce useful results :).
Ben
--
Raise your hand if you're invulnerable.
[ben@morrow.me.uk]
------------------------------
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 V11 Issue 1770
***************************************