Tuesday, 30 September 2008

Optionally using Smart::Comments

Finally figured out how to turn Smart::Comments on and off as command line arguments:


shell> cat if.pl
#! /usr/bin/env perl

use 5.010_000;
use if
qr{\A -+ smart \z}ixms ~~ @ARGV,
'Smart::Comments' => '####', '###';

#### Going to sleep for intervals:
for ( 1 .. 5 ) { ### Speeping ... [%] Done
sleep 2;
}

exit 0;
shell> ./if.pl --smart

### Going to sleep for intervals:
Speeping ........ [50%] Done


You can also get the same effect like so:


...
use if
$ENV{SMART},
'Smart::Comments' => '####', '###';
...

shell> SMART=1 ./if.pl

1 comment:

Unknown said...

Probable better to use the $ENV{SMART} version as --smart does not play well with Getopt::Long =(