in reply to parsing a line of text with inconsistent delimiters
# assuming; ... my $str = "WB(1,2)= 0.000, 1.23, TB(1,2)= 0.0, 253.0, TMB(1,2) += 0.0, 1.0, SL(1,2)= 0.00, 1.00"; sub replace { my ($extracted_number) = @_; # calculate or query the new number. For example; my $new_number = $extracted_number + 1; return $new_number; } $str =~ s/ (?<=,) # Precondition: There should be a comma before, \s* (\d+\.\d+) # ... and it should be a floating number! /replace($1)/xges; print "$str\n";
---------------------------------
life is ...
$mutation = sub { $_[0] =~ s/(.)/rand()<0.1?1-$1:$1/ge };
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: parsing a line of text with inconsistent delimiters
by mattgarrett (Initiate) on Sep 18, 2007 at 17:26 UTC |