Fellow Monks,
I am seeking guidance on preprocessing STDIN without first putting it all into an @array or writing it to a file, which offends my sensibilities.
Consider the following CODE:
if ( $opt_e ) {
# Preprocess STDIN and strip email header
$start_of_body=0;
while ( !($start_of_body) ){
$line=<STDIN>;
if($line eq "\n") { $start_of_body=1; }
}
$twig->parse( \*STDIN);
}
else {
print "Reading from STDIN, press CTRL+D when finished.\n";
$twig->parse( \*STDIN);
}
}
The purpose of this code is to allow email that contains XML in the body to be piped and processed by the script. However, the XML parser only handles XML and I must strip off the email header. I am reading STDIN one line at a time and when I detect that I have reached the end of the header, I pass the *FileHandle for STDIN to the XML parser method. The *FileHandle should now be at the start of the XML or email body, but it appears empty.
If I call the parse method and pipe just straight XML to the script, all is well as seen in the else code branch.
Can anyone explain this behavior?
Humbly,
UUOC