RE: [Perl-unix-users] concating problem??
by Matt Schneider other posts by this author
Apr 21 2003 10:14AM messages near this date
Re: [Perl-unix-users] concating problem??
|
[Perl-unix-users] Printing File name
Ben,
I would guess that your input $line[11] has a newline at the end. So if you do:
my $string = $line[11];
chomp $string;
my ($month, $day, $year) = split('/', $string);
my $new_date = join('-', $year, $month, $day);
it should fix it. However if the incoming line is in DOS format you will need to do
my $string = $line[11];
chop $string;
chop $string;
my ($month, $day, $year) = split('/', $string);
my $new_date = join('-', $year, $month, $day);
instead.
Matt Schneider
Programmer/System Administrator
SKLD Information Services, LLC
-----Original Message-----
From: Ben Wilson [mailto:bwilson@[...].net]
Sent: Monday, April 21, 2003 11:17 AM
To: perl-unix-users@[...].com
Subject: [Perl-unix-users] concating problem??
Hi,
I am at my wits end here. I am trying to change a date format
from month/day/year to year-month-day. Easy right?
This works as expected:
#!/usr/bin/perl
use strict;
my $string = "9/1/2001";
my ($month, $day, $year) = split('/', $string);
my $new_date = join('-', $year, $month, $day);
print "$new_date\n";
but this doesn't :
...
my $string = $line[11];
my ($month, $day, $year) = split('/', $string);
my $new_date = join('-', $year, $month, $day);
...
$new_date becomes: "-month-day". I tried:
$new_date = $year.'-'.$month.'-'.$day;
But I get the same result. After some experimentation, it seems
the month is starting at the beginning of the string, and
overwriting everything after it. During debugging, I see the
split works fine, I just can't seem to put it back together
correctly.
Can anyone enlighten me?
Thanks,
Ben
_______________________________________________
Perl-Unix-Users mailing list
Perl-Unix-Users@[...].com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
|