Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Perl6, modifying @*INC

by molecules (Monk)
on Aug 05, 2010 at 14:36 UTC ( #853149=perlquestion: print w/replies, xml ) Need Help??
molecules has asked for the wisdom of the Perl Monks concerning the following question:

I was going to try to help flamey with his LWP::Simple problem. However, I had a different problem. I need to modify my @*INC, but have not been successful with it. Here are a couple of my attempts:
use v6; BEGIN{ push @*INC, 'C:\Rakudo\lib';} use LWP::Simple;
This gives the following error:
===SORRY!=== Confused at line 2, near "BEGIN{ pus" shell returned 1

I also tried:
use v6; push @*INC, 'C:\Rakudo\lib'; use LWP::Simple;
Which gives the following error:
===SORRY!=== Unable to find module 'LWP::Simple' in the @*INC directories. (@*INC contains: C:\Documents and Settings\HP_Administrator/.perl6/lib /Parrot-2.5.0/lib/parrot/languages/perl6/lib .)s ENTER or type command to continue shell returned 1

I am using Rakudo Star, installed on Windows using the MSI installer.

On my Linux installation trying to use the BEGIN block also gives an error. However, LWP::Simple is already in one of the @*INC paths.

Just a note that it is actually more intuitive to use unshift instead of push when modifying @*INC. This puts your added path at the beginning of @*INC, where it will be given precedence over "default" paths.

Replies are listed 'Best First'.
Re: Perl6, modifying @*INC
by moritz (Cardinal) on Aug 05, 2010 at 15:49 UTC
    BEGIN{ push @*INC, 'C:\Rakudo\lib';}

    Add a space before the opening curly: BEGIN { @*INC.push( 'C:\Rakudo\lib' );}

    The reason is that {...} directly after a statement is parsed as a postcircumfix, which is very handy if you want to access hash elements like %hash{$key} (but which is intentionally not special-cased to hashes).

    The error message could be improved, though.

    Perl 6 - links to (nearly) everything that is Perl 6.

      I also noticed that the indirect method syntax for push doesn't work inside the BEGIN block. I wasn't sure if that was a feature or something still to be done.
        It's a well-known bug. Unfortunately we have some roadmap items to complete before we can fix that - we need to have static lexical pads at compile time to make built-in functions available in BEGIN blocks.
        Perl 6 - links to (nearly) everything that is Perl 6.
Re: Perl 6, modifying @*INC
by chromatic (Archbishop) on Aug 05, 2010 at 15:46 UTC

    That (the indirect object syntax, not the missing space) looks like a parsing bug. I managed to get things to work with:

    BEGIN { @*INC.push( 'C:\Rakudo\lib' ) };

    You might want to ask on #perl6 if this is a known bug.

    Update: parenthetical note added.


      UPDATE: Also, thanks for all of your work on Perl6.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://853149]
Approved by zwon
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (1)
As of 2017-08-17 02:53 GMT
Find Nodes?
    Voting Booth?
    Who is your favorite scientist and why?

    Results (278 votes). Check out past polls.