in reply to DATA munging data

You might want to try some persistence modules, e.g. Data::Dumper, Data::Denter, and/or Storable. These will allow you to serialize a perl data structure to a string, which can be written to a file, and read it back in later and deserialize it back to the structure. You can then use an external file, which is safer as you can't accidentally overwrite pieces of your script. Also, the modules will allow for if you must store more complex structures later, whereas simply flat-filing it will not.

Update: Fixed as per chipmunk's reply.

Replies are listed 'Best First'.
Re: Re: DATA munging data
by chipmunk (Parson) on May 10, 2001 at 07:25 UTC
    I tend to agree that saving the data to a separate file is a better solution. However, it's not true that __END__ doesn't work with <DATA>. Either __END__ or __DATA__ may be used to signify the end of the code and the beginning of data which may be read from the special DATA filehandle.

    perldata:

    The tokens __END__ and __DATA__ may be used to indicate the logical end of the script before the actual end of file. Any following text is ignored, but may be read via a DATA filehandle: main::DATA for __END__, or PACKNAME::DATA (where PACKNAME is the current package) for __DATA__.

    And an example:

    #!perl while (<DATA>) { print; } __END__ Hello, world!
    produces: Hello, world!