in reply to Re^3: parsing metadata
in thread parsing metadata
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.
|
|---|