Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-31-2005, 03:31 PM   #1
Registered: May 2004
Location: Chicago, IL
Distribution: SuSE Linux Professional 9.1
Posts: 50

Rep: Reputation: 15
Perl file conversion results in a truncated file

I wrote a perl script to take an exported icalendar/vcalendar file from Kontact/Korganizer and split it into individual event files so they can be viewed on an ipod. Everything works except for one thing I can't figure out. Every calendar entry produces its own individual file successfully, except the last file created is always incomplete, thus rendering that event unviewable by the ipod. (So, with a calendar containing 47 events, file "event0047.ics" is incomplete and unviewable). This happens when run on both Windows and Linux (perl 5.8.6), and consistently happens, no matter how many entries a calendar contains. Any insights would be greatly appreciated. Here is the script (usage: $ [calendar_name.ics]):


# cal2ipod
# perl script to reformat icalendar output from Kontact for use on Apple ipod
# Kris Shaffer, (C) 2005

# -----Begin Program-----
use strict;

# put icalendar header in separate array
my $file = shift;
open CAL, $file or die "No calendar file expressed!\n$!";
my @headtmp = <CAL>;
my @head;
foreach (0..2) {
  $head[$_] = $headtmp[$_];

open CAL, $file or die "No calendar file expressed!\n$!";
my @orig = <CAL>;
foreach (1..3) {
  shift @orig;

# generate temporary file with remaining event data
open TEMPOUT, "> icaltemp" or die "Failed to create temp file icaltemp.ics: $!";
print TEMPOUT @orig;

open TEMPIN, 'icaltemp' or die "Failed to open temp file icaltemp.ics: $!";

# create individual files for each entry
$/ = "";
my $entryfile;
my $event;
my $num = 1;

while (<TEMPIN>) {
  my $numf = (sprintf '%04s', $num);
  $entryfile = "event" . $numf . '.ics';
  open ENTRYFILE, "> $entryfile" or die "Failed to create calendar entry $!";
  my @entry = @head;
  push @entry, $_;
  print ENTRYFILE @entry;
  print "$entryfile created.\n";

unlink "icaltemp";


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Text File conversion agallant Programming 16 05-24-2004 09:01 AM
File system conversion kadaver Slackware 4 11-18-2003 05:07 AM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 09:09 PM
File Conversion justaguynsrq Slackware 4 05-26-2003 08:10 PM
File conversion in Java Paulo Ges Programming 1 04-15-2003 02:39 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:29 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration