I vote confusion.

Programming Perl says that

  use Module LIST;

is exactly equivalent to

  BEGIN {
    require "Module.pm";
    Module->import(LIST);
  }

So the code below is going to act like

  BEGIN {
    eval "{
      BEGIN {
        require "lib.pm";
        lib->import('/usr/prod/xxx/xxx/perl/lib/');
        }
      }"
  }

Now `use lib path' just adds F<path> to the module search path.  Perl will 
start running, byte compile the script, and execute BEGIN sections.  In this 
section it will find an eval so will byte compile the string and execute it.  
The final result will be indistinguishable from

  use lib '/usr/prod/xxx/xxx/perl/lib/';

apart from the above simpler form perhaps taking a (humanly) un-noticable 
shorter time to run since there's not the runtime string eval involved.

To beat this dead horse a touch more had the eval not been in quotes the byte 
compilation would have happened at the same time as the main script and would 
basically be a no-op.

  $0.02,
  -ljr


On Mar 14, 2012, at 10:44 AM, Bryan Rivera wrote:

> Has anyone ever seen something like the code snippet below? I came
> across this and figured I was just missing something. Why would you
> want to 'use lib' inside an eval inside a BEGIN block? I think it's
> all kinds of wrong.
> 
> BEGIN {
>    eval "{ use lib '/usr/prod/xxx/xxx/perl/lib/'; }";
> }
> 
> -Bry
> _______________________________________________
> Houston mailing list
> [email protected]
> http://mail.pm.org/mailman/listinfo/houston
> Website: http://houston.pm.org/

_______________________________________________
Houston mailing list
[email protected]
http://mail.pm.org/mailman/listinfo/houston
Website: http://houston.pm.org/

Reply via email to