Thanks, it works now.
But I still a little confused with the "use lib" and the BEGIN block, which one is executed first, the "use lib" or the BEGIN block?
And, I find that the BEGIN block's location makes difference. If I put it ahead of the script like this:
use strict; use warnings; use FindBin; use lib "$FindBin::Bin/lib"; use lib "$FindBin::Bin/lib/perl5/site_perl/5.8.5"; BEGIN { use Config; require lib; print "archname:$Config{archname}\n"; if ($Config{archname} =~ /^x86_64/) { print "x86_64\n"; lib->import( "$FindBin::Bin/lib64/perl5/5.8.5/x86_64-linux-thread-multi", "$FindBin::Bin/lib64/perl5/site_perl/5.8.5/x86_64-linux-thread +-multi"); } else { print "i386\n"; lib->import( "$FindBin::Bin/lib/perl5/5.8.5/i386-linux-thread-multi", "$FindBin::Bin/lib/perl5/site_perl/5.8.5/i386-linux-thread-mul +ti"); } } use utf8; use threads; use Carp; use IO::Socket::SSL; use IO::Select; use Log::Log4perl;
My script works well, but if I put the BEGIN block at the tail like this:
use strict; use warnings; use FindBin; use lib "$FindBin::Bin/lib"; use lib "$FindBin::Bin/lib/perl5/site_perl/5.8.5"; use utf8; use threads; use Carp; use IO::Socket::SSL; use IO::Select; use Log::Log4perl; BEGIN { use Config; require lib; print "archname:$Config{archname}\n"; if ($Config{archname} =~ /^x86_64/) { print "x86_64\n"; lib->import( "$FindBin::Bin/lib64/perl5/5.8.5/x86_64-linux-thread-multi", "$FindBin::Bin/lib64/perl5/site_perl/5.8.5/x86_64-linux-thread +-multi"); } else { print "i386\n"; lib->import( "$FindBin::Bin/lib/perl5/5.8.5/i386-linux-thread-multi", "$FindBin::Bin/lib/perl5/site_perl/5.8.5/i386-linux-thread-mul +ti"); } }
It throw the error "Can't locate Net/SSLeay.pm in @INC", and I can't find the right path in @INC.
Where the BEGIN block exactly should be? The very beginning of the script, even before "use strict; use warnning"?

I also change the $Config{archname64} to $Config{archname} and, use $Config{archname} =~ /^x86_64/ to decide whether It is a x86_64 host. Because I find that $Config{archname64} is empty(although existed) in both i386 and x86_64 Perl.


In reply to Re^3: How to instrust Perl to load the right modules based on architecture? by sunshine_august
in thread How to instrust Perl to load the right modules based on architecture? by sunshine_august

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.