Don't just make up code when you post. Test it first to see if it really does what you think it does:
$line[0] = 'i need $money'; # set variable directly, since I don't ha +ve your file. $line[0] =~ s/" "/" "/g; print $line[0]; # not $lines[0]
prints
i need $money
Before you complain, it doesn't matter that I used single quotes here, since reading from a file does not interpolate anything.

Also, s/"  "/" "/g does not remove spaces, except when you've got two spaces with double quotes around them. then it replaces that with a single space with quotes around it.

update: please also use strict and warnings. It's not annoying if it really helps.

update 2: just to stress the important point: reading data from a file / socket / other file-like handles does not interpolate any "special" characters..

There are a few exceptions to this rule: reading in text mode (vs binary mode) will translate the line-separator to "\n" and using a character-encoding layer will translate the binary encoding to one perl can understand natively.

In theory IO layers can do anything they want to the data read, but you wouldn't use them by accident, and they aren't enabled by default.

The only time $, % and @ etcetera will be interpolated is when they're used in literal strings in perl code. That includes eval STRING, do and friends and (possibly relevant here) using the //e //ee etc regex modifiers (for the replacement part of a substitution).

See also quote and quote-like operators and regex quote-like operators.


In reply to Re: help! reading in special characters from file by Joost
in thread help! reading in special characters from file by confused_programmer

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.