/[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.6 by joko, Sun Nov 17 07:18:59 2002 UTC revision 1.9 by joko, Thu Dec 5 13:54:00 2002 UTC
# Line 3  Line 3 
3  #  $Id$  #  $Id$
4  #  #
5  #  $Log$  #  $Log$
6    #  Revision 1.9  2002/12/05 13:54:00  joko
7    #  + fix: let 'deep_copy' print its message out (instead of die)
8    #
9    #  Revision 1.8  2002/12/01 22:11:35  joko
10    #  + sub cmd
11    #  + sub run_cmds
12    #
13    #  Revision 1.7  2002/11/29 04:44:53  joko
14    #  - sub array_getRelations
15    #  + sub getNewPerlObjectByPkgName
16    #
17  #  Revision 1.6  2002/11/17 07:18:59  joko  #  Revision 1.6  2002/11/17 07:18:59  joko
18  #  + sub deep_copy  #  + sub deep_copy
19  #  #
# Line 26  Line 37 
37    
38  package libp;  package libp;
39    
40    use strict;
41    use warnings;
42    
43  require Exporter;  require Exporter;
44  @ISA = qw( Exporter );  our @ISA = qw( Exporter );
45  @EXPORT = qw(  our @EXPORT_OK = qw(
46      Dumper      Dumper
47      md5 md5_hex md5_base64      md5 md5_hex md5_base64
48      ParseDate UnixDate      ParseDate UnixDate
# Line 39  require Exporter; Line 53  require Exporter;
53      getDirList      getDirList
54      now      now
55      deep_copy      deep_copy
56        getNewPerlObjectByPkgName
57        cmd
58        run_cmds
59  );  );
60    
 use strict;  
 use warnings;  
   
61  use Data::Dumper;  use Data::Dumper;
62  use Digest::MD5 qw(md5 md5_hex md5_base64);  use Digest::MD5 qw(md5 md5_hex md5_base64);
63    
# Line 111  sub stripHtml { Line 125  sub stripHtml {
125    return $result;    return $result;
126  }  }
127    
 sub array_getRelations {  
   my $a_ref = shift;  
   my $b_ref = shift;  
   my @a = @{$a_ref};  
   my @b = @{$b_ref};  
   
   my @isect = my @diff = my @union = ();  
   my $e;  
   my %count;  
     
   foreach $e (@a, @b) { $count{$e}++ }  
   
   foreach $e (keys %count) {  
       push(@union, $e);  
       push @{ $count{$e} == 2 ? \@isect : \@diff }, $e;  
   }  
     
   my $result = {  
     union => \@union,  
     isect => \@isect,  
     diff => \@diff,  
   };  
   
 }  
128    
 sub array_getDifference {  
   my $res = array_getRelations(shift, shift);  
   return $res->{diff};  
 }  
129    
130    
131  # =============================================  # =============================================
# Line 216  sub now { Line 202  sub now {
202    return strftime("%Y-%m-%d %H:%M:%S", localtime);    return strftime("%Y-%m-%d %H:%M:%S", localtime);
203  }  }
204    
205    # ACK's go to ...
206  sub deep_copy {  sub deep_copy {
207    my $this = shift;    my $this = shift;
208    if (not ref $this) {    if (not ref $this) {
# Line 226  sub deep_copy { Line 213  sub deep_copy {
213      +{map { $_ => deep_copy($this->{$_}) } keys %$this};      +{map { $_ => deep_copy($this->{$_}) } keys %$this};
214    } elsif (ref $this eq "CODE") {    } elsif (ref $this eq "CODE") {
215      $this;      $this;
216    } else { die "what type is $_?" }    #} else { die "deep_copy asks: what type is $this?" }
217      } else { print "deep_copy asks: what type is $this?", "\n"; }
218    }
219    
220    sub getNewPerlObjectByPkgName {
221      my $pkgname = shift;
222      my $args = shift;
223      #$logger->debug( __PACKAGE__ . "->getNewPerlObjectByPkgName( pkgname $pkgname args $args )" );
224      my $evstring = "use $pkgname;";
225      eval($evstring);
226      #$@ && $logger->error( __PACKAGE__ . ':' . __LINE__ . " Error in eval $evstring: " .  $@ );
227      $@ && print( __PACKAGE__ . ':' . __LINE__ . " Error in eval \"$evstring\": " .  $@ );
228      return $pkgname->new($args);
229    }
230    
231    sub cmd ($) {
232      my $cmd = shift;
233      $cmd = 'perl ' . $cmd;
234      my $sep = "-" x 90;
235      print $sep, "\n";
236      print "  ", $cmd, "\n";
237      print $sep, "\n";
238      system($cmd);
239      print "\n";
240    }
241    
242    sub run_cmds {
243      foreach (@_) {
244        cmd($_);
245      }
246  }  }
247    
248  1;  1;

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.9

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