I'm trying to store some data into a rather complex file structure and I'm having a little trouble with the syntax. I have two structs (one embedded within the other) that look like this:

struct Appt => { startTime => '$', endTime => '$', }; struct Day => { date => '$', appts => '@', numAppts => '$', };
You'll notice that the Day struct contains an array which I intend to be an array of Appt structs. I then have an array of Day structs (and a counter), like this:

my @days; my $dayCount = 0;
I seem to be able to add Day structs to my array, days, like this:

sub hdl_start { my ($p, $elt, %atts) = @_; if ( $elt eq 'DAY' ) { # Create a new Day struct my $temp = Day->new(); # Set the date element of that struct $temp->date($atts{"DATE"}); # Insert that struct into my array, days $days[$dayCount] = $temp; } $currEle = $elt; }
Unfortunately, I'm unable to add any elements to the appts array within the Day struct. This is the code I'm currently trying to use to add a new Appt struct to the appts array:

# Get the number of appointments my $numAp = $days[$dayCount]->numAppts; # Create a new Appt struct my $temp = Appt->new(); # Set the startTime element within my new Appt struct $temp->startTime("$str"); # Insert my new Appt struct into the appts array $days[$dayCount]->appts[$numAp] = $temp;
The error I am given looks like this: syntax error at line 81, near "->appts[". (Line 81 is the final line of code listed above.)

I'm assuming it's just a syntax error, but, unfortunately, I've been unable to track it down. I was hoping one of you could help.

Thanks,
-Sherlock

In reply to Syntax Error with Embedded Structs by Sherlock

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.