Using the seek function to seek a byte range

Discussion in 'Perl' started by reddyfire, Dec 2, 2008.

  1. reddyfire

    reddyfire New Member

    Joined:
    Dec 2, 2008
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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.
     
  2. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,645
    Likes Received:
    87
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    http://blog.pradeep.net.in
    Code:
    #!/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
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice