/[cvs]/nfo/perl/libs/libp.pm
ViewVC logotype

Diff of /nfo/perl/libs/libp.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.3 by cvsjoko, Fri Jul 19 18:13:50 2002 UTC revision 1.5 by joko, Sun Oct 27 18:34:28 2002 UTC
# Line 3  Line 3 
3  #  $Id$  #  $Id$
4  #  #
5  #  $Log$  #  $Log$
6    #  Revision 1.5  2002/10/27 18:34:28  joko
7    #  + sub now
8    #
9    #  Revision 1.4  2002/08/16 19:06:39  cvsjoko
10    #  + sub getDirList
11    #
12  #  Revision 1.3  2002/07/19 18:13:50  cvsjoko  #  Revision 1.3  2002/07/19 18:13:50  cvsjoko
13  #  no message  #  no message
14  #  #
# Line 27  require Exporter; Line 33  require Exporter;
33      stripHtml stripSpaces stripNewLines toReal trim      stripHtml stripSpaces stripNewLines toReal trim
34      croak      croak
35      array_getDifference      array_getDifference
36        getDirList
37        now
38  );  );
39    
40  use strict;  use strict;
# Line 47  use POSIX qw(strftime); Line 55  use POSIX qw(strftime);
55    
56  use Carp;  use Carp;
57    
58    use DirHandle;
59    
60    
61  ########################################  ########################################
62    
# Line 127  sub array_getDifference { Line 137  sub array_getDifference {
137    return $res->{diff};    return $res->{diff};
138  }  }
139    
140    
141    # =============================================
142    # "global" vars used in directory-recursive-parsing
143    my $dirlist_buf;
144    my @dirlist_path;
145    my $dirlist_base;
146    
147    sub entry_callback {
148    
149      my $entry = shift;
150    
151      # CHECKS
152      # dont't use this:
153      if ($entry eq '.' || $entry eq '..') { return; }
154    
155      # PREPARE
156      # prepare path to current entry
157      my $cur_entry = join('/', @dirlist_path, $entry);
158      # prepare path to current entry (absolute)
159      my $cur_entry_abs = join('/', $dirlist_base, @dirlist_path, $entry);
160    
161      # ENTRY
162      # add current entry to buffer
163      $dirlist_buf .= $cur_entry . "\n";
164    
165      # (SUB-)DIRECTORY
166      # check if current entry is a (sub-)directory ...
167      if (-d $cur_entry_abs) {
168        push @dirlist_path, $cur_entry;
169        # ... and parse this (recursion here!!!)
170        iterate_path($cur_entry_abs);
171        pop @dirlist_path;
172      }
173    }
174    
175    sub iterate_path {
176    
177      my $path = shift;
178    
179      # create new "DirHandle"-object
180      my $d = new DirHandle $path;
181      if (defined $d) {
182    
183        # iterate through all entries in $path ($d->read) and call out entry-handler on each entry
184        while (defined(my $line = $d->read)) {
185          entry_callback($line);
186        }
187    
188        undef $d;
189      }
190    }
191    
192    sub getDirList {
193    
194      $dirlist_base = shift;
195    
196      # reset vars
197      $dirlist_buf = '';
198      @dirlist_path = ();
199    
200      # start parsing file-structure
201      iterate_path($dirlist_base);
202    
203      # return complete list of directory-content including files and subdirs
204      # entries are newline (\n) - seperated
205      return $dirlist_buf;
206    
207    }
208    # =============================================
209    
210    
211    sub now {
212      return strftime("%Y-%m-%d %H:%M:%S", localtime);
213    }
214    
215  1;  1;

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.5

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed