Thread Split und Speichern oder mit RegEx speichern (9 answers)
Opened by Spider-Mann at 2005-07-23 19:07

coax
 2005-07-23 21:59
#56630 #56630
User since
2003-08-11
457 Artikel
BenutzerIn
[default_avatar]
Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/perl

 use strict;
 use warnings;

 use Time::Local;

 sub date2uts( $ );

 while(<DATA>) {
     if( m/ ^ (-?\d+?); (\d{2}-\d{2}-\d{4});
              (-?\d+?); (\d{2}-\d{2}-\d{4} | yesterday);
              (.+)                                      $ /x ) {

 my($num_a, $num_b, $date_a) = ( $1, $3, date2uts($2));

         my $date_b = $4 eq 'yesterday' ? timelocal(0, 0, 0, (localtime)[3 .. 5])
                                        : date2uts( $4 );

         printf("Number_A: %d\tDate_A: %d\nNumber_B: %d\tDate_B: %d\n",
                $num_a, $date_a, $num_b, $date_b);
     } else {
         printf(STDERR "Skipped: %s\n", $_);
     }
 }

 sub date2uts ( $ ) { # date to unixtimestamp
     if( $_[0] =~ /^(\d{1,2})-(\d{1,2})-(\d{4})$/ ) {
         return timelocal( 0, 0, 0, $1, $2 - 1, $3 - 1900 );
     } else {
         die "Date string not valid!\n";
     }
 }

_ _DATA_ _
433076;16-02-2004;0;12-03-2005;--==EXECUTER==--
423595;15-04-2003;-746;yesterday;Keyfinder
442191;12-10-2004;0;yesterday;Spider-Mann

Bei _ _DATA_ _ muessen die Leerzeichen zwischen den Unterstrichen weg.
,,Das perlt aber heute wieder...'' -- Dittsche

View full thread Split und Speichern oder mit RegEx speichern