From IT Mission Linux Tips, Hacks, Tutorials, Howtos - Itmission.org

Main: Perl-command-Line

Reading from a File


The -n switch allows you to loop through a file whose name is provided at the command line.

The Perl statements are enclosed in quotes, and the file or files are listed at the end of the command line.

The -e switch allows Perl to execute Perl statements at the command line instead of from a script.

This is a good way to test simple Perl statements before putting them into a script file.

shine@shine:~$ perl -ne 'print if /^shine/ ;' /etc/passwd
shine:x:1000:1000:shine,,,:/home/shine:/bin/bash
shine@shine:~$ 

shine@shine:~$ perl -e 'print "My name is Shine\n";'
My name is Shine
shine@shine:~$ 

Retrieved from http://www.itmission.org/Main/Perl-command-Line
Page last modified on July 16, 2012, at 03:04 PM