search and replace confusion



What I'm trying to do with the following code is convert
some iCal files so that a specific application will read
them.

The problem is that this application can't deal with
entries that have a date but no time.

(Full examples below.) For example, if I have a

DTSTART:20050616

in the file, I want to convert it to:

DTSTART:20050616T070000Z

But with my code below this line prints as:

T070000Z20050616

overwriting instead of appending the time value.

It seems like this should be simple, and because
of that I'm getting kind of frustrated with this
-- damn it I should be able to do this.

I've tried several different things and they all
overwrite instead of append.

I've tried:

s/$/T070000Z\n/;
my $startline=$ . "T070000Z\n";
and
my $startline= join "",$_,"T070000Z\n";

And get the same results with each of them.

My code:
(the last stanza, where I append a ",*" is because
I'm also trying to convert the data to a public
calendar too. But it does the same thing, overwrites
the beginning of the line instead of appending.)

#!/usr/bin/perl
# convert
# usage: convert <filenames>
use warnings;
use strict;

foreach my $argnum (0 .. $#ARGV){
my $inputfile = $ARGV[$argnum];
open FILE, '<', $inputfile or die "Cannot open $inputfile: $!";

while ( <FILE> ) {
chomp $_;
if (/DTSTART:/) {
my $startline= $_ . "T070000Z\n";
print $startline;
}
elsif (/DTEND:/) {
s/$/T170000Z\n/;
print $_;
}
elsif (/X-SQ-EVTOWNERS:/) {
my $ownerline = join "", $_, ",*\n"/;
print $ownerline;
}
else {
print $_."\n";
}
}

close FILE;
}

Sample data:

BEGIN:VEVENT
UID:sm_cal_evt_20050523T201350Z_example_com
SEQUENCE:0
PRIORITY:5
DTSTAMP:20050523T201350Z
CREATED:20050523T201350Z
LAST-MODIFIED:20050523T201350Z
STATUS:
DTSTART:20050616
SUMMARY:Someguy - PTO
DESCRIPTION:
COMMENT:
DTEND:20050616
X-SQ-EVTDOMAIN:zeffert_com
X-SQ-EVTCREATOR:mikeprice
X-SQ-EVTLASTUPDATOR:someguy
X-SQ-EVTOWNERS:kodak,someguy
X-SQ-EVTREADABLEUSERS:
X-SQ-EVTWRITEABLEUSERS:
X-SQ-EVTPARENTCALENDARS:sm_cal_20050401T193810Z_example_com
END:VEVENT

Thanks in advance for any help,

--J(K)

.



Relevant Pages

  • RE: search and replace confusion
    ... some iCal files so that a specific application will read ... overwriting instead of appending the time value. ... X-SQ-EVTREADABLEUSERS: ...
    (perl.beginners)
  • RE: search and replace confusion
    ... > some iCal files so that a specific application will read ... X-SQ-EVTREADABLEUSERS: ... > overwriting instead of appending the time value. ...
    (perl.beginners)
  • Re: luactivate and the -s switch
    ... Synchronization of selected files is in progress... ... Appending selected files... ... Except the "Overwriting selected files" never takes place. ...
    (comp.sys.sun.admin)
  • Re: gui problem
    ... guidata(hObject, timeplot5); ... The second line is overwriting (not appending to) the first ... and hence the handles structure is being lost. ...
    (comp.soft-sys.matlab)
  • RE: search and replace confusion
    ... overwriting instead of appending the time value. ... You are most likely not going to chomp the ... If you find a line which needs appending, ... Prev by Date: ...
    (perl.beginners)