Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Text file:#!/usr/bin/perl use strict; use warnings; my $filename = 'dir/people.txt'; open(my $fh_out, '>', $filename) or die "Could not open file out '$fi +lename' $!"; open(my $fh_in, '<', $filename) or die "Could not open file in'$filen +ame' $!"; # Read in line at a time while( my $line = <$fh_in> ) { # If the file start with blank line replace it with these headers if ( $line =~ /^\S/ ) { print $fh_out, "Name, City, State, Zip"; } } close $fh_in; close $fh_out;
my $file = " JOHND,NY,NY,11111 MARY,SOMEWHERE,OK,22222 JOE,LONDON,LO,33444 ";
Name,City,State,Zip JOHND,NY,NY,11111 MARY,SOMEWHERE,OK,22222 JOE,LONDON,LO,33444
|
|---|