Professional Web Applications Themes

Class::Struct - want to access structure within structure - PERL Modules

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); #this isn't working blockArray = (blockArray, $block1); #would then like to access the Steps within the Blocks foreach $tempBlock (blockArray) ...

  1. #1

    Default Class::Struct - want to access structure within structure

    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); #this isn't working

    blockArray = (blockArray, $block1);

    #would then like to access the Steps within the Blocks
    foreach $tempBlock (blockArray) {
    foreach $tempStep ($tempBlock->steps) { #
    print $tempStep->number;
    }
    }

    nelson331 Guest

  2. #2

    Default Re: Class::Struct - want to access structure within structure


    nelson331 wrote:
    > my $block1 = Block->new();
    > $block1->number(1);
    > $block1->steps(stepArray); #this isn't working
    The docs for Class::Struct
    [url]http://search.cpan.org/~jhi/perl-5.8.0/lib/Class/Struct.pm[/url]

    do not show that type of usage. Only this usage:
    With one or two arguments, the first argument is an index specifying
    one element of the array; the second argument, if present, is assigned
    to the array element. If the element type is '', the accessor returns
    the array element value. If the element type is '*', a reference to
    the array element is returned.

    -- meaning, that you can only put in one element at a time.


    Also:
    1 - what are you resorting to objects for in this case anyway? The
    standard Perl data structures look like they can handle this problem.

    2 - Class::Accessor is much more popular for this sort of thing. I
    prefer Class::Prototyped myself.

    3 - You might find some more help on perlmonks.org for this type of
    question.

    Good luck

    metaperl@gmail.com Guest

Similar Threads

  1. Copy a table in Access structure only with CF query
    By jimWPX in forum Coldfusion Database Access
    Replies: 3
    Last Post: June 4th, 02:33 PM
  2. Add to Structure
    By H3ath0r in forum Coldfusion - Getting Started
    Replies: 4
    Last Post: September 24th, 12:57 AM
  3. Class v. Structure
    By Just Me in forum ASP.NET Web Services
    Replies: 4
    Last Post: July 27th, 01:43 PM
  4. Hiding Abstrected Class Structure in WSDL
    By Ashishthaps in forum ASP.NET Web Services
    Replies: 0
    Last Post: July 19th, 12:50 AM
  5. W3D structure...
    By Glorfind3l in forum Macromedia Director 3D
    Replies: 2
    Last Post: February 26th, 10:00 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139