$log = LogFile->new($cfg{logdir} . '/tpchc.log', ($tpchc->{args}->{debug}) ? 1 : 0)

Can someone please tell me what this means

1 Answers

1
interduo On

The code is creating a new LogFile object, which takes two arguments: the path to the log file and a debug boolean flag.

In this case the first argument is using concatenation (with the period) and the second argument is being set using a ternary if-else.

Perl is a compile-at-run-time language so it allows you to write arguments directly in a constructor this way (though there are limits to this). It's the same as doing:

my $file  = $cfg{logdir} . '/tpchc.log';
my $debug = $tpchc->{args}->{debug} ? 1 : 0;
my $log   = LogFile->new($file, $debug);

Incidentally, simple hashes and hashrefs (but not objects) can be interpolated in a string, so you don't actually need to concatenate the $file line:

my $file = "$cfg{logdir}/tpchc.log";

Some people find that easier to read and some don't so to each their own.