We have moved to www.dataGenX.net, Keep Learning with us.

Sunday, October 21, 2012

Useful Perl Scripts : Part-3


@array = (1,2,3,4);
print $array[$#array];



@array = (1,2,3,4);
print $array[-1];

To Insert line number in a file from command line

perl -pi -e'$_ = sprintf "%04d %s", $., $_' filename

 To Edit the file content from command line

perl -pi -e 's/cat/dog/' filename


$str = "hello";    # original string
$ref = \$str;       # compute $ref that points to $str
print "$$ref\n"; # prints "hello" -- identical to "$str\n";

 For more..

njoy the simplicity.......
Atul Singh

No comments :

Post a Comment