User Tools

Site Tools


tutorials:perl:parse_first_name.pl
parse_first_name.pl
# parse_first_name.pl
# Read from an input file 
# (containing a list of full names) 
# and write the first names to an output file. 
# Assume the two filenames are provided in the command line. 
 
my $in_file = shift;
my $out_file = shift;
 
open IN, "<$in_file";
open OUT, ">$out_file";
while ( my $line = <IN> ) {
	chomp $line;
	my ( $first_name, $last_name ) = split /\s/, $line;
	print OUT "$first_name\n";
}
close OUT;
close IN;
tutorials/perl/parse_first_name.pl.txt · Last modified: 2012/06/15 00:35 by chkuo