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

Hi,

I am required to access files on a different server using a Perl script. Earlier, when I was running my scripts with files on the same server, it ran just fine. Now, I am not sure how to go about changing my glob function or even use something new to achieve this task.

This is what I originally had to access these files on the same server:
@files = glob "/mmk1/rdd/load/file.txt"

Now, the files are the same but the server is different. I can't write Perl scripts on that server because all my Perl modules are installed on the old server. Is there a way to solve this issue?

Thanks a lot for your help!
  • Comment on Accessing files on another server within perl script

Replies are listed 'Best First'.
Re: Accessing files on another server within perl script
by kcott (Archbishop) on Aug 16, 2013 at 07:07 UTC

    G'day vihar,

    Welcome to the monastery.

    'This is what I originally had to access these files on the same server:
    @files = glob "/mmk1/rdd/load/file.txt"'

    I don't know what this is supposed to tell us; perhaps some further explanation was omitted. In list context (as you have here), glob performs filename expansion on the expression provided; as you have no wildcards, all this does is:

    $ perl -Mstrict -Mwarnings -le ' my @files = glob "/mmk1/rdd/load/file.txt"; print "@files"; ' /mmk1/rdd/load/file.txt
    "I can't write Perl scripts on that server because all my Perl modules are installed on the old server. Is there a way to solve this issue?"

    You can add a coderef hook to @INC (see perlvar: General Variables) that may be able to do this for you. See require for details; the basic idea is to do something like this (completely untested):

    push @INC, \&get_remote_module; sub get_remote_module { my ($coderef, $filename) = @_; open my $module_fh, '-|', "<$filename transfer command>" or die "m +esg: $!"; return $module_fh; }

    where "<$filename transfer command>" might be (simplistically) "curl scheme://your.domain/perl/lib/path/$filename".

    Update: fixed typo s/sub get_remote_modue/sub get_remote_module/

    -- Ken

      Thanks for your suggestion.

      I just put the glob function in there to just give you guys an idea of what was going on. But you are right, it wasn't clear.

      My main goal is to work with .txt files so I can parse them for proper records. These files are located on a different server and I need to access them from my server. Is there an easier way to use some sort of Perl command or something really easy so I can look into these files and validate them for proper data?

      Thanks

        "Is there an easier way to use some sort of Perl command or something really easy so I can look into these files and validate them for proper data?"

        You need to access the remote file. How you do so depends on what services the remote server has. Can you download the file via ftp/www? Can you mount the disk on the remote server containing these files?

        You then need to parse the files, what format are they? What do you consider "proper data"?

        Until scientists invent magic you're going to have to do some research. If you want help with something you have to provide enough information for people to make suggestions. How do I post a question effectively? has advice on this. It doesn't work isn't a response anyone can help you with.

Re: Accessing files on another server within perl script
by boftx (Deacon) on Aug 15, 2013 at 21:16 UTC

    My gut response is that unless you can remote mount the other server's drive on yours you are probably looking at using something like Net::FTP to bring the files over to your server and then work with them.

    If, on the other hand, you can remote mount the new server's drive then you just need to adjust the path accordingly and you should be good to go.

Re: Accessing files on another server within perl script
by Anonymous Monk on Aug 16, 2013 at 00:02 UTC

    Hi,

    Can you access the files from the command line?

    If you can, try that in the perl program.

    J.C.

      It doesn't work from command line either.