Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^4: dynamic loading modules

by sdetweil (Sexton)
on Sep 03, 2012 at 16:58 UTC ( #991479=note: print w/replies, xml ) Need Help??


in reply to Re^3: dynamic loading modules
in thread dynamic loading modules

thx.. that works, but I don't understand 'why'.. how does the compiler know NOT to require the Win32 module in this case, but in my existing source, with no explicit use statement it does?

anyhow.. now I have the same problem with TieRegistry <code> use Win32::TieRegistry; $Registry->Open(keyname);

the doc says 'new(keyname)' should work, and then there are a bunch of functions off the handle..

but I get Autoload is deprecated. or open not found.

then must be some easy, clear way to handle this. without having to know the internals of every package.

Replies are listed 'Best First'.
Re^5: dynamic loading modules
by Anonymous Monk on Sep 03, 2012 at 17:04 UTC
      well, that requires learning ANOTHER pile of function..

      but I have my answer.. SOMETHING tells the compiler things are different..

      load 'package' value = package::function(); vs use Package::function; value = Package::Function;
      and maybe its just my mis understanding
      the value = is the same. the use vs load is to tell the runtime how to resolve.
      'use' means compiled in to some internal table,
      'load' means dynamically added to the same table.

        Perhaps you should have a look at the source of File::Spec. Or perhaps not. Think about the following construct first:

        (Each code block represents a properly named file)

        package MyProject::OSSpecific::base; use strict; use warnings; sub niceOSName { my $class=shift; die "$class does not implement an OS specific niceOSName() method" +; } sub tempDir { die "I don't know how to find a temp directory"; } sub pathSep { return '/'; } sub installTo { die "Should not happen"; } # much more methods 1;
        package MyProject::OSSpecific::doslike; use strict; use warnings; use parent 'MyProject::OSSpecific::base'; sub tempDir { return 'c:\\temp'; } sub pathSep { return '\\'; } # much more methods 1;
        package MyProject::OSSpecific::dos; use strict; use warnings; use parent 'MyProject::OSSpecific::doslike'; use Some::DOS::Specific::Module; sub niceOSName { my $x=`command /c ver`; chomp $x; return $x; } sub installTo { return 'C:\myproject'; } 1;
        package MyProject::OSSpecific::MSWin32; use strict; use warnings; use parent 'MyProject::OSSpecific::doslike'; use Win32; sub niceOSName { return Win32::GetOSName(); } sub installTo { return 'C:\\Program Files\\MyProject'; } 1;
        package MyProject::OSSpecific::unixlike; use strict; use warnings; use parent 'MyProject::OSSpecific::base'; sub niceOSName { my $x=`uname -a`; chomp $x; return $x; } sub tempDir { return '/tmp'; } sub pathSep { return '/'; } # much more methods 1;
        package MyProject::OSSpecific::freebsd; use strict; use warnings; use parent 'MyProject::OSSpecific::unixlike'; use Something::Created::Only::For::FreeBSD; sub installTo { return '/usr/local/myproject'; } 1;
        package MyProject::OSSpecific::linux; use strict; use warnings; use parent 'MyProject::OSSpecific::unixlike'; use Something::Very::Linux::Specific; sub installTo { return '/opt/myproject'; } 1;
        And finally:
        packame MyProject::OSSpecific; use strict; use warnings; use parent 'MyProject::OSSpecific::'.$^O; # <-- this is the most impor +tant trick here. 1;
        In your code:
        use strict; use warnings; use MyProject::OSSpecific; print "This program should be installed to ",MyProject::OSSpecific->in +stallTo(),"\n";

        Alexander

        --
        Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

        well, that requires learning ANOTHER pile of function.

        Well, it requires learning substantially less than your current approach :) just copy/paste, it will work, all your problems will disappear

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://991479]
help
Chatterbox?
[kcott]: marioroy, not much to go on. Searching "slow logging" (by me) produces no results; just "slow" gives a screenful. Perhaps, "Searching large files a block at a time" which had a performance aspect and you had some imput also.
[gnosti]: Hi, Looking for a module that can add HH:MM:SS durations like 1:40, 1:00:24.13 and 12.3? I see on CPAN more modules with absolute dates. TIA
[kcott]: s/imput/input/
[Corion]: DateTime::Duration ? Personally,I convert stuff to seconds using Time::Piece or Time::Local and then add the seconds and then use POSIX::strftime to print them as hours again
[marto]: good morning all, TCIF
[gnosti]: I'm reading from ffmpeg lengths of video clips in H:M:S and needing to add them and format them back to H:M:S for feeding back to ffmpeg
[marioroy]: kcott Thanks

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (9)
As of 2017-08-18 08:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Who is your favorite scientist and why?



























    Results (297 votes). Check out past polls.

    Notices?