Help needed on language change-adding folder in expression (PERL)
Hello,
I'd really like some help on this, a PERL-CGI script. How can I add the server's root folder of "my_folder" to this: ~ s/_e\.shtml/_f\.shtml/ This 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 add the server's root of "french" folder in there. For example; and yes I know it's not right: ~ s/_e\.shtml/(MY_FOLDER)_f\.shtml/ 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 get the 'french' file (file_f.shtml) in the /f/ folder (/ being the root). #!/usr/bin/perl # # # 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? } |
As no-one has answered, I'll give it a crack.
TBH, I'm not entirely clear on what you're doing without a fuller example of the data (ie src & tgt filepaths). However, have a look at this snippet (tested), which I believe may be the answer, or at least close. Code:
$var1='/dir/e/x_e.shtml'; HTH |
Hello and thanks for replying. The entire script is above; the script is to show the user, a link to the same page but in a different language when they click on the .pl link; for example "This page in English" from a French page (welcome_f.shtml) which would lead to the English equivalent of (Welcome_e.shtml) but in a different folder, being either /e/ or /f/ (e-English and f-French). TBH, I don't know why the "print" statement is doing in my original script lol. That's probably why it might be confusing.
|
Well my example changes the filename and then changes the dir path for you.
Does that not work, if not why not? I always advise testing as a non-CGI script first to get make it easier to get the processing code correct, then use the same method inside the CGI version. |
I'm a "newbie" in a way, but can modify scripts to a certain point, just can't write them from scratch. Am trying to figure out how to implement your suggestion into my existing script. Any chance on a total re-write with my example above?
|
Not really ... I don't do CGI ;)
Anyway, just remember that what you are fundamentally asking about (I believe) is really just string shuffling; it doesn't matter that they contain dir/file paths. So, just write a basic script like mine and experiment until you 'get it' Here are some good Perl links http://perldoc.perl.org/ http://www.perlmonks.org/?node=Tutorials and ask again if you get stuck |
All times are GMT -5. The time now is 01:15 AM. |