declare structure

Discussion in 'Perl Misc' started by Rose, Mar 9, 2008.

  1. Rose

    Rose Guest

    One day i found some codes by others write like this way (i can't remember
    the exact codes):

    a[0]->idx = 1; # or => 1?
    a[0]->name = "foo";
    a[0]->loc = "earth";

    I doubt it's OO programing but Perl in 21 Days told me that may be another
    story. I'm not using associative array because i need all 3 or more
    information later and associative array may not provide convenient way for
    me to retrieve the information. Could anybody shed some light on what topic
    I should refer to ?
     
    Rose, Mar 9, 2008
    #1
    1. Advertising

  2. Rose

    Ben Morrow Guest

    Quoth Keith Keller <-francisco.ca.us>:
    > On 2008-03-09, Rose <> wrote:
    > >
    > > a[0]->idx = 1; # or => 1?
    > > a[0]->name = "foo";
    > > a[0]->loc = "earth";

    >
    > It was probably more like
    >
    > $a[0]->{idx}=1;
    >
    > It could also have been (unlikely)
    >
    > $a[0]->idx(1);


    It *could* also have been

    $a[0]->idx = 1;

    using something like

    {
    package My;

    my $idx;

    sub idx : lvalue method { $idx }
    }

    my @a = bless [], 'My';

    This construction is considered a bad idea nowadays, as it's very hard to
    insert a proper 'set' method later.

    Ben
     
    Ben Morrow, Mar 9, 2008
    #2
    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. mosfet
    Replies:
    1
    Views:
    414
    lallous
    Dec 15, 2003
  2. nm
    Replies:
    1
    Views:
    368
    Victor Bazarov
    May 4, 2006
  3. sharat
    Replies:
    5
    Views:
    395
    John Carson
    Dec 17, 2006
  4. PerlFAQ Server

    FAQ 7.8 How do I declare/create a structure?

    PerlFAQ Server, Feb 12, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    108
    PerlFAQ Server
    Feb 12, 2011
  5. PerlFAQ Server

    FAQ 7.8 How do I declare/create a structure?

    PerlFAQ Server, Feb 22, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    104
    PerlFAQ Server
    Feb 22, 2011
Loading...

Share This Page