prints$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]
Before you complain, it doesn't matter that I used single quotes here, since reading from a file does not interpolate anything.i need $money
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |