in reply to Grepping the filehandler
print and the array assignment provide list context to the <> operator (readline), which causes it to return all (remaining) lines from the handle, while =~ provides scalar context, which causes the operator to only return the next line - unless you set $/ to undef for slurp mode, but in this case I recommend local $/; in a new block to limit the scope of the change.
Update: grep also provides list context, so you can say e.g. my @matching_lines = grep {/.../} <$fh>;. Also added note on local. Added another link.
|
|---|