Navid M. wrote: > Hi Rob, > > I'm not very familiar with the qq() operator. I > always thought this is included when the programmer > wants to include the quote character in a string > without having to escape it with a backslash. > Ex: $string = qq(this is a " without escaping it);
Exactly. It lets you write a double-quoted string using whatever delimiter characters you want. In the same way as / .. / is a regex match, which can be written m/ .. / or m( .. ) or m# .. #, the string "abc" can be written qq"abc" or qq(abc) or qq#abc#. You can also write a single-quoted string with q(abc), which is the same as 'abc'. See perldoc perlop under "Regexp Quote-Like Operators" for others. > > Can you please explain me the logic behind > eval qq("$var"); and why it works. Right. As I said in my post, and as you've decided yourself, it's the same as eval "\"$var\""; or eval qq(qq($var)); (if you use a pair of brackets, (), [], {} or <> as the delimiters then they nest properly like this). As we had $fileName = "File"; $var = '1>>$fileName'; a call like this eval "$var"; is the same as trying to compile the Perl statement 1>>$fileName; which, as you found, isn't Perl. But "1>>$fileName"; is, and the double-quotes will allow $fileName to be interpolated. So we need a string with these characters: '"', '1', '>', '>', '$', 'f', 'i', 'l', 'e', 'N', 'a', 'm', 'e', '"' which, I think you can see, is "\"1>>\$fileName\"" or "\"$var\"" It gets a little tricky getting your head around the difference between quote characters in the string, and quote characters delimiting the Perl string constant. That's why I used the qq() construct instead. eval qq(qq($var)) gets interpolated at execution to eval 'qq(1>>$fileName)' so the eval executes Perl code qq(1>>$fileName) which interpolates a second time to '1>>File' Whew! I hope that helped! Cheers, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]