in reply to Trouble with path syntax

Since you are a "totally Perl illiterate", you might like a description of what the code actually does.
1: my($thebase) = ($file =~ /(.*)\/[^\/]+/); 2: my($html,$html2); 3: if (!-e $file){ 4: $thebase =~ s/\/[^\/]+$/\/default/;
as an example, I set $file = "1/2/3/4.txt";
1: applies a regular expression to $file; assigns the directory $file resides in to $thebase ($thebase = "1/2/3").
3: checks whether $file does not exist.
4: if $file does not exist, the last directory component of $thebase is replaced by "default". ($thebase = "1/2/default").

daniel.

Replies are listed 'Best First'.
Re: Re: Trouble with path syntax
by diamich (Initiate) on Aug 29, 2003 at 16:07 UTC
    Thanks for the feedback. I had kind of figured that

    3: if (!-e $file) checked to see if $file did not exist, so I changed it to

    if (-e $file){
    So that it would execute and append the /default. It failed miserably :-(

    $file does exist and = /home/digizms2/public_html/cgi-bin/linkmanage/templates/

    What I need is for the code to check if it exists and if it does, then to make

    $thebase = /home/digizms2/public_html/cgi-bin/linkmanage/templates/default

    Any tips?