Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

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

by mosh (Scribe)
on Jul 14, 2005 at 11:02 UTC ( #474821=perlquestion: print w/replies, xml ) Need Help??
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 ?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://474821]
Approved by Nevtlathiel
Front-paged by blazar
help
Chatterbox?
[ambrus]: (b) a good presentation system that lets the presenter quickly interactively edit the slides live during a presentation, to combine the advantages of blackboard and overhead slide styles in modern tech
[Corion]: Heh - in university, I cheated on (a) by doing blackboard presentations using chalk. But those were 2 hour presentations, not quick/essential/ reduced presentations where you want to show something quick
[ambrus]: (either on just one screen or two screens). this is necessary because
[ambrus]: overhead slide plus blackboard is inconvenient because the lighting conditions are different and they require separate areas you can't quickly repartition, and typing on keyboard is faster and more convenient than writing on a blackboard
[Corion]: (b) would be cool. I've thought about this doing Pod editing, and even simply regenerating/live updating the browser makes things much more interactive
[ambrus]: modern computers have way enough processing power to allow this, at least for geeks who are willing to spend a few weeks to learn a tricky new user interface like vim
[Corion]: ambrus: Well, for mathematical notation, I find blackboard much more convenient than a computer. But when inserting text or moving text around, the computer wins obviously
[ambrus]: But either of these is a big problem in practice, so I'd need to spend like thirty years of my life to solve (a) and five more years to solve (b)
[ambrus]: Corion: yes, CURRENTLY the blackboard is more convenient
[ambrus]: and it's not like I want to ban blackboards anyway

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (10)
As of 2017-09-26 10:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (293 votes). Check out past polls.

    Notices?