This doesn't look *too* bad to me. There are a few style deviations (I won't say violations since most of these standard are not rules per se). You only indent two spaces. The Perl standard is 4 spaces (personally I prefer 3 spaces, but that's just me). You're 2 space indents don't seem quite enough to sufficiently mark the indented blocks.
if (!($ARGV[0])) { would be better written without the extranous do-nothing parentheses:
if (! $ARGV[0]) {. This code
} elsif (!($ARGV[0] =~ /^-/)) { is unnecessarily complex. This is better:
} elsif ($ARGV[0] !~ /^-/) {. If you use the perl
-s switch in your #! line you could simplify the logical structure of your program considerably since that will handle processing the command line option for you. Also all those if/elsif/else blocks tend to cover up the real core functionality of your program. There are an array of other syntactic tools in Perl that would let your code be clearer and shorter. Rather than go through all of them, let me just show you another way to approach the same problems that gives much clearer results:
#!c:\perl\bin\perl.exe -ws
use strict;
use Crypt::Twofish_PP;
die "Syntax: crypt.pl (-e|-d) Text" unless @ARGV == 1;
my $crypt = Crypt::Twofish_PP->new('innatelyinsecure');
print $e ? $crypt->encrypt(shift @ARGV) :
$d ? $crypt->decrypt(shift @ARGV) :
"Invalid mode argument (must be -e or -d)";
Now, if you read about the way that perl -s works you'll see that my version behaves a little differently than yours; it's not as tight with the command line. You could have multiple options listed even things that are not -d or -e.
IMO there's nothing really bad in your code, but you are definitely not using the full range of expressive and functionaly power in Perl to create code that is optimally clear to a human reader.
--DrWhy
"If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."
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.