
andrew_b
stranger
Dec 5, 2005, 3:54 PM
Post #12 of 22
(1665 views)
|
|
Re: [MrPJ] interpolating variables in a string from a file
[In reply to]
|
Can't Post
|
|
Sorry, I've been making some assumptions about your comprehension. 'Variable Interpolation' might sound confusing but it's really a simple concept...I can walk you through it (or any good beginner Perl book should cover it). It's really quite similar to Shell programming. See, within single quotes, no characters are interpreted. Within double quotes, some interpretations are performed. For example, variables can be used within a double quoted string, but won't be interpreted within a single quoted string. (There are lots of useful alternative quoting mechanisms. See perdoc perlop for more.) Now, once in a while...not very often mind you, but once in a while, you may run into a situation where you have a single quoted string (or a string that Perl interprets as single quoted) where you *want* to have Perl preform variable interpolation. (That's what this thread is about.) How can you say to Perl, "Hey Perl...treat this single quoted string like it was double quoted". See...not so scary. As for the answer, one of the perldoc manpages (perlfaq4) tells us exactly how to do this (which I should have consulted before I started this ridiculous thread). It's actually a snap. So now you know! btw - Now next time you hear someone say, 'Be wary of using variables in strings' or 'There are better ways to do that', but not be able to tell you *why* (or provide any workable alternative) you'll know that they are just full of crap! hth
|