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

I have my string built like:
 $string = "This is my string with @strings\n";
And using strict and warning makes my sctipt to fail because of "possible unintended interpolation....", but actually it is an intended interpolation, what is the best way to avoid that?

Replies are listed 'Best First'.
Re: Array interpolation in a string
by jettero (Monsignor) on Jan 21, 2008 at 11:24 UTC

    use strict might do the trick...

    perldiag says that the warning means (specifically): "You said something like `@foo' in a double-quoted string but there was no array @foo in scope at the time. If you wanted a literal @foo, then write it as \@foo; otherwise find out what happened to the array you apparently lost track of."

    That tells me that you hadn't previously declared or populated that array.

    -Paul

Re: Array interpolation in a string
by grinder (Bishop) on Jan 21, 2008 at 13:35 UTC

    If it's intended interpolation, then you have probably made a typo in the name of the variable. The warning is saying that you are trying to interpolate an array whose name is unknown.

    If you don't intend to interpolate it (e-mail addresses are notorious for triggering this), just add backslash (\) before the @. That tells the tokeniser that it is a literal @, and not the opening sigil of an array to be interpolated.

    If you don't care either way, write:

    use warnings; no warnings 'ambiguous';

    and then the message will never appear.

    • another intruder with the mooring in the heart of the Perl