Home > Archive > PERL Beginners > January 2008 > Pseudo-hashes are deprecated
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Pseudo-hashes are deprecated
|
|
| Harry Bennett 2008-01-29, 8:13 am |
| I am using this line:
foreach my $pair (keys %{$config{server}}) {
......
}
but get the warning:
Pseudo-hashes are deprecated at ......
I am using the example from 'Programming Perl (third edition)' Section 9.4.3
I guess my ultimate question would be, what have they been deprecated to?
And an example would be GREATLY appreciated.
TIA
| |
| John W. Krahn 2008-01-29, 8:13 am |
| Harry Bennett wrote:
> I am using this line:
>
> foreach my $pair (keys %{$config{server}}) {
> .....
> }
>
> but get the warning:
>
> Pseudo-hashes are deprecated at ......
>
> I am using the example from 'Programming Perl (third edition)' Section 9.4.3
>
> I guess my ultimate question would be, what have they been deprecated to?
> And an example would be GREATLY appreciated.
See the "Pseudo-hashes: Using an array as a hash" section from:
perldoc perlref
And also:
perldoc fields
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
| |
| Chas. Owens 2008-01-29, 8:13 am |
| On Jan 29, 2008 7:45 AM, Harry Bennett <harry@saltyshells.com> wrote:
> I am using this line:
>
> foreach my $pair (keys %{$config{server}}) {
> .....
> }
>
> but get the warning:
>
> Pseudo-hashes are deprecated at ......
>
> I am using the example from 'Programming Perl (third edition)' Section 9.4.3
>
> I guess my ultimate question would be, what have they been deprecated to?
> And an example would be GREATLY appreciated.
snip
The error is being printed at that line, but its cause is earlier in
your code. The following code has no error
#!/usr/bin/perl
use strict;
use warnings;
my %config = (
server => { one => 1, two => 2, three => 3 }
);
foreach my $pair (keys %{$config{server}}) {
print "$pair\n";
}
The error is really the use of pseudo-hashes. They have not been
replaced with anything because they turned out to be a bad idea. The
goal was to have the speed of an array, but the easy of use of a hash.
The implementation wound up doing neither and cluttering up the
source*. The other feature of pseudo-hashes, the compile time
checking of the keys, has been preserved in the fields pragma**.
* from http://use.perl.org/article.pl?sid=01/07/16/127257
The extra code to support pseudo-hashes slowed down all arrays
and hashes by 10 to 15%.
** see perldoc fields or http://perldoc.perl.org/fields.html
| |
| Peter Scott 2008-01-29, 7:11 pm |
| On Tue, 29 Jan 2008 07:45:00 -0500, Harry Bennett wrote:
> I am using this line:
>
> foreach my $pair (keys %{$config{server}}) {
> .....
> }
>
> but get the warning:
>
> Pseudo-hashes are deprecated at ......
>
> I am using the example from 'Programming Perl (third edition)' Section 9.4.3
>
> I guess my ultimate question would be, what have they been deprecated to?
You don't need to know, because they don't work at all in 5.10, and
besides, that example doesn't use them; you translated it incorrectly.
> And an example would be GREATLY appreciated.
Somehow you got an arrayref containing a hashref inside $config{server},
and that maketh a pseudohash (see section 8.3.5):
my $sudoh = [ {foo => 1, bar => 2} ];
my %config = (server => $sudoh );
You wanted just the hashref there.
--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/
| |
| Paul Lalli 2008-01-29, 7:12 pm |
| On Jan 29, 7:45=A0am, ha...@saltyshells.com (Harry Bennett) wrote:
> I am using this line:
>
> foreach my $pair (keys %{$config{server}}) {
> .....
>
> }
>
> but get the warning:
>
> Pseudo-hashes are deprecated at ......
>
> I am using the example from 'Programming Perl (third edition)' Section 9.4=
..3
One of us is very . I'm guessing you. There is no such thing
as "9.4.3" in the third edition of the Camel. There is a chapter 9,
of course, and indeed it deals with multi-dimensional structures. But
there is no such example listed in it.
Paul Lalli
| |
| Rob Dixon 2008-01-29, 10:09 pm |
| Paul Lalli wrote:
> On Jan 29, 7:45 am, ha...@saltyshells.com (Harry Bennett) wrote:
>
> One of us is very . I'm guessing you. There is no such thing
> as "9.4.3" in the third edition of the Camel. There is a chapter 9,
> of course, and indeed it deals with multi-dimensional structures. But
> there is no such example listed in it.
The O'Reilly Perl CD Bookshelf has a section numbering system. 9.4.3 is
the section titled "Access and Printing of a Hash of Hashes" on page 281
of the printed book.
Rob
|
|
|
|
|