[30326] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1569 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 22 21:18:40 2008

Date: Thu, 22 May 2008 18:09:15 -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, 22 May 2008     Volume: 11 Number: 1569

Today's topics:
    Re: creating directory before a module is loaded. <spamtrap@dot-app.org>
    Re: creating directory before a module is loaded. <ben@morrow.me.uk>
    Re: creating directory before a module is loaded. <spamtrap@dot-app.org>
    Re: maintaining order in a hash (without Tie::IxHash) sln@netherlands.co
    Re: maintaining order in a hash (without Tie::IxHash) <simon.chao@fmr.com>
    Re: maintaining order in a hash (without Tie::IxHash) <uri@stemsystems.com>
    Re: maintaining order in a hash (without Tie::IxHash) <uri@stemsystems.com>
    Re: maintaining order in a hash (without Tie::IxHash) <simon.chao@fmr.com>
    Re: maintaining order in a hash (without Tie::IxHash) <glex_no-spam@qwest-spam-no.invalid>
    Re: maintaining order in a hash (without Tie::IxHash) <spamtrap@dot-app.org>
    Re: maintaining order in a hash (without Tie::IxHash) <simon.chao@gmail.com>
    Re: maintaining order in a hash (without Tie::IxHash) <szrRE@szromanMO.comVE>
    Re: maintaining order in a hash (without Tie::IxHash) <szrRE@szromanMO.comVE>
    Re: maintaining order in a hash (without Tie::IxHash) <simon.chao@gmail.com>
    Re: maintaining order in a hash (without Tie::IxHash) <1usa@llenroc.ude.invalid>
    Re: maintaining order in a hash (without Tie::IxHash) <simon.chao@gmail.com>
    Re: maintaining order in a hash (without Tie::IxHash) sln@netherlands.co
    Re: maintaining order in a hash (without Tie::IxHash) <1usa@llenroc.ude.invalid>
    Re: Perl 6 <@ .invalid>
    Re: Perl 6 <spamtrap@dot-app.org>
        Range of number <david.hunter@gmail.com>
    Re: Range of number <cwilbur@chromatico.net>
    Re: Range of number <simon.chao@fmr.com>
    Re: using m//g to parse multi-line records without an o <noreply@gunnar.cc>
    Re: using m//g to parse multi-line records without an o <someone@example.com>
    Re: using m//g to parse multi-line records without an o <jimsgibson@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 22 May 2008 16:25:48 -0400
From: Sherman Pendley <spamtrap@dot-app.org>
Subject: Re: creating directory before a module is loaded.
Message-Id: <m1hccqt7ar.fsf@dot-app.org>

gsa <hsggwk@gmail.com> writes:

> How do I
> tell mainCode.cgi to create a directory before it loads example.pm?

Place the code to create the directory in a BEGIN block that's above the
"use example" statement:

    BEGIN {
        my $dirname = '/whatever';
        mkdir($dirname) or die("Could not create $dirname: $!");
    }
    use example;

Have a look at "perldoc perlmod" for details about BEGIN and other special
code blocks.

sherm--

-- 
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net


------------------------------

Date: Thu, 22 May 2008 22:59:05 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: creating directory before a module is loaded.
Message-Id: <9u6hg5-cdf.ln1@osiris.mauzo.dyndns.org>


Quoth gsa <hsggwk@gmail.com>:
> Hi all,
>        Thanks for your responses. Here is part of my test code.
> 
> testInline.pl
> ---------------
> #!/usr/bin/perl -
> w
> use strict;
> use lib './libPvalueCalculation';
> use pvalueCalculation;
> 
> BEGIN {
>     my $return= `mkdir /tmp/RAP/test`;
>     print "return: $return\n";
> }

No, the BEGIN block needs to come *before* you load the module, and you
want to 'die' if you can't create the directory.

Ben

-- 
  The cosmos, at best, is like a rubbish heap scattered at random.
                                                           Heraclitus
  ben@morrow.me.uk


------------------------------

Date: Thu, 22 May 2008 19:44:24 -0400
From: Sherman Pendley <spamtrap@dot-app.org>
Subject: Re: creating directory before a module is loaded.
Message-Id: <m1lk21sy3r.fsf@dot-app.org>

Ben Morrow <ben@morrow.me.uk> writes:

> you want to 'die' if you can't create the directory.

That's a bit of an overreaction, don't you think? It'd be quite good enough
for the *program* to die. :-)

sherm--

-- 
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net


------------------------------

Date: Thu, 22 May 2008 13:22:28 -0700
From: sln@netherlands.co
Subject: Re: maintaining order in a hash (without Tie::IxHash)
Message-Id: <69lb349rl94blcsh0uth9vb0j043peoojs@4ax.com>

On Thu, 22 May 2008 10:20:17 -0700 (PDT), nolo contendere <simon.chao@fmr.com> wrote:

>Many times, there exists a module on CPAN that solves a problem I'm
>attempting to solve.
>I'm aware that generally the better choice to solving such a problem
>is to use the CPAN module.
>However, regarding the problem of maintaining sort order of a hash,
>and the Tie::IxHash module, I have a question.
>
>I've heard that Tie::IxHash can be a little slow, and the cost of
>using this in addition to installation costs (where developers don't
>have the permission to have modules installed, especially across all
>environments, and the process for having the module(s) installed by
>admins can be trying to say the least) is much higher than the simple
>solution of adding an extra sortval attribute to a hash value, where
>the value of sortval is simply an incremented counter.
>
>then if you need to access the hash in the order in which items were
>inserted, you could simply:
>
>for my $key ( sort { $hash{$a}{sortval} <=> $hash{$b}{sortval} } keys
>%hash ) {
>    # do something
>}
>
>
>Is there something wrong with my reasoning? Would this solution be a
>good candidate for addition into the FAQ How can I make my hash
>remember the order I put elements
>          into it?
>

Why is it so important to have a hash sorted?
What would a hash be necessary for then?

Wouldn't an array be better in that case?



------------------------------

Date: Thu, 22 May 2008 13:26:57 -0700 (PDT)
From: nolo contendere <simon.chao@fmr.com>
Subject: Re: maintaining order in a hash (without Tie::IxHash)
Message-Id: <9b56c529-e039-4cb9-b079-2b190d7d8a4f@k13g2000hse.googlegroups.com>

On May 22, 4:22=A0pm, s...@netherlands.co wrote:
> On Thu, 22 May 2008 10:20:17 -0700 (PDT), nolo contendere <simon.c...@fmr.=
com> wrote:
> >Many times, there exists a module on CPAN that solves a problem I'm
> >attempting to solve.
> >I'm aware that generally the better choice to solving such a problem
> >is to use the CPAN module.
> >However, regarding the problem of maintaining sort order of a hash,
> >and the Tie::IxHash module, I have a question.
>
> >I've heard that Tie::IxHash can be a little slow, and the cost of
> >using this in addition to installation costs (where developers don't
> >have the permission to have modules installed, especially across all
> >environments, and the process for having the module(s) installed by
> >admins can be trying to say the least) is much higher than the simple
> >solution of adding an extra sortval attribute to a hash value, where
> >the value of sortval is simply an incremented counter.
>
> >then if you need to access the hash in the order in which items were
> >inserted, you could simply:
>
> >for my $key ( sort { $hash{$a}{sortval} <=3D> $hash{$b}{sortval} } keys
> >%hash ) {
> > =A0 =A0# do something
> >}
>
> >Is there something wrong with my reasoning? Would this solution be a
> >good candidate for addition into the FAQ How can I make my hash
> >remember the order I put elements
> > =A0 =A0 =A0 =A0 =A0into it?
>
> Why is it so important to have a hash sorted?
> What would a hash be necessary for then?
>
> Wouldn't an array be better in that case?

One thing that pops into my head is automatic real-time uniqueness of
elements, another is O(1) lookup.
It's the best of both arrays and hashes.


------------------------------

Date: Thu, 22 May 2008 21:06:02 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: maintaining order in a hash (without Tie::IxHash)
Message-Id: <x7tzgqoxqe.fsf@mail.sysarch.com>

>>>>> "nc" == nolo contendere <simon.chao@fmr.com> writes:

  nc> I understand that in many cases people who bring up ordered hashes
  nc> would be better served by using another data structure, but it seems
  nc> that enough people have asked about this, and it is useful enough to
  nc> have a module written for it on CPAN, and be included in the FAQ. Now
  nc> before you argue that just because lots of people ask about it and it
  nc> is a module doesn't mean that it's useful, don't forget my last caveat
  nc> that it is in the FAQ. Lots of people ask about variable variable
  nc> names too (symrefs, whatever you want to call them), but they are much
  nc> more harmful than useful, and their use is discouraged by the majority
  nc> of knowledgeable Perl hackers out there, and there is no FAQ
  nc> encouraging the use of a module that manages symrefs.

  nc> Also, I don't really see the contradiction of the terms 'sorted' and
  nc> 'hash'. Just because you associate a key with a value, why can't you
  nc> want those pairs ordered?

in another post i explained why sort and hash aren't compatible. you can
hack something together that sorta works but it will always have some
flaw or problem. you may not even run into those problems with any
particular use but when you scale things up stuff will break. hashes
autoresize as needed with insert/delete. arrays do not and neither do
counters. so scaling can cause issues. sorting a special subkey means
you have more overhead in hash accesses by the 'order'. normal key
access with keys() is O(1) so that is another change. it may not
matter. it may if you expect hashes to be very fast. order hashes are
not hashes but a subtly different beast. that is the point we are trying
make. sure you can do it but don't expect it to be a pure hash
anymore. caveat coder.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


------------------------------

Date: Thu, 22 May 2008 21:09:23 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: maintaining order in a hash (without Tie::IxHash)
Message-Id: <x7prreoxkt.fsf@mail.sysarch.com>

>>>>> "nc" == nolo contendere <simon.chao@fmr.com> writes:

  nc> One thing that pops into my head is automatic real-time uniqueness of
  nc> elements, another is O(1) lookup.
  nc> It's the best of both arrays and hashes.

but you don't get that. read my other post. you actually get worse than
either of those if you scale and do lots of adds/deletes.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
--------- Free Perl Training --- http://perlhunter.com/college.html ---------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------


------------------------------

Date: Thu, 22 May 2008 14:50:23 -0700 (PDT)
From: nolo contendere <simon.chao@fmr.com>
Subject: Re: maintaining order in a hash (without Tie::IxHash)
Message-Id: <b220b6f0-9e33-463f-8c89-697d8c8e6273@r66g2000hsg.googlegroups.com>

On May 22, 5:06=A0pm, Uri Guttman <u...@stemsystems.com> wrote:
> >>>>> "nc" =3D=3D nolo contendere <simon.c...@fmr.com> writes:
>
> =A0 nc> I understand that in many cases people who bring up ordered hashes=

> =A0 nc> would be better served by using another data structure, but it see=
ms
> =A0 nc> that enough people have asked about this, and it is useful enough =
to
> =A0 nc> have a module written for it on CPAN, and be included in the FAQ. =
Now
> =A0 nc> before you argue that just because lots of people ask about it and=
 it
> =A0 nc> is a module doesn't mean that it's useful, don't forget my last ca=
veat
> =A0 nc> that it is in the FAQ. Lots of people ask about variable variable
> =A0 nc> names too (symrefs, whatever you want to call them), but they are =
much
> =A0 nc> more harmful than useful, and their use is discouraged by the majo=
rity
> =A0 nc> of knowledgeable Perl hackers out there, and there is no FAQ
> =A0 nc> encouraging the use of a module that manages symrefs.
>
> =A0 nc> Also, I don't really see the contradiction of the terms 'sorted' a=
nd
> =A0 nc> 'hash'. Just because you associate a key with a value, why can't y=
ou
> =A0 nc> want those pairs ordered?
>
> in another post i explained why sort and hash aren't compatible. you can
> hack something together that sorta works but it will always have some
> flaw or problem. you may not even run into those problems with any
> particular use but when you scale things up stuff will break. hashes
> autoresize as needed with insert/delete. arrays do not and neither do
> counters. so scaling can cause issues. sorting a special subkey means
> you have more overhead in hash accesses by the 'order'. normal key
> access with keys() is O(1) so that is another change. it may not
> matter. it may if you expect hashes to be very fast. order hashes are
> not hashes but a subtly different beast. that is the point we are trying
> make. sure you can do it but don't expect it to be a pure hash
> anymore. caveat coder.
>

Caveat Coder? Is that an insult?


------------------------------

Date: Thu, 22 May 2008 17:18:42 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: maintaining order in a hash (without Tie::IxHash)
Message-Id: <4835f142$0$87068$815e3792@news.qwest.net>

nolo contendere wrote:
[...]
> Caveat Coder? Is that an insult?

Someone using a Latin term for their identity that doesn't know what 
caveat means?

Oh, and no that's not an insult either. :-P


------------------------------

Date: Thu, 22 May 2008 18:38:10 -0400
From: Sherman Pendley <spamtrap@dot-app.org>
Subject: Re: maintaining order in a hash (without Tie::IxHash)
Message-Id: <m13aoat165.fsf@dot-app.org>

"A. Sinan Unur" <1usa@llenroc.ude.invalid> writes:

> In any case, the point Uri is making is simple. There is really no good
> excuse not to use CPAN modules.

There is, on the other hand, a seemingly endless supply of bad excuses
for not doing so. :-)

sherm--

-- 
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net


------------------------------

Date: Thu, 22 May 2008 15:56:07 -0700 (PDT)
From: nolo contendere <simon.chao@gmail.com>
Subject: Re: maintaining order in a hash (without Tie::IxHash)
Message-Id: <acf382ba-21a0-40b0-9db5-b0a809f5d8aa@m73g2000hsh.googlegroups.com>

On May 22, 6:18=A0pm, "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
wrote:
> nolo contendere wrote:
>
> [...]
>
> > Caveat Coder? Is that an insult?
>
> Someone using a Latin term for their identity that doesn't know what
> caveat means?
>
> Oh, and no that's not an insult either. :-P

I know what caveat means, I was more shocked at the name-calling. I
asked what I thought was a reasonable question, cited the FAQ, posted
working code, answered questions, and yet got insulted. Wouldn't you
be a little incredulous? It was completely uncalled for, not
constructive, and downright rude. And I HAVE posted help here, so
according to Uri's logic, DO get a say.

Jeez!


------------------------------

Date: Thu, 22 May 2008 16:02:43 -0700
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: maintaining order in a hash (without Tie::IxHash)
Message-Id: <g14u2k01sqh@news4.newsguy.com>

Jürgen Exner wrote:
> nolo contendere <simon.chao@fmr.com> wrote:
>> However, regarding the problem of maintaining sort order of a hash,
>> and the Tie::IxHash module, I have a question.
[...]
> If you are trying to force an order on a hash then probably you are
> using the wrong data structure in the first place and you would be
> better off using an array.

If one wants to use a hash && maintain order, just keep an array of 
(desired) @fields and use a construct along the lines of:

   foreach my $data (@hash{@fields}) { ... }
   foreach my $field (sort @fields) { my $data = $hash{$field}; ... }

Or:

   my @data = @hash{@fields};

To sort in a particular order, one need only sort the @fields array.

-- 
szr 




------------------------------

Date: Thu, 22 May 2008 16:05:57 -0700
From: "szr" <szrRE@szromanMO.comVE>
Subject: Re: maintaining order in a hash (without Tie::IxHash)
Message-Id: <g14u8m01svc@news4.newsguy.com>

sln@netherlands.co wrote:
> On Thu, 22 May 2008 10:20:17 -0700 (PDT), nolo contendere
> <simon.chao@fmr.com> wrote:
[...]
>> Is there something wrong with my reasoning? Would this solution be a
>> good candidate for addition into the FAQ How can I make my hash
>> remember the order I put elements
>>          into it?
>>
>
> Why is it so important to have a hash sorted?
> What would a hash be necessary for then?
>
> Wouldn't an array be better in that case?

You don't sort the hash. You sort an array containing fields/keys from 
the hash:

   my @fields = sort { ... } keys %hash;
   ...
   foreach my $field (@fields) {
      my $item = $hash{$field}
      ...
   }

-- 
szr 




------------------------------

Date: Thu, 22 May 2008 16:20:22 -0700 (PDT)
From: nolo contendere <simon.chao@gmail.com>
Subject: Re: maintaining order in a hash (without Tie::IxHash)
Message-Id: <c75d3641-cf24-4ca6-8fc9-5b714e3a56a6@34g2000hsh.googlegroups.com>

On May 22, 7:05=A0pm, "szr" <sz...@szromanMO.comVE> wrote:
> s...@netherlands.co wrote:
> > On Thu, 22 May 2008 10:20:17 -0700 (PDT), nolo contendere
> > <simon.c...@fmr.com> wrote:
> [...]
> >> Is there something wrong with my reasoning? Would this solution be a
> >> good candidate for addition into the FAQ How can I make my hash
> >> remember the order I put elements
> >> =A0 =A0 =A0 =A0 =A0into it?
>
> > Why is it so important to have a hash sorted?
> > What would a hash be necessary for then?
>
> > Wouldn't an array be better in that case?
>
> You don't sort the hash. You sort an array containing fields/keys from
> the hash:
>
> =A0 =A0my @fields =3D sort { ... } keys %hash;
> =A0 =A0...
> =A0 =A0foreach my $field (@fields) {
> =A0 =A0 =A0 my $item =3D $hash{$field}
> =A0 =A0 =A0 ...
> =A0 =A0}
>

you could just do:

for my $key ( sort keys %hash ) {
    # do something with $hash{$key}
}

=2E..but i was talking about maintaining the insertion order, not
sorting by alpha or number


------------------------------

Date: Thu, 22 May 2008 23:35:38 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: maintaining order in a hash (without Tie::IxHash)
Message-Id: <Xns9AA6C74F2EC6Casu1cornelledu@127.0.0.1>

nolo contendere <simon.chao@gmail.com> wrote in news:acf382ba-21a0-40b0-
9db5-b0a809f5d8aa@m73g2000hsh.googlegroups.com:

> On May 22, 6:18 pm, "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>
> wrote:
>> nolo contendere wrote:
>>
>> [...]
>>
>> > Caveat Coder? Is that an insult?
>>
>> Someone using a Latin term for their identity that doesn't know what
>> caveat means?
>>
>> Oh, and no that's not an insult either. :-P
> 
> I know what caveat means, I was more shocked at the name-calling. I
> asked what I thought was a reasonable question, cited the FAQ, posted
> working code, answered questions, and yet got insulted. Wouldn't you
> be a little incredulous? It was completely uncalled for, not
> constructive, and downright rude.

I am sorry, I fail to see the insult. The word caveat is simply latin 
for "beware". So, "caveat coder" means is a warning to the coder (in 
this case you) that things are not as straightforward as they seem and 
some of your statements are not necessarily valid.

Looking at it in context, Uri said:

    	sure you can do it but don't expect it to 
    	be a pure hash anymore. caveat coder.

There is no insult. None. Zero. Zilch. Nil. 
http://en.wiktionary.org/wiki/s%C4%B1f%C4%B1r.

> And I HAVE posted help here, so according to Uri's logic, 
> DO get a say.
> 
> Jeez!

Jeez indeed. You do have a say. You made some claims of dubious validity 
and posted some code of dubious utility. These issues were discussed 
rigorously. I cannot find anything in this thread that could be 
construed as an insult to you.

Sinan

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/


------------------------------

Date: Thu, 22 May 2008 16:49:27 -0700 (PDT)
From: nolo contendere <simon.chao@gmail.com>
Subject: Re: maintaining order in a hash (without Tie::IxHash)
Message-Id: <bd0a63b4-2604-4259-8910-78e99bf623e9@p25g2000hsf.googlegroups.com>

On May 22, 7:35=A0pm, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
> nolo contendere <simon.c...@gmail.com> wrote in news:acf382ba-21a0-40b0-
> 9db5-b0a809f5d...@m73g2000hsh.googlegroups.com:
>
>
>
> > On May 22, 6:18=A0pm, "J. Gleixner" <glex_no-s...@qwest-spam-no.invalid>=

> > wrote:
> >> nolo contendere wrote:
>
> >> [...]
>
> >> > Caveat Coder? Is that an insult?
>
> >> Someone using a Latin term for their identity that doesn't know what
> >> caveat means?
>
> >> Oh, and no that's not an insult either. :-P
>
> > I know what caveat means, I was more shocked at the name-calling. I
> > asked what I thought was a reasonable question, cited the FAQ, posted
> > working code, answered questions, and yet got insulted. Wouldn't you
> > be a little incredulous? It was completely uncalled for, not
> > constructive, and downright rude.
>
> I am sorry, I fail to see the insult. The word caveat is simply latin
> for "beware". So, "caveat coder" means is a warning to the coder (in
> this case you) that things are not as straightforward as they seem and
> some of your statements are not necessarily valid.
>
> Looking at it in context, Uri said:
>
> =A0 =A0 =A0 =A0 sure you can do it but don't expect it to
> =A0 =A0 =A0 =A0 be a pure hash anymore. caveat coder.
>
> There is no insult. None. Zero. Zilch. Nil.http://en.wiktionary.org/wiki/s=
%C4%B1f%C4%B1r.

>
> > And I HAVE posted help here, so according to Uri's logic,
> > DO get a say.
>
> > Jeez!
>
> Jeez indeed. You do have a say. You made some claims of dubious validity
> and posted some code of dubious utility. These issues were discussed
> rigorously. I cannot find anything in this thread that could be
> construed as an insult to you.
>

Ahh, I do think you're right. I interpreted 'caveat' as an adjective
(with a pejorative undertone), when I think Uri may have meant it as
an imperative verb. Apologies for being overly sensitive, Uri.


------------------------------

Date: Thu, 22 May 2008 17:09:03 -0700
From: sln@netherlands.co
Subject: Re: maintaining order in a hash (without Tie::IxHash)
Message-Id: <de2c345ug67uut4q4m89hstoicvb1mf2rj@4ax.com>

On Thu, 22 May 2008 13:22:28 -0700, sln@netherlands.co wrote:

>On Thu, 22 May 2008 10:20:17 -0700 (PDT), nolo contendere <simon.chao@fmr.com> wrote:
>
>>Many times, there exists a module on CPAN that solves a problem I'm
>>attempting to solve.
>>I'm aware that generally the better choice to solving such a problem
>>is to use the CPAN module.
>>However, regarding the problem of maintaining sort order of a hash,
>>and the Tie::IxHash module, I have a question.
>>
>>I've heard that Tie::IxHash can be a little slow, and the cost of
>>using this in addition to installation costs (where developers don't
>>have the permission to have modules installed, especially across all
>>environments, and the process for having the module(s) installed by
>>admins can be trying to say the least) is much higher than the simple
>>solution of adding an extra sortval attribute to a hash value, where
>>the value of sortval is simply an incremented counter.
>>
>>then if you need to access the hash in the order in which items were
>>inserted, you could simply:
>>
>>for my $key ( sort { $hash{$a}{sortval} <=> $hash{$b}{sortval} } keys
>>%hash ) {
>>    # do something
>>}
>>
>>
>>Is there something wrong with my reasoning? Would this solution be a
>>good candidate for addition into the FAQ How can I make my hash
>>remember the order I put elements
>>          into it?
>>
>
>Why is it so important to have a hash sorted?
>What would a hash be necessary for then?
>
>Wouldn't an array be better in that case?

I see you can pass parameters as arrays and read it as a hash.
I see you can pass parameters as hash and read it as array.

Is that true? If so, why is it important to sort hash?



------------------------------

Date: Fri, 23 May 2008 00:09:13 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: maintaining order in a hash (without Tie::IxHash)
Message-Id: <Xns9AA6CD00EFF77asu1cornelledu@127.0.0.1>

nolo contendere <simon.chao@gmail.com> wrote in
news:bd0a63b4-2604-4259-8910-78e99bf623e9@p25g2000hsf.googlegroups.com: 

> On May 22, 7:35 pm, "A. Sinan Unur" <1...@llenroc.ude.invalid> wrote:
>> nolo contendere <simon.c...@gmail.com> wrote in
>> news:acf382ba-21a0-40b0- 
>> 9db5-b0a809f5d...@m73g2000hsh.googlegroups.com: 
>>
>>
>>
>> > On May 22, 6:18 pm, "J. Gleixner"
>> > <glex_no-s...@qwest-spam-no.invalid> 
> 
>> > wrote:
>> >> nolo contendere wrote:
>>
>> >> [...]
>>
>> >> > Caveat Coder? Is that an insult?

 ...

>> > I know what caveat means, I was more shocked at the name-calling.

 ...

>> I am sorry, I fail to see the insult. The word caveat is simply latin
>> for "beware". So, "caveat coder" means is a warning to the coder (in
>> this case you) that things are not as straightforward as they seem
>> and some of your statements are not necessarily valid.
>>
>> Looking at it in context, Uri said:
>>
>>         sure you can do it but don't expect it to
>>         be a pure hash anymore. caveat coder.

 ...

> Ahh, I do think you're right. I interpreted 'caveat' as an adjective
> (with a pejorative undertone),

Say you tell me you are going to go to Turkey and you want to go 
shopping for rugs. My response to you would be "caveat emptor". That is 
a warning to you to be cautious in your dealings rather than an insult.

As far as "ordered" hashes are concerned, I feel they only slightly less 
dangerous than Turkish carpet salesmen. ;-)

> when I think Uri may have meant it as an imperative verb.

That is the only apparent interpretation to me.

See, when my code is reviewed by Uri, I feel good because I know I have 
just received advice that I could not have found in my immediate circle. 

The same valuation applies to the comments of many others here even when 
they point out embarassing errors I have made.

> Apologies for being overly sensitive, Uri.

I would like to suggest that you avoid being so sensitive to serious 
criticism of your code and ideas and distinguish better among those who 
provide useful input from the rest of the crowd. ;-)

Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/


------------------------------

Date: Thu, 22 May 2008 14:54:53 -0700
From: "Gordon Etly" <@ .invalid>
Subject: Re: Perl 6
Message-Id: <69m8deF337o9qU1@mid.individual.net>

Sherman Pendley wrote:
> Gordon Etly wrote:

> > Yes, one should be appreciative of anyone who offers you help.

> You weren't.

Trying to speak for me now, are you? And who exactly offered *me* help?


> > Many people who receive decent help seem quite thankful.

> You did, and you weren't.

Please get over your self and stop making all these assumptions. So far 
you are wrong on all counts. I was not offered such help, and further, 
this was not about me, so clearly you have missed the entire point 
altogether.


> > What I see happening, though, is some people, who otherwise
> > offer actual help, taking out some frustrations

> You were wrong about "PERL vs. Perl".

Why? Because *you* say so? Do you even *know* what my argument actually 
was? Or are you just going along with the crowd instead of thinking for 
yourself and bothering to actually fully read what you are attempting to 
comment on?


> This grudge of yours, and the constant bitching and moaning

How interesting. My commenting has as always been in response to someone 
else, when I see something I really don't like. There are times with 
people from your crowd actively refer back to subjects that were 
supposedly "closed" already. Uri did this not too long ago, yet I saw no 
one complaining then. He and others join in and complain when I comment 
on someone else's post, yet it's ok for them.

I am not the one carrying any vendetta. I just call 'em out as I see 
'em. I've said it before, and I'll say it again: don't want your posting 
commented on, then please don't post, because that's exactly what you 
are inviting by posting in an open/public forum or newsgroup.


> Seriously. You had a misconception about the name of the language, and

That wasn't what the argument was about. You are falling down the same 
road as other people; assume you know what something was without 
actually bothering to really check. This has become to typical of your 
crowd.


> Or keep whining - I don't care, your latest sock puppet is joining all
> your others in my killfile. *plonk*

"Gordon Etly", my name, is the only name I've ever used, but keep 
believing what you want to believe.


-- 
G.Etly 




------------------------------

Date: Thu, 22 May 2008 19:21:42 -0400
From: Sherman Pendley <spamtrap@dot-app.org>
Subject: Re: Perl 6
Message-Id: <m1prrdsz5l.fsf@dot-app.org>

"Gordon Etly" <@ .invalid> writes:

> Sherman Pendley wrote:
>
>> This grudge of yours, and the constant bitching and moaning
>
> How interesting. My commenting has as always been in response to someone 
> else, when I see something I really don't like.

Precisely - you only comment when you don't like something. Most people
call that bitching and moaning. You're not even *trying* to make a positive
contribution here. You're like a dog pissing on food he doesn't want,
just to make sure the other dogs won't eat it.

> There are times with 
> people from your crowd actively refer back to subjects that were 
> supposedly "closed" already.

Because I believe that subject to be the root cause of your unhappiness
with this group. You started your life here with a simple question based
on a misunderstanding of how TROFF formats man pages - the name of the
language is capitalized at top of "man perl" because that's how *all*
man pages are formatted. If you look at "man sh" you'll see "SH" at the
top too, and "PYTHON" at the top of "man python." The fact that the top
line of a man page is all caps implies *nothing* about the correct name
of the documented tool.

That misunderstanding isn't unreasonable - it's a natural conclusion to
arrive at. The problem arose when several folks pointed out your mistake,
and you launched on a tirade about how "PERL" should be acceptable.

If you had simply said "oops, my bad," you wouldn't be in the doghouse
here. It's your own obnoxious reaction to being corrected that's the source
of your problems getting along with the regulars here, not your misspelling
of the word "Perl."

>> Or keep whining - I don't care, your latest sock puppet is joining all
>> your others in my killfile. *plonk*
>
> "Gordon Etly", my name, is the only name I've ever used

Don't play dumb. I'm talking about your ever-changing email address, and
you damn well know that. You're not even using real addresses - the only
reason you're changing it is to escape from killfiles.

Please - if you hate this group so much, just leave. Or, at least stop
being a hypocrite, telling people to killfile you and then changing your
address just to escape those killfiles and get in everyone's face again.

sherm--

-- 
My blog: http://shermspace.blogspot.com
Cocoa programming in Perl: http://camelbones.sourceforge.net


------------------------------

Date: Thu, 22 May 2008 13:18:42 -0700 (PDT)
From: One <david.hunter@gmail.com>
Subject: Range of number
Message-Id: <cf7d48b1-9b8b-41f5-a89f-cde09dc52c0f@m45g2000hsb.googlegroups.com>

Hi all -

I have a pre-determined low number and a pre-determined high number.
I simply need to know if my variable is within that range, and if so
print YES

I looked at Number::Range but thouhgt it was over kill.

Should I use a regex ?

Thx.




------------------------------

Date: Thu, 22 May 2008 16:25:01 -0400
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: Range of number
Message-Id: <86skwa13z6.fsf@mithril.chromatico.net>

>>>>> "O" == One  <david.hunter@gmail.com> writes:

    O> Hi all - I have a pre-determined low number and a pre-determined
    O> high number.  I simply need to know if my variable is within that
    O> range, and if so print YES

    O> I looked at Number::Range but thouhgt it was over kill.

    O> Should I use a regex ?

Why not just use a conditional expression?

if ($number <= $MAXNUM && $number >= $MINNUM) .....

Charlton




-- 
Charlton Wilbur
cwilbur@chromatico.net


------------------------------

Date: Thu, 22 May 2008 13:33:47 -0700 (PDT)
From: nolo contendere <simon.chao@fmr.com>
Subject: Re: Range of number
Message-Id: <19acdc89-9f10-4f82-967a-302dce4297f0@56g2000hsm.googlegroups.com>

On May 22, 4:18=A0pm, One <david.hun...@gmail.com> wrote:
> Hi all -
>
> I have a pre-determined low number and a pre-determined high number.
> I simply need to know if my variable is within that range, and if so
> print YES
>
> I looked at Number::Range but thouhgt it was over kill.
>
> Should I use a regex ?
>
I wouldn't.

What's wrong with:

my ( $low, $high ) =3D ( 1, 10 );
my $num =3D shift;

# check if $num is defined, and a number, etc..
print "YES\n" if ( $num >=3D $low && $num <=3D $high );



------------------------------

Date: Thu, 22 May 2008 22:35:32 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: using m//g to parse multi-line records without an outside delimiter
Message-Id: <69m3m9F33r9m5U1@mid.individual.net>

Alex Stankevich wrote:

< mbox data snipped >

> I have a data file with multi-line records where the records are
> delimited by some character pattern which is also part of the
> beginning of the record. I'd like to iterate through these records
> while capturing the entire record in a scalar variable.

How about:

     my @msgs;
     my $tmp = <DATA>;
     while (<DATA>) {
         if ( /^From / ) {
             push @msgs, $tmp;
             $tmp = $_;
         } else {
             $tmp .= $_;
         }
     }
     push @msgs, $tmp;

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


------------------------------

Date: Fri, 23 May 2008 00:00:10 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: using m//g to parse multi-line records without an outside delimiter
Message-Id: <eOnZj.4447$KB3.363@edtnps91>

Alex Stankevich wrote:
> undef $/;
> $file = <DATA>;
> 
> print "---using m//g ---\n";
> while ($file =~ /^(From \w+\@xyz.com.*?)(?=^From \w+\@xyz.com)/gms) {
> 	print $1;
> 	print '<' x 60, "\n";
> }

[ SNIP ]

> I'm looking for help with fixing the regex I have in the while loop to
> not leave out the last record in the file, and suggestions for better
> ways of approaching this problem altogether.

while ( $file =~ /^(From \w+\@xyz.com.*?)(?=^From \w+\@xyz.com|\z)/gms ) {


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: Thu, 22 May 2008 17:11:19 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: using m//g to parse multi-line records without an outside delimiter
Message-Id: <220520081711192509%jimsgibson@gmail.com>

In article
<3101a95e-5b38-45eb-81b8-e20f3a1e3559@z72g2000hsb.googlegroups.com>,
Alex Stankevich <astankevich@gmail.com> wrote:

> undef $/;
> $file = <DATA>;
> 
> print "---using split---\n";
> foreach (split /From \w+\@xyz.com/, $file) {
>   print $_;
>   print '<' x 60, "\n";
> }
> 
> 
> __DATA__
> From mail@xyz.com
> Header1: val1
> To: abc@xyz.com
> Subject: bla
> 
> body 1 of the email
> 
> From root@xyz.com
> Header1: val1
> To: abc@xyz.com
> Subject: bla
> 
> body 2 of the email
> 
> From user01@xyz.com
> Header1: val1
> To: abc@xyz.com
> Subject: bla
> 
> body 3 of the email


> The faq and the book suggested the split as another approach, however,
> the problem with it is that I don't know how to capture the string
> which matches it, and because it's part of the record (its beginning),
> I need to retain it.

You can capture the split delimiter by enclosing the delimiter pattern
in parentheses. Since you then have two parts to each record, you might
want to capture everything in an array first (memory permitting):

  my @messages = split( /(From \w+\@xyz.com/), $file);

(further processing left as an exercise.)

-- 
Jim Gibson


------------------------------

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 1569
***************************************


home help back first fref pref prev next nref lref last post