There's no need to push the results to a file; we're only reading from DATA here since it's convenient for self-contained example scripts. Just use backticks or the qx operator - as you already have, in fact.

As for the error message you're getting, it doesn't seem to be related to the snippet you shared. In fact, the line

my $value = $1 if($re =~ /^value: (.*)/); + | warn $attribute,$value;

That said - you're declaring $attribute and $value inside the loop here, meaning that they will go out of scope and be created anew with each iteration, so at any given time, at most one of them is going to have a defined value.

The solution is to move the declarations (my $attribute; and my $value;) out of the loop. Even then, be careful that in each iteration, they both just represent the last attribute and value seen, meaning that a) they'll be uninitialized until a attribute: and a value: line has been encountered, and b) they'll go out of sync if you have seen a new attribute: line but not its corresponding value: line yet, so be careful what you do with them at which time.


In reply to Re^4: parsing metadata by AppleFritter
in thread parsing metadata by Anonymous Monk

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.