Rather than try to juggle files and paths yourself, you could employ the File::Basename and File::Spec core modules to do the heavy lifting. They have the advantage of being portable and well-tested. I have written a script which I think is doing what you are after but I use those modules to manipulate the paths and I use regular expressions with captures (see perlretut, perlre and perlreref) rather than your split.

use strict; use warnings; use Cwd qw{ abs_path }; use File::Basename; use File::Spec; my $scriptPath = abs_path( $0 ); my $path = ( fileparse( $scriptPath ) )[ 1 ]; my $configFileName = File::Spec->catfile( $path, q{spw750353.ini} ); open my $configFH, q{<}, $configFileName or die qq{open: < $configFileName: $!\n}; my $fileFromConfig = q{}; my $pathFromConfig = q{}; while( <$configFH> ) { if( m{^myfile=(.+)} ) { $fileFromConfig = $1; } elsif( m{^path=(.+)} ) { $pathFromConfig = $1; } else { warn qq{$_ : line not recognised\n}; } } close $configFH or die qq{close: < $configFileName: $!\n}; my $fullPath = File::Spec->catfile( $pathFromConfig, $fileFromConfig ); print qq{$fullPath\n};

Here is the .ini file, shown both from the Cygwin (*nix-like) environment and from the command prompt under Windows XP.

$ cat spw750353.ini myfile=bbbbbbb.txt path=aaaaaaaaaaaaaaa $
C:\cygwin\home\johngg\perl\Monks>type spw750353.ini myfile=bbbbbbb.txt path=aaaaaaaaaaaaaaa C:\cygwin\home\johngg\perl\Monks>

Here is the script running unaltered in both environments.

$ ./spw750353 aaaaaaaaaaaaaaa/bbbbbbb.txt $
C:\cygwin\home\johngg\perl\Monks>perl spw750353 aaaaaaaaaaaaaaa\bbbbbbb.txt C:\cygwin\home\johngg\perl\Monks>

Note how the modules use the path separator appropriate to the environment without programmer intervention.

I hope this is helpful.

Cheers,

JohnGG


In reply to Re: Weird string by johngg
in thread Weird string by AoZus

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.