in reply to write and read the same file not display the output
Another option is to close the file, and then reopen it for reading:
use strict; use warnings; open my $fo, '+>>', "outfile.txt" or die "Error:$!\n"; print $fo "how r u\n"; print $fo "hey suresh their\n"; print $fo "in bangalore\n"; close $fo; open my $fi, '<', "outfile.txt" or die "Error:$!\n"; while ( my $line = <$fi> ) { print "$line"; my $a = index( $line, "suresh" ); print "$a\n"; } close $fi;
Output:
how r u -1 hey suresh their 4 in bangalore -1 how r u -1 hey suresh their 4 in bangalore -1
I'm assuming your meant index instead of substr.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: write and read the same file not display the output
by ulaksh (Acolyte) on Sep 05, 2012 at 00:53 UTC | |
by Rudolf (Pilgrim) on Sep 05, 2012 at 01:53 UTC | |
by Kenosis (Priest) on Sep 05, 2012 at 02:07 UTC | |
by Rudolf (Pilgrim) on Sep 05, 2012 at 03:08 UTC | |
by Kenosis (Priest) on Sep 05, 2012 at 04:53 UTC | |
|