perl - Develop a program to analyze the directory structure of a Linux disk and identify any files larger that 500kbytes -


I am trying to develop a program that will analyze the directory structure of a Linux disk and files larger than 500kbytes Will recognize

  #! Use the / usr / bin / perl file: Search :: Rules; Use warnings; My $ filelist; Sub buildfile {open ($ filelist, "& gt;", "filelist.txt") || $ Die ;; # Find the Find rule and # $ ($ "',' dev ',' bin ') in my $ sub-directory = file :: search :: rule-> directory-> Provide a specific list of directories to scan; # Meaning of pattern and my file = files stored on file @ :: :: search :: rule-> size ('500') - & gt; In ($ subdirectors); Print $ filelist map {"$ _ \ n"} @ files; Return \ $ filelist;  

}

I think it's worth using To know the functioning of your work, which is around file :: find :: rule is a cover, despite the use of the module dozens, I still have to always read the documentation, and I think A simple file :: find solution is often easy to read.

Some comments on your code

  • You must use always hard as well as < Code> Use warnings at the top of each pearl program, especially if you are seeking help for it

  • The closer the variable to the first point of your usage must be declared. Instead of and or for flow control, and & amp; Amp; It is better to use

      open my $ filelist, '& gt;', 'filelist.txt' or '  $$!! Local variable names are traditionally written with only short-case alphanumeric and underscores, so your subprakash will ideally be spelled  build_file  and  $ sub-code  will < Code> $ sub_dirs  or  $ subdirs . Capital letters are reserved for global identifiers, such as package name 

  • using map array of stars with a new line at the end of each array One memory is worthless to print. It will generate a whole new list of strings along the new line and send that entire list to print at a time. The IMO is very clear, and only one line has been drawn and passed at a time. I

      print $ filelist "$ _ \ n" for @files  < / Pre> 

    Print

  • I can not imagine why you should return the value of file handle $ filelist In any case, you do not want to reference to handle the file, and simply except for the subtitle return, to write the file more, after the substrate returns. Return $ filelist is correct

I will write something like this

  Use strict; Use warnings; File :: Use Search; Sub-build_file {my @dirs = @_; Open my $ list_fh, '& gt;', 'filelist.txt' or die $!; Find (sub {return until -f; print $ list_fh $ file :: find: name, "\ n" if -s _> 500 * 1024;}, @ dirs); Return $ list_fh; } My $ FH = build_file ('Adi', 'Dev', 'Bin'); Print $ FH "and after the list of files \ n";  

Comments

Popular posts from this blog

Editing Python Class in Shell and SQLAlchemy -

import - Python ImportError: No module named wmi -

uislider - In a MATLAB GUI, how does one implement a continuously varying slider from a GUIDE created .m file? -