[30985] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2230 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 23 16:09:51 2009

Date: Mon, 23 Feb 2009 13:09:17 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 23 Feb 2009     Volume: 11 Number: 2230

Today's topics:
    Re: how to get unblocked by perl.org? jidanni@jidanni.org
    Re: Parsing keyword=value pairs (Tim McDaniel)
    Re: processing XML posts through a web server <RedGrittyBrick@spamweary.invalid>
    Re: programming by evolution? <see_website@mindprod.com.invalid>
    Re: programming by evolution? <xahlee@gmail.com>
        pseudo hash syntax in 5.10 <patrick.viet___GRR___@gmail.com.nospam>
    Re: pseudo hash syntax in 5.10 <none@none.com>
    Re: pseudo hash syntax in 5.10 <thepoet_nospam@arcor.de>
    Re: pseudo hash syntax in 5.10 <tadmc@seesig.invalid>
    Re: pseudo hash syntax in 5.10 <patrick.viet___GRR___@gmail.com.nospam>
    Re: pseudo hash syntax in 5.10 <patrick.viet___GRR___@gmail.com.nospam>
    Re: pseudo hash syntax in 5.10 <patrick.viet___GRR___@gmail.com.nospam>
    Re: pseudo hash syntax in 5.10 <none@none.com>
    Re: pseudo hash syntax in 5.10 <perl@marc-s.de>
    Re: pseudo hash syntax in 5.10 <noreply@gunnar.cc>
    Re: pseudo hash syntax in 5.10 (Tim McDaniel)
    Re: pseudo hash syntax in 5.10 (Tim McDaniel)
    Re: pseudo hash syntax in 5.10 (Tim McDaniel)
    Re: pseudo hash syntax in 5.10 <noreply@gunnar.cc>
    Re: Sorting hash of hashes <justin.0810@purestblue.com>
    Re: Sorting hash of hashes (Greg Bacon)
    Re: utf8 and chomp <jfeit@ics.muni.cz>
    Re: utf8 and chomp <anfi@onet.eu>
    Re: utf8 and chomp <jfeit@ics.muni.cz>
    Re: weird matching variable behavior <juliani.moon@gmail.com>
        Where is the standard output coming from in the followi <cdalten@gmail.com>
    Re: Where is the standard output coming from in the fol (Greg Bacon)
    Re: XML Simple force array xhoster@gmail.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 24 Feb 2009 02:29:40 +0800
From: jidanni@jidanni.org
Subject: Re: how to get unblocked by perl.org?
Message-Id: <87prh9c8h7.fsf@jidanni.org>

Well, after leaving some messages on
$ whois perl.org|grep Phone
Admin Phone:+1.8665501313
it seems I am making progress on getting myself unblocked from sending
mail to *@perl.org. It seems also they can mail me but I can't reply.

One thing I have learned thru the ordeal is apparently there is a
single point of failure, with no alternative means of contacting them,
hence my post to this newsgroup.

Anyway, most interesting is this bounce:

Hi. This is the qmail-send program at x1.develooper.com.
I'm afraid I wasn't able to deliver your message to the following addresses.
This is a permanent error; I've given up. Sorry it didn't work out.

<rt-perl5@rt.perl.org>:
Sorry, I couldn't find any host named rt.perl.org. (#5.1.2)

--- Below this line is a copy of the message.

Return-Path: <jidanni@jidanni.org>
Received: (qmail 6079 invoked by uid 225); 21 Feb 2009 18:49:34 -0000
Delivered-To: perlbug@perl.org
Received: (qmail 6075 invoked by alias); 21 Feb 2009 18:49:33 -0000
X-Spam-Status: No, hits=0.0 required=8.0
	tests=
X-Spam-Check-By: la.mx.develooper.com
Received: from mailbigip.dreamhost.com (HELO homiemail-a4.dreamhost.com) (208.97.132.5)
    by la.mx.develooper.com (qpsmtpd/0.28) with ESMTP; Sat, 21 Feb 2009 10:49:31 -0800
Received: from jidanni.org (122-127-35-131.dynamic.hinet.net [122.127.35.131])
	(using TLSv1 with cipher AES256-SHA (256/256 bits))
	(No client certificate requested)
	by homiemail-a4.dreamhost.com (Postfix) with ESMTP id 49C8641518
	for <perlbug@perl.org>; Sat, 21 Feb 2009 10:49:27 -0800 (PST)
To: perlbug@perl.org
Subject: the perldoc man page should say SEE ALSO perlpod
From: jidanni@jidanni.org
Date: Sun, 22 Feb 2009 02:49:24 +0800
Message-ID: <87skm7k4ln.fsf@jidanni.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii

The perldoc man page should say SEE ALSO perlpod.

P.S., if this bug gets through in the mail it will be a miracle.


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

Date: Mon, 23 Feb 2009 16:43:12 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: Parsing keyword=value pairs
Message-Id: <gnujn0$lib$1@reader1.panix.com>

In article
<8f634fe6-abac-4552-9cf5-762b320f9750@i38g2000yqd.googlegroups.com>,
pgodfrin  <pgodfrin@gmail.com> wrote:
>Greetings,
>I'm looking to have an input file that has keyword=value pairs.
 ...
>So - anyone have some suggestions on a good way to read the input
>file of pairs?

    use Config::Properties;
?

-- 
Tim McDaniel, tmcd@panix.com


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

Date: Mon, 23 Feb 2009 11:16:01 +0000
From: RedGrittyBrick <RedGrittyBrick@spamweary.invalid>
Subject: Re: processing XML posts through a web server
Message-Id: <49a28571$0$2518$da0feed9@news.zen.co.uk>


Jack wrote:
> Ok call me stupid, but can anyone explain the best way to

The best way to do anything is with whatever tools you personally are
familiar with, or inclined to learn, that will do the job. For these 
reasons I try to avoid asking "what is the best ...".


> process bi directional XML coming in via an http post,

This sounds like SOAP. Is it?
http://en.wikipedia.org/wiki/SOAP


> using an IIS webserver..

I've not used Perl with IIS. Best ask in an IIS forum. I've no doubt IIS
can be persuaded to run Perl CGI scripts. I wouldn't expect IIS to do
this efficiently since I imagine IIS developers regard CGI as a legacy
architecture to be deprecated.

> I know CPAN has XML modules, etc.

Indeed. See also SOAP::Lite.


> but how does this process work - ie a file is posted to the webserver
> and saved to a directory where perl then parses it ??

Not usually.
http://en.wikipedia.org/wiki/Common_Gateway_Interface

With SOAP, your client is basically calling methods
(procedures/functions/subroutines) defined in a Perl module on the
server. To the software developer it is very much like normal subroutine
calls.

http://en.wikipedia.org/wiki/Remote_procedure_call

SOAP can be used for a form of RPC where the parameters and return 
values are converted to XML for transmission (this is called 
serialization or marshalling) - but the application programmer usually 
doesn't have to deal with XML.


> How do you use perl to post a response back through IIS ?

Have you read some Perl CGI documentation or tutorials?
Have you read `perldoc CGI`?



-- 
RGB


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

Date: Mon, 23 Feb 2009 04:56:54 -0800
From: Roedy Green <see_website@mindprod.com.invalid>
Subject: Re: programming by evolution?
Message-Id: <n375q4d933h748c5bnpfjrbcrvdilvn7vt@4ax.com>

On 19 Feb 2009 18:56:42 GMT, Albert van der Horst
<albert@spenarnc.xs4all.nl> wrote, quoted or indirectly quoted someone
who said :

>Note here, that eXtreme
>>Programing is one of the snake oil,

Extreme programming is a variant on Deming's idea of constant
incremental improvement that revolutionised quality in manufacturing.

It is also based on the obvious idea that you will be smarter after
you have used some version of a program than you are today. There are
so many computer programs perfectly compliant with specs that looked
good on paper but nobody ever tested with actual use to refine them
until the project was "complete" and it was too expensive to fix them.


-- 
Roedy Green Canadian Mind Products
http://mindprod.com

One path leads to despair and utter hopelessness. The other, 
to total extinction. Let us pray we have the wisdom to choose correctly. 
~ Woody Allen .


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

Date: Mon, 23 Feb 2009 07:54:48 -0800 (PST)
From: Xah Lee <xahlee@gmail.com>
Subject: Re: programming by evolution?
Message-Id: <67b81919-4e73-4943-a6bc-5863e9a93a3a@j39g2000yqn.googlegroups.com>

On Feb 23, 4:56 am, Roedy Green <see_webs...@mindprod.com.invalid>
wrote:
> On 19 Feb 2009 18:56:42 GMT, Albert van der Horst
> <alb...@spenarnc.xs4all.nl> wrote, quoted or indirectly quoted someone
> who said :
>
> >Note here, that eXtreme
> >>Programing is one of the snake oil,
>
> Extreme programming is a variant on Deming's idea of constant
> incremental improvement that revolutionised quality in manufacturing.
>
> It is also based on the obvious idea that you will be smarter after
> you have used some version of a program than you are today. There are
> so many computer programs perfectly compliant with specs that looked
> good on paper but nobody ever tested with actual use to refine them
> until the project was "complete" and it was too expensive to fix them.

2009-02-09

Today, i happened to run across a blog on the eXtreme Programing
FUCK.
http://www.yosefk.com/blog/extreme-programming-explained.html

Great article!

  Xah
$B-t(B http://xahlee.org/



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

Date: Mon, 23 Feb 2009 18:40:22 +0100
From: Patrick Viet <patrick.viet___GRR___@gmail.com.nospam>
Subject: pseudo hash syntax in 5.10
Message-Id: <49a2df76$0$7585$426a34cc@news.free.fr>

Hello,

I've been using a weird syntax to assign elements from a hash to array 
for several years now. Doesn't work in 5.10. I saw the changelog and it 
said pseudo-hashes didn't exist. Didn't know it was pseudo hash I was 
using... Anybody knows how to adapt my code ?

Here it is :

$h = {
   a => 'data1',
   b => 'data2',
   c => 'data3',
   ...
};

my ($data_a,$data_b) = @{$h}{'a','b'};

Any other idea to do this ? Obviously an alternative syntax would be :

my $data_a = $h->{'a'};
my $data_b = $h->{'b'};

But this kind of sucks because my real usage is like this :

(in sql req)
while(my $href = $sth->fetchrow_hashref) {
   my $key = join('|',@{$href}{@cols_primary});

Which is really practical ...

Any ideas ?

Thanks,

-- 
   Patrick Viet


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

Date: Mon, 23 Feb 2009 19:15:10 +0100
From: Matija Papec <none@none.com>
Subject: Re: pseudo hash syntax in 5.10
Message-Id: <gnup3n$fk5$1@ss408.t-com.hr>

Patrick Viet wrote:
> Hello,
> 
> I've been using a weird syntax to assign elements from a hash to array
> for several years now. Doesn't work in 5.10. I saw the changelog and it
> said pseudo-hashes didn't exist. Didn't know it was pseudo hash I was
> using... 

You were using hash slice on the regular hash, nothing to worry about.

> Here it is :
> 
> $h = {
>   a => 'data1',
>   b => 'data2',
>   c => 'data3',
>   ...
> };
> 
> my ($data_a,$data_b) = @{$h}{'a','b'};

This should also work under 5.10, what kind of error do you get when
reading hash slice?



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

Date: Mon, 23 Feb 2009 20:11:30 +0100
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: pseudo hash syntax in 5.10
Message-Id: <49a2f4ba$0$31880$9b4e6d93@newsspool3.arcor-online.net>

Patrick Viet wrote:
> I've been using a weird syntax to assign elements from a hash to array 
> for several years now. Doesn't work in 5.10. I saw the changelog and it 
> said pseudo-hashes didn't exist. Didn't know it was pseudo hash I was 
> using... Anybody knows how to adapt my code ?
> 
> Here it is :
> 
> $h = {
>   a => 'data1',
>   b => 'data2',
>   c => 'data3',
>   ...
> };
> 
> my ($data_a,$data_b) = @{$h}{'a','b'};
> 
> Any other idea to do this ? Obviously an alternative syntax would be :
> 
> my $data_a = $h->{'a'};
> my $data_b = $h->{'b'};
> 
> But this kind of sucks because my real usage is like this :
> 
> (in sql req)
> while(my $href = $sth->fetchrow_hashref) {
>   my $key = join('|',@{$href}{@cols_primary});
> 
> Which is really practical ...

Anonymous hash slices do still work in 5.10, but for readability
reasons you might consider using map anyway.

while( my $href = $sth->fetchrow_hashref ) {
    my $key = join('|', map { $href->{$_} } @cols_primary );
}

-Chris


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

Date: Mon, 23 Feb 2009 13:05:25 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: pseudo hash syntax in 5.10
Message-Id: <slrngq5srl.hi5.tadmc@tadmc30.sbcglobal.net>

Patrick Viet <patrick.viet___GRR___@gmail.com.nospam> wrote:
> Hello,
>
> I've been using a weird syntax to assign elements from a hash to array 
> for several years now. 


The "weird syntax" looks like a "hash slice" rather than a "pseudo hash"
to me...


> Doesn't work in 5.10. 


Have you seen the Posting Guidelines that are posted here frequently?

Are you getting an error message?

If so, what is the exact text of the message?

If not, then what does "doesn't work" mean when you say it?

That is, what were you expecting it to do, and what is it doing instead?


> I saw the changelog and it 
> said pseudo-hashes didn't exist. Didn't know it was pseudo hash I was 
> using... 


pseudo-hashes apply only to arrays.

There is only one array in all of the code that you've posted.

Is the 1st element in @cols_primary a reference to a hash?

If not, then there are no pseudo hashes here...


> Anybody knows how to adapt my code ?
>
> Here it is :
>
> $h = {
>    a => 'data1',
>    b => 'data2',
>    c => 'data3',
>    ...
> };
>
> my ($data_a,$data_b) = @{$h}{'a','b'};


That is a vanilla hash slice.

I don't expect that hash slices were broken in 5.10 (I don't have 5.10 yet).


> Any other idea to do this ? Obviously an alternative syntax would be :
>
> my $data_a = $h->{'a'};
> my $data_b = $h->{'b'};
>
> But this kind of sucks because my real usage is like this :
>
> (in sql req)
> while(my $href = $sth->fetchrow_hashref) {
>    my $key = join('|',@{$href}{@cols_primary});
>
> Which is really practical ...


You have not shown us the contents of @cols_primary, so we cannot
comment on this piece of code.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


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

Date: Mon, 23 Feb 2009 21:02:54 +0100
From: Patrick Viet <patrick.viet___GRR___@gmail.com.nospam>
To: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: pseudo hash syntax in 5.10
Message-Id: <49A300EE.2040002@gmail.com.nospam>

> Have you seen the Posting Guidelines that are posted here frequently?

No sorry, i'm not a thorough usenet poster, I didn't know there was such 
a thing. But that I understand :

 > Have you seen the Posting Guidelines that are posted here frequently?
 > Are you getting an error message?
 > If so, what is the exact text of the message?
 > If not, then what does "doesn't work" mean when you say it?
 > That is, what were you expecting it to do, and what is it doing
 > instead?

So I'll post some more detail.

BTW I got the stuff to work. But I don't understand why it doesn't work 
anymore while it did in 5.8 ...

Here is my full test :

--------------------
#!/usr/bin/perl

use warnings;
use strict;

my $h = {
   a => 'test1',
   b => 'test2',
   c => 'test3',
};

my @list = qw(a b);

my ($var1,$var2) = @{%$h}{@list};

print "var1 : $var1 $var2\n";
--------------------

$ ./test
Can't use string ("3/8") as a HASH ref while "strict refs" in use at 
 ./test line 14.

And if I take out the % on the my var1,var2 line, I get what I expected:

$ ./test
var1 : test1 test2

I've solved my problem in the sense that my software can work again, but 
I don't understand what that message is, why it stopped working in 5.10, 
and where that 3/8 crap comes from (?!)


Other script that produces the same result without hash ref :


--------------------
#!/usr/bin/perl

use warnings;
use strict;

my %h = (
   a => 'test1',
   b => 'test2',
   c => 'test3',
);

my @list = qw(a b);

my ($var1,$var2) = @{\%h}{@list};

print "var1 : $var1 $var2\n";

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

Isn't there anything less crappy than \% that's valid in 5.10 ? I tried 
quite a bit of things  without getting my "var1 : test1 test2" expected 
result.

-- 
   Patrick Viet


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

Date: Mon, 23 Feb 2009 21:04:09 +0100
From: Patrick Viet <patrick.viet___GRR___@gmail.com.nospam>
Subject: Re: pseudo hash syntax in 5.10
Message-Id: <49a30129$0$3526$426a34cc@news.free.fr>

 > Have you seen the Posting Guidelines that are posted here frequently?

No sorry, i'm not a thorough usenet poster, I didn't know there was such 
a thing. But that I understand :

 > Have you seen the Posting Guidelines that are posted here frequently?
 > Are you getting an error message?
 > If so, what is the exact text of the message?
 > If not, then what does "doesn't work" mean when you say it?
 > That is, what were you expecting it to do, and what is it doing
 > instead?

So I'll post some more detail.

BTW I got the stuff to work. But I don't understand why it doesn't work 
anymore while it did in 5.8 ...

Here is my full test :

--------------------
#!/usr/bin/perl

use warnings;
use strict;

my $h = {
   a => 'test1',
   b => 'test2',
   c => 'test3',
};

my @list = qw(a b);

my ($var1,$var2) = @{%$h}{@list};

print "var1 : $var1 $var2\n";
--------------------

$ ./test
Can't use string ("3/8") as a HASH ref while "strict refs" in use at 
 ./test line 14.

And if I take out the % on the my var1,var2 line, I get what I expected:

$ ./test
var1 : test1 test2

I've solved my problem in the sense that my software can work again, but 
I don't understand what that message is, why it stopped working in 5.10, 
and where that 3/8 crap comes from (?!)


Other script that produces the same result without hash ref :


--------------------
#!/usr/bin/perl

use warnings;
use strict;

my %h = (
   a => 'test1',
   b => 'test2',
   c => 'test3',
);

my @list = qw(a b);

my ($var1,$var2) = @{\%h}{@list};

print "var1 : $var1 $var2\n";

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

Isn't there anything less crappy than \% that's valid in 5.10 ? I tried 
quite a bit of things  without getting my "var1 : test1 test2" expected 
result.

-- 
   Patrick Viet


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

Date: Mon, 23 Feb 2009 21:05:13 +0100
From: Patrick Viet <patrick.viet___GRR___@gmail.com.nospam>
Subject: Re: pseudo hash syntax in 5.10
Message-Id: <49a30169$0$3526$426a34cc@news.free.fr>

sorry for double post i'm not so good at using thunderbird


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

Date: Mon, 23 Feb 2009 21:19:12 +0100
From: Matija Papec <none@none.com>
Subject: Re: pseudo hash syntax in 5.10
Message-Id: <gnv0c9$3o9$1@ss408.t-com.hr>

Patrick Viet wrote:

> my ($var1,$var2) = @{\%h}{@list};

less crappy version:
my ($var1,$var2) = @h{@list};

;)

> print "var1 : $var1 $var2\n";
> 
> --------------------
> 
> Isn't there anything less crappy than \% that's valid in 5.10 ? I tried
> quite a bit of things  without getting my "var1 : test1 test2" expected
> result.
> 


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

Date: Mon, 23 Feb 2009 21:28:54 +0100
From: Marc Lucksch <perl@marc-s.de>
Subject: Re: pseudo hash syntax in 5.10
Message-Id: <gnv0u7$1d8u$1@ariadne.rz.tu-clausthal.de>

Patrick Viet schrieb:
> my @list = qw(a b);
> 
> my ($var1,$var2) = @{%$h}{@list};
Well, there is you problem right there, because in your first post you 
wrote:
 > @{$h}{@list}
and here you wrote:
 > @{%$h}{@list};
Which is a different thing. scalar %$h gives you the bucket information 
(3/8) in your case, means: 3 of 8 buckets are filled.

Quote man perldata:

 > If you evaluate a hash in scalar context, it returns false if the hash
 > is empty. If there are any key/value pairs, it returns true; more
 > precisely, the value returned is a string consisting of the number of
 > used buckets and the number of allocated buckets, separated by a
 > slash. This is pretty much useful only to find out whether Perl's
 > internal hashing algorithm is performing poorly on your data set. For
 > example, you stick 10,000 things in a hash, but evaluating %HASH in
 > scalar context reveals "1/16" , which means only one out of sixteen
 > buckets has been touched, and presumably contains all 10,000 of your
 > items. This isn't supposed to happen. If a tied hash is evaluated in
 > scalar context, a fatal error will result, since this bucket usage
 > information is currently not available for tied hashes.

> --------------------
> #!/usr/bin/perl
> 
> use warnings;
> use strict;
> 
> my %h = (
>   a => 'test1',
>   b => 'test2',
>   c => 'test3',
> );
> 
> my @list = qw(a b);
> 
> my ($var1,$var2) = @{\%h}{@list};

You should better do this (no refrences needed):

my ($var1,$var2) = @h{@list};

Simple way to remember this:

$h{a}: Scalar of %h
%h: Hash %h
@h{@ab} = array from %h of the keys in @ab.

Marc "maluku" Lucksch


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

Date: Mon, 23 Feb 2009 21:28:03 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: pseudo hash syntax in 5.10
Message-Id: <70gfapF59f4oU1@mid.individual.net>

Patrick Viet wrote:
> 
> my ($var1,$var2) = @{%$h}{@list};
-----------------------^

What is that % character supposed to do? It was not there in your 
initial post.

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


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

Date: Mon, 23 Feb 2009 20:45:26 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: pseudo hash syntax in 5.10
Message-Id: <gnv1t5$smr$1@reader1.panix.com>

In article <gnv0u7$1d8u$1@ariadne.rz.tu-clausthal.de>,
Marc Lucksch  <perl@marc-s.de> wrote:
>Patrick Viet schrieb:
>> --------------------
>> #!/usr/bin/perl
>> 
>> use warnings;
>> use strict;
>> 
>> my %h = (
>>   a => 'test1',
>>   b => 'test2',
>>   c => 'test3',
>> );
>> 
>> my @list = qw(a b);
>> 
>> my ($var1,$var2) = @{\%h}{@list};
>
>You should better do this (no refrences needed):
>
>my ($var1,$var2) = @h{@list};

Note that Marc changed the quoted code but left it quoted and with
Viet's attribution.  The original had
    my $h = { ... };
but the new version above has
    my %h = ( ... );

That is, Marc changed it from a scalar variable that contained a
reference to a hash - to a hash variable that contained, well, a hash.

I agree that that using a hash, instead of a reference to a hash, is
better is in this kind of case.  I just wanted to point out that
goalposts were being moved silently.

-- 
Tim McDaniel, tmcd@panix.com



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

Date: Mon, 23 Feb 2009 20:48:00 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: pseudo hash syntax in 5.10
Message-Id: <gnv220$smr$2@reader1.panix.com>

In article <gnv0c9$3o9$1@ss408.t-com.hr>, Matija Papec  <none@none.com> wrote:
>Patrick Viet wrote:
>
>> my ($var1,$var2) = @{\%h}{@list};
>
>less crappy version:
>my ($var1,$var2) = @h{@list};

Please test your code before making suggestions.  With the original
    my $h = {
       a => 'test1',
       b => 'test2',
       c => 'test3',
    };
the "less crappy" version (under perl -w and use strict) gives
    Global symbol "%h" requires explicit package name at
        local/test/051.pl line 15.
    Execution of local/test/051.pl aborted due to compilation errors.

As Marc (silently) noted, you have to change the assignment from
$h = {...} to %h = (...).

-- 
Tim McDaniel, tmcd@panix.com


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

Date: Mon, 23 Feb 2009 20:55:28 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Re: pseudo hash syntax in 5.10
Message-Id: <gnv2g0$smr$3@reader1.panix.com>

In article <gnv0u7$1d8u$1@ariadne.rz.tu-clausthal.de>,
Marc Lucksch  <perl@marc-s.de> wrote:
>Patrick Viet schrieb:
>> my @list = qw(a b);
>> 
>> my ($var1,$var2) = @{%$h}{@list};
>Well, there is you problem right there, because in your first post you 
>wrote:
> > @{$h}{@list}
>and here you wrote:
> > @{%$h}{@list};
>Which is a different thing. scalar %$h gives you the bucket information 
>(3/8) in your case, means: 3 of 8 buckets are filled.

To expand on that: in, @{EXPR}{list} (for whatever happens to be
"EXPR" in any particular case), the syntax requires that EXPR be a
reference to a hash, or be the bare name of a hash variable itself.
If EXPR is indeed an expression, like %$h, it is evaluated, so far as
I can tell, in a scalar context.  As Marc noted, that gives you a
string that tells you information about the hash table (here, that
there are 3 elements and 8 buckets, I think, but I can't find it
quickly in the man pages).

In Perl 5.10, and I suspect in many earlier versions, you can use
either
     @{$h}{@list}
or
     @$h{@list}

But, as Marc noted, using a real hash variableis better in this case,
avoiding the extra $ in lots of cases.

-- 
Tim McDaniel, tmcd@panix.com


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

Date: Mon, 23 Feb 2009 22:00:37 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: pseudo hash syntax in 5.10
Message-Id: <70gh7rF5ed9lU1@mid.individual.net>

Tim McDaniel wrote:
> But, as Marc noted, using a real hash variableis better in this case,
> avoiding the extra $ in lots of cases.

I'm not sure that Marc noted that. Besides, considering that the OP's 
real code is:

     while(my $href = $sth->fetchrow_hashref) {
       my $key = join('|',@{$href}{@cols_primary});

I'm somewhat confused by your advice.

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


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

Date: Mon, 23 Feb 2009 10:26:56 -0000
From: Justin C <justin.0810@purestblue.com>
Subject: Re: Sorting hash of hashes
Message-Id: <25c5.49a279f0.1ded9@zem>

On 2009-02-20, Greg Bacon <gbacon@hiwaay.net> wrote:
> Justin C wrote:
>
>: J. Gleixner wrote:
>:
>: > Having keys like 1,2,3, etc. is not very descriptive and after a few
>: > months, when you look at your code again, you'll wish you used
>: > something that made sense.
>:
>: I have, within the code, described the construction, and the numbers
>: are the column numbers within the report, so it's not overly
>: confusing.
>
> Using sequence numbers as keys in a hash is often a strong sign
> that you should use an array instead. However...

Yes, you've made me think about that, and I think you're right, an array
would have done the job.

Following the comments here I can see a bit of a re-write is needed. All
comments have been noted, and I shall review the code in a while. I
actually need the code to be working this week due to company year-end,
and it is in working order just now. It is only of use at stock-take
time anyway, I'll review it as soon as we've finished with it so it's
better for next time.



> I assume you used comments to describe the construction. Consider
> Rob Pike's advice[*]:
>
>     If your code needs a comment to be understood, it
>     would be better to rewrite it so it's easier to
>     understand.

That's something I *really* should think about... actually, I think I'm
going to print it and tape it to the bottom of my monitor.


>
> [*] http://www.lysator.liu.se/c/pikestyle.html

Interesting read.


> *The Practice of Programming* (a book Pike co-authored with
> Brian Kernighan -- the K in K&R) succinctly advises: "Give names
> to magic numbers." That is, use meaningful symbolic names instead
> of bare numeric literals.

I'm working through a K&R book at the moment (well, when I'm not
studying for YachtMaster sailing qualification), it's a second attempt,
and I have to say, it's much easier this time round. I'm understanding
many concepts through becoming familiar with [P|p]erl.

	Justin.

-- 
Justin C, by the sea.


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

Date: Mon, 23 Feb 2009 12:30:11 -0600
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: Sorting hash of hashes
Message-Id: <pa6dnYfoPc6udj_UnZ2dnUVZ_g-WnZ2d@posted.hiwaay2>

Justin C wrote

: Greg Bacon wrote
:
: > Using sequence numbers as keys in a hash is often a strong sign
: > that you should use an array instead. However...
:
: Yes, you've made me think about that, and I think you're right, an
: array would have done the job.

In this case, using a hash would be even clearer (which I meant
to suggest by "However..." and the rest of my post, but looking
back, I see that I wasn't clear). Keep your structure, but at the
last level, use column names rather than numbers.

Someone else in this thread gave the same good advice.

: [...]
: I'm working through a K&R book at the moment (well, when I'm not
: studying for YachtMaster sailing qualification), it's a second
: attempt, and I have to say, it's much easier this time round. I'm
: understanding many concepts through becoming familiar with [P|p]erl.

Good luck with your qualification!

Note that /[P|p]erl/ matches "Perl", "perl", and "|erl". You've
conflated /[Pp]erl/ and /(P|p)erl/. Prefer the former pattern:
the latter, although equivalent, looks odd. (There's also a small
performance penalty.)

Greg
-- 
Comfort rides shotgun with the temporary.
    -- Daniel Weinshenker


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

Date: Mon, 23 Feb 2009 17:05:55 GMT
From: Josef Feit <jfeit@ics.muni.cz>
Subject: Re: utf8 and chomp
Message-Id: <KFJ38A.905@news.muni.cz>

Utf8 and chomp problem:

Thank you for replies.
I tried to rewrite the script, but the problem seems
to persist.
UTF8 displayed OK, so I am sending the improved script.

I tried it on my OpenSuse 11.0 Linux under cs_CZ.UTF-8
locale and on the server (Debian I think, with
LANG=en_US.UTF-8 etc. (and v5.8.8 Perl).

The results are the same: the strings produced
are different. I will try to force the utf8 etc,
but it seems strange anyway.

Josef


#!/usr/bin/perl
# ----------------------------
# echo "náláx" >text.txt
# thisscript text.txt
# ----------------------------
use warnings;
use strict;
use encoding 'utf-8';

my %ascii = (
      'á' => 'a',
);

my $line = <>;
my $linech = $line;
chomp $linech;

for my $l ( $line, $linech ){
   print length($l), ": ";
   for my $char (split //, $l){
      if( exists( $ascii{$char} ) ){
         print "+";
      }else{
         print "-";
      }
   }
   print "\n";
}

Output (orig/chomped):
8: --------
5: -+-+-



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

Date: Mon, 23 Feb 2009 18:23:11 +0100
From: Andrzej Adam Filip <anfi@onet.eu>
Subject: Re: utf8 and chomp
Message-Id: <8izvptv178@gregg.anfi.chickenkiller.com>

Josef Feit <jfeit@ics.muni.cz> wrote:

> Utf8 and chomp problem:
>
> Thank you for replies.
> I tried to rewrite the script, but the problem seems
> to persist.
> UTF8 displayed OK, so I am sending the improved script.
>
> I tried it on my OpenSuse 11.0 Linux under cs_CZ.UTF-8
> locale and on the server (Debian I think, with
> LANG=en_US.UTF-8 etc. (and v5.8.8 Perl).
>
> The results are the same: the strings produced
> are different. I will try to force the utf8 etc,
> but it seems strange anyway.
>
> Josef
>
>
> #!/usr/bin/perl
> # ----------------------------
> # echo "náláx" >text.txt
> # thisscript text.txt
> # ----------------------------
> use warnings;
> use strict;
> use encoding 'utf-8';
>
> my %ascii = (
>       'á' => 'a',
> );
>
> my $line = <>;
> my $linech = $line;
> chomp $linech;
>
> for my $l ( $line, $linech ){
>    print length($l), ": ";
>    for my $char (split //, $l){
>       if( exists( $ascii{$char} ) ){
>          print "+";
>       }else{
>          print "-";
>       }
>    }
>    print "\n";
> }
>
> Output (orig/chomped):
> 8: --------
> 5: -+-+-

Have you tried to use STDIN marked as utf8 stream?

thisscript < text.txt

  binmode( STDIN, ':utf8') or die;
  my $line = <STDIN>;

-- 
[pl>en Andrew] Andrzej Adam Filip : anfi@onet.eu : anfi@xl.wp.pl
We have met the enemy, and he is us.
  -- Walt Kelly


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

Date: Mon, 23 Feb 2009 20:31:36 GMT
From: Josef Feit <jfeit@ics.muni.cz>
Subject: Re: utf8 and chomp
Message-Id: <KFJCr3.KBq@news.muni.cz>

Andrzej Adam Filip napsal(a):
> Josef Feit <jfeit@ics.muni.cz> wrote:
> 
>> Utf8 and chomp problem:
>>
>> Thank you for replies.
>> I tried to rewrite the script, but the problem seems
>> to persist.
>> UTF8 displayed OK, so I am sending the improved script.
>>
>> I tried it on my OpenSuse 11.0 Linux under cs_CZ.UTF-8
>> locale and on the server (Debian I think, with
>> LANG=en_US.UTF-8 etc. (and v5.8.8 Perl).
>>
>> The results are the same: the strings produced
>> are different. I will try to force the utf8 etc,
>> but it seems strange anyway.
>>
>> Josef
>>
>>
>> #!/usr/bin/perl
>> # ----------------------------
>> # echo "náláx" >text.txt
>> # thisscript text.txt
>> # ----------------------------
>> use warnings;
>> use strict;
>> use encoding 'utf-8';
>>
>> my %ascii = (
>>       'á' => 'a',
>> );
>>
>> my $line = <>;
>> my $linech = $line;
>> chomp $linech;
>>
>> for my $l ( $line, $linech ){
>>    print length($l), ": ";
>>    for my $char (split //, $l){
>>       if( exists( $ascii{$char} ) ){
>>          print "+";
>>       }else{
>>          print "-";
>>       }
>>    }
>>    print "\n";
>> }
>>
>> Output (orig/chomped):
>> 8: --------
>> 5: -+-+-
> 
> Have you tried to use STDIN marked as utf8 stream?
> 
> thisscript < text.txt
> 
>   binmode( STDIN, ':utf8') or die;
>   my $line = <STDIN>;
> 
I have tried it now - no change in the output.
However when the $line is set directly in the program,
the results are as expected (my $line = "náláx";)

And if I run it as
thisscript < text.txt

(with <) it works OK as well, even without the binmode setting:

thisscript < text.txt
6: -+-+--
5: -+-+-

thisscript text.txt
8: --------
5: -+-+-


Regards
Josef



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

Date: Mon, 23 Feb 2009 10:58:11 -0800 (PST)
From: "juliani.moon@gmail.com" <juliani.moon@gmail.com>
Subject: Re: weird matching variable behavior
Message-Id: <012cffd8-44af-4fbb-ac59-fca57c72b458@e6g2000vbe.googlegroups.com>

Thank you for all replies.  I've learnt more than I would expect.

Appreciate it!

Joe


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

Date: Mon, 23 Feb 2009 11:30:40 -0800 (PST)
From: grocery_stocker <cdalten@gmail.com>
Subject: Where is the standard output coming from in the following program
Message-Id: <a051e278-3f93-4404-b7bd-b38a52637db5@v13g2000yqm.googlegroups.com>

Given the following...

m-net% more bbs.pl
#!/usr/bin/perl

use strict;
use warnings;

open my $out, '|-', 'bbs' or die "cannot open pipe to bbs";

print $out "find nope a=cdalten\n";

close $out or die "cannot close pipe to bbs: $!";

it produces....

m-net% ./bbs.pl
YAPP 3.1.1  Copyright (c)1995 Armidale Software
Registered to: Arbornet

                                Welcome to the
                         February General Conference


                            fairwitness:  jerryr

41 newresponse items and 9 brandnew items
First item 1, last 80
No matches found.

Now leaving February General...
m-net%


The question is, where is the standard output coming from? The child
process?


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

Date: Mon, 23 Feb 2009 13:50:34 -0600
From: gbacon@hiwaay.net (Greg Bacon)
Subject: Re: Where is the standard output coming from in the following program
Message-Id: <RPKdnTzI7r2XYz_UnZ2dnUVZ_o3inZ2d@posted.hiwaay2>

grocery_stocker wrote

: Given the following...
: [...]
: 
: The question is, where is the standard output coming from? The
: child process?

Yes. The child process inherits the parent's standard output.

Observe:

    $ cat try
    #! /usr/bin/perl

    use warnings;
    use strict;

    my @sub = ("perl", "-e", <<'EOCode');
      print "[$$]: Hi!\n";
      chomp($_ = <>);
      print "[$$]: Got [$_]\n";
    EOCode

    print "[$$]: starting child...\n";
    open my $out, "|-", @sub;

    print $out "Hello, child process!\n";

    close $out or die "$0: unhappy child\n";
    $ ./try
    [14631]: starting child...
    [14632]: Hi!
    [14632]: Got [Hello, child process!]

Perl's magic variable $$ is the current process id.

Hope this helps,
Greg
-- 
When a true genius appears in this world, you may know him by this sign,
that the dunces are all in confederacy against him. 
    -- Jonathan Swift


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

Date: 23 Feb 2009 16:34:45 GMT
From: xhoster@gmail.com
Subject: Re: XML Simple force array
Message-Id: <20090223113333.442$Kr@newsreader.com>

"-Brad-" <thesnake_123@-NO-S_P_A_M-hotmail.com> wrote:
> Hi all,
>
> I have an xml file that looks like :
>
> <control_file name="XXXX_99.ctl">
>     <files_ps count="2">
>         <file seq="1" name="file1.gz" size="1107045" />
>         <file seq="2" name="file2.gz" size="1107045" />
>     </files_ps>
> </control_file>
>
> I would like to be able to loop through all the child elements under
> files_ps, and print out their attribute values.
> I was planning on using forcearray on the 'file' node so I can loop
> through all the array elements, but I cant seem to get it to work.

ForceArray only has an effect when there is exactly one element.  If there
is more than one element (like your 'file') then it is already put into
an array.  If less than one, there is nothing there in the first place.

But after it is put into an array, the action of KeyAttr might re-arrange
it into a hash.  The default value for KeyAttr is ['name', 'key', 'id'],
and since all of your "file" elements have a attribute named 'name', it
gets rearranged into a hash using 'name' as the key.

So what you need to do is add KeyAttr=>undef.

Your current example doesn't need the ForceArray, but if you every expect
to get a file_ps that has only one file, then you should keep the
ForceArray as well.

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: 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 2230
***************************************


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