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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I split this in WinNT?

Status
Not open for further replies.

ejaj

Programmer
Sep 26, 2002
7
0
0
DE
Hi..

I am facing one strange problem. I cant split and rejoin this on a winNt platform. The example follows:

$input=c:\final\test\test1.txt

I want to get rid of the last part and check whether the path is valid or not.
my desired output should be
$output= c:\final\test
but i cant split the directories into fields with field speparator.
My script follows:

$input=$ARGV[0];
@edit_array=split(/\/,$input);
pop(@edit_array);
$pattern=join(/\/,@edit_array);
$path_final=$pattern."/" ;
print "The edited path is: $path_final\n";



...But.. i find lotz of error regarding "Backslash found where operator expected.. run away multiline "..etc...etc..

Can any1 help me regarding this?

Ejaj
 
Hi,
Do you need to 'ESCAPE' the backslash by using 2 of them.

/ \ \ /

---
 
Have you looked into the File::Basename module?

Code:
use File::Basename qw/fileparse/;
my ($name, $path, $suffix) = fileparse($ARGV[0], @suffixlist);
# @suffixlist can be set in code or from @ARGV...
if (-e $ARGV[0]) { print "The edited path is: $path\n"; }
else { print "'$path' is not valid.\n"; }

I didn't test this, but I'd probably use something like this...[wink]

HTH Notorious P.I.G.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top