Using module for different operating systems

M

Michael

I have a crossplatform script, which requires the utf8 module for Linux
version. Windows version don't need this module (I/O is wrong when it is
present). How to restrict appearing of this module to Lunix version
without deleting this string every time when it's necessary?
"use utf8 if $^O eq 'linux' " does not work.
 
P

Peter J. Holzer

I have a crossplatform script, which requires the utf8 module for Linux
version. Windows version don't need this module (I/O is wrong when it is
present).

The UTF-8 pragma doesn't affect I/O, it only says that the source code
is encoded in UTF-8. So you are probably barking up the wrong tree here.

If a script using the utf8 pragma behaves differently on Linux and
Windows you probably have converted it from one encoding to another
when you transferred the script from one OS to the other. Make sure that
the script is UTF-8-encoded on both systems.

It is also possible that you made a different mistake (possibly a wrong
encoding on I/O) which doesn't have anything to do with the utf8 macro
directly but which is masked by a (probably erroneous) use of the utf8
macro. This is hard to guess, though, we would need to see a minimal
script which demonstrates the behaviour.
How to restrict appearing of this module to Lunix version
without deleting this string every time when it's necessary?
"use utf8 if $^O eq 'linux' " does not work.

I won't answer that because I think that isn't the problem and I prefer
solving the real problem instead of patching over the symptoms.

hp
 
J

Jürgen Exner

Michael said:
I have a crossplatform script, which requires the utf8 module for Linux
version. Windows version don't need this module (I/O is wrong when it is
present). How to restrict appearing of this module to Lunix version
without deleting this string every time when it's necessary?
"use utf8 if $^O eq 'linux' " does not work.

perldoc -f use:
[...]. It is exactly equivalent to
BEGIN { require Module; Module->import( LIST ); }
[...]

In other words: 'use' is executed at compile time, long before the "if"
would ever make a difference.

So don't use use() but instead require() directly to load the module at
runtime.

jue
 
C

C.DeRykus

[...]
"use utf8 if $^O eq 'linux' " does not work.

The 'if' pragma has been available in Perl for
some time. See: perldoc if


use if ($^O eq 'linux'), utf8;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top