in reply to Splitting file into separate files based on record lengths and identifiers
Thank-you, I will try that.
This is what I've tried to date, with help to build the if clauses with expressions, but as soon as I removed the first $ record it broke, and I'm still none the wiser as to why
Thanks!#!/usr/bin/perl use strict; use warnings; open my $data_fh, '<', 'data.txt' or die "could not open data.txt: $!\ +n"; open my $dollar_fh, '>', 'dollar.txt' or die "could not open dollar.tx +t: $!\n"; open my $star_fh, '>', 'asterisk.txt' or die "could not open asterisk. +txt: $!\n"; open my $percent_fh, '>', 'percent.txt' or die "could not open dollar. +txt: $!\n"; while( <$data_fh> ){ chomp; while( length ){ if( s{ (\d+) \$ }{}msx ){ my $len = $1; my $data = substr( $_, 0, $len, '' ); print $dollar_fh "$data\n" or die "could not print to dollar.txt +: $!\n"; } if( s{ (\d+) \* }{}msx ){ my $len = $1; my $data = substr( $_, 0, $len, '' ); print $star_fh "$data\n" or die "could not print to asterisk.txt +: $!\n"; } if( s{ (\d+) \% }{}msx ){ my $len = $1; my $data = substr( $_, 0, $len, '' ); print $percent_fh "$data\n" or die "could not print to percent.t +xt: $!\n"; } } } close $dollar_fh or die "could not close dollar.txt: $!\n"; close $star_fh or die "could not close asterisk.txt: $!\n"; close $percent_fh or die "could not close percent.txt: $!\n"; close $data_fh or die "could not close data.txt: $!\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Splitting file into separate files based on record lengths and identifiers
by kennethk (Abbot) on Aug 25, 2010 at 21:58 UTC | |
by monty77 (Initiate) on Aug 25, 2010 at 22:09 UTC | |
by kennethk (Abbot) on Aug 25, 2010 at 22:41 UTC |