in reply to Re^3: opening file for editing
in thread opening file for editing

oh well, this seems to be more straightforward solution, thats fine..but can this be done by opening file only once

Replies are listed 'Best First'.
Re^5: opening file for editing
by keszler (Priest) on Oct 09, 2011 at 12:59 UTC

    1. Monks have mentioned the documentation for open
    2. Monks provided hyperlinks to the documentation for open
    3. Monk specifically mentioned the +< and +> operators

    Did you read it?

      i happen to read but i couldnt figure out a solution
        ok, here's a quick code for your reference. This is an implementation for :

        Re^3: opening file for editing
        by pvaldes (Scribe) on Oct 09, 2011 at 17:08 HKT

        I guess that's the best option for you. So please re-read the logic from that post.

        # code not tested! my $srcFile = "/path/to/file.ext"; open F, "<", $srcFile; # this trip is READ my @data = <F>; # this can be danger if you have a big file close F; open F, ">", $srcFile; # this trip is WRITE foreach my $line ( @data ) { $line =~ s/your_regex/expected_replacement/; print F $line; } close F;

        HTH