Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Jan 162010
 

Playing with qw() function in Perl

Answer:

The qw (quote word) function is very useful to generate a list of words.

E.g.

my @names = ('peter', 'john', 'mark');

print @names;

my @names2 = qw(peter john mark);

print @names2;

As you can see above, the use of qw() made the code more readable.

Jan 132010
 

Read command line arguments in Perl

Answer:

To read the command line arguments in Perl, you need to play with the special array $ARGV

E.g. test.pl

#!/usr/bin/perl
use strict;

print $ARGV[0];

Then execute

# perl test.pl hello
hello

The first argument will be printed to the screen.