LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 01-31-2005, 02:31 PM   #1
kshaffer
Member
 
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: $ cal2ipod.pl [calendar_name.ics]):

Code:
#!/usr/bin/perl

# 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";
  $num++;
}

unlink "icaltemp";
 
  


Reply



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 08:01 AM
File system conversion kadaver Slackware 4 11-18-2003 04:07 AM
perl(Cwd) perl(File::Basename) perl(File::Copy) perl(strict)....What are those? Baldorg Linux - Software 1 11-09-2003 08:09 PM
File Conversion justaguynsrq Slackware 4 05-26-2003 07:10 PM
File conversion in Java Paulo Góes Programming 1 04-15-2003 01:39 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:48 PM.

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