1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#! /usr/bin/perl use strict; use warnings; use Tie::File; # Filename must be the script's first argument my $filename = shift; die "Please specify filename to be modified!\n" if ! defined $filename; die "'$filename' does not exist...\n" if ! -e $filename; die "'$filename' is a directory...\n" if -d _; die "File '$filename' is not writable...\n" if ! -w _; tie my @lines, 'Tie::File', $filename or die "Cannot tie '$filename': $!\n"; # remove last 5 elements of @lines my @move = splice @lines, -5, 5; # add removed elements in the beginning of @lines unshift @lines, @move; untie @lines;
perl skript.pl dateiname.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#! /usr/bin/perl use strict; use warnings; use Tie::File; # Filename must be the script's first argument my $filename = shift; die "girls_lpz.txt\n" if ! defined $filename; die "'$filename' does not exist...\n" if ! -e $filename; die "'$filename' is a directory...\n" if -d _; die "File '$filename' is not writable...\n" if ! -w _; tie my @lines, 'Tie::File', $filename or die "Cannot tie '$filename': $!\n"; # remove last 5 elements of @lines my @move = splice @lines, -5, 5; # add removed elements in the beginning of @lines unshift @lines, @move; untie @lines;
1
2
# Jede Stunde zur 5. Minute Job ausfuehren
5 * * * * /full/path/to/script.pl /other/full/path/to/file.txt 1>/tmp/crontab.txt 2>&1
1 2 3 4 5 6 7
open(my $file, "<", ...); my @lines = <$file>; close $file; unshift @lines, pop @lines for (1..5); open(my $file, ">", ...); print $file $_ for @lines; close $file;
die "girls_lpz.txt\n" if ! defined $filename;
open(my $file, "<", "girls_lpz.txt") or die "Error in open: $!";