Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Re: add double quotes to a perl variable

by Kenosis (Priest)
on Nov 15, 2013 at 20:33 UTC ( #1062789=note: print w/replies, xml ) Need Help??

in reply to add double quotes to a perl variable

Add chomp:

while (<$filehandle>) { chomp; ... print "$escaped_wquotes\n";

(Also, consider changing || die to or die -- it's a precedence issue...)

Replies are listed 'Best First'.
Re^2: add double quotes to a perl variable
by casperdaghost (Initiate) on Nov 15, 2013 at 20:40 UTC
    ok so there was a new line at the end of each interation of while. while adds a new line after each print?

      An input record separator (found in Perl's variable $/ and usually set to \n) determines the end of a line ('record') when reading from a file--like you were doing in your while loop. It's kept on the end of the line, unless you do something like chomping the line. In your case, not removing the input record separator produced undesirable results in your final output. (Sometimes, however, the very last line of a file may not terminate with an input record separator, because the line ends at the end of the file.)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1062789]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (3)
As of 2017-07-23 04:21 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (343 votes). Check out past polls.