脚本帮助,链接到不同子文件夹中的文件
我真的很想得到一些帮助,一个 PERL-CGI 脚本(完整的工作脚本如下)。
如何将服务器的根文件夹(folder_f)添加到此:
〜s/_e.shtml/_f.shtml/
这段代码搜索所有出现的_e.shtml并将它们替换为_f.shtml(它位于同一文件夹中) )。
然而,在这之间,我希望能够在其中添加服务器的“folder_f”文件夹的根目录,或者如果必须的话可以采用其他方式。
我的脚本称为“change-language.pl” - 在“file_e.shtml”中有一个指向它的超链接。单击时,它将尝试查找文件“file_f.shtml”。
例如我希望它做什么:
〜s/_e.shtml/(FOLDER_F)_f.shtml/(在下面的脚本中找到,但我添加了(FOLDER_F)。
我尝试过:$calling_page =~ s/_e.shtml/'s/^/$.\f'/_f.shtml/;
但它不起作用
。感谢任何人在这方面的帮助,因为据我所知,我似乎无法正确理解
下面的完整脚本,该脚本仅在两个语言文件(file_e.shtml 和 file_f.shtml)都驻留在其中时才有效 。我需要能够让脚本工作,以便它能够找到文件(file_f.shtml),但位于服务器根目录上名为“FOLDER_F”文件夹的不同子文件
夹中 。脚本的 $calling_page =~ s/_e.shtml/_f.shtml/; 有没有办法做到这一点:
$calling_page =~ s/_e.shtml(FOLDER_F)/_f.shtml/ - FOLDER_F 位于括号中是我希望能够修改脚本的地方,以便它转到子文件夹并在 FOLDER_F 子文件夹中获取 file_f.shtml 。
到目前为止,我所拥有的都是有效的,但只有在 _e.shtml 和 _f.shtml 文件位于同一文件夹中时才有效:
#!/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?
}
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:
#!/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?
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解你的描述,你想将文件夹名称插入到 URL 中,如下所示:
如果是这种情况,那么你可以使用以下正则表达式来执行此操作:
If I understood your description correctly, you want to insert a folder name into an URL, like this:
If this is the case, then you can do this using this regular expression: