Help needed on language change-adding folder in expression (PERL)
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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?
}
Last edited by fredfletcher; 09-12-2011 at 12:02 AM.
Reason: added PERL at end of subject
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.
Note that the s/// notation in Perl is borrowed from sed, and like sed, you can use a different pattern separator if the string(s) use the '/' char eg use ':' instead, to avoid LTS https://secure.wikimedia.org/wikiped...hpick_syndrome
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?
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
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.