On Nov 9, 2009, at 16:25, axr0284 wrote: > Hi, > I am completely stumped with how to proceed with this. > I have a program where the user inputs a path to a file. This is under > windows xp > > The path can be relative > ..\..\..\synthesis\int_code.psm > .\program\synthesis\int_code.psm > > or absolute > c:\command\tool\program\synthesis\int_code.psm > > I do not know what it is in advance. > > 1)I would need perl to be able to distinguish between a relative and > absolute path
Fortunately there are lots of tools to do this in perl. :) > > 2) If the path is relative, create an absolute path from that. > > My orignal idea was to locate ..\ with regex using m/([.]{2}\\)/ This > would indicate if the path is relative or not > > use cd to obtain the present working directory. Is there a better way > to do this??? Yes; Cwd To find out more, look up Cwd in perl documentation. In short its like this: use Cwd; my $dir = getcwd; use Cwd 'abs_path'; my $abs_path = abs_path($file); > > Can anybody help me with this or can you think of a better idea. Avoid starting your solution with a regex if you can. Regexes tend to get complicated quickly. :) Jeremiah -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/