If you're going to
use IO::Handle, use it, don't just stick it in there and then ignore it. Code which makes use of a few methods from
IO::Handle, but otherwise uses the regular functions looks schizophrenic. It's not unlike driving on the right hand side of the road most of the time, but sometimes, switching to the left side for no clear reason. Confusing, at best, especially when you're adding code somewhere in the middle. Which method do you use then?
IO::Handle would have you do it like so:
#!/usr/bin/perl -w
#
# test.pl -- IO:: test code...
use strict;
use warnings;
use diagnostics;
use IO::File;
my @list = qw[ one.tmp two.tmp three.tmp ];
my @handles = map { IO::File->new(">$_") } @list;
foreach my $handle (@handles)
{
$handle->print("Hi how the hell are ya!");
$handle->close();
}
A few notes:
I'm using
map to convert your @list list into the @handles list.
map is great at performing list conversions, so I try to use it as much as possible. Stuff in, stuff out. No mess.
When you're calling functions, try and put brackets on them to make it clear what you're doing. Sometimes the interpreter can get a little confused about what is the function and what is the object. Throwing brackets in makes it very clear, even to the reader.
If you open with
IO::Handle,
close with it too. That is, don't use the internal
close method on an object. Only use that on something created with the internal
open method. Make everything match up, because sometimes the object does something important that you are skipping.