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

Hi monks!

Maybe the subjest isn't so clear, I'll try to explain:

I have a script that is loaded dynamically and contains, few includes.
The script also contains "use Filter::Include" line.

I'd like to save a global parameter that keeps the current read file.
It doesn't have to be a global parameter, I just want to print to screen every time the interpreter moves to another include file.

Do anyone have an idea how to do it ?

TIA,
Mosh.

Update: Finally I found a way to improve the Filter-Include package !

The inprovement is made by adding dedicated function to the Fiter-Include dump file and catch it by AUTOLOAD sub.
Working great !!

If anyone is intrested in the improvement, let me know.
Mosh.

  • Comment on I'd like to have an indication when the interpreter moves to the next file (using Filter-Include)?

Replies are listed 'Best First'.
Re: I'd like to have an indication when the interpreter moves to the next file (using Filter-Include)?
by blazar (Canon) on Jul 14, 2005 at 11:18 UTC
    How 'bout playing with code in @INC? See require.

    E.g. something like:

    #!/usr/bin/perl use strict; use warnings; use lib sub { warn "Attempt to load `$_[1]'"; undef }; use File::Find; __END__
    which gives me
    $ perl foo.pl Attempt to load `File/Find.pm' at foo.pl line 5. Attempt to load `warnings/register.pm' at foo.pl line 5. Attempt to load `Cwd.pm' at foo.pl line 5. Attempt to load `vars.pm' at foo.pl line 5. Attempt to load `XSLoader.pm' at foo.pl line 5. Attempt to load `File/Basename.pm' at foo.pl line 5. Attempt to load `re.pm' at foo.pl line 5. Attempt to load `File/Spec.pm' at foo.pl line 5. Attempt to load `File/Spec/Unix.pm' at foo.pl line 5. Attempt to load `Scalar/Util.pm' at foo.pl line 5. Attempt to load `List/Util.pm' at foo.pl line 5. Attempt to load `DynaLoader.pm' at foo.pl line 5. Attempt to load `AutoLoader.pm' at foo.pl line 5.
Re: I'd like to have an indication when the interpreter moves to the next file (using Filter-Include)?
by broquaint (Abbot) on Jul 14, 2005 at 13:41 UTC
    There is no way to do this through the current interface, but you can bodge it e.g
    BEGIN { require Filter::Include; my $old_source = *Filter::Include::source{CODE}; *Filter::Include::source = sub { print "Including $_[0]\n"; goto &$old_source; }; Filter::Include->import; }
    I could add this feature to the module if you'd like (probably as an import() parameter), it could do with some tidying up anyhow.
    HTH

    _________
    broquaint

      I'd be grateful if you add this feature to the module.
Re: I'd like to have an indication when the interpreter moves to the next file (using Filter-Include)?
by artist (Parson) on Jul 14, 2005 at 11:26 UTC
    Not sure if this is going to help, but here it is anyway.
    { my $count = 0; sub counter { $count ++; print "Included File # $count\n"; } } require "file.pl" && counter(); require "file2.pl" && counter();
    --Artist
      Nope...

      As I see, there will be no option, but to change the Filter::Include, I think that I'll add before the conversion (it convert the script with the includes, to one big script that contains in it all the source of the include files), a dedicated command that will be an indication for begin of new include file, and catch it with AUTOLOAD sub

      What do you think ?