Leser: 22
1 2 3 4 5 6 7 8 9 10 11 12 13
my $directory = ('../htdocs/archive/'); my $prefix = 'Arch'; my $suffix = 'php'; my @dateien = glob($directory.'/'.$prefix.".*".$suffix); opendir DIR, $directory or die $!; while( my $entry = readdir DIR ){ print "<h1>"; print $entry,"\n<br>"; print "</h1>"; } closedir DIR;
1 2 3 4 5 6 7
my $html_file = ('Archive_01.php'); open my $html_fh, '<', $html_file or die $!; print "<h1>"; print <$html_fh>; print "</h1>"; close $html_fh;
2011-03-03T13:36:23 PeterMaffayFolgende Dinge habe ich mir zusammen gesucht:
Code (perl): (dl )1 2 3 4 5 6 7 8 9 10 11my $directory = ('../htdocs/archive/'); my $prefix = 'Arch'; my $suffix = 'php'; my @dateien = glob($directory.'/'.$prefix.".*".$suffix); opendir DIR, $directory or die $!; while (my $entry = readdir DIR) { ... } closedir DIR;
1 2 3 4 5 6 7
opendir DIR, $directory or die $!; while (my $entry = readdir DIR) { ... next if $entry !~ m/^$prefix/; # Prefix doesn't match => next filename next if $entry !~ m/$suffix$/; # Sufffix doesn't match => next filename ... }
1 2 3 4 5 6 7 8 9 10 11 12
my $directory = ('../htdocs/archive/'); my $prefix = 'Arch'; my $suffix = 'php'; opendir DIR, $directory or die $!; while (my $entry = readdir DIR) { next if $entry !~ m/^$prefix/; # Prefix doesn't match => next filename next if $entry !~ m/$suffix$/; # Sufffix doesn't match => next filename print $entry,"\n<br>"; } closedir DIR;
2011-03-03T16:29:27 PeterMaffayDanke schon mal hierfür. Aber wie bekomme ich die Dateien, die ich nun einlese, geöffnet?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
my $directory = ('../htdocs/archive/'); my $prefix = 'Arch'; my $suffix = 'php'; opendir DIR, $directory or die $!; while (my $entry = readdir DIR) { next if $entry !~ m/^$prefix/; # Prefix doesn't match => next filename next if $entry !~ m/$suffix$/; # Sufffix doesn't match => next filename print $entry,"\n<br>"; } closedir DIR; open my $entry_file, '<', $entry or die $!; print "<h1>"; print <$entry_file>; print "</h1>"; close $entry_file;
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
my $directory = '../htdocs/archive/'; my $prefix = 'Arch'; my $suffix = 'php'; my $dir; opendir $dir, $directory or die "$directory $!"; while (my $entry = readdir $dir) { next if $entry !~ m/^$prefix/; # Prefix doesn't match => next filename next if $entry !~ m/$suffix$/; # Sufffix doesn't match => next filename print $entry,"\n<br>"; my $entry_file; # Datei in Verzeichnis öffnen open ($entry_file, '<', "$directory/$entry") or die "$entry_file $!"; print "<h1>"; print <$entry_file>; print "</h1>"; close $entry_file; } closedir $dir;
QuoteZusätzliche möchte ich den inkludierten Inhalt noch mit <h1> auszeichnen und eine Möglichkeit eine Liste mit 10 Listenpunkten (<ul>) anlegen.
1 2 3 4 5 6
open my $fh, '<', $path or die $!; my @first5; for (1 .. 5) { defined( my $line = <$fh> ) or last; push @first5, $line; }
my @first5 = (<$fh>)[0 .. 4];
1 2 3 4 5 6
open ($entry_file, '<', "$directory/$entry") or die "$entry_file $!"; my @first5 = (<$fh>)[0 .. 4]; for (1 .. 5) { defined( my $line = <$fh> ) or last; push @first5, $line; }