sheasbys has asked for the wisdom of the Perl Monks concerning the following question:
use File::Copy; my($input_file) = $ARGV[0]; my($output_file) = $ARGV[1]; if ( !defined($input_file) || !defined($output_file) ) { print "Error: usage: ss7jurisdiction input_file output_file\n"; } else { # -----Backup the input files in case of error----- copy( $input_file, $input_file . ".bak" ) or die "Could not backup file $input_file to $input_file.bak: $!\ +n"; # -----Attempt to open all of the files----- open( INFILE, $input_file ) || die( "Could not read input file 1 ( +$input_file): $!" ); open( OUTPUT, "> " . $output_file ) || die( "Could not open output + file ($output_file): $!" ); while (<INFILE>) { my $line = $_; chomp($line); # -----A line starting with a '2' is a header and is left unch +anged if ( $line !~ m/^2/ ) { # -----Locate postions 100 and 149 $juris1 = substr( $line, 99, 1 ); $juris2 = substr( $line, 148, 1 ); $juris1 = "9"; $juris2 = "Z"; # -----Generate the output string----- $output_line = substr( $line, 0, 98 ) . $juris1 . substr( $line, 100, 48 ) . $juris2 . substr( $line, 149, 61 ) . "\n"; print OUTPUT $output_line; last; } } # -----Close all of the files----- close( INFILE ); close( OUTPUT ); }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Replacing Text At Specific Positions
by Util (Priest) on Jun 05, 2007 at 16:05 UTC | |
by sheasbys (Initiate) on Jun 05, 2007 at 16:53 UTC | |
Re: Replacing Text At Specific Positions
by ikegami (Patriarch) on Jun 05, 2007 at 15:48 UTC | |
by ikegami (Patriarch) on Jun 05, 2007 at 16:01 UTC | |
Re: Replacing Text At Specific Positions
by shmem (Chancellor) on Jun 05, 2007 at 15:48 UTC | |
Re: Replacing Text At Specific Positions
by FunkyMonk (Chancellor) on Jun 05, 2007 at 15:49 UTC | |
Re: Replacing Text At Specific Positions
by naikonta (Curate) on Jun 05, 2007 at 15:52 UTC |