in reply to joining two variables and printing them to a file?

If I modifiy your code so that it is stand alone and doesn't require external applications then I don't see the problem you describe. Can you modify this code to reproduce the error (without introducing external dependencies)?

use strict; use warnings; my @times; my $timeDisplay; my $timeMinute = '56'; my $timeHour = '34'; while(my $line = <DATA>) { chomp $line; unshift(@times, $line); } $timeDisplay = join (":", "$timeHour", "$timeMinute"); unshift(@times, $timeDisplay); #puts in new time to queue foreach my $i (@times) { #prints back into fileTimes to update print "$i\n"; } __DATA__ 12:34 56:78

Prints:

34:56 56:78 12:34

My guess is that your external application (date) is returning newlines at the end of its string. You might want to take a look at some of the Perl date and time handling functions (time, gmtime and localtime) and modules (Date::EzDate and many others) rather than calling an external application.


DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: joining two variables and printing them to a file?
by terms5 (Initiate) on Apr 25, 2006 at 06:33 UTC
    doh! It was date that was messing me up, the POSIX thing cleared it right up! Thanks a lot! I didn't even know those functions existed, guess I have a lot of reading to do. ^_^