open CONFIG, '<', 'three_Freds';

In addition to what the others have pointed out, I would very strongly recommend you use the more modern form of open with lexical file handles instead of global handles, and that you check the return value of the function for errors. That would look something like the following. By the way, what is the point of the $three_Freds variable if you're not using it? Also, note that s/\n/Wilma/g; won't do anything since you're removing the newline on each line with chomp.

#!/usr/bin/env perl use warnings; use 5.012; my $in_filename = 'three_Freds'; my $out_filename = 'three_Freds.out'; open my $config_fh, '<', $in_filename or die "$in_filename: $!"; open my $output_fh, '>', $out_filename or die "$out_filename: $!"; my $three_Freds = $ARGV[0]; if (! defined $three_Freds) { die "Usage: $0 filename"; } while (<$config_fh>) { chomp; s/fred/\n/gi; s/Wilma/Fred/gi; s/\n/Wilma/g; print $output_fh $_; }

In reply to Re: Usage of File Handles by haukex
in thread Usage of File Handles by catfish1116

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.