Modul Recursive Directory

Dulu sebelum nemuin modul ini, untuk baca atau pengecekan suatu file yang ada dalam sub-sub direktory aku menggunakan fungsi recursive yang lumayan agak panjang. Tapi untung nya setelah nemuin nih modul, untuk baca file yang ada didalam sub-sub direktory terasa begitu mudah. Berikur contoh scriptnya :

#!/usr/bin/perl
use strict;
#–Modul Recursive Directory–
use File::Find;

my($Group, $Text) = @ARGV;
my $Spool = “/var/spool”; # or wherever your newsspool lives
$| = 1; # so we can see it run
find(\&Kibo, “$Spool/$Group”);

sub Kibo
{
-d and print “$_\n”;
-f and /^\d+$/ or return;
print “$_\r”;

open(ARTICLE, $_) or return;
my @lines = ();

for my $line (@lines)
{
$line =~ /$Text/o and print $line;
}
}

.."..Blogging : Programing.."..


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s