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

Sunday, October 21, 2012

Useful Perl Scripts : Part-3



#!/usr/bin/perl

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


      (OR)

#!/usr/bin/perl

@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




#!/usr/bin/perl

$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