Howdy, I have a file with 2968 commands (on different lines and all ending with \n) in a file named "subfile". I would like to put each of the commands in their own file (i.e. subfile0, subfile1, ... , up to subfile2967) Heres how far ive got.....
#!/usr/bin/perl -W $NumOfSim = shift(@ARGV); chomp($me = `id -un`); $PATH = "/home/$me/src/Tc/Scheme4/Simulation$NumOfSim"; open(FILEIN,"<$PATH/subfile") || die "Cannot open subfile\n"; @row_data = <FILEIN>; close FILEIN; for($j=0;$j<2968;$j++) # jmax = number of job subs { open(FILEOUT,">$PATH/subfile$j") || die "Cannot open subfile$j \n"; foreach $line(@row_data) { chomp($line); $cmd = "$line "; print FILEOUT "$cmd \n"; }#$line }
...when i try to print each command to its own file, ALL the commands go to ALL the files ?? I know ive messed up on the loops but confused where it went wrong and confused how to fix it. im a perl virgin, pls be kind.

In reply to loop da loop chomp chomp loop chomp blurp oops by frenchcr

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.