Class::Struct array assignment and access

Discussion in 'Perl Misc' started by nelson331, Apr 29, 2006.

  1. nelson331

    nelson331 Guest

    I want to access a structure within a structure. Below is what I had
    in mind. Please help.

    #!/perl/bin/perl
    use Class::Struct;

    struct Step => {
    number => '$',
    otherstuff => '$',
    };

    struct Block => {
    number => '$',
    steps => '@', #should be an array of "Step"s
    };

    my $step1 = Step->new();
    $step1->number(1);

    my $step2 = Step->new();
    $step2->number(2);

    #will eventually be in side a loop @stepArray = (@stepArray,
    $tempStep);
    @stepArray = ($step1, $step2);

    my $block1 = Block->new();
    $block1->number(1);
    $block1->steps(@stepArray);

    @blockArray = (@blockArray, $block1);

    #would then like to access the Steps within the Blocks
    foreach $tempBlock (@blockArray) {
    foreach $tempStep ($tempBlock->steps) {
    print $tempStep->number;
    }
    }
    nelson331, Apr 29, 2006
    #1
    1. Advertising

  2. "nelson331" <> wrote in news:1146335481.061030.164470
    @i40g2000cwc.googlegroups.com:

    > I want to access a structure within a structure. Below is what I had
    > in mind. Please help.


    I don't understand what you need help with.

    > #!/perl/bin/perl


    This is an odd shebang line for sure.

    > @blockArray = (@blockArray, $block1);


    There is no mention of @blockArray before this line.

    Make sure to put

    use strict;
    use warnings;

    in your script, and tell us, please, what is your question?

    Sinan

    --
    A. Sinan Unur <>
    (remove .invalid and reverse each component for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Apr 29, 2006
    #2
    1. Advertising

  3. nelson331

    nelson331 Guest

    The shebang line is for windows.
    The @blockArray was only for example.

    Basically, I want to access a structure within a structure. I need to
    be able to store and retrieve.
    nelson331, Apr 29, 2006
    #3
  4. "nelson331" <> wrote in news:1146344317.750874.232720
    @i39g2000cwa.googlegroups.com:

    [ Please read the posting guidelines for this group, and quote some
    context when you reply ]

    > The shebang line is for windows.


    You don't need a shebang line for Windows.

    > The @blockArray was only for example.
    >
    > Basically, I want to access a structure within a structure. I need to
    > be able to store and retrieve.


    Please don't post pseudo-code. Post a short but complete script which
    others can run (as described in the posting guidelines) to show what you
    have tried and what does not work.

    Sinan

    --
    A. Sinan Unur <>
    (remove .invalid and reverse each component for email address)

    comp.lang.perl.misc guidelines on the WWW:
    http://augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html
    A. Sinan Unur, Apr 29, 2006
    #4
    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. Chris Fogelklou
    Replies:
    36
    Views:
    1,371
    Chris Fogelklou
    Apr 20, 2004
  2. Replies:
    3
    Views:
    1,080
  3. Daniel
    Replies:
    4
    Views:
    545
    White Wolf
    Nov 27, 2009
  4. Noob
    Replies:
    25
    Views:
    1,466
    Nick Keighley
    Dec 9, 2009
  5. Tuan  Bui
    Replies:
    14
    Views:
    470
    it_says_BALLS_on_your forehead
    Jul 29, 2005
Loading...

Share This Page