A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Jump to

Quick reference

Showing posts with label compiler. Show all posts
Showing posts with label compiler. Show all posts

A unary-plus sign before a package name in Perl

ok +Some::Package::Foo->a_method_call($var), 'test succeeded';

This is to get around Perl's 'indirect object syntax'.
Otherwise
ok Mock::Basic->update(...);
looks like
Mock::Basic->ok->update(...);
which is probably not what is intended.
ok(Mock::Basic->update(...)); works as well.

It tells the parser "Hi. Since I have a leading (unary) plus sign, I'm now a scalar expression, so I qualify to match the first item in ok()'s prototype; please do not get confused and interpret me as a class name you should call an ok() method on."

Demonstration:
perl -MCGI -MTest::More -e'ok 1, "ok"; ok +CGI->new, +CGI->new; ok scalar CGI->new, "scalar"; ok( CGI->new, "brackets" ); ok CGI->new, "no plus";'
ok 1 - ok
ok 2 - CGI=HASH(0x8b68c0)
ok 3 - scalar
ok 4 - brackets
Undefined subroutine CGI::ok
 at -e line 1

See alsoand

How to tell if a perl script is only being syntax checked

The special variable $^C will be true if the script is only being compiled with: perl -c script.pl

location of C libs on nolsearch09

according to gcc -print-search-dirs

/usr/lib/gcc-lib/i386-redhat-linux/3.2.3/../../../bcc/include

or

/usr/lib/bcc/include