Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^2: Writing portable code

by tobyink (Canon)
on Mar 08, 2013 at 10:08 UTC ( [id://1022374]=note: print w/replies, xml ) Need Help??


in reply to Re: Writing portable code
in thread Writing portable code

The disadvantage here is that the WinFunctions package is still parsed and compiled on Linux machines, and the symbol table still exists using up memory, even if it never gets used.

For a handful of small functions this is unlikely to cause many performance problems.

What you need to look out for though are cases where, say, WinFunctions not only will not run on Linux, but won't even compile on Linux (e.g. because it uses some Win32::* module). Careful use of run-time require should generally solve this.

package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

Replies are listed 'Best First'.
Re^3: Writing portable code
by DrHyde (Prior) on Mar 11, 2013 at 11:34 UTC

    Even thinking about having a few unused entries in the symbol table is a ridiculous micro-optimisation.

    If you want to keep the code clean and in one file, then I suggest something like this ...

    use Devel::CheckOS; setup_for_platform(); ... application code goes here ... # decide what platform-specific code to use sub setup_for_platform { if(os_is('MicrosoftWindows')) { *do_stuff = \&do_stuff_for_windows; } elsif(os_is('Unix')) { *do_stuff = \&do_stuff_for_unix; } else { die("Don't know about $^O\n"); } } # platform-specific function implementations sub do_stuff_for_unix { ... } sub do_stuff_for_windows { ... }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1022374]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-23 18:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found