Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File::spec->catfile not working in UNIX

Status
Not open for further replies.

drkestrel

MIS
Sep 25, 2000
439
GB

I have
Code:
#!/usr/local/ActivePerl-5.6/bin/perl
use File::Spec;         #For platform independent file path manipulation
#Read in config file and put key/value pair into vars Hashtable
open CONFIGFILE,$ARGV[0];    
    while(<CONFIGFILE>){
        if (/^(\w+)=(.*)$/)
     	{
            $vars{$1} = $2;
        }
    }
close CONFIGFILE;

$root           = $vars{&quot;root&quot;};
print &quot;ROOT IS &quot;;
print $root;
print &quot;\n&quot;;
my $today       = &quot;20010310&quot;;
$today1         = File::Spec->catfile($root,$today);  
print $today1;

The above functions normally in NT, but under Solaris, I get the following printout

ROOT IS /home/myID/
/20010310


What have I done wrong?
 
I found out that it is the NT/UNIX file line feed problem when I am reading in configuration variables from file!!

Is there a portable way of doing pattern matching on newlines?? I thought $/ is cool, but may be not!!

Saving config file in UNIX format solved my last post (FTP problem as well, how crazy :) )
 
I'm probably missing something but why aren't you using \n instead? Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
do you mean use \n instead of $
but I think Windows use \n\r or \r\n (can't remember which way round!), but anyway, isn't $ meant to be portable?
 
Perl understands the new-line character (&quot;\n&quot;) on different OS's

If you use it on a unix system it will interpret it as just an LF character whilst on a DOS/NT/Winxx system it means the CRLF pair.

But yes -- the pattern you're using looks fine actually, it's what I would have written.

what about trying (/^(\w+)=(.*)\s*$/ Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top