Very nicely indented and done. Just some minor points:
1. glob is not that portable (BSD,DOS,Windows,SYS V), it is a mess. I prefer readdir and grep over glob.
2. I prefer lining up the { and } brackets over the old style 'C' way.
3. The best thing I liked about your code was that it was nicely spaced out. Whitespace is one of the most important things to put into code! Yes, blank lines are important!
4. I may have some mistakes below, but I think it continues along your fine way.
use strict; use warnings; my $dir = '.'; # for my $file (glob("$dir/*.seq")) # "glob" is not portable even amoungst *nix systems # and certainly not amoungst Windows systems. opendir(DIR,$dir) or die "unable to open directory $dir:$!"; foreach my $file ( grep{/\.seq$/ && -f $dir/$_}readdir DIR) { my $output_path = "$dir/$file.out"; my $input_path = "$dir/$file"; open (my $in, '<', $input_path) or die "Unable to open $input_path: $!"; open (my $out, '>', $output_path) or die "Unable to open $output_path: $!"; while (<$in>) { s/\^\^/\n^^/g; print $out $_; # oopps ; was missing... } close ($in); close ($out); unlink ($input_path) or die "unable to unlink $input_path: $!"; rename ($output_path, $input_path) or die "Unable to rename $output_path to $input_path:$!"; }
Update: the unlink before rename is not necessary.

In reply to Re^2: Writing to file... by Marshall
in thread Writing to file... by perl_n00b

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.