Beefy Boxes and Bandwidth Generously Provided by pair Networks DiBona
Perl Monk, Perl Meditation
 
PerlMonks  

Re^3: File NCopy concat

by Anonymous Monk
on Sep 14, 2006 at 18:57 UTC ( [id://573027]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Re^2: File NCopy concat
in thread File NCopy concat

Yes, its actually File::NCopy.... the files needs to have space in them. So Im trying a find a way to do this keeping the spaces in.

Replies are listed 'Best First'.
Re^4: File NCopy concat
by GrandFather (Saint) on Sep 14, 2006 at 19:10 UTC

    Try using File::Copy instead. File::NCopy seems to be broken.

    Update: the following illustrates the issue:

    use strict; use warnings; use File::Copy; use File::NCopy; use constant FILENAME_1 => 'File with spaces in the name.txt'; use constant FILENAME_2 => 'File with spaces in the name2.txt'; use constant FILENAME1 => 'Filename.txt'; use constant FILENAME2 => 'Filename2.txt'; open outFile, '>', FILENAME1; print outFile "Some text in non-spaced out file\n"; close outFile; open outFile, '>', FILENAME_1; print outFile "Some text in the spaced out file\n"; close outFile; File::NCopy::copy (FILENAME1, FILENAME2) or warn "Non-spaced to non-sp +aced failed with NCopy\n"; File::NCopy::copy (FILENAME_1, FILENAME2) or warn "Spaced to non-space +d failed with NCopy\n"; File::NCopy::copy (FILENAME1, FILENAME_2) or warn "Non-spaced to space +d failed with NCopy\n"; File::NCopy::copy (FILENAME_1, FILENAME_2) or warn "Spaced to spaced f +ailed with NCopy\n"; File::Copy::copy (FILENAME1, FILENAME2) or warn "Non-spaced to non-spa +ced failed with Copy\n"; File::Copy::copy (FILENAME_1, FILENAME2) or warn "Spaced to non-spaced + failed with Copy\n"; File::Copy::copy (FILENAME1, FILENAME_2) or warn "Non-spaced to spaced + failed with Copy\n"; File::Copy::copy (FILENAME_1, FILENAME_2) or warn "Spaced to spaced fa +iled with Copy\n";

    prints:

    Spaced to non-spaced failed with NCopy Spaced to spaced failed with NCopy

    DWIM is Perl's answer to Gödel
      File::NCopy's copy's argument is a glob pattern, not a file name. This pattern is passed to glob, which considers spaces to be pattern seperators, not literals. Refer to the passage I emphasised in the following snippet from File::Glob's documentation:

      Since v5.6.0, Perl's CORE::glob() is implemented in terms of [File::Glob's] bsd_glob(). Note that they don't share the same prototype — CORE::glob() only accepts a single argument. Due to historical reasons, CORE::glob() will also split its argument on whitespace, treating it as multiple patterns, whereas bsd_glob() considers them as one pattern.

      Update: File::NCopy works if you execute the following before calling copy:

      { package File::NCopy; use File::DosGlob qw( glob ); }

      And if the spaces are backslashed (or quoted).
      And if / is used as the path seperator on Windows.

      $filename = 'c:/directory\\ name/file\\ name.txt'; $filename = '"c:/directory name/file name.txt"'; $filename = 'c:/"directory name"/"file name.txt"';

      Truly, File::NCopy should be used with care if not considered outright broken. At the very least, it would be best if File::NCopy used bsd_glob rather than glob.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://573027]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.