Filepointer in Perl
|
Original Message
|
Name: deeps
Date: July 10, 2006 at 10:38:45 Pacific
Subject: Filepointer in PerlOS: Unix/WindowsCPU/Ram: 1GB |
Comment: I have a Perl script in which i read a file. When i find a particular string in that file, i open another file from another server and then return back to the server where i was reading the file from. I wish to continue reading the file from the point where i left and brached out to read another file. Is it possible to store the filepointer somewhere and return reading the file. Example of the above code is: open(f1,file1.txt) while(<f1>) { if(/String1/){ open(f2,<file2 from 2nd server>) while(<f2>){ . . } close(f2); } if(/String2/) { print $_; } } close(f1); Solution 1: I work around now by directing the whole file in an array like @arr = <f1> and then read the array in loop. But is there a way where i could store the filepointer somewhere and when i return from the first loop i can search for String2 in the the file1.txt. Thanks
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: deeps
Date: July 10, 2006 at 11:09:45 Pacific
Subject: Filepointer in Perl |
Reply: (edit)I guess, i found out the mistake. Perl does store the filepointer in memory. I had the file closed after step1 and before the search of String2. I had given an explicit statement of close(f1) instead if close(f2).
Report Offensive Follow Up For Removal
|
Use following form to reply to current message: