Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Perl (http://www.go4expert.com/forums/perl/)
-   -   Using the seek function to seek a byte range (http://www.go4expert.com/forums/using-seek-function-seek-byte-range-t15371/)

reddyfire 2Dec2008 23:58

Using the seek function to seek a byte range
 
So I'm trying to use the seek function to seek a couple of lines of the file without going to the end of the file. Just trying to stay within a certain byte range. Here is my code.

Code:

#!/usr/local/bin/perl
print "content-type: text/html\n\n";
open (FILE, "< file.txt") or die("File not found");
seek FILE, 21,0;
while(<FILE>)
{
  print;
}
close(FILE);
exit;

What would I need to do to only stay within a certain byte range and display the text only in that byte range without going to the end of the file. I have looked all over but can't seem to figure out how to do this without going to the end of the file.

pradeep 8Jan2009 16:00

Re: Using the seek function to seek a byte range
 
Code: Perl

#!/usr/local/bin/perl
print "content-type: text/html\n\n";
open (FILE, "< file.txt") or die("File not found");
seek FILE, 0,21;
while(<FILE>)
{
   print;
}
close(FILE);
exit;


http://perldoc.perl.org/functions/seek.html


All times are GMT +5.5. The time now is 23:25.