LivinTheDream126 has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks, I am using Perl to split a .dxf file into multiple files based on the location of "<<<.+>>>". Right now I am able to split the file how I want it, but I want the name of each new file to be what was in between the "<<<" ">>>". I have attached my code with the current way of naming the new files. I am very new to Perl so any other suggestions are very welcome. Thanks in advance for any help!
my $count = 0; my $separator = '<<<.+>>>'; open my $in, '<', 'Fixed_Square.dxf' or die "Unable to open Fixed_Squa +re.dxf: $!\n"; open my $out, '>', 'fixed_square0.txt' or die "Unable to write to fixe +d_square0.txt: $!\n"; while (<$in>) { if (/^(.*?)$separator(.*)$/) { print $out $1 if $1; close $out; $count++; open $out, '>', 'fixed_square' . $count . '.txt' or die "Unable to + write to fixed_square${count}.txt: $!\n"; print $out $2 if $2; } else { print $out $_ ; } } close $out; close $in or die "Unable to close $in: $!\n"; 1;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Splitting a Text File
by choroba (Cardinal) on Jul 26, 2013 at 16:19 UTC | |
by LivinTheDream126 (Initiate) on Jul 26, 2013 at 16:46 UTC | |
Re: Splitting a Text File
by hdb (Monsignor) on Jul 26, 2013 at 16:45 UTC |
Back to
Seekers of Perl Wisdom