Search notes:

Perl function: seek

The following example script reads two lines from itself ($0). Then, it uses seek with a negative argument to go back in the input file by the length of the second line. Thus, next next line that is read from $f is the second line (which will be assigned to $second_line_again).
When the script is run, it will print use warnings;.
#!/usr/bin/perl
use warnings;
use strict;

open (my $f, '<', $0) or die;

my $first_line  = <$f>;
my $second_line = <$f>;


seek ($f, -length($second_line), 1);

my $second_line_again = <$f>;

print $second_line_again;
Github repository about-perl, path: /functions/seek.pl

See also

The libc functions lseek and fseek.
Perl functions

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758207383, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/Perl/functions/seek(61): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78