Loading ...
Sorry, an error occurred while loading the content.

search and replace

Expand Messages
  • Chris LaFrance
    I have a variable called $amts which is gathered from a table in a MySQL databse. This variable is a list of numbers (amounts), what I am trying to do is
    Message 1 of 1 , Jul 2, 2002
    • 0 Attachment
      I have a variable called $amts which is gathered from a table in a MySQL
      databse. This variable is a list of numbers (amounts), what I am trying to
      do is replace the spaces with the + sign to have output like this:

      original: 200.00 420.00 50.00 60.00
      new: 200.00+420.00+50.00+60.00


      here's a chunk of the code:

      sub total { # Determines total amount spent
      $gettotal = $db-> prepare ("SELECT amount FROM $table");
      $gettotal-> execute;

      while ( (@rows = $gettotal -> fetchrow_array) != undef)
      {
      $count++;
      $amts=$rows[0];
      $formula=~s/ /+/ ,$amts;
      };

      print qq(
      Formula: $formula
      );
      $gettotal-> finish;
      }


      I was using s/// to search and replace but I am not getting any output at
      all right now. I've tried both of the following to do this with no luck.

      $formula=~s/ /+/ ,$amts;
      $formula=~s/ /\+/ ,$amts;

      Any direction on this would be appreciated. Thanks.

      --
      Chris LaFrance
      chris@...
    Your message has been successfully submitted and would be delivered to recipients shortly.