ghenry has asked for the wisdom of the Perl Monks concerning the following question:

Dear all,

I am currently having a discussion on the fedora-extras-list about the RPM for rsnapshot, which I maintain.

This statement has come up:

"I don't see much reason why a perl script should be i386"

Now, how I understand it, is that perl (/usr/bin/perl etc.) will be compiled for a certain architecture, but can that same script/program work on a x64_86/Sparc etc.?

Does it just depend on the modules that you use?

Thanks.

Walking the road to enlightenment... I found a penguin and a camel on the way.....
Fancy a yourname@perl.me.uk? Just ask!!!
  • Comment on Can a perl program always be architecture-independent?

Replies are listed 'Best First'.
Re: Can a perl program always be architecture-independent?
by hardburn (Abbot) on Apr 12, 2005 at 15:01 UTC

    If your program opens a hardcoded file at "/tmp/foo.bar", then it won't work on Windows (which is why the Java cross-platform standards say you can't hardcode file paths).

    Other programs may make subtle assumptions about the word size (32-bits vs. 64-bits).

    Doing unlink $file won't delete the file on systems that have versioned filesystems (like VMS). In such a case, unlinking the file returns it to the previous version. You have to do while(-e $file) { unlink $file } to completely get rid of it.

    Cross-platform issues are often subtle and cover a wider range of cases than any one programmer could possibly remember. The only real way to know is to try it on the platform and test throughly.

    "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

Re: Can a perl program always be architecture-independent?
by brian_d_foy (Abbot) on Apr 12, 2005 at 15:35 UTC
    Now, how I understand it, is that perl (/usr/bin/perl etc.) will be compiled for a certain architecture, but can that same script/program work on a x64_86/Sparc etc.?

    The perl interpreter is compiled and runs on the native architecture.

    The Perl script is a completely different beast: it's the text file that you pass around. Text doesn't care what system it's on, unless you tell that text to do something system-dependent.

    --
    brian d foy <brian@stonehenge.com>

      That is how I understand it. It depends on what the text has in it.

      Time to dig deep into rsnapshot

      Walking the road to enlightenment... I found a penguin and a camel on the way.....
      Fancy a yourname@perl.me.uk? Just ask!!!
Re: Can a perl program always be architecture-independent?
by Anonymous Monk on Apr 12, 2005 at 15:09 UTC
    There are a number of things in Perl, where Perl provides just a thin layer over the system libraries. What it does itself, and what it leaves to the system varies from version to version, from platform to platform, and from configuration to configuration (it matters for instance whether you are using PerlIO or stdio - PerlIO wasn't an option in 5.004, and wasn't the default in 5.6, but is the default in 5.8.x (but you still can use stdio).

    Certain things behave, or can behave different on different OSses. For details, see "perlport.pod". So while many perl scripts will run fine (and identical) on any platform perl runs on, some perl programs won't. So putting it in i386 makes sense.

Re: Can a perl program always be architecture-independent?
by polettix (Vicar) on Apr 12, 2005 at 15:11 UTC
    I suggest a look at perldoc perlport.

    Flavio (perl -e "print(scalar(reverse('ti.xittelop@oivalf')))")

    Don't fool yourself.
Re: Can a perl program always be architecture-independent?
by talexb (Chancellor) on Apr 12, 2005 at 15:16 UTC

    I think the answer is probably "Yes, most of the time."

    Perl releases are tested on a variety of platforms and (I imagine) are tweaked until all tests pass. Thus, a program that uses core Perl only should be architecture neutral.

    Things may get interesting when CPAN modules are used -- I don't have any idea how they are tested on different platforms.

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

Re: Can a perl program always be architecture-independent?
by radiantmatrix (Parson) on Apr 12, 2005 at 18:45 UTC

    I don't think you're asking about platform dependence in the usual way. When you talk about moving between different OS platforms (e.g. Windows to Linux or vice-versa), Perl can be platform-independent, if the developer chooses not to use platform-specific code.

    But, it appears you're talking about using the same OS (Fedora) on different hardware. The answer is simple: Perl scripts are interpreted, so as long as the interpreter works on that hardware, your script will too. Module use shouldn't even be affected, though XS modules may have to be compiled for that architecture.

    In short, Perl scripts are architecture-independent (so long as there is a working interpreter) by default, but are platform-independent through careful programming. (architecture is the hardware, platform is the OS and related components).

    radiantmatrix
    require General::Disclaimer;
    s//2fde04abe76c036c9074586c1/; while(m/(.)/g){print substr(' ,JPacehklnorstu',hex($1),1)}

      Yes, sorry. The same OS, but on different hardware.

      "The answer is simple: Perl scripts are interpreted, so as long as the interpreter works on that hardware, your script will too."

      As long as that version of Perl, supports the features used in that script, yes.

      But in my situation, it will be the same Perl core, just different hardware, so you are right. Thanks.

      Walking the road to enlightenment... I found a penguin and a camel on the way.....
      Fancy a yourname@perl.me.uk? Just ask!!!
      The only Perl modules that shouldn't be architecture-independent for the purpose of RPM are ones that use XS. But it's pretty clear from how the question was asked that there's no XS involved here. Your script could depend on modules that use XS, and hence are architecture-specific, but that's no reason to make your script architecture-specific unless you bundle those modules with your script's distribution.

      Labelling those dependencies is another problem. It seems like older perl RPMs provided things like "XML::Simple" or maybe it was "perl-XML-Simple". Newer ones now seem to instead provide "perl(XML::Simple)".