[26216] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8402 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 9 21:05:41 2005

Date: Fri, 9 Sep 2005 18:05:04 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 9 Sep 2005     Volume: 10 Number: 8402

Today's topics:
    Re: Complex data structures and variable scope (Anno Siegel)
    Re: converting a hash where the value is a list of list <jgibson@mail.arc.nasa.gov>
    Re: converting a hash where the value is a list of list <lynn.watts@ugs.com>
        IPC::Shareable Problem with multidimentional hash <scottalordaNOSPAM@libello.com>
    Re: IPC::Shareable Problem with multidimentional hash xhoster@gmail.com
    Re: Replace substring "_.modem_" with modem price from  (Hue-Bond)
    Re: Replace substring "_.modem_" with modem price from  (Anno Siegel)
    Re: script attack <emschwar@pobox.com>
    Re: script attack <no@email.com>
        Where is "while ()" documented? <socyl@987jk.com.invalid>
    Re: Where is "while ()" documented? <someone@example.com>
    Re: Where is "while ()" documented? <xman@nospam.tv>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 9 Sep 2005 19:10:33 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Complex data structures and variable scope
Message-Id: <dfsmn9$5sg$1@mamenchi.zrz.TU-Berlin.DE>

Henry Law  <news@lawshouse.org> wrote in comp.lang.perl.misc:
> On 9 Sep 2005 10:05:19 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno
> Siegel) wrote:
> 
> >Reading
> >the file paragraph-wise simplifies things because each loop processes
> >one person.  
> 
> That's the key suggestion; I hadn't even considered trying paragraphs.

The key is really to have the loop operate one person at a time.  Then
"my %person" recreates %person in sync with how it is consumed into
%people.  Paragraph mode is a convenient way to do that, given the
data format.

An alternative would be to enclose an inner loop that builds a person
(well a %person, somewhat less of a challenge).  The outer loop would
only ever read the first line of each person, like this:

    my %people;
    while ( <DATA> ) {
        my %person;
        while ( defined ) {
            chomp;
            last unless length;
            my ( $key, $val) = split /:/;
            if ( $key eq 'qual' ) {
                push @{ $person{ quals}}, $val;
            } else {
                $person{ $key} = $val;
            }
            $_ = <DATA>;
        }
        $people{ $person{ name}} = \ %person;
    }
    __DATA__
    ...

It could be streamlined into doing all input in the inner loop.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: Fri, 09 Sep 2005 11:13:34 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: converting a hash where the value is a list of lists to just a list
Message-Id: <090920051113340982%jgibson@mail.arc.nasa.gov>

In article <4321b6db$1@usenet.ugs.com>, Lynn <lynn.watts@ugs.com> wrote:

> Hi All,
> 
> I have a hash where the values are a list of lists. What I would like to do 
> is
> convert this to a hash where the value is just a reference to an array that 
> contains
> the list of lists. Below is my attempt to convert this to what I want, the 
> problem
> is that I am loosing some people in the process!
> 
> use strict;
> use warnings;
> use Data::Dumper;
> my %people = (
>     'hillrich' => [ [5308125], [2053628], [5312468], [5312492] ],
>     'hsieh' => [ [5312182], [5312613], [5312517] ],
>     'prakash'  => [],
>     'florencb' => [
>         [1420688], [1420596], [5312242], [5306884], [5305217], [5248521],
>     ],
>     'x_shukl' => []
> );
> my %new_format_people=();
> foreach my $person(keys %people)   {

Add this line here:

    $new_format_people{$person} = [];

>  foreach my $item (@{ $people{$person} })   {
>   for ( @$item)   {
>            push @{$new_format_people{$person}},$_;
>   }
>  }
> }
> 
> print Dumper(\%new_format_people);
> 
> output is:
[snipped]
> 
> I lost prakash and x_shukl in the conversion process. How can I keep these 
> people
> in the new hash I am creating?
> 
> Thanks
> 
> Lynn 
> 
>


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

Date: Fri, 9 Sep 2005 11:29:12 -0700
From: "Lynn" <lynn.watts@ugs.com>
Subject: Re: converting a hash where the value is a list of lists to just a list
Message-Id: <4321dafb$1@usenet.ugs.com>

Hi John,

John W. Krahn wrote:
> Lynn wrote:
>>
(my stuff snipped)

>
> $ perl -e'
> use Data::Dumper;
> my %people = (
>    hillrich => [ [5308125], [2053628], [5312468], [5312492] ],
>    hsieh    => [ [5312182], [5312613], [5312517] ],
>    prakash  => [],
>    florencb => [ [1420688], [1420596], [5312242], [5306884],
> [5305217], [5248521], ],
>    x_shukl  => [],
>    );
> my %new_format_people = %people;
> $_ = [ map ref() ? @$_ : $_, @$_ ] for values %new_format_people;
> print Dumper \%new_format_people;

Wow, I need to study this! Thanks a lot :-)

> John 




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

Date: Fri, 09 Sep 2005 23:01:56 +0200
From: =?ISO-8859-1?Q?S=E9bastien_Cottalorda?= <scottalordaNOSPAM@libello.com>
Subject: IPC::Shareable Problem with multidimentional hash
Message-Id: <4321f7a6$0$4298$636a15ce@news.free.fr>

Hi all,

I need to use that kind of shared hash:
%shared_hash = (
	'123456' => {
		'bla' => 123,
		'bli' => 465,
		ect ...
	},
	ect ...
);

with about 500 primary keys.
When I "feed" the %shared_hash, I note that the system create as many 
shared segment and semaphore than there are primary keys.

As you can imagine, my process died with "Could not create semaphore 
set: No space left on device at line ..."

If I create small complex structure (10 primary keys), the program works 
perfectly.

If I well understand the perldoc IPC::Shareable documentation, I can 
create as complex shared structure I want, I don't understand why it 
crashes.

Here is a simple code that ever crash:

#!/usr/bin/perl -w
use strict;
use IPC::Shareable;
my $glue = 'data';
my %options = (
                create    => 1,
                exclusive => 1,
                mode      => 0644,
                destroy   => 1,
                );
my %colours;
tie %colours, 'IPC::Shareable', $glue, { %options } or
     die "server: tie failed\n";
my ($i,$j);
for $i (1 .. 300){
     for $j (1..3){
         $colours{$i}{$j} = "fall";
         print " 500 ... \n" if ($i==500);
         print "1000 ... \n" if ($i==1000);
         print "1500 ... \n" if ($i==1500);
         print "2000 ... \n" if ($i==2000);
     }
}
print "Charged - Press a key to continue -\n";
my $e=<STDIN>;
foreach $i ( keys %colours){
     print "$i => \n";
     foreach $j (keys %{$colours{$i}}){
         print "    $colours{$i}{$j}\n";
     }
}
exit;


If someone as a clue ?
Thanks in advance for any help.

Sebastien


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

Date: 10 Sep 2005 00:14:02 GMT
From: xhoster@gmail.com
Subject: Re: IPC::Shareable Problem with multidimentional hash
Message-Id: <20050909201402.986$c4@newsreader.com>

Sébastien_Cottalorda <scottalordaNOSPAM@libello.com> wrote:
> Hi all,
>
> I need to use that kind of shared hash:
> %shared_hash = (
>         '123456' => {
>                 'bla' => 123,
>                 'bli' => 465,
>                 ect ...
>         },
>         ect ...
> );
>
> with about 500 primary keys.
> When I "feed" the %shared_hash, I note that the system create as many
> shared segment and semaphore than there are primary keys.

Yes.  This fact is documented.


> As you can imagine, my process died with "Could not create semaphore
> set: No space left on device at line ..."
>
> If I create small complex structure (10 primary keys), the program works
> perfectly.
>
> If I well understand the perldoc IPC::Shareable documentation, I can
> create as complex shared structure I want,

As you said yourself, a small "complex" structure works perfectly.  It is
not the complexity, but the cardinality, that is the problem.

> I don't understand why it
> crashes.

What is there to not understand?

 ...
[2] IPC::Shareable provides no pre-set limits, but the system does. Namely,
there are limits on the number of shared memory segments that can be
allocated and the total amount of memory usable by shared memory. ...

You could try using Storable or Data::Dumper to collapse the inner
structures into flat strings for storage.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Fri, 9 Sep 2005 19:40:39 +0000 (UTC)
From: "David Serrano (Hue-Bond)" <responder_solo_en_el_grupo@yahoo.es>
Subject: Re: Replace substring "_.modem_" with modem price from $price ?
Message-Id: <slrndi3p9n.hp8.responder_solo_en_el_grupo@genus.hue-bond.info>

Anno Siegel, vie20050909@11:01:39(CEST):
>
>     s/_modem_/$price/ for @fileList;
>
>     print "$_\n" for @fileList;

Just a note. I think walking the array only once would be better
performance-wise, wouldn't it?

for (@fileList) {
  s/_modem_/$price/;
  print "$_\n";
}

Or, shorter;

s/_modem_/$price/, print "$_\n" for @fileList;


-- 
 David Serrano


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

Date: 9 Sep 2005 23:31:32 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Replace substring "_.modem_" with modem price from $price ?
Message-Id: <dft60k$dnv$1@mamenchi.zrz.TU-Berlin.DE>

David Serrano (Hue-Bond) <responder_solo_en_el_grupo@yahoo.es> wrote in comp.lang.perl.misc:
> Anno Siegel, vie20050909@11:01:39(CEST):
> >
> >     s/_modem_/$price/ for @fileList;
> >
> >     print "$_\n" for @fileList;
> 
> Just a note. I think walking the array only once would be better
> performance-wise, wouldn't it?

It might.  Only a benchmark would tell.  In combination with actual IO
the difference isn't going to be large.

I set the print statement it off in an extra loop because it is only there
to show that the rest of the program worked.  It shows an intent, efficiency
wasn't on my mind.

> for (@fileList) {
>   s/_modem_/$price/;
>   print "$_\n";
> }
> 
> Or, shorter;
> 
> s/_modem_/$price/, print "$_\n" for @fileList;

Yes, but it combines two actions one of which is likely to go away
in a finished program.

Anno
-- 
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article.  Click on 
"show options" at the top of the article, then click on the 
"Reply" at the bottom of the article headers.


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

Date: Fri, 09 Sep 2005 13:09:53 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: script attack
Message-Id: <etoll26xdku.fsf@wilson.emschwar>

Brian Wakem <no@email.com> writes:
> 'local our' is common use in mod_perl.
>
> http://perl.apache.org/docs/1.0/guide/porting.html#The_First_Mystery

Okay, fair enough; all the mod_perl I've done has been with Mason,
which hides all that with the MasonAllowGlobals Apache directive.
Even so, I look at those examples, and think, "You know, if they just
passed variables around, instead of using globals, they wouldn't need
'local our' at all."

But thanks for the correction; if I find myself using mod_perl with
other templating engines, I will remember that.

-=Eric


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

Date: Fri, 09 Sep 2005 20:35:45 +0100
From: Brian Wakem <no@email.com>
Subject: Re: script attack
Message-Id: <3oe6giF5iim5U1@individual.net>

Eric Schwartz wrote:

> Brian Wakem <no@email.com> writes:
>> 'local our' is common use in mod_perl.
>>
>> http://perl.apache.org/docs/1.0/guide/porting.html#The_First_Mystery
> 
> Okay, fair enough; all the mod_perl I've done has been with Mason,
> which hides all that with the MasonAllowGlobals Apache directive.
> Even so, I look at those examples, and think, "You know, if they just
> passed variables around, instead of using globals, they wouldn't need
> 'local our' at all."


Yes it's best put to use when porting a load of existing mod_cgi scripts to
mod_perl.  Wacking a load of 'local our's in can save hours, and time is
money.

Even so, a global my (and many scripts will have one) will not be shared
correctly between subs, so you use our, but in mod_perl it will hold on to
the memory it used after the script has finished.   local our therefore
helps keep memory usage down.



-- 
Brian Wakem
Email: http://homepage.ntlworld.com/b.wakem/myemail.png


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

Date: Fri, 9 Sep 2005 18:57:31 +0000 (UTC)
From: kj <socyl@987jk.com.invalid>
Subject: Where is "while ()" documented?
Message-Id: <dfslur$ovk$1@reader1.panix.com>




I've looked in perlsyn, but I can't find documentation for the
special case in which the expression controlling the while loop is
empty, e.g.

  while () {
    # infinite loop
  }

I.e. "while ()" apparently behaves like "while (1)".  Is this
documented anywhere?

Thanks,

kj

-- 
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.


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

Date: Fri, 09 Sep 2005 21:32:43 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: Where is "while ()" documented?
Message-Id: <%bnUe.234132$HI.154595@edtnps84>

kj wrote:
> I've looked in perlsyn, but I can't find documentation for the
> special case in which the expression controlling the while loop is
> empty, e.g.
> 
>   while () {
>     # infinite loop
>   }
> 
> I.e. "while ()" apparently behaves like "while (1)".  Is this
> documented anywhere?

I believe it's related to the fact that "for (;;) {...}" (which was inherited
from C) is an infinite loop with an empty conditional.


John
-- 
use Perl;
program
fulfillment


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

Date: Fri, 9 Sep 2005 23:59:02 +0200
From: "xman" <xman@nospam.tv>
Subject: Re: Where is "while ()" documented?
Message-Id: <dft0j0$r9h$1@ss405.t-com.hr>

here http://www.plsgoogleit.com/


"kj" <socyl@987jk.com.invalid> wrote in message 
news:dfslur$ovk$1@reader1.panix.com...
>
>
>
> I've looked in perlsyn, but I can't find documentation for the
> special case in which the expression controlling the while loop is
> empty, e.g.
>
>  while () {
>    # infinite loop
>  }
>
> I.e. "while ()" apparently behaves like "while (1)".  Is this
> documented anywhere?
>
> Thanks,
>
> kj
>
> -- 
> NOTE: In my address everything before the first period is backwards;
> and the last period, and everything after it, should be discarded. 




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

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


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