Re: Switching with case in perl ?




Quoth "Petr Vileta" <stoupa@xxxxxxxxxxxxx>:
lerameur wrote:

for my $minute (0..59) {
my $logtime = strftime("%y%m%d%H%M", 0, $minute, $hours, $day, $month
-1, $year + 100), "\n"; #line 20
print $logtime,"\n";
}

error: Useless use of constant in void context at line 20.

Not an error: a warning. The distinction is important.

Maybe you have format or parameters in reverse order :-)

You can write this

my $logtime = strftime("%y%m%d%H%M\n", $year + 100, $month -1, $day, $hours,
$minute);

I think you're confusing strftime with sprintf. The former does not
expect its parameters in the order they are used, it expects a whole
broken-out 'struct tm' (second, minute, hour, day, month, year in that
order). See perldoc POSIX.

my $logtime = strftime("%y%m%d%H%M", $year + 100, $month -1, $day, $hours,
$minute) . "\n";
# use dot for concate instead comma operator

The comma operator never concatenates... the mystery is why the OP
thought it did :).

Ben

.



Relevant Pages

  • Re: Interesting warning I get
    ... bool foo = false; ... I don't see a comma operator inside my brackets. ... Neither warning nor error when compiled with VS 2003 SP1... ...
    (microsoft.public.vc.language)
  • Re: Interesting warning I get
    ... I don't see a comma operator inside my brackets. ... Neither warning nor error when compiled with VS 2003 SP1... ... C4709 issued with VS2003 SP1, ...
    (microsoft.public.vc.language)