I'd find a different tutorial because that one is just dumb. $" is used as a separator, but "the start of every" is not a job you do with a separator. A sane way to do "start of every line" is:

print "#$_" while defined $_ = <>;

with appropriate file handling as required. Speaking of which, always use the three parameter open and lexical file handles:

open my $info, '<', $file or die "Can't open '$file': $!\n";

and remember that in general you can't "in place edit" files - they just don't work that way. Instead you need to make an updated copy of the file then rename or remove the old version and rename the new file to the original file's name. Perl can help a lot with that using the $^I ($INPLACE_EDIT) special variable that allows you to set the file extension to be appended to the backup (original) version of the file so you can write code like:

local @ARGV = $file; local $^I = '.bak'; print "#$_" while defined $_ = <>;

Which will "inplace edit" $file and create a backup copy of the original file by appending '.bak' to the original file name. Note that you could process a batch of files using the same code simply by adding the file names to the list assigned to @ARGV.

Perl is the programming world's equivalent of English

In reply to Re: Using $" by GrandFather
in thread Using $" by Bugz

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.