C struct equivalent

Discussion in 'Perl Misc' started by Martin Johansen, Jan 24, 2005.

  1. Hello

    I need to use structure like:

    struct{
    int x;
    array *a;
    int z;
    }s;

    Can I access some structure in perl using e.g. s.a or similar

    Thanks.
    Martin Johansen, Jan 24, 2005
    #1
    1. Advertising

  2. Martin Johansen

    Guest

    "Martin Johansen" <> wrote:
    > Hello
    >
    > I need to use structure like:
    >
    > struct{
    > int x;
    > array *a;
    > int z;
    > }s;
    >
    > Can I access some structure in perl using e.g. s.a or similar


    perldoc -q struct

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
    , Jan 24, 2005
    #2
    1. Advertising

  3. Martin Johansen <> wrote:

    > Subject: C struct equivalent



    perldoc -q struct

    How can I make the Perl equivalent of a C structure/C++ class/hash or
    array of hashes or arrays?

    How do I declare/create a structure?


    You are expected to check the Perl FAQ *before* posting to
    the Perl newsgroup.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Jan 25, 2005
    #3
  4. Martin Johansen wrote:

    > Hello
    >
    > I need to use structure like:
    >
    > struct{
    > int x;
    > array *a;
    > int z;
    > }s;
    >
    > Can I access some structure in perl using e.g. s.a or similar
    >
    > Thanks.


    Normal way to do this is with a hash:

    my %s = (
    x => 0,
    a => [],
    z => 0
    );

    --
    Christopher Mattern

    "Which one you figure tracked us?"
    "The ugly one, sir."
    "...Could you be more specific?"
    Chris Mattern, Jan 25, 2005
    #4
  5. Thanks

    That solved the problem.
    Martin Johansen, Jan 25, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RA Scheltema
    Replies:
    3
    Views:
    380
    RA Scheltema
    Jan 6, 2004
  2. Gunnar G

    struct in struct

    Gunnar G, May 31, 2004, in forum: C++
    Replies:
    14
    Views:
    784
  3. Chris Fogelklou
    Replies:
    36
    Views:
    1,345
    Chris Fogelklou
    Apr 20, 2004
  4. Jim Langston
    Replies:
    4
    Views:
    486
    Jim Langston
    Aug 28, 2007
  5. Giles Bowkett
    Replies:
    9
    Views:
    135
    Robert Klemme
    Jan 10, 2008
Loading...

Share This Page