Using module for different operating systems

Discussion in 'Perl Misc' started by Michael, Dec 13, 2010.

  1. Michael

    Michael Guest

    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.
     
    Michael, Dec 13, 2010
    #1
    1. Advertising

  2. On 2010-12-13 10:45, Michael <> wrote:
    > 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
     
    Peter J. Holzer, Dec 13, 2010
    #2
    1. Advertising

  3. Michael <> wrote:
    >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
     
    Jürgen Exner, Dec 13, 2010
    #3
  4. Michael

    C.DeRykus Guest

    On Dec 13, 2:45 am, Michael <> wrote:

    [...]

    > "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;

    --
    Charles DeRykus
     
    C.DeRykus, Dec 14, 2010
    #4
  5. Michael

    Michael Guest

    14.12.2010 8:45, C.DeRykus пишет:
    > On Dec 13, 2:45 am, Michael<> wrote:
    >
    > [...]
    >
    >> "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;
    >
    > --
    > Charles DeRykus


    Thank you.

    Michael
     
    Michael, Dec 14, 2010
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bruce Lee
    Replies:
    11
    Views:
    1,768
    Thomas G. Marshall
    Dec 5, 2004
  2. eino
    Replies:
    1
    Views:
    435
    =?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?=
    May 8, 2007
  3. Santhosh1992

    Computer operating systems

    Santhosh1992, Apr 5, 2008, in forum: Java
    Replies:
    3
    Views:
    358
    Mark Space
    Apr 5, 2008
  4. George

    Computer operating systems

    George, Apr 6, 2008, in forum: Java
    Replies:
    1
    Views:
    379
    George
    Apr 6, 2008
  5. George

    Computer operating systems

    George, Apr 6, 2008, in forum: C++
    Replies:
    10
    Views:
    609
Loading...

Share This Page