in reply to Removing dots

It's hard to say what the best solution would be without knowing exactly what dots you don't want removed, but for the example you give,

s/\.//;
does the job. Or
s/\.(?!txt$)//g
...or
s/\.(?![^.]+$)//g

the lowliest monk

Replies are listed 'Best First'.
Re^2: Removing dots
by Anonymous Monk on May 08, 2005 at 14:52 UTC
    ok let's say if i want it to look like Hello.1txt would s/\.(?=txt$)//g do the job?

      You can get your answer more quickly by firing up the debugger and just trying it out:

      % perl -de 1 DB<1> $s = 'Hello.1.txt' DB<2> $s =~ s/\.(?=txt$)//g # in this case the /g is superfluous DB<3> p $s Hello.1txt
      And faster still (in the long run) if you just study perlre.

      the lowliest monk

      If you really want to remove all but the first occurance:

      $filename =~ /\./; substr($filename, $-[0]+1) =~ s/\.//g if @-;