myggel has asked for the wisdom of the Perl Monks concerning the following question:

if i substitute a string by:
   $three=~s/"/-eee-/g;
and print it with:
   print $three;
it's ok but if i print it to a file:
   print MY_FILE "blabla $three";
it' the $three before substitution.
why is that? how can i avoid that?

thanx for any help.
michael

Edited by planetscape - added code tags

Replies are listed 'Best First'.
Re: substitution doesn't work properly?
by japhy (Canon) on Dec 11, 2005 at 17:31 UTC
    I doubt anyone here can replicate your problem. Can you please show us the minimal amount of code YOU can run that produces this problem?

    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
Re: substitution doesn't work properly?
by NetWallah (Canon) on Dec 11, 2005 at 18:23 UTC
    You may have a problem with quotes matching in unexpected ways.

    As japhy says - show us some code!

         You're just jealous cause the voices are only talking to me.

         No trees were killed in the sending of this message.    However, a large number of electrons were terribly inconvenienced.

Re: substitution doesn't work properly?
by BorgCopyeditor (Friar) on Dec 11, 2005 at 19:22 UTC
    A minimal code sample that reproduces the problem is essential if you're going to get any useful help. That said, the most likely explanation, just to expand on what the above poster already said, is that you've placed your variable in single quotes in your print statement. One difference between single and double quotes is that double quotes allow "interpolation"; stated roughly, they substitute the values of variables for their names. To get into the nitty-gritty of it, you should read perldoc perlop, especially the section on "Quote and Quote-like Operators."

    BCE
    --Your punctuation skills are insufficient!

Re: substitution doesn't work properly?
by CountOrlok (Friar) on Dec 12, 2005 at 00:23 UTC
    No one can say for sure unless they see your code, but to me it seems like a classic example of global/local variables.
    -imran
Re: substitution doesn't work properly?
by spiritway (Vicar) on Dec 13, 2005 at 02:22 UTC

    I tried what I could of your code. First, it's not clear to me what you intended with your double quotation mark in the s/// function. Was it your intent to replace quotation marks by "-eee-"?

    When I ran it both ways (printed to STDOUT and to a file), the results were the same - the substitution was performed, and I got "-eee-" both on the screen and in the file

    My guess is that you've somehow eliminated the bug while trying to show us the problem. See if you can come up with a short script that cuts out all the unnecessary stuff, but that still produces the bug.

    I've found that most of the time, when I try to reduce the code to the bare minimum that still has the bug, I wind up figuring out what the problem is myself - the bug suddenly shows up very clearly, once all the other stuff has been removed.

    Finally, when you're showing code, use the <code> tags. They automatically format the code into legible form.