Thanks, synapse0 (and others who replied also) for the suggestions. 8^)
I'm not familiar with the eq 'lc' ? lc() : uc(); syntax from print OUT $uclc eq 'lc' ? lc() : uc();. Would you be so kind as to explain how that works?
Updated: 2001-07-29 07:40 CDT
Here's what I ended up using. Thanks again, and ++ to all who offered suggestions in nodes and CB!
cheers,
Don
striving toward Perl Adept
(it's pronounced "why-bick")
#!/usr/bin/perl -w
use strict;
my $uclc = shift or Usage();
Usage() unless ($uclc eq 'uc' or 'lc');
while(<>) { print $uclc eq 'uc' ? uc() : lc(); }
sub Usage {
print "\n Usage: uclc.pl (uc|lc) < infile > outfile\n\n";
exit;
}
=head1 NAME
uclc.pl
=head1 SYNOPSIS
uclc.pl (uc|lc) < infile > outfile"
Convert alpha characters in text file to uppercase (or lowercase).
=head1 UPDATED
2001-07-26 16:30 CDT
Simplify code for (in|out)put of STD(IN|OUT).
Remove unnecessary "or Usage()" from first two input lines.
Replace if/else with ternary "?:".
my $munged;
if ($uclc eq 'uc') { $munged = uc(); }
else {$munged = lc(); }
print OUT $munged;
While instead of for so file read line-by-line not slurp entire fil
+e.
Post efficiency SoPW to PerlMonks
2001-07-25
Initial working code.
=head1 TODOS
None that I know of.
=head1 TESTED
ActivePerl 5.61 on Win2kPro
=head1 AUTHOR
ybiC
=head1 CREDITS
Thanks to synapse0, OeufMayo, crazyinsomniac, Masem,
MZSanford, virtualsue, Hoffmater, tilly, clemburg,
and ichimunki for suggestions.
And to davorg for "Data Munging with Perl".
Oh yeah, and to some guy named vroom.
=cut
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|