in reply to Re: Hi Monks could you pls help Perl dummy user
in thread Hi Monks could you pls help Perl dummy user

I used strict and warnings but it doesn't go into any other directories other than current. Thus recursion doesn't work correctly i guess. Could you pls help me tofix it now?

#!/usr/bin/perl # #Author: Yury Sibirski #Name: users_home_dir #Date: 16 December 2014 #Purpose: This program analyze the directory structure of a Linux disk + and identify any files larger than 500 kbytes # use strict; use warnings; my $path = shift || '.'; read_dir($path); sub read_dir { my $dir = shift; opendir (my $DH, $dir) or die "Couldn't open current directory +: $!"; while (my $file = readdir($DH)) {#print "$file\n"; if ($file eq "." or $file eq "..") { next; } elsif (-z $file) { next; } elsif (-r $file and -f $file) { my $size = -s $file; print $file," ",$size, "\n" if $size > 200; } elsif (-d $file) { read_dir($file); } } closedir $DH; }

Replies are listed 'Best First'.
Re^3: Hi Monks could you pls help Perl dummy user
by LanX (Saint) on Dec 17, 2014 at 01:46 UTC
    works for me!

    Cheers Rolf

    (addicted to the Perl Programming Language and ☆☆☆☆ :)

      It checks all your directories and prints files that bigger than 200?
        it descends only one level, because the second read_dir gets a one-dir path which isn't valid from top level.

        either use chdir $dir; and chdir '..' at start and end or keep a full path.

        you already got full functioning code with File::Find , better use it.

        Cheers Rolf

        (addicted to the Perl Programming Language and ☆☆☆☆ :)