Perl Special Variables (some)

 Posted by at 2:52 pm  Coding & Scripting, Perl  Comments Off on Perl Special Variables (some)
May 032010
 

# a few of the most common special variables
# $_ default input
# $.  line numbers
# $1, $2, $3, etc. Pattern results
# $! System error number or string
# $@ eval() error
# $$  Process ID (PID)
# $0  Program name
# @_  List of arguments for subroutine
# @ARGV  List of command-line arguments
# @INC  List of paths Perl searches for libraries and modules
# %ENV  List of environment variables

Use Perl to display a file with line numbers

 Posted by at 2:45 pm  Coding & Scripting, Perl  Comments Off on Use Perl to display a file with line numbers
May 032010
 

I’m not sure how a Perl code snippet will react in a CMS posting so I’ve commented it out; if you have use for this simple script remove the “#” comment characters.  The code could be named anything, I call it readme.pl and it is run from the command prompt as ‘perl readme.pl filename‘. The file utilizes the default file handle within the “while()” to open the file referred to by @ARGV (a special variable) and two common special variables “$.” and “$_” for line numbers and default input respectively.

#!/usr/bin/perl
#
# use strict;
# use warnings;
#
# main(@ARGV);
#
# sub main
# {
# while() {# using the special file handle to read lines from the command line
# print “$. $_”;
#  }
#}