First you open a file, read all the data there is, close the filehandle and then pass that filehandle to some method. That doesn't look right.

Second, not everything has to be an object for gawd's sake.

open my $fh, '<', '/home/test.xml' or die "Could not open file\n"; printFile($fh); close $fh;

Third, don't use prototypes. They are not what you think. It's not a way to ensure a subroutine receives a certain number of parameters, it's a way to create a subroutine that is parsed in some special way, more or less similar to some builtin.

Four, the printFile() is way too complicated. Why do you read the line into $_ and then copy to $line. Either read it directly to $line or keep on using $_. Also why chomp off the newline and append it again?

sub printFile { my $fh = $_[0]; while (<$fh>) { print $_; } }


In reply to Re: Sending xml message in perl by Jenda
in thread Sending xml message in perl by mikes300

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.