On 2002 Jul 31 (Wed) 15:55:09 -0400, Chris Nandor <[EMAIL PROTECTED]> wrote: > > At 12:45 -0700 2002.07.31, Noah Hoffman wrote: >> I call a function, runTestHarness() that uses the Win only Iprocess mod. >> If I comment out the few lines in this function that use the words >> imported from >> Iprocess.pm, everything compiles. But when I include the lines in the >> function (example below), I get an error like: >> >> "Bareword 'INHERITED' no allowed while 'strict subs' in use" >> >> Is there a way to conditionally compile the code in the runTestHarness >> function as well? > > I am not sure what the problem is. A similar example: > > #!perl -wl > use strict; > > runTestHarness(); > > BEGIN { > if ($^O eq 'MacOS') { > # now importing all the constants > eval "use MacPerl qw(kMacPerlQuitIfFirstScript)"; > } > } > > sub runTestHarness { > print kMacPerlQuitIfFirstScript; > } > > It prints "3", as it should.
Sure, it prints "3", but only on a Mac. Try it on a non-Mac machine. You get an error, because kMacPerlQuitIfFirstScript is a bareword, and you never did anything to tell Perl it's a function. I'm not sure what the best way to handle this is. I suspect the best thing to do is to put all the functions that require Win32::IProcess into a seperate module, and then conditionally include that module if you're on a Windoze machine. But it depends on your code. It may not be possible to divide things like this. You could also make sure that all your barewords are imported somehow. For example, this will work: BEGIN { my @constants = qw( SW_SHOWNORMAL SW_SHOWDEFAULT SW_SHOWMAXIMIZED SW_HIDE SW_SHOW SW_MAXIMIZE FOREGROUND_RED FOREGROUND_GREEN FOREGROUND_BLUE BACKGROUND_RED BACKGROUND_GREEN BACKGROUND_BLUE FOREGROUND_INTENSITY NORMAL_PRIORITY_CLASS PROCESS_ALL_ACCESS INHERITED FLOAT DIGITAL NULL CREATE_NEW_CONSOLE NOPATH); if($^O =~ /Win32/) { require Win32::IProcess; import Win32::IProcess @constants; } else { require constant; import constant map {$_ => 0} @constants; } } On non-Windoze machines, all of your constants are functions that return 0. This may mean that if you accidentally use them on a non-Windows machine, they'll give you bogus values without any warning, and bad things could happen. -- Randall M! Gee, Keeper of Gummi Wisdom ([EMAIL PROTECTED])