Thread Perlscript gesucht (12 answers)
Opened by majas at 2012-06-15 21:13

Linuxer
 2012-06-15 23:09
#159057 #159057
User since
2006-01-27
3891 Artikel
HausmeisterIn

user image
Schnellschuß (ungetestet):

Code (perl): (dl )
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;
meine Beiträge: I.d.R. alle Angaben ohne Gewähr und auf Linux abgestimmt!
Die Sprache heisst Perl, nicht PERL. - Bitte Crossposts als solche kenntlich machen!

View full thread Perlscript gesucht