On Fri, May 6, 2011 at 11:43 PM,  <wolken.f...@web.de> wrote:
> Can someone tell me, where is the fault, please? And for the case, there are 
> 80 data´s in the line, is there a shorter style to find & change them?
>

You showed a slash between the numbers but mentioned earlier that the
numbers can be in any format in the string. In any case, the code
below should work for that too. :)

A problem with your regex is that it will only match numbers with a
decimal point. Unless your input always has a decimal point, you need
to take care of whole numbers too.

Try this:

while( <$in> ) {
   my @matches = m/(\d+\.\d+|\d+)/g; # This looks for decimal numbers
and then whole numbers

   # II am matching on the default $_ up there. If you give an array
on the left side, you get all your matches in it
  #  if no matches the array will be empty

   #for your example
   print "$matches[0]\n" if @matches;

  # if you want to print all the numbers, comma separated
    print join(",", @matches), "\n"  if @matches;
}

- Sandip

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to