Hello everyone, I recently learned that you can get the amount of lines in a file by doing this:
@temp = <$file> # file is the file handle $lines = scalar @temp
The only need for @temp here is so that scalar can read <$file> as an array. Technically, I could just write "$lines = scalar( <$file> )" or "$lines = @{[ (<$file>) ]}". The problem is that the former doesn't work, and the latter gives $lines = 1.
How do I shrink that chunk of code into a one liner?
In reply to Forcing array context on a file handle by ronmrdechai
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |