perl - Search directory and store in hash -


With the user's input, I should search my sub-directory, unless there is a designated 'list' in the fixed list. The question is how to store the path in the hash so that I can retrieve the data and then display it.

My directory tree:

  - gt; Blue - & gt; Aug21 --- & gt; Projects ---- & gt; List ----- & gt; Name / TMP / General / Place / Brand-> Red - & gt; January 03 - & gt; Yellow - & gt; June 22 - - & gt; Progeb ---- & gt; List  

directory.pl:

  use strict; Use warnings; Looking for print "directory ... \ n"; & Amp; Search_dir ('/ tmp / generic / place / brand'); #could 'tmp / general / place / brand / blue / Aug21' should be my ($ input, $ tt, $ str, $ fn, @ pp, @ cap); Sub search_rate {$ input = shift; Opendir DH, $ input or die "$!"; While ($ _ = readdir (DH)) {Next if $ _ eq "." Or $ _ eq ".."; If ($ _ eq "list") {$ fn = $ input '/'. $ _; Push @PP, $ FN; Return; } And {$ fn = $ input} '/' $ _; } If (-d $ fn) {push @ cap, $ fn; }} If (scalar @ cap == 0) {return; } Foreach (@cap) {& amp; Search_dir ($ _); }} If the directory (@PP) {print} is located ... ... \ n "; Forex Currency $ tt (@pp) {$ str = '/ tmp / general / location / brand'; $ Tt = ~ s / $ str / g; Print $ tt, "\ n"; #Hash? $ File {$ color} {$ date} {$ volume} {$ list} = partition (/ \ //, $ tt); }} Else {print "directory could not be searched \ n"; }  

Expected output:

Searching directory ... located directory ... / blue / August 21 / project / list / yellow / june 22 / Prosab / Catalog information: 1 Color: blue Date: August 212 Project: Proogious Information: 2 Color: Yellow Date: June 22 Project: ProZeb

Linux can be easy. Quick and dirty but it will work.

  my @dirs = '/ usr / bin / find -name "/ tmp / general / place / brand /" -type d`; Chomp (@dirs); My $ data = {}; Merry Der Dyer (@dirs) (My @ Path = Split (/ \ //, $ dir); # If you (Scalar (@ path)> = 7 & amp; $ path [7] eq 'List') Has got a list in the correct depth {$ dir = ~ s! / Tmp / general / place / brand !!; print "$ dir got \ n"; print "color:". $ Path [4]; .}}  

Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -