Leser: 1
|< 1 2 >| | 11 Einträge, 2 Seiten |
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
use Tk::JPEG;
my @bilder;
my $j;
pic();
for($j=0;$j<@bilder;$j++)
{
# Hier muss der Fehler sein, die Schleife selbst funktioniert
#-------------------------------------------------------
my $fenster=MainWindow->new();
my $img = $fenster->Photo(-file =>$bilder[$j], -format => "JPEG");
$fenster->Label(-image => $img)->pack;
$fenster->Button(-text => 'OK', -command => 'exit')->pack;
MainLoop();
}
sub pic
{
my @datei;
my $i;
opendir(DIR,"test");
while(@datei = readdir(DIR))
{
for($i=0;$i<@datei;$i++)
{
if($datei[$i]=~/.jpg/)
{
push( @bilder, $datei[$i] )
}
}
}
closedir(DIR);
}
-command => sub { $fenster->destroy(); }
while(@datei = readdir(DIR)) {
1
2
3
while (my $datei = readdir(DIR)) {
next unless /\.jpg$/; # . wird zu einem beliebigen zeichen, also escapen
push (@bilder, $_);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#! /usr/bin/perl
use warnings;
use strict;
use Tk;
use Tk::JPEG;
use FindBin;
my $pattern = "$FindBin::Bin/test/*.jpg";
foreach my $bild (glob($pattern)) {
my $fenster = MainWindow->new();
my $img = $fenster->Photo(-file =>$bild, -format => "JPEG");
$fenster->Label(-image => $img)->pack;
$fenster->Button(-text => 'OK', -command => sub { $fenster->destroy() })->pack;
MainLoop();
} # foreach
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
29
30
31
32
33
34
35
36
37
use FindBin;
....
my $image;
my $mw = MainWindow->new();
our @files = glob("$FindBin::Bin/test/*.jpg");
my ($imageFile) = &GetNextFile();
my $button = $imageFrame->Button(-image => $image)
->pack(-fill => 'both', -expand => 1);
$button->configure(-command => sub {
($imageFile) = &GetNextFile();
$button->configure(-image => $image);
});
&Tk::MainLoop;
# ---------------------------------------
sub GetNextFile {
while (my $file = shift(@files)) {
next if -d "$inputDir/$file";
if ($file =~ /\.jpe?g$/) {
unless (ref($image)) {
eval {
$image = $imageFrame->Photo(-file => "$file", -format => 'jpeg');
};
if ($@) {
print "$file: $@\n"; $image = undef; next;
} # if
} # unless
return (&File::Basename::basename($file));
} # while
} # GetNextFile
1
2
3
4
5
6
$ mkdir "dir with spaces"
$ touch "dir with spaces"/haha
$ perl -e '@x = glob("dir with spaces/*"); warn @x'
dirwith at -e line 1.
$ perl -e '@x = glob("dir\\ with\\ spaces/*"); warn @x'
dir with spaces/haha at -e line 1.
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
use Tk::JPEG;
my @bilder;
my $j;
pic();
for($j=0;$j<@bilder;$j++)
{
my $fenster = MainWindow->new();
my $img = $fenster->Photo(-file => $bilder[$j], -format => "JPEG", );
$fenster->Button( -image => $img,
-command => sub
{
$fenster->destroy();
}
)->pack;
MainLoop();
}
sub pic
{
my @datei;
my $i;
opendir(DIR, "test");
@datei = readdir(DIR);
for $i (0..$#datei)
{
if($datei[$i]=~/.jpg/)
{
push( @bilder, $datei[$i] )
}
}
closedir(DIR);
}
Cannot open &´test.jpg&´in mode &´r&´ at c:/Perl/site/lib/Tk/Image.pm line 21
opendir(DIR, "test")
1
2
3
4
5
6
my $baseDir = "test";
...
opendir(DIR, $baseDir) or die "Error: couldn't open dir '$baseDir': $!\n";
my @datei = grep { -f "$baseDir/$_" and /\.jpe?g$/ } readdir(DIR);
...
my $img = $fenster->Photo(-file => "$baseDir/$bilder[$j]", -format => "JPEG", );
|< 1 2 >| | 11 Einträge, 2 Seiten |