davidgareau
asked on
Why would I use single-quoted instead of double-quoted string literals --- David's Perl Project (Day 3 of 60)
I've just finished the first 3 chapters of Learning Perl and I didn't understand why Perl even offers the use of single-quoted string literals. I mean it seems like there was nothing that they added that couldn't be fixed with a simple work around while using double quotes. I'm sure that more reasons will come to light later, but could you give me the major ones, and some example code that could not be done using a double-quoted string literal instead?
david
david
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
what are the q and qq things?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks for the help and info guys
ASKER
Would you code this way?
print 'Hello what value do you want for the variable? ';
$var1 = <STDIN>;
print "The variable you chose is $var1\n";
the first line in single-quotes for speed, the second in double for the interpolation and use of escape characters.
Also, when typing that I was about to add the \n to the end of the first line, but couldn't in single-quote, and I thought, would it be allowed to do something like
print 'Hello what value do you want for the variable?'.\n;
and simply concactenate it onto the single-quoted string literal or is that wrong syntax, also would it be worth the time or would you just leave it in double quotes?
ozo>>>>>
Is this correct. So, in both instances I would see on the screen the following:
print "x is $x\n";
would you need to add another semicolon after both of those examples?