On 5/8/06, Xuning Wang <[EMAIL PROTECTED]> wrote:

Subject: Unsolvable? How to extract...

"Unsolvable?" There are many unsolvable problems in the world. Few of
them deserve to be posted to a beginners' discussion group.

I have a question about replacing $ sign when it is
before a digit.

It's done the same way as replacing a $ sign that isn't before a digit.

For example:

$str = "$1.12";

If you mean a real dollar sign, you have to backslash it. As you've
written that, it uses Perl's $1 variable. I assume you mean that $str
is the five-character string normally written in Perl as '$1.12'.

I want to extact the dollar amount 1.12 from $str.

You don't have to modify $str in order to do that.

  my($dollar_amount) = ($str =~ /\$(\d+\.\d\d)/);  # maybe?

If I do this:
$str =~ s/\$//;

$str then become .12.

Not if it had been '$1.12' before the substitution.

I can't use this:
$str ='$1.12'   because the $1.12 is read from a file.

You seem to be under the impression that dollar signs in a data file
will be meaningful to Perl. No; data is data. Unless you're doing
something silly like using eval on a string, of course. Don't do that.

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to