10 Einträge, 1 Seite |
QuoteIch brauche die Zahlen, den String und das Datum1 bzw. Datum2 bzw. "yesterday" in Epochsekunden.433076;16-02-2004;0;12-03-2005;--==EXECUTER==--
423595;15-04-2003;-746;yesterday;Keyfinder
442191;12-10-2004;0;yesterday;Spider-Mann
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
my ($entry1, $entry2, $entry3, $entry4, $entry5) = split (/\s*;\s*/, $entry, 5);
if ($entry1 =~ /^\d+$/) {
$i::zahl1 = $entry1;
}
my ($day1, $month1, $year1) = split (/\s*-\s*/, $entry2, 3);
if ($day1 =~ /\d{2}/ and $month1 =~ /\d{2}/ and $year1 =~ /\d{4}/) {
$i::date1 = timegm (0,0,0,$day1,($month1 - 1),$year1);
}
if ($entry3 =~ /^\d+$/) {
$i::zahl2 = $entry3;
}
if ($entry4 =~ /^yesterday$/i) {
$i::date2 = $^T - 24*60*60;
} else {
my ($day2, $month2, $year2) = split (/\s*-\s*/, $entry4, 3);
$i::date2 = timegm (0,0,0,$day2,($month2 - 1),$year2);
}
$i::name = $entry5;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
if ($entry =~ /^(\d+);(\d{2})-(\d{2})-(\d{4});(\d+);(\d{2})-(\d{2})-(\d{4})|(yes)(ter)(day);(.+)/i) {
$i::zahl1 = $1;
$i::date1 = timegm (0,0,0,$2,($3 - 1),$4);
$i::zahl2 = $5;
if ($6.$7.$8 =~ /^yesterday$/i) {
$i::date2 = $^T - 24*60*60;
} else {
$i::date2 = timegm (0,0,0,$6,($7 - 1),$8);
}
$i::name = $entry5;
}
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
1 2 3 4 5 6 7 8 9 10 11
while(<DATA>) { if( m/ ^ (-?\d+?); (\d{2}-\d{2}-\d{4}); # matcht: '-123; 12-05-2005;' (-?\d+?); (\d{2}-\d{2}-\d{4} | yesterday); # matcht: '-123; 12-05-2005;' # oder 'yesterday;' (.+) &n bsp; &n bsp; &n bsp; $ /x ) {
1
2
my $date_b = $4 eq 'yesterday' ? timelocal(0, 0, 0, (localtime)[3 .. 5])
: date2uts( $4 );
1
2
3
4
5
6
my $date;
if( $4 eq 'yesterday' ) {
$date_b = timelocal(0, 0, 0, (localtime)[3 .. 5]);
} else {
$date_b = date2uts( $4 );
}
1
2
3
4
5
6
7
8
9
10
sub date2uts ( $ ) { # date to unixtimestamp
# wenn erstes Argument auf das Datumsformat zutrifft
if( $_[0] =~ /^(\d{1,2})-(\d{1,2})-(\d{4})$/ ) {
# dann gib Timestamp zurueck
return timelocal( 0, 0, 0,$1, $2 - 1, $3 - 1900 );
} else { # ansonsten Fehler
die "Date string not valid!
";
}
}
sub date2uts( $ );
sub date2uts( $ );
[E|B,24.07.2005, 12:18]Siehe auch perldoc perlsub.
10 Einträge, 1 Seite |