1
2
3
4
Datei "Auswahl_006.png"...
Use of uninitialized value $in in chomp at ./bilder.pl line 20.
Use of uninitialized value $in in string eq at ./bilder.pl line 22.
Use of uninitialized value $in in string eq at ./bilder.pl line 25.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/perl
use warnings;
use strict;
my @filenames = ();
## read filenames
while(<>){
chomp;
push ( @filenames, $_);
}
## check filenames
while ( my $file = pop(@filenames) ){
print "Datei \"$file\"...\n";
system("eog $file");
print "Umbenennen? j/n [n] ";
chomp ( my $in = <>);
if ( $in eq "j" ){
print "ok\n";
}
elsif ( $in eq "q" ){
last;
}
}
ls -1 *.png | head -3 | ./bilder.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
Datei "Auswahl_006.png"...
Use of uninitialized value $in in chomp at ./bilder.pl line 20.
Use of uninitialized value $in in string eq at ./bilder.pl line 22.
Use of uninitialized value $in in string eq at ./bilder.pl line 25.
Umbenennen? j/n [n] Datei "Auswahl_005.png"...
Use of uninitialized value $in in chomp at ./bilder.pl line 20.
Use of uninitialized value $in in string eq at ./bilder.pl line 22.
Use of uninitialized value $in in string eq at ./bilder.pl line 25.
Umbenennen? j/n [n] Datei "Auswahl_004.png"...
Use of uninitialized value $in in chomp at ./bilder.pl line 20.
Use of uninitialized value $in in string eq at ./bilder.pl line 22.
Use of uninitialized value $in in string eq at ./bilder.pl line 25.
Umbenennen? j/n [n]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/usr/bin/perl
use warnings;
use strict;
use Term::ReadLine;
my $term = Term::ReadLine->new('Eingabe');
my $prompt = "Umbenennen? j/n [n] ";
## read filenames
while(<>){
chomp;
my $file = "$_";
print "Datei \"$file\"...\n";
system("eog $file");
my $res = $term->readline($prompt);
if ( $res eq "j" ){
print "ok\n";
}
elsif ( $res eq "q" ){
last;
}
}
1
2
3
4
5
6
7
8
9
> ls -1 *.png | head -3 | ./bilder.pl
Datei "Auswahl_004.png"...
Umbenennen? j/n [n] j
ok
Datei "Auswahl_005.png"...
Umbenennen? j/n [n] n
Datei "Auswahl_006.png"...
Umbenennen? j/n [n] j
ok
1 2 3 4 5 6 7 8 9
sub getFilenames { my $directory = shift; my $suffix = shift; opendir(my $dh, $directory) || die; my @a = readdir($dh); @a = grep(/\Q$suffix\E$/, @a); close($dh); return @a; }
2018-01-02T13:19:43 hlubenowIch würde nicht eine Pipe zu Shellbefehlen aufmachen (vor allem, wenn ich danach noch von Tastatur lesen will), sondern auch die Dateinamen mit Perl einlesen:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
#! /usr/bin/perl use strict; use warnings; use 5.010; # input is specified as file arguments; read them manually without magic my @files; for my $file ( @ARGV ) { open my $fh, '<', $file; while ( my $file = <$fh> ) { push @files, $file; } } chomp( @files ); # show read filenames and ask for input for my $file ( @files ) { print "say something: "; chomp ( my $input = <STDIN> ); say "$file: $input"; }
perl t.pl <( ls -1 *.pl )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#! /usr/bin/perl use strict; use warnings; use 5.010; # read file names from argument list my @files = @ARGV; for my $file ( @files ) { print "say something: "; chomp ( my $input = <STDIN> ); say "$file: $input"; }