Jason Balicki <mailto:[EMAIL PROTECTED]> wrote:

: 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.

    Not when I tried it. It was appended.

     I did need to correct a typo, but this line
doesn't do what you want.

: my $ownerline = join "", $_, ",*\n"/;

  my $ownerline = join "", $_, ",*\n";


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


    Why not just loop through file names and avoid the extra
variable?

foreach my $file ( @ARGV ) {
    open FILE, '<', $file or die "Cannot open $file: $!";

: 
:                 while ( <FILE> ) {
:                         chomp $_;

    Why chomp it here? You are most likely not going to chomp the
line.



:                         if (/DTSTART:/) {
:                                 my $startline= $_ . "T070000Z\n";
:                                 print $startline;

    You're jumping through too many hoops. Print $_ each time.
If you find a line which needs appending, chomp it and append
it first.

    while ( <FILE> ) {

        if ( /DTSTART:/ or /DTEND:/ ) {
            # Same as "chomp $_;".
            chomp;

            # The ".=" operator appends new text to a string.
            $_ .= "T070000Z\n";

        } elsif ( /X-SQ-EVTOWNERS:/ ) {
            chomp;
            $_ .= ",*\n";

        }

        # same as "print $_;".
        print;
    }



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to