To improve Calculate Number of Days Command

前端 未结 2 1736
滥情空心
滥情空心 2021-01-27 16:02

Would like to generate report, which calculate the number of days, the material is in the warehouse. The number of days is the difference between date ($3 field) t

2条回答
  •  伪装坚强ぢ
    2021-01-27 16:09

    Here is an example in Perl:

    use feature qw(say);
    use strict;
    use warnings;
    
    use Text::CSV;
    use Time::Piece;
    
    my $csv = Text::CSV->new;
    my $te = Time::Piece->strptime('01-OCT-14', '%d-%b-%y');
    my $fn = 'Input.csv';
    open (my $fh, '<', $fn) or die "Could not open file '$fn': $!\n";
    chomp(my $head = <$fh>);
    say "$head,Ageing-NoOfDays";
    while (my $line = <$fh>) {
        chomp $line;
        if ($csv->parse($line)) {
            my $t = ($csv->fields())[2];
            my $tp = Time::Piece->strptime($t, '%d-%b-%y.%T');
            my $s = $te - $tp;
            say "$line," . $s->days;
        } else {
            warn "Line could not be parsed: $line\n";
        }
    }
    close($fh);
    

提交回复
热议问题