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

I want to open read a ini file on network from a linux/unix machine. My ini file could be on unix/linux/windows machine. I am not able to read file using the network path. Kindly let me know the way to read file.
use Config::IniFiles; my $INI_FILE_PATH = "//machine_ip/folder in which file is present/tes +t.ini"; if (!(-e "$INI_FILE_PATH" )) { print STDERR "Error:File not present"; } my $cfgObject = new Config::IniFiles( -file => $INI_FILE_PATH ); my $configSpecPath = $cfgObject->val('SECTION", "PARAMETER");
On executing the code it is giving me error saying that "Error:File not present" Please let me know what am I doing wrong here. Thanks, Rapunzel

Replies are listed 'Best First'.
Re: not able to read remote file from linux machine
by ikegami (Patriarch) on Nov 10, 2008 at 09:25 UTC

    You're assuming -e returns false because the file isn't present. That might not be the case. Change

    print STDERR "Error:File not present";

    to

    die("Can't stat config file \"$INI_FILE_PATH\": $!\n");

    The important part is the use of $!.

      Or the OP may need $^E for the extended error code/message.

      with this code it is giving the same error.  die("Can't stat INI file \"$INI_FILE_PATH\": $!\n"); I got following error "Can't stat INI file "//machine_ip/some folder/test.ini": No such file or directory" What I think is problem is because file is on some other machine.
        I think problem is because file is on some other machine.

        Maybe you want to install samba, which would allow you to access Windows files from a Linux box.

        I missed the bit in the OP about the script being run on a unix machine. In unix
        //machine_ip/some folder/test.ini
        means
        /machine_ip/some folder/test.ini
        You'll need to mount the remote file system to access it, or access it through samba.