Apr 29, 2012

use of $_

#!F:\Perl\bin\perl -w
use strict;

1) print "\n", $_ for (1..10);

2)
my %hash = ( a => 100, b => 200, c => 300);
print "\n", $_ for keys(%hash);:

Apr 27, 2012

CPAN - Perl Modules Repository



   



You can find lots and useful perl modules in the site www.cpan.org
The commonly used modules are :
1) strict
2) warnings
3) Time::Local
4) CGI
5) Data::Dumper
6) Carp etc.,


Another way to delete old files in perl

Note: 
1) Please remove comment (#)
2) 'unlink' is the command used to remove file in Unix
 
#!perl
foreach my $file (</path/to/logs/*.log>) {
  next unless -M $file > 7;
  print "Deleting the File $file...\n";
  # unlink $file or die "Failed to remove file $file: $!";
}
-->

Apr 26, 2012

Delete files older than X days on Linux


find /path/to/files* -mtime +5 -exec rm {} \;

This is an example, which deletes files older than 5 days from unix command line itself

Note:
1)  Apply this from unix command line itself