Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

data structures

by perlsyntax (Pilgrim)
on Nov 27, 2007 at 18:25 UTC ( [id://653326]=perlquestion: print w/replies, xml ) Need Help??

perlsyntax has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: data structures
by jdporter (Paladin) on Nov 27, 2007 at 18:38 UTC
Re: data structures
by moritz (Cardinal) on Nov 27, 2007 at 18:32 UTC
    Data structures hold data, erm, well, in a structured way, i.e. making it easy to access the part of the data that you want.

    Generally data structures are passive, meaning they don't do anything on their own.

    You can use Data::Dumper to inspect data structures.

Re: data structures
by gamache (Friar) on Nov 27, 2007 at 18:31 UTC
    Perl's two primary data structures are the array and the hash. An array keeps its elements in a certain order; a hash is unordered but stores each of its values under a certain 'key', which may then be used to retrieve a given value. Arrays and hashes may both contain other arrays and hashes; in this case, they actually contain a reference to the array or hash.

    If you want to see what these data structures look like, try use Data::Dumper; followed by print Dumper (\%hash), for instance.

Re: data structures
by toolic (Bishop) on Nov 27, 2007 at 18:39 UTC

      When I was first learning Perl it was a struggle. One of the "breakthrough moments" for me was when I started understanding what information was in each of the many perldocs. Studying what's where as documented in perl might help that.

      I'm thinking that if you need to step back from perldsc, that the next step (back) might be perldata.

      Also, since the starting point here was you reading an oop book, you might check out:

      I humbly seek wisdom.
Re: data structures
by perlfan (Vicar) on Nov 27, 2007 at 19:39 UTC
    my $scalar = 'abc'; print "$scalar\n";
    my @array = ('abc', 123, 'dog'); for (@array) { print "$_\n"; }
    Hash (aka, associative array):
    my %hash = ( bob => 'dog', sue => 'cat', jim => 'parrot',); for (keys(%hash)) { print "$_ has a $hash{$_}.\n"; }
    There are others, but I think if I mention them your head will explode. Master these, then start thinking about combining them into complex data structures such as arrays of arrays, hashes of hashes, etc.

    Also, don't post questions just for XP - if you don't have thoughtful questions to ask, then you're gonna get down modded like you have been. I've tried to tell you this in private chat, but apparently you don't understand what I am meaning.
Re: data structures
by roboticus (Chancellor) on Nov 28, 2007 at 01:47 UTC

    Other monks have given you some pointers to perl data structures. I thought that I'd take a moment and point you to a couple of books on the subject that are pretty good. They're oldies but goodies:

    • "Algorithms + Data Structures = Programs"; Wirth
    • "Data Structures and Algorithms"; Aho, Hopcroft & Ullman
      i read them books after i finsh Object Oriented book first.
Re: data structures
by artist (Parson) on Nov 27, 2007 at 20:58 UTC
    How did you get the term 'data structure' ? May be we can explain better to you. Data can be structured in variety of ways for different purpose. Many times they are associated with algorithms. WikiPedia Article contains useful information for you. List of Data Structures can also help you.
Re: data structures
by apl (Monsignor) on Nov 27, 2007 at 20:40 UTC
    What is a data structures
    The stuff that dreams are made of!

    and what do they do
    Anything they want to, as long as the Department of Homeland Security doesn't catch them.

    and how does one look like?
    They look just like constants and variables, but have flashing ruby eyes.

    Just read Perl Monks with learning disabilities, and took the appropriate step. My attempt at humor was not intended as an insult.
Re: data structures
by aquarium (Curate) on Nov 27, 2007 at 22:27 UTC
    a data structure is a collection of data with an inherent or otherwise contrived, in any case pre-determined, order.
    they do themselves. because the order is pre-determined, so are the methods to create/read/update/delete elements at will. In fact, it could be said that a data structure is defined through the access methods
    how does a data structure look like?..hmm...about 6 feet tall...only kidding. pick any ordered data, e.g. spreadsheet.
    the hardest line to type correctly is: stty erase ^H
      It not homework i was reading my oop book on perl and i want to know more about it.:)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://653326]
Approved by randyk
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-04-23 20:14 GMT
Find Nodes?
    Voting Booth?

    No recent polls found