Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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>

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

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 surveying the Monastery: (9)
As of 2015-12-01 07:51 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (795 votes), past polls