Hi All,
I have a file with the following contents (temp.txt).
A1110
G1115
B1110
C1111
D1111
E1113
F1115
and so on. I have to read the contents from this file and create 2 seperate files. The 1st file contains the lines ending with 0 and 1 while the 2nd file contains the lines ending with 3 and 5. I can do this easily by creating a seperate perl script. But I have a constraint. I should not write a seperate file to do this processing.
I am calling the perl from a shell script. Is there any way of calling the Perl program "in-line" with all the required parameters? "In-line" means no seperate file containing the script.
Is it worth doing this? Is there a better way of doing it?
Is there a reason not to just use a Perl script, instead of a shell script? We can definitely do all the work in one Perl script.
#!/usr/bin/perl
use strict; use warnings;
die "Usage: perl script_name INPUT_FILE_NAME\n" unless @ARGV; my $file = shift; open INPUT, '<', $file or die "File error: $!"; open SMALLOUT, '>', "01$file" or die "File error: $!"; open BIGOUT, '>', "2+$file" or die "File error: $!";
while (<INPUT>) { chomp; if (/[01]\s*$/) { print SMALLOUT "$_\n"; } else { print BIGOUT "$_\n"; } }
close INPUT; close SMALLOUT; close BIGOUT;
__END__
Hope that helps.
James
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>