Reg. Associative array in perl
--Next_1101887142---0-203.199.83.38-30623
Content-type: text/plain;
charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
Dear All, =0A =0A Please check the below coding because I actually expec=
t one =0Aoutput but this code print unpredictable output. I expect the =0Af=
ollowing output. =0A =0AApache =0AWindows =0ADos =0ALinux =0AUnix =0ASolari=
s =0A =0ABut Machine giving output is below =0A****************************=
******* =0ALinux =0AApache =0AWindows =0AUnix =0ASolaris =0ADos =0A =0A%Ite=
ms =3D =0A(Apache=3D>apache,Windows=3D>windows,Dos=3D>dos,Linux=3D> linux,Un=
ix=3D>unix,Solaris=3D>solaris); =0A foreach $keys (keys %Items) { =
=0A print "$keys\n"; =0A }; =0A =0AWhy this conflict?. Pl=
ease clear my doubt. I actually expect =0Athis out. =0A =0AApache =0AWindow=
s =0ADos =0ALinux =0AUnix =0ASolaris =0A =0ATo get this output what I need=
to do Mail me as early as possible =0A =0Aby =0APRabahar
--Next_1101887142---0-203.199.83.38-30623--
Re: Reg. Associative array in perl
On 1 Dec 2004, Prabahar Mosas wrote:
Please check the below coding because I actually expect one
output but this code print unpredictable output. I expect the
following output.
Apache
Windows
Dos
Linux
Unix
Solaris
But Machine giving output is below
***********************************
Linux
Apache
Windows
Unix
Solaris
Dos
%Items =
(Apache=>apache,Windows=>windows,Dos=>dos,Linux=>linux,Unix= >unix,Solaris=>solaris);
foreach $keys (keys %Items) {
print "$keys\n";
};
Why this conflict?. Please clear my doubt. I actually expect
this out.
Apache
Windows
Dos
Linux
Unix
Solaris
To get this output what I need to do Mail me as early as possible
Well that's the way hashes work. If you have a recent version of Perl, at
least the order will be the same.
However to do what you want, you could use the Tie::IxHash module
use Tie::IxHash;
......
tie %Items, "Tie::IxHash";
See the Perl Cookbook, Ch 5.6
See perldoc Tie::IxHash
(Tie::IxHash - ordered associative arrays for Perl)
Owen
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
Re: Reg. Associative array in perl
On Wed, 1 Dec 2004, Owen Cook wrote:
I meant to say
>
Well that's the way hashes work. If you have a recent version of Perl, at
least the order will be the same different order each time you run the
program.
Owen
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>
Re: Reg. Associative array in perl
>>>>> "Owen" == Owen Cook <rcook [at] pcug.org.au> writes:
Owen> Well that's the way hashes work. If you have a recent version of Perl, at
Owen> least the order will be the same different order each time you run the
Owen> program.
Actually, that's exactly backwards. :)
On recent versions of Perl, the order is *deliberately* randomized to
prevent certain denial-of-service attacks against Perl programs acting
on user-selected data.
On older versions of Perl, the order was consistent and predictable
(although *apparently* "chaotic").
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn [at] stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
--
To unsubscribe, e-mail: beginners-unsubscribe [at] perl.org
For additional commands, e-mail: beginners-help [at] perl.org
<http://learn.perl.org/> <http://learn.perl.org/first-response>