I tried these two tweaks to move that logic outside the for(@in) loop. The first doesn't work because (correct me if I'm wrong) $_ is empty when $munged is declared. The second fails with this compilation error: syntax error at uclc.pl line (push @munged, $munged();), near "$munged(" and I'm not clear just what's happening there.
So my questions for the wise bretheren and sisteren are:# tweak one my @munged; my $munged = lc() if ($uclc eq 'lc'); $munged = uc() if ($uclc eq 'uc'); for(@in) { push @munged, $munged; } # tweak two my @munged; my $munged = lc if ($uclc eq 'lc'); $munged = uc if ($uclc eq 'uc'); for(@in) { push @munged, $munged(); }
#!/usr/bin/perl -w use strict; my $uclc = shift or Usage(); my $infile = shift or Usage(); my $outfile = shift or Usage(); Usage() unless ($uclc eq 'lc' or 'uc'); open (IN, "< $infile") or die "Error opening $infile for read: $!"; my @in = <IN>; close IN or die "Error closing $infile after read: $!"; my @munged; for(@in) { my $munged = lc() if ($uclc eq 'lc'); $munged = uc() if ($uclc eq 'uc'); push @munged, $munged; } open (OUT, "> $outfile") or die "Error opening $outfile for write: $!" +; print OUT for(@munged); close OUT or die "Error closing $outfile after write: $ +!"; ###################################################################### +#### sub Usage { die "\n Usage: uclc.pl (lc|uc) infile outfile\n"; } ###################################################################### +####
In reply to More efficient munging if infile very large by ybiC
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |