RE: search and replace confusion
- From: "Wagner, David --- Senior Programmer Analyst --- WGO"
- Date: Thu, 26 May 2005 11:02:04 -0700
Jason Balicki wrote:
> 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
>
I ran your code by removing the outer loop and placing the data as __DATA__ . The output I got was:
BEGIN:VEVENT
UID:sm_cal_evt_20050523T201350Z_example_com
SEQUENCE:0
PRIORITY:5
DTSTAMP:20050523T201350Z
CREATED:20050523T201350Z
LAST-MODIFIED:20050523T201350Z
STATUS:
DTSTART:20050616T070000Z
SUMMARY:Someguy - PTO
DESCRIPTION:
COMMENT:
DTEND:20050616T170000Z
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
The above seems to be what you stated you wanted. I did nothing else in processing. I am running on AS Perl 5.8.3 build 809
Here is the code I executed:
while ( <DATA> ) {
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";
}
}
__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
Wags ;)
> 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)
*******************************************************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
*******************************************************
.
- Follow-Ups:
- RE: search and replace confusion
- From: Jason Balicki
- RE: search and replace confusion
- Prev by Date: RE: search and replace confusion
- Next by Date: RE: search and replace confusion
- Previous by thread: RE: search and replace confusion
- Next by thread: RE: search and replace confusion
- Index(es):
Relevant Pages
|