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

i have been trying to do a very basic thing, am not sure whether it can be done or not.
i want to assign '' into a variable so that when the variable is interpolated into a string, it is replaced by '' and not empty nothing.

$a = # what should i do? ; print $a; # should print: ''

and not nothing.
thanks.

20040610 Edit by Corion: Added formatting

Replies are listed 'Best First'.
Re: how to assign empty single quotes into a string
by muntfish (Chaplain) on Jun 10, 2004 at 09:55 UTC

    Just for clarity - you want the value of $a to be a string containing two single-quote (apostrophe) characters? If so, try this:

    use strict; my $a = "''"; print "$a\n";

    As an aside, if you use <code> tags when posting, it makes it a lot easier to figure out what you mean...

    s^^unp(;75N=&9I<V@`ack(u,^;s|\(.+\`|"$`$'\"$&\"\)"|ee;/m.+h/&&print$&;

      This is so much easier now than in the BASIC years when you had to write chr$(34) to get a double quote.

Re: how to assign empty single quotes into a string
by Zaxo (Archbishop) on Jun 10, 2004 at 09:55 UTC

    "''" will do; so will q('').

    After Compline,
    Zaxo

      As will
      '\'\''

      This is Perl, there's always at least one way to do it!

        Or even $var = chr(39) x 2;


        Examine what is said, not who speaks.
        "Efficiency is intelligent laziness." -David Dunham
        "Think for yourself!" - Abigail
Re: how to assign empty single quotes into a string
by mawe (Hermit) on Jun 10, 2004 at 09:56 UTC
    Hi!

    Do you mean something like this?:
    $a = "\'\'"; print $a; # prints "
    UPDATE: Just realized that it also works without the backslashes :-/