I'm not new to Perl, but I use it far too rarely to learn everything one needs to remember. Now I'm writing a simple script that iterates over each line of a file and makes a few changes as needed. The interesting part looks like this:
while (<>)
{
$modified_line = ... # modify current line as required
print $modified_line; # print out the modified line
}
This is all working fine, but I only need to apply a few changes in the beginning of the file, and I don't like the idea of iterating over every single line only for that. I would rather like to break out of the loop upon a particular condition and print out the rest of the input file unchanged. Is this possible?
while (<>)
{
$modified_line = ... # modify current line as required
print $modified_line; # print out the modified line
last if /^\[.*]$/; # break out if line is enclosed in []
}
# how to print out the rest of the file unchanged here?