But why tell him to read a filename at all in the case? I find that if one is taking filenames on the commandline, it's much better to use the diamond operator and let perl decide whether I should be reading from a bunch of files or STDIN, which allows for more flexibility.
And some technical critique - you didn't guard your print $last. This is what I have in mind:____________#!/usr/bin/perl use strict; use warnings; my $prevline; while (<>) { if(/ALARM:/) { print $. - 1, ": $prevline" if defined $prevline; print "$.: $_"; } $prevline = $_; }
In reply to Re^2: when reading a file how to print a line one above the current line??
by Aristotle
in thread when reading a file how to print a line one above the current line??
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |