Monomachus wrote: > Ok here I am at the 9th chapter ... > But here is a thing that isn't working at my computer : > > Exercices: > > Write a program to add a copyright line to all of your exercise answers so > far, by placing a line such as: > > ## Copyright (C) 20XX by Yours Truly > > > Place it in the file immediately after the "shebang" line. You should edit > the files "in place" and keep a backup. Presume that the program will be > invoked with the filenames to edit on the command line. > > [15] Extra extra credit exercise: Modify the previous program so it doesn't > edit the files that contain the copyright line. Hint: You might need to know > that the name of the file being read by the diamond operator is in $ARGV > > first program was: > > $^I = ".bak"; # make backups > while (<>) { > if (/^#!/) { # is it the shebang line? > $_ .= "## Copyright (C) 20XX by Yours Truly\n"; > } > } > > and that was perfectly working at my computer; but the second one:
That won't work unless you print the current line. > my %do_these; > foreach (@ARGV) { > $do_these{$_} = 1; > } > while (<>) { > if (/^## Copyright/) { > delete $do_these{$ARGV}; > } > } > @ARGV = sort keys %do_these; > $^I = ".bak"; # make backups > while (<>) { > if (/^#!/) { # is it the shebang line? > $_ .= "## Copyright (c) 20XX by Yours Truly\n"; > } > } > > > Isn't working (in Windows)... I need to push Ctrl-C to stop the proccess. That looks like it should work, if you add print to print out the current line. > And one more thing: > why can't I just print smth like: > > $^I = ".bak"; # make backups > while (<>) { > unless (/^## Copyright/){ > if (/^#!/) { # is it the shebang line? > $_ .= "## Copyright (C) 20XX by Yours Truly\n"; > } > print; > } > } That won't work because you are testing for /^## Copyright/ first but that line comes after the /^#!/ line. John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>