The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #6 (permalink)  
Old 05-20-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
With perl -le '...' filename you get the open/close dance for free. In a more complex script, you probably don't want that. If you have the script set up to read the file in question then you can skip the open/close, and simply do my @f = <> like in your original one-liner.

If you already have the file's contents in a variable $string, then you can count the newlines in there with a simple $lines = () = $string =~ m/\n/g -- this is a cryptic shorthand for a rather complex series of commands which would again take multiple lines in longhand, unobfuscated form.