in reply to Extracting money from a double quoted string

Why don't you just single-quote your string?

As an alternative, you could quote the dollar sign, so that Perl knows you don't mean the variable $9:

my $string= "Price is \$9.99 on our website";

Replies are listed 'Best First'.
Re^2: Extracting money from a double quoted string
by sherab (Scribe) on Dec 06, 2014 at 19:01 UTC
    String is being slurped into a variable. Can you slurp into a single quote string?

      Your program that you posted above does not show any string slurping.

      All data read from a file is not reinterpreted. Data read from a file is treated similar to data in single quotes.

      Maybe now is a good time to post a program that shows what you are actually doing. If your real problem is with a program that reads data from a file, then please post such a program and a (short, but representative) file to read from. Also, please show the output you get, and the output you expect.

      When debugging how Perl sees data, it often helps me to print out the data right after having read it from a file:

      my $string= read_file('some_file.txt'); print "Read: [[$string]]\n";

      Update: Upon rereading your node, I think your problem is exemplified through your question:

      Can you slurp into a single quote string?

      Once a string has been read by Perl, be it from the source code or from a file, there is no distinction for Perl between "single quoted" and "double quoted" strings. Strings are plain values.

      The only moment where strings get treated differently by Perl is when they are created. Double-quoted strings in source code are subject to variable interpolation and escape character replacement (\n to newline, \t to tab, for example). Single-quoted string are only subject to some very limited escape character replacement (\\ to \, \' to '). Data read from a file is subject to neither. See Quote and Quote-like Operators for further reading.

      Can you slurp into a single quote string?

      The distinction between single quotes and double qoutes exists only with relation to string literals, i.e. strings that are in the source text of a script or module. I'd say that is the reason for our collective misunderstanding.

      That said, as a "shot into the blue", do you perhaps eval your string?