in reply to Adding '#' in the beginning of each line
You should only have to add one line and modify another.
This strongly implies that you have been given an existing program to modify. It's hardly fair to expect us to do the work without giving us the same head start that you had.
Use the $" variable.
This is perhaps the most puzzling part of the question. I'm not sure how using $" is ever going to make this task easier. The obvious solution is something like:
print "# $_" while <>;
And even a solution that uses $" like:
my @file = <>; $" = '#'; print "@file";
will omit the # from the first line of the output.
I strongly suspect that whoever set this homework doesn't really know that they are doing.
Unexpected things can happen with files, so you may find it helpful to use the -w option as mentioned in the section on running Perl programs.
This is more evidence that the question was written by someone with very little knowledge of Perl. The -w option was surplanted by "use warnings" six years ago. You should only be taught about -w as an item of historical interest.
If you really want to learn Perl then give up this course and buy a good book.
"The first rule of Perl club is you do not talk about
Perl club."
-- Chip Salzenberg
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Adding '#' in the beginning of each line
by Hofmator (Curate) on Aug 16, 2006 at 09:56 UTC |