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

Hi all, I am attempting to glob as such :

glob("\\sottbuild1f\\blacksea\\daily\\oqp\\*inst.tar.gz");

This is a remote network location, within my corporate LAN. This returns back nothing (empty array). Is there a way I can get around this ?

Thanks in advance, Travis

Replies are listed 'Best First'.
Re: globbing on remote network paths
by Corion (Patriarch) on Jun 19, 2007 at 16:07 UTC

    Most likely, your backslashes are interpreted in the doublequotes by Perl. Try some diagnostic messages to debug the problem:

    my $path = "\\sottbuild1f\\blacksea\\daily\\oqp\\*inst.tar.gz"; print "Searching files in >>$path<<\n"; my @files = glob($path);

    Also, glob isn't completely suitable for getting files in a directory because it treats spaces in the path differently from how Perl treats spaces everywhere else, because glob tries to emulate a shell. I commonly use the following code to switch glob to a sane(r) behaviour:

    use File::Glob qw(bsd_glob); my @programs = glob 'C:/Program Files';
      Corion,
      I have wondered this for sometime, but never asked. The docs for glob in recent versions indicate that it is implemented using File::Glob and the documentation indicates that File::Glob is a Perl extension for BSD glob routine. If this is the case, than shouldn't glob already be doing a bsd_glob?

      Update: I just read further down in the docs where it says: "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."

      Cheers - L~R

Re: globbing on remote network paths
by ikegami (Patriarch) on Jun 19, 2007 at 18:06 UTC
    "\\sottbuild1f\\blacksea\\daily\\oqp\\*inst.tar.gz"

    results in

    \sottbuild1f\blacksea\daily\oqp\*inst.tar.gz

    I think you want

    \\sottbuild1f\blacksea\daily\oqp\*inst.tar.gz

    which would be represented by the literal

    "\\\\sottbuild1f\\blacksea\\daily\\oqp\\*inst.tar.gz"
Re: globbing on remote network paths
by nimdokk (Vicar) on Jun 19, 2007 at 16:07 UTC
    Is this supposed to be a UNC? a relative directory? You might take a look at using File::Spec to build your path to make sure that the directory seperators are correct. Something like
    $path=File::Spec->catfile('//server','share','dir-1','*inst.tar.gz');
    You might need to play around with this some to get it to work right. You might also want to chdir to the directory prior to running the glob.
      I had this same issue and changed glob to use the forward slash convention for directories (instead of the Windows back slash). ie my @files = glob( "\\\\server\\dir\\*" ) does not work my @files = glob ( "//server/dir/*" ) does work