Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: More efficient munging if infile very large

by OeufMayo (Curate)
on Jul 26, 2001 at 15:54 UTC ( #99950=note: print w/replies, xml ) Need Help??

in reply to More efficient munging if infile very large

Okay, here's my attempt at this one, it should be slightly more efficient than using arrays, but you really should benchmark that...:

#!/usr/bin/perl -w use strict; unless ($ARGV[0] eq '-lc' || $ARGV[0] eq '-uc' ){ die "usage: lcuc [-uc | -lc] file\n"; } my $op = substr(shift @ARGV, 1, 2); while(<>){ no strict 'refs'; print &{$op}($_) } sub lc{ lc shift } sub uc{ uc shift }

TMTOWTDI Update (as suggested by tilly)

I'll admit that this one is cleaner than the above code. :)

#!/usr/bin/perl -w use strict; my %ops = ( 'lc' => sub {lc shift }, 'uc' => sub {uc shift }, ); my $case = shift @ARGV; unless (exists $ops{$case}){ die "usage: lcuc [", join(' | ', keys %ops), "] file\n"; } while(<>){ print $ops{$case}->($_); }
my $OeufMayo = new PerlMonger::Paris({http => ''});</kbd>

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://99950]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (10)
As of 2016-10-25 15:26 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (323 votes). Check out past polls.