sub remove_cruft
{
my $line = shift;
# do stuff to one $line here.
$line;
}
# use as:
while (my $l = <$fh>)
{
$l = remove_cruft($l);
$l = remove_other_cruft($l);
$l = remove_yet_more_cruft($l);
# or ...
$l = $_->($l) foreach (\&remove_cruft, \&remove_other_cruft, \&remov
+e_yet_more_cruft);
# or ...
$l = remove_yet_more_cruft(remove_other_cruft(remove_cruft($l)));
# on second thought, don't do that last one :-)
}
Option Six
sub remove_cruft
{
# do stuff to single line $_[0];
}
# use as:
while (my $l = <$fh>)
{
remove_cruft($l);
remove_other_cruft($l);
remove_yet_more_cruft($l);
# or ...
$_->($l) foreach (\&remove_cruft, \&remove_other_cruft, \&remove_yet
+_more_cruft);
}
The options are endless. What I highly discourage you from doing is writing shell script in perl. I've seen that so many times that it makes me cringe each time. Whether that is to write my $data = `grep blah $filename` rather than open my $fh, $filename; my $data = join '', grep { /blah/ } <$fh>; (and this is just the least perlish of the not-shell-script options), or it's system("mkdir $dir"); rather than mkdir $dir ... there are some really nifty perl idioms that take care of these things for you. They say you can write ForTran in any language. Same is true of shell scripts :-) |