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

hi. i am a novice with perl still, and for a project that i am working on i need to include slurp.pm for a file, and am getting error
"Can't locate File/Slurp.pm in @INC (@INC contains: C:\Program Files\A +ctiveState Komodo 2.5 c:\sandbox\xpp\localbin\lib \\DPSICORP.COM\XyEn +terprise\XPP\localbin\lib \\DPSICORP.COM\XyEnterprise\XPP\localbin\li +b C:/Perl/lib C:/Perl/site/lib .) at C:\sandbox\directory_change.pl l +ine 4.BEGIN failed--compilation aborted at C:\sandbox\directory_chang +e.pl line 4.
can anyone inform me of how i can compile this module correctly?
-thanks

Replies are listed 'Best First'.
Re: slurp::file
by marto (Cardinal) on Jul 25, 2005 at 15:12 UTC
Re: slurp::file
by Transient (Hermit) on Jul 25, 2005 at 15:11 UTC
    Use ppm
    C:\Perl>ppm PPM - Programmer's Package Manager version 3.1. Copyright (c) 2001 ActiveState Corp. All Rights Reserved. ActiveState is a devision of Sophos. Entering interactive shell. Using Term::ReadLine::Stub as readline lib +rary. Type 'help' to get started. ppm> search Slurp Searching in Active Repositories 1. File-OldSlurp [2004.0430] Read and write files with a single c +ommand 2. File-OldSlurp [2004.0430] Read and write files with a single c +ommand 3. File-Slurp [9999.09] Efficient Reading/Writing of Complet +e Files 4. File-Slurp [2004.0904] Read and write files with a single c +ommand 5. File-Slurp [9999.01] Efficient Reading/Writing of Complet +e Files 6. File-Slurp [9999.02] Efficient Reading/Writing of Complet +e Files 7. File-Slurp [9999.04] Efficient Reading/Writing of Complet +e Files 8. File-Slurp [9999.06] Efficient Reading/Writing of Complet +e Files 9. File-Slurp [9999.07] Efficient Reading/Writing of Complet +e Files 10. File-Slurp [9999.08] Efficient Reading/Writing of Complet +e Files 11. File-Slurp [9999.09] Efficient Reading/Writing of Complet +e Files 12. File-Slurp-Tree [1.22] slurp and emit file trees as nested +hashes 13. File-Slurp-Tree [1.22] slurp and emit file trees as nested +hashes 14. Slurp [0.4] Slurp entire files into variables 15. Slurp [0.4] (none) 16. Tie-Slurp [0.01] tie a scalar to a named file 17. Tie-Slurp [0.01] tie a scalar to a named file ppm> install File-Slurp ==================== Install 'File-Slurp' version 9999.09 in ActivePerl 5.8.6.811. ==================== Downloaded 7673 bytes. Extracting 5/5: blib/arch/auto/File/Slurp/.exists Installing C:\Perl\html\site\lib\File\Slurp.html Installing C:\Perl\site\lib\File\Slurp.pm Successfully installed File-Slurp version 9999.09 in ActivePerl 5.8.6. +811. ppm>
Re: slurp::file
by graff (Chancellor) on Jul 26, 2005 at 02:10 UTC
    Maybe I'm just old fashioned (or I'm not paying enough attention), but I don't quite understand why this:
    use File::Slurp; # ... my $file_data = read_file( 'file.name' );
    is so much better than this:
    my $file_data = do { local $/; open(I,'file.name'); <I> };
    or why this:
    use File::Slurp; #... my @lines = read_file( 'file.name' );
    is better than this:
    open( I, 'file.name' ); my @lines = <I>;
    I realize that the man page for File::Slurp covers a lot more than that, but it doesn't seem as though it really adds all that much in terms of simplifying things that are already pretty easy just using unadorned functions that are already in common use (setting $/, using binmode, etc). And it doesn't seem to help much in terms of providing any extra layer of OS-independence.

    So if the previous replies provide what you need in order to install the module, and you really want to do that, then good, go that way and be glad. But if you still have problems trying to use the module, look up the "fundamentals" on the things you really need to do -- it won't be that hard to work out a solution without the using module.

      One reason, I'd imagine, is just simplicity of code reuse -- less chance of miscoding by mistake. However, there are other benefits. There's an extensive article on the topic. For example:

      Excerpt from Perl Slurp Ease by the author of File::Slurp

      Fast Slurping

      Somewhere along the line, I learned about a way to slurp files faster than by setting $/ to undef. The method is very simple, you do a single read call with the size of the file (which the -s operator provides). This bypasses the I/O loop inside perl that checks for EOF and does all sorts of processing. I then decided to experiment and found that sysread is even faster as you would expect. sysread bypasses all of Perl's stdio and reads the file from the kernel buffers directly into a Perl scalar. This is why the slurp code in File::Slurp uses sysopen/sysread/syswrite. All the rest of the code is just to support the various options and data passing techniques.

      That said -- knowing the fundamentals is good too. If I'm just slurping a text file once of a known, manageable size, then using the standard idiom would make sense. But once I'm writing that idiom more than a couple times, I'm going to want to code it as a subroutine -- and that's when I'd rather use File::Slurp rather than roll my own each time.

      -xdg

      Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.