Not neato, not handy.
There are already a lot of modules that handle files in lots of ways. And Perl's internal open function is not too bad either (since the three-argument form was invented, that is).
You don't need to use FileHandle to automatically assign a file handle. In recent Perls, you can just use a scalar to do so:
use Carp;
sub simpleopen {
my ($mode, $file) = @_;
my $fh;
open($fh, $mode, $file) or croak $!;
return $fh
}
my $logfile = simpleopen('>>', "$0.log");
And still, that's code I wouldn't use, because there's already a perfect OO solution to that:
IO::File.
use IO::File;
my $logfile = IO::File->new("$0.log", 'a');
I wonder why you used custom letters (qw/R W O F/), where the rest of the world uses qw/r a w/ and r+/w+/a+ (or even rw).
You might like to know the
qw// operator, that acts like
split ' ':
%i = qw(R < W >> O +> F +<);.
Last, I'd like to tell you to (I would force you, if I could) read
perlstyle. Indent! Add whitespace after commas! Indent some more!
2;0 juerd@ouranos:~$ perl -e'undef christmas'
Segmentation fault
2;139 juerd@ouranos:~$
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.