Come for the quick hacks, stay for the epiphanies. | |
PerlMonks |
Re: Need to search for a string in a fileby Utilitarian (Vicar) |
on Oct 20, 2011 at 10:43 UTC ( [id://932617]=note: print w/replies, xml ) | Need Help?? |
You needn't pull the whole file into memory just to search for one line. The caret character,(^), means start of the line in a regex. Read perlre, these meta-characters is the second subject covered. You can match save and exit the loop in one statement.
print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."
In Section
Seekers of Perl Wisdom
|
|