$main::data[0] accesses an element of the package global array  @main::data but there is no such array.

There is a package global scalar  $main::data that has been initialized with a reference to an anonymous array. An element of this anonymous array can be accessed by an expression like  $main::data->[0] or (shudder)  $main::data->[$main::i]

Had these variables been lexicals, Perl would have told you of the absence of  @data given that you are enabling warnings and strictures. As all your variables are fully-qualified package global variables, no such hints can be given.

Update: It's a small point in the wider context of what you are doing in the OPed code, but I'm curious why the single lexical you have chosen to use in your code is in the  output() subroutine: the  $fh lexical file handle. It is very common still to see code written using package global file handles. Why, I wonder, did you choose a lexical in this instance? (Although package file handles are still very common, they are not IMHO very kosher.)


In reply to Re: Saving data to file by AnomalousMonk
in thread Saving data to file by viored

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.