in reply to Sending xml message in perl
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 $_; } }
|
|---|