Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re^3: Print out an XML file to browser

by virtualsue (Vicar)
on Feb 20, 2007 at 05:56 UTC ( #601030=note: print w/replies, xml ) Need Help??

in reply to Re^2: Print out an XML file to browser
in thread Print out an XML file to browser

Two things:
  1. If you know you want to output xml, then print header('text/xml'); is a lot simpler.
  2. Always check to see if your 'open' succeeded. Your error message means that your script didn't open the file.
#!/usr/local/bin/perl use strict; use warnings; use CGI qw(:standard); use CGI::Carp qw(fatalsToBrowser); print header('text/xml'); my $file = "/some/file.xml"; open(XMLFILE, $file) or die "Failed to open $file, $!"; while (<XMLFILE>){ print; }

Replies are listed 'Best First'.
Re^4: Print out an XML file to browser
by lakeTrout (Scribe) on Feb 20, 2007 at 06:58 UTC
    Thanks Virtualse

    The above code seems to work but I get a bad headder error. It "works" mening in prints by hand, just not to the browser. What might cause that?
Re^4: Print out an XML file to browser
by been42 (Curate) on Feb 20, 2007 at 14:55 UTC
    Thanks for the correction. I thought I remembered that it was something simple, but I guess I just skipped over that in the docs when I looked.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://601030]
[stevenlm87]: Needs help. I am taking an online class for perl and is using Padre. How can I get a list from the input in this code? print "What are your favorite hobbies? "; my $hobbies = <STDIN>; chomp $hobbies; print "Your favorite hobbies are '$hobbies'\n";

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (8)
As of 2017-02-23 19:48 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (350 votes). Check out past polls.