Leser: 22
QuoteWrite a programm to add a copyright line to all of your exercise answers so far, by placing a line like "## Copyright (C) 20XX by Yours Truly". In the file immerdiately after the "shebang" line. You should edit the files "in place," keeping a backup. Presume that the programm will be invoked with the filenames to edit already on the command line.
1
2
3
4
5
6
7
8
9
10
11
#!/usr/bin/perl
use warnings;
use strict;
$^I = "~";
while (<>) {
if(/^#!/) {
$_ .= "## Copyright (C) 2009 by tuxus\n";
}
print;
}
$_ .= "\n## Copyright (C) 2009 by tuxus\n";
Quote$INPLACE_EDIT
$^I
The current value of the inplace-edit extension. Use "undef" to
disable inplace editing. (Mnemonic: value of -i switch.)
QuoteC:\>perl --help
Usage: C:\Perl\bin\perl.exe [switches] [--] [programfile] [arguments]
[...]
-i[extension] edit <> files in place (makes backup if extension supplied)
2009-11-19T08:55:36 CrianDeine Lösung ist nicht ganz richtig, falls noch mehr Zeilen mit ^#! anfangen, wird der String mehrfach eingefügt.
Du könntest dir noch merken, ob du schon eingefügt hast.
perl -i -e '$/=undef; <>; s/^(#!.+?\n)/$1## Copyright (C) 2009 by tuxus\n/; print' test.pl
2009-11-19T08:55:36 Crian...
Was mich auch nicht schlauer macht.
perl --help verrät dann
...