okay. Ich gebe mich geschlagen.
Das passiert bei mir nur, wenn ich in /home/rootcris/ bin und das script mit scripts/filesize.pl aufrufe...
Das allerdings dann auch nicht mehr, wenn ich Cwd benutze...
Ich hab es in der Bash aufgerufen. Hier der Code, wenn er noch interessiert:
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/usr/bin/perl
use strict;
use warnings;
use Cwd;
my $test=0;
my $name;
my $wert;
my $dir;
use Getopt::Std;
my %opts;
getopts('hd:f:m', \%opts);
if ($opts{h})
{
print "Usage:\n";
print "filesize.pl -h for help\n";
print "filesize.pl -f [filename] to show the size of [filename]\n";
print "filesize.pl -d [directory] to show the sizes of all files in [directory]\n";
print "filesize.pl to show the sizes of all files in the current directory\n";
}
elsif ($opts{f})
{
my $f = getcwd;
opendir(DIR, "$f");
my @dir = readdir(DIR);
closedir(DIR);
foreach (@dir)
{
if ($_ eq $opts{f})
{
$test=1;
}
}
if ($test)
{
$_ = (-s "$opts{f}");
$wert = &size($_);;
$name = $opts{f};
write;
}
else {
print "Datei $opts{f} exisiert nicht!\n";
}
}
$dir = getcwd unless(defined($opts{d}));
if (defined($opts{d}))
{
if (-d "$opts{d}")
{
$dir = $opts{d};
} else {
print "$opts{d} existiert nicht oder ist kein Verzeichniss!\n";
exit 0;
}
}
unless (defined($opts{h}) || defined($opts{f}))
{
# opendir(DIR, "$dir") or die $!;
opendir(DIR, ".") or die $!;
my @array = readdir(DIR);
closedir(DIR);
my %hash;
my %for;
my @size;
format STDOUT_TOP =
Dateiname Dateigroesse
====================================
.
foreach(@array)
{
my $i = 0;
if ($opts{d})
{
chdir $dir;
}
$hash{$_} = (-s $_);
my $file = (-s $_);
$for{$file} = $_;
$i++;
push @size, $file;
}
my @sort = sort { $a <=> $b } @size;
foreach(@sort)
{
if (-f "$for{$_}")
{
my $data = $_;
&size($_);
$name = $for{$data};
$wert = $_;
format STDOUT =
@<<<<<<<<<<<<<<<<< @>>>>>>>>>>>>>>>>
$name, $wert
.
write;
}
}
}
sub size
{
if ($_ < 1024)
{
$_ .= " bytes";
} elsif ( $_ > 1024 && $_ < 1048576)
{
$_ = sprintf("%.2f", $_ / 1024);
$_ .= " kb";
} elsif ( $_ > 1048576 && $_ < 1099511627776)
{
$_ = sprintf("%.2f", $_ / 1048576);
$_ .= " mb";
} else
{
$_ = sprintf("%.2f", $_ / 1099511627776);
$_ .= " gb";
}
return $_;
}
Sorry nochmal :)
perl -Mstrict -Mwarnings -e 'package blub; sub new { bless {} } sub bar {my $self=shift; $self->{bla}="5065726c2d436f6d6d756e697479"; return $self->{bla};} my $foo=blub->new();print "Hallo ";print pack("H*",$foo->bar()); print "\n"'
http://perl-tutor.de