The input file file.xml contains some legal xml with root html tag with content in it. I have set the record separator to undef, so that the entire file is slurped into $records as one big line. In the regex match below, I am trying to get the contents of the html element. This works when I use a literal as the input, but not when I use the variable $records as the input to match, I get 'Use of uninitialized value $text in string at... ' at run time. Why? Am I not capturing the result of the match into $text?
use strict;
use warnings;
open FILE_IN, '<file.xml';
open FILE_OUT, '>results.txt';
$/ = undef;
my $records = <FILE_IN>;
my $text = "";
($text) = $records =~ m/<html>(.*)<\/html>/;
print "$text";
close FILE_IN;
close FILE_OUT;
Puzzling.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.