in reply to Accessing files on another server within perl script

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

Replies are listed 'Best First'.
Re^2: Accessing files on another server within perl script
by vihar (Acolyte) on Aug 16, 2013 at 14:31 UTC
    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.