in reply to RE: Timezones in Perl
in thread Timezones in Perl

There are a couple of stylistic points that I'd like to make about your code - one more serious than the other.

The more serious one is that you're using array slices where you want scalars. That is where you're using @local_tm[2] you should be using $local_tm[2].

The less serious issue is that you don't need to split up the parameters to print. You can do something like this:

print "$local_tm[2]:$local_tm[1]:$local_tm[0] $tz\n";

or (to get the formatting a little nicer) you can use printf:

printf '%02d:%02d:%02d %d', $local_tm[2], $local_tm[1], $local_tm[0], $tz;

or (to really show people how well you know Perl) use printf and an array slice:

printf '%02d:%02d:%02d %d', @local_tm[2, 1, 0], $tz;

--
<http://www.dave.org.uk>

European Perl Conference - Sept 22/24 2000
<http://www.yapc.org/Europe/>

Replies are listed 'Best First'.
RE: RE: RE: Timezones in Perl
by ArthurDent (Acolyte) on Jun 26, 2000 at 18:13 UTC
    Thanks...

    The code I posted was basically just a quick hack as a proof of concept more than anything.. I obviously should have used $local_tm[2] rather than with the @. That was just stupidity on my part, combined with inexperience in perl. If I was doing something more valuable than just a proof of concept, I would have used printf rather than print.

    Thanks for the help though!

    Ben