The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

Ralph (5) [Avatar] Offline
#1
Hello,

On page 31, looking at Single Quotes, * in scripts example,
the dollar sign appears as a dollar sign in the output.

My confusion is WRT page 33's
print "'$alaska' awarded Alaska cruise" ;
Here the dollar sign successfully translates what follows as a variable.

HOW? That fact that the apostrophes are within quotes make them no longer cause enclosed characters lose any special meanings???

And I thought I got through that w/o confusion..
tmaher (37) [Avatar] Offline
#2
Re: Apostrophe clarification needed
> Hello,

On page 31, looking at Single Quotes, * in
scripts
example,
the dollar sign appears as a dollar sign in the
output.


Correct.



> My confusion is WRT page 33's

<TT>print "'$alaska' awarded Alaska cruise" ;</TT>

> Here the dollar sign successfully translates what follows as a variable.


Correct, because a dollar sign within double quotes is recognized as a special character.



> HOW? That fact that the apostrophes are within
quotes make them no longer cause enclosed characters to
lose any special meanings???


Exactly! 8-}


Single quotes (aka "apostrophes") only remove special meanings when
they are recognized as special themselves. A single quote within double quotes loses its special meaning—it becomes a "literal" character:


<TT>print "Howard's End" # same in Shell and Perl

Howard's End

</TT>

In like fashion, a double quote within single quotes also loses its special meaning:


<TT>print 'Howard said: "The End!"' # same in Shell and Perl

Howard said: "The End!"

</TT>


> And I thought I got through that w/o confusion.




I hope this helps!