LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-11-2008, 04:39 AM   #1
kenneho
Member
 
Registered: May 2003
Location: Oslo, Norway
Distribution: Ubuntu, Red Hat Enterprise Linux
Posts: 657

Rep: Reputation: 40
Perl scripting: Data structure similar to C's "struct"


Hi.


I'm trying to create an array of nodes. In C I would typically make an array and fill it with instances of a "struct" structure. How can this be done in perl?

Regards,
kenneho
 
Old 05-11-2008, 09:48 AM   #2
Su-Shee
Member
 
Registered: Sep 2007
Location: Berlin
Distribution: Slackware
Posts: 510

Rep: Reputation: 53
Take a look into "perllol" and "perlref" - you can have either an array (index by number, has a range) or a hash (index by key which must be something which leads no matter how perlish you might get there to something string-ish in the end, no range).

Into both you may put more or less anything - especially references (you're possibly more comfortable with "pointer" here) to: other arrays or hashes, to named or anonymous functions, to filehandles...

You don't need to declare size or data type of the content in advance and either hashes and arrays will grow as you go and add elements.

Both list types come with a set of functions to manipulate them (adding/substracting elements, deleting, checking for existence..) and most perl loops are list-aware and support some sugarcoating for easier access.

Wether you need an array or a hash, you'll have to decide.
 
Old 05-11-2008, 05:45 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,356

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
And here's the tutorial: http://perldoc.perl.org/perldsc.html
 
Old 05-25-2008, 08:20 AM   #4
kenneho
Member
 
Registered: May 2003
Location: Oslo, Norway
Distribution: Ubuntu, Red Hat Enterprise Linux
Posts: 657

Original Poster
Rep: Reputation: 40
Thanks for the advice.

I ended up putting hashes in an array, which worked out fine.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
g++ doesn't support "C-struct member initialization" extension of gcc? ta0kira Programming 8 04-13-2008 02:57 PM
C declaration problem for a "typedef struct". Spirals Linux - Software 3 03-17-2008 07:52 AM
C/C++ functions similar to BASH's "cp", "mv", "mkdir", etc? kornerr Programming 10 04-23-2006 09:48 AM
problem "make"ing gtk+ "/usr/bin/env: perl -w" caid Linux - Newbie 8 07-29-2005 04:51 AM
LFS 4.1: Stalled at Perl, "missing seperator" error from "make" SparceMatrix Linux From Scratch 1 06-07-2003 03:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:30 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration