while (<IN>) {

Read the file 'curve12.data' line by line and put the current line in the $_ variable.

if (/^Curve(\d):/.../^\s*$/) {

Look for a block of text that starts with the line matching /^Curve(\d):/ and ends with the line matching /^\s*$/ and store a single numerical digit between 'Curve' and ':' in the $1 variable.

if (defined($1) && $1==1 && /^\d/) {print $c1 "$_\n";}; if (defined($1) && $1==2 && /^\d/) {print $c2 "$_\n"};

If $1 is defined, which it always is because we wouldn't get here unless (\d) matched, and $1 is equal to one and the current line starts with a numerical digit then print the current line with an additional trailing newline to the file 'curve1.out'.   Also, if $1 is equal to two then print the current line with an additional trailing newline to the file 'curve2.out'.

Could also be written as:

#!/usr/bin/perl use warnings; use strict; my %out = map { my $name = "curve$_.out"; open my $FH, '>', $name or die "cannot open $name $!"; $_ => $FH; } 1, 2; my $in ='curve12.data'; open my $IN, '<', $in or die "cannot open $in $!"; while ( <$IN> ) { if ( /^Curve(\d):/ .. /^\s*$/ ) { next unless /^\d/; exists $out{ $1 } and print { $out{ $1 } } "$_\n"; } }

In reply to Re: # Translation by jwkrahn
in thread # Translation by GiJoe

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.