The Roopak Times am Donnerstag, 13. Oktober 2005 09.39: > Hi All Hi
> Sorry to disturb you again but the same program is creating a heap of > troubles > this time it is not showing any results at all, it takes an input and then > forgets to process, > the program is here > > *use warnings; > use strict;* > > *print "Plz enter the path name:"; > my $DIR=<STDIN>; > chomp($DIR); > if($DIR=~/([a-z]+)/) > { > print $1 if defined; > print $2 if defined; > print $3 if defined; > }* > > what i want is to print is all the directory names in a given path. This program won't run because of the '*'... Each of the 3 print lines should be changed to print $1 if defined $1; # example ...but you won't get values in $2 and $3 because the regex only catches $1. See perldoc -f defined perldoc perlre perldoc perlretut perldoc perlrequick Then, with your regex, no '/' or '\' will be matched. Here is a version: use strict; use warnings; use File::Spec; # see perldoc File::Spec print "Plz enter the path name: "; chomp(my $DIR=<STDIN>); # shorter my @dirs = File::Spec->splitdir($DIR); # portable way to do it print @dirs; # will only print defined parts ("directory names") # Sessions: Plz enter the path name: /a/b/c abc Plz enter the path name: a/b/c abc Note that there is no difference between abs. and rel. paths. See perldoc File::Spec to detect these two cases. hth, joe -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>