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;

In reply to Splitting a Text File by LivinTheDream126

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.