473,385 Members | 1,588 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

[perl-python] 20050118 keyed list

© # -*- coding: utf-8 -*-
©
© # in Python, there's a special type of
© # data structure called keyed list. it
© # is a unordered list of pairs, each
© # consists of a key and a value. It is
© # also known as dictionary.
©
© # define a keyed list
© aa = {'john':3, 'mary':4, 'jane':5, 'vicky':7}
© print aa
©
© # getting value from a key
© print 'mary is', aa['mary']
©
© # delete an entry
© del aa['vicky']
© print aa
©
© # get just the keys
© print aa.keys()
©
© # check if a key exists
© print aa.has_key('mary')
©
© # to learn more,
© # type help() and DICTIONARIES
© # or see
© # http://python.org/doc/2.3.4/tut/node7.html
©
© -------------------------------------------
© # in perl, keyed-list is done like this:
©
© %a = ('john',3, 'mary', 4, 'jane', 5, 'vicky',7);
© use Data::Dumper qw(Dumper);
© print Dumper \%a;
©
© # the syntax of keyed list in Perl is too complex
© # to be covered in a short message.
© # see "perldoc perldata" for an unix-styled course.
©
© Xah
© xa*@xahlee.org
© http://xahlee.org/PageTwo_dir/more.html

Jul 18 '05 #1
6 1841
"Xah Lee" <xa*@xahlee.org> wrote:

: # the syntax of keyed list in Perl is too complex
: # to be covered in a short message.

You've got to be joking. You couldn't even muster enough skill to provide
Perl equivalents for the four simple Python statements you showed?

: # see "perldoc perldata" for an unix-styled course.

It's good to see your opinion on the _fantastic incompetent writting_[1] of
Perl's documentation has changed enough that you can recommend it to
novices.

[1]Message-ID: <7f**************************@posting.google.com >

Jul 18 '05 #2
Xah Lee wrote:
© # in perl, keyed-list is done like this:
Just FYI: those thingies are called hashes. The legacy name would be
associative array.
© %a = ('john',3, 'mary', 4, 'jane', 5, 'vicky',7);
© use Data::Dumper qw(Dumper);
© print Dumper \%a;
Wow, my compliments. The very first time that using Data::Dumper actually
may do something useful (formats the data more nicely). Still, why you are
passing a reference is beyond me.
© # the syntax of keyed list in Perl is too complex
© # to be covered in a short message.
Excuse me? If (using the same examples as for your Python section)
print "Mary is $a{mary}";
delete $a{vicky}; print %a;
print keys(%a);
exists $a{mary};
is too complex for your to cover, then I strongly suggest you stop posting
your "explanations".
© # see "perldoc perldata" for an unix-styled course.


Excuse me? Do you mind explaining where exactly perldata is "Unix-styled"?

jue
Jul 18 '05 #3
Also sprach Jürgen Exner:
Xah Lee wrote:

© %a = ('john',3, 'mary', 4, 'jane', 5, 'vicky',7);
© use Data::Dumper qw(Dumper);
© print Dumper \%a;


Wow, my compliments. The very first time that using Data::Dumper actually
may do something useful (formats the data more nicely). Still, why you are
passing a reference is beyond me.


How else would you use 'Dumper' on a hash?

Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus}) !JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexi ixesixeseg;y~\n~~dddd;eval
Jul 18 '05 #4
Jay Tilton wrote:
: # the syntax of keyed list in Perl is too complex
: # to be covered in a short message.
JFTR: "keyed lists" are called dictionaries in Python.

[1]Message-ID: <7f**************************@posting.google.com >


This guy's wish-wash is starting to be funny, after all!

Reinhold
Jul 18 '05 #5
Jürgen Exner wrote:
© # see "perldoc perldata" for an unix-styled course.


Excuse me? Do you mind explaining where exactly perldata is "Unix-styled"?


Remember: Perl == Unix == Satan.

Reinhold
Jul 18 '05 #6
Tassilo v. Parseval wrote:
Also sprach Jürgen Exner:
Xah Lee wrote:

© %a = ('john',3, 'mary', 4, 'jane', 5, 'vicky',7);
© use Data::Dumper qw(Dumper);
© print Dumper \%a;


Wow, my compliments. The very first time that using Data::Dumper
actually may do something useful (formats the data more nicely).
Still, why you are passing a reference is beyond me.


How else would you use 'Dumper' on a hash?


Well, fair enough. If you do a plain
print Dumper(%a);
you do loose a lot of the nifty pretty printing that is provided by Dumper
otherwise.

jue
Jul 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Mark Wilson CPU | last post by:
This must be easy, but I'm missing something... I want to execute a Perl script, and capture ALL its output into a PHP variable. Here are my 2 files: -------------------------------------...
3
by: David F. Skoll | last post by:
Hi, I'm tearing my hair out on this one. I'm trying to embed a Perl interpreter into a C program. I need to be able to create and destroy the interpreter periodically, but will never actually...
1
by: Julia Bell | last post by:
I would like to run the same script on two different platforms. The directory in which the script(s) will be stored is common to the two platforms. (I see the same directory contents regardless...
1
by: sm00thcrimnl13 | last post by:
if i have windows 2000 and know how to write perl scripts, how to i actuvate the script through perl?
1
by: smsabu2002 | last post by:
Hi, I am facing the build problem while installing the DBD-MySql perl module (ver 2.9008) using both GCC and CC compilers in HP-UX machine. For the Build using GCC, the compiler error is...
13
by: Otto J. Makela | last post by:
I'm trying to install to php the Perl-1.0.0.tgz package (from http://pecl.php.net/package/perl, enabling one to call perl libraries) to a pre-existing Solaris system. Unfortunately, the attempt...
6
by: surfivor | last post by:
I may be involved in a data migration project involving databases and creating XML feeds. Our site is PHP based, so I imagine the team might suggest PHP, but I had a look at the PHP documentation...
4
by: billb | last post by:
I installed a perl extension for PHP to use some perl inside my php primarily because I have perl working with oracle and not php and oracle. So I want to use my old perl scripts, and use the...
4
by: vijayarl | last post by:
Hi All, i have the following software installed in my system : 1.OS: Win2k 2.Eclipse Version used :3.4.0 & even the perl too... 1. I have imported the my own perl project in Eclipse, when i...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.