1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help on Adding a sub-folder in script

Discussion in 'Perl' started by fredfletcher, Sep 12, 2011.

  1. fredfletcher

    fredfletcher New Member

    Sep 12, 2011
    Likes Received:
    Trophy Points:

    I'd really like some help on this, a PERL-CGI script (complete working script is below).

    How can I add the server's root folder (folder_f) to this:

    ~ s/_e\.shtml/_f\.shtml/

    This bit of code searches all occurences of _e.shtml and replaces them with _f.shtml (it being in the same folder).

    Yet, in between that, I would like to be able to add the server's root of "folder_f" folder in there, or done another way if it has to.

    My script is called "change-language.pl" - which has a hyperlink to it in "file_e.shtml". When clicked, it will try to find the file "file_f.shtml".

    For example of what I would like it to do:

    ~ s/_e\.shtml/
    (FOLDER_F)_f\.shtml/ (found in script below, but I added (FOLDER_F).

    I tried: $calling_page =~ s/_e\.shtml/'s/^/$.\f'\/_f\.shtml/;

    but it did not work. It brings me to the same _e.shtml file.

    I would really appreciate anyone's help on this one, as I can't seem to get it right, with what I know so far.

    The complete script is below, which works but only if both language files (file_e.shtml and file_f.shtml) reside in the same folder. I need to be able to have the script work, so that it will find the file (file_f.shtml) but in a different sub-folder on the server's root called "FOLDER_F" folder.

    In the part $calling_page =~ s/_e\.shtml/_f\.shtml/; of the script, is there a way to do this:

    $calling_page =~ s/_e\.shtml(FOLDER_F)/_f\.shtml/; - FOLDER_F being in parentheses is where I would like to be able to have the script modified so that it goes to a sub-folder and get file_f.shtml in FOLDER_F sub-folder.

    What I have so far follows WORKS, but only works if both _e.shtml and _f.shtml files are in the same folder:

    # get the URL for the Web page that called this script
    $calling_page = $ENV{'HTTP_REFERER'};
    if($calling_page =~ /(.*)\#.*/) {
    # # only take the first part up to the #
    $calling_page = $1;}
    # ignore any file that is not _e.shtml or _f.shtml and do nothing!
    # is this an _e.shtml file?
    if($calling_page =~ /_e\.shtml/) {
    # replace the suffix
    $calling_page =~ s/_e\.shtml/_f\.shtml/;
    print "Location: $calling_page\n\n";
    # then is this an _f.shtml file?


Share This Page