I'm tinkering with a script which writes a fixed wrapper around perl source which is fed to it through STDIN. The wrapper code needs data which is currently stored after an __END__ tag. A problem arises if the input source uses its own DATA handle.

Following some hints in Camel3, I've tried declaring package Wrapped; before the input code to qualify the __DATA__ tag. This fail with the main::DATA handle reading from the guest code's __DATA__ tag to the end of the file. Schematically, the resulting code is structured like this:

#!/usr/bin/perl -w use strict; =pod Output: Name "Extra::DATA" used only once: possible typo at ./camtst line 23. From main Extra datum __END__ This data is for main Read on closed filehandle <DATA> at ./camtst line 23. From Extra =cut print "From main ", <DATA>; package Extra; print "From Extra", <DATA>; package main; __DATA__ Extra datum __END__ This data is for main
Is it possible to use two DATA tags in the same file? I don't see a way to change namespace after the first is seen.

I'd appreciate any explanations or links about fine control of the DATA filehandle. I can obviously store namespace main's data in a heredoc or some other construct, so my question is entirely in "Search of Perl Wisdom". Thanks.

After Compline,
Zaxo

Edit Petruchio Thu Sep 20 09:11:38 UTC 2001 - Added READMORE tag.


In reply to Scope of the DATA handle by Zaxo

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.