in reply to parsing and evaluating a string

What is the correct sum of the following characters?

   {   123
   k   107
   p   112
   *    42
+
-----
 ???

They don't really add in a numeric sense.

What is the bigger picture here? What are you trying to accomplish?

At least the parsing part shouldn't be too difficult:

my $string = "char(123)+char(107)+char(112)+char(42)"; my @characters = map{ chr $_ } $string =~ m/(\d+)/g; print "$_\n" foreach @characters;

Dave

Replies are listed 'Best First'.
Re^2: parsing and evaluating a string
by bfdi533 (Friar) on Apr 24, 2006 at 12:52 UTC

    Sorry, should have been a bit more clear. The '+' is a concat operator not a sum operator.

      Maybe this then:

      use strict; use warnings; my $input = "char(123)+char(107)+char(112)+char(42)"; my $output .= chr( $_ ) foreach $input =~ m/(\d+)/g; print "$output\n";

      Dave