1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/perl -w
use strict;
my $count = 0;
open (LS, "ls |");
while (<LS>)
{
$count += 1;
print $count . ". " . chomp(<LS>);
}
close (LS)
or die "Fehler beim Ausführen von ls!";
1 2 3 4 5 6
while (my $line = <LS>) { chomp $line; $count += 1; print $count . ". " . $line; }
QuoteIt returns the total number of characters removed from all its arguments.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/perl -w
use strict;
my $count = 0;
open (LS, "ls |");
while (my $line= <LS>)
{
$count += 1;
chomp($line);
printf("$count $line\n");
}
close (LS)
or die "Fehler beim Ausführen von ls!";
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#!/usr/bin/perl use warnings; use strict; use Cwd; my $dh; opendir($dh, getcwd()) or die; my @files = readdir($dh); close($dh); @files = sort(@files); my $i; foreach $i (0 .. $#files) { if ($files[$i] eq "." || $files[$i] eq "..") { next; } print $i + 1 . ". " . $files[$i] . "\n"; }
1 2 3 4 5
use strict; use warnings; open my $dir, "dir |" or die $^E; printf "Zeile: %s => %s\n", $. , do{chomp; $_} while <$dir>;
1
2
3
4
use IO::Dir;
my $count = 0;
my $dir = IO::Dir->new(".") or die;
$count++ while $dir->read;