<?xml version="1.0" encoding="windows-1252"?>
<node id="99983" title="(code) Re: (2) More efficient munging... (improved lc() uc() snippet)" created="2001-07-26 14:16:55" updated="2005-07-19 22:12:24">
<type id="11">
note</type>
<author id="14909">
ybiC</author>
<data>
<field name="doctext">
Thanks, [synapse0] &lt;i&gt;(and others who replied also)&lt;/i&gt; for the suggestions. &amp;nbsp; 8^)

&lt;p&gt;
I'm not familiar with the &lt;code&gt;eq 'lc' ? lc() : uc();&lt;/code&gt; syntax from &lt;code&gt;print OUT $uclc eq 'lc' ? lc() : uc();&lt;/code&gt;. &amp;nbsp; Would you be so kind as to explain how that works?

&lt;p&gt;
&lt;b&gt;Updated: &lt;/b&gt; 2001-07-29  07:40 CDT
&lt;p&gt;
Here's what I ended up using. &amp;nbsp; Thanks again, and ++ to all who offered suggestions in nodes and CB!

&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;cheers,
&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Don
&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;i&gt;striving toward &lt;a href="http://prometheus.frii.com/~gnat/yapc/2000-stages/"&gt;Perl Adept&lt;/a&gt;&lt;/i&gt;
&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;font size="-2"&gt;(it's pronounced &amp;quot;why-bick&amp;quot;)&lt;/font&gt;

&lt;code&gt;#!/usr/bin/perl -w

use strict;

my $uclc = shift or Usage();
Usage() unless ($uclc eq 'uc' or 'lc');
while(&lt;&gt;) { print $uclc eq 'uc' ?  uc() : lc(); }

sub Usage {
   print "\n Usage: uclc.pl (uc|lc) &lt; infile &gt; outfile\n\n";
   exit;
   }

=head1 NAME

 uclc.pl

=head1 SYNOPSIS

 uclc.pl (uc|lc) &lt; infile &gt; 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 file.
   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

&lt;/code&gt;</field>
<field name="root_node">
99943</field>
<field name="parent_node">
99947</field>
</data>
</node>
