Hier ist ein kleines Perl-Skript, das die Aufgabe erfüllt:
#!/usr/bin/perl use strict; use warnings; # Retrieve all html files in an array my @files = glob '*.html'; # "slurp" mode undef $/; # loop over all files for my $file(@files) { # open file in read mode open my $fhi, '<', $file or die "Can't open '$file' for reading: $!"; # retrieve content in a single string my $content = <$fhi>; close $fhi; # remove extension (my $without_ext = $file) =~ s/\.[^.]+$//; #/this is a comment for syntaxic color! # add h1 tag with filename $content =~ s~<body[^>]*>~$&\n<h1>$without_ext</h1>~s; # open same file in write mode open my $fho, '>', $file or die "Can't open '$file' for writing: $!"; # write the modified string in the file print $fho $content; }