Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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}->($_); }
<kbd>--
my $OeufMayo = new PerlMonger::Paris({http => 'paris.mongueurs.net'});</kbd>


Comment on Re: More efficient munging if infile very large
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2014-09-17 23:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (100 votes), past polls