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

Hi all,

I want to print the following -
Seán Connery
with the following code
my $f = "\x{0301}"; $html = qq( <html>Sea$fn Connery<html> ); print html;
But perl sees $fn not $f, what should I do?
Cheers,
Barry.

Replies are listed 'Best First'.
Re: qq function with variables
by Golo (Friar) on Oct 24, 2004 at 15:53 UTC
    <html>Sea${f}n Connery<html>
    should do.
      Indeed it does, thanks.
Re: qq function with variables
by bobf (Monsignor) on Oct 24, 2004 at 16:12 UTC

    You need to tell perl where the variable name stops and where the rest of the text begins, using curlies. Without such a distinction in the example below, "$var12" could mean either $var12 or the value given by join( '', $var1, '2' ).

    use strict; use warnings; my $var1 = 'one'; my $var12 = 'twelve'; print "$var12\n"; # prints 'twelve' print "${var1}2\n"; # prints 'one2'

    This is discussed in perldata, "Scalar value constructors".