in reply to Re^2: searching for a substring in a string
in thread searching for a substring in a string

Clunky, but clear, change that line in the array and re-write the file:
open ( FH, "p.txt" ); my @output = <FH>; close ( FH ); open ( FH, ">p.txt" ); for $i (0 ..#@output) { if ($output[$i] =~ /.*(test.*\.txt).*/) { $output[$i] =~ s/.*(test.*\.txt).*/test29-01-05\.txt/ last; } for $i (0 ..#@output) { print "$output[$i]"; } close ( FH );

Forget that fear of gravity,
Get a little savagery in your life.

Replies are listed 'Best First'.
Re^4: searching for a substring in a string
by Anonymous Monk on Feb 02, 2005 at 20:20 UTC
    Thank you all for the reply.

    Is there a way to check also after how many semi-colons the particular string is located in a string?

    So, if

    myFiles = test1234.txt; hello3456.txt; world7890.txt;

    Then, test1234.txt is located after Zero semicolons

    and hello3456.txt is located after One semicolons

    and world7890.txt is located after Two semicolons