Skip to content

Commit 34d8de0

Browse files
author
l1n
committed
Stdout option and VCALENDAR switchout
1 parent 7430400 commit 34d8de0

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

csv2ical.pl

+15-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
use strict;
44
use warnings;
55

6-
use local::lib 'perl5';
6+
use if -d "perl5", 'local::lib' => 'perl5';
77

88
use Getopt::Long;
99
use Pod::Usage;
10+
use File::Temp qw( :POSIX );
1011

1112
use Tie::iCal;
1213
use DateTime::Format::ICal;
@@ -19,19 +20,23 @@
1920

2021
my $file;
2122
my $help = 0;
23+
my $stdout = 0;
24+
my $vcal = 0;
2225
my %shows;
2326

2427
GetOptions (
2528
'file=s' => \$file,
26-
'help' => \$help,
27-
) and $file
29+
'stdout' => \$stdout,
30+
'vcal' => \$vcal,
31+
'help' => \$help,
32+
) and ($file || $stdout)
2833
or die pod2usage( # Print documentation and quit if bad opts
2934
-exitval => $help, # With return value 0 if $help was not set
3035
-verbose => 2 # Print all the sections
3136
);
3237

38+
$file = tmpnam() if $stdout;
3339
system "touch $file";
34-
3540
tie %shows, 'Tie::iCal', $file;
3641

3742
my %dayHash = (
@@ -92,6 +97,12 @@
9297

9398
untie %shows;
9499

100+
unless ($vcal) {
101+
my $staging = tmpnam();
102+
system "echo BEGIN:VCALENDAR > $staging && grep -v VCALENDAR $file >> $staging && echo END:VCALENDAR >> $staging && cat $staging > $file && rm $staging";
103+
}
104+
system "cat $file && rm $file" if $stdout;
105+
95106
__END__
96107
97108
=head1 NAME

0 commit comments

Comments
 (0)