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.

In reply to Re: Real World 1, Great Expectations 0 by tadman
in thread Real World 1, Great Expectations 0 by hsmyers

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.