ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
I am trying to write a script in Perl that would generate a PHP site that is actually not that complicated. My only problem is that I do not have the option to operate with 2 files so I need to have everything in 1 Perl file. I need to have the PHP file inside the Perl file in some form of variable or something like that. Is it possible to put a php code like that into a var in perl?
What you could do is have a single output variable, and constantly concatenate to it depending on the flow control:
Code:
...
my $var = '<font size="2">';
my $bold = '<b>';
my $italic = '<i>';
$var .= $bold if ($style == 'bold');
$var .= $italic if ($option == 'italic');
# Close the open tags...
$var .= '</i></b></font>';
...
The one problem you will almost certainly run into with this, is that you may not always know which tags are open or closed. You will probably have to incorporate a function to scan through a line (before it's printed) and ordinally close any open tags (ie. <i> was the last opened tag, so close it first) by simply taking the tag opening string, and inserting a forward slash "/" after the opening "<". The sub-problem that arises from this is tags with extended information - "<font size=2 color=...>" - and having to deal with taking out everything in between "<tagname" and the closing ">", but that could easily be taken care of with a regular expression.
I went through the regular expressions again and realized that there are differences between the ' and " signs. When I tried this:
Code:
$var = "<?
print 'Hello';
$ccol = sad;
?>";
i bumped into an error. Then I replaced the " to ' and the ' to \' that way it worked without the use strict part of the code. I got only a warning. Why isn't it working with the use strict; stuff too? What is wrong with it?
#!/usr/bin/perl
print while <DATA>;
__DATA__
put your
php
code in
here
It is readable, however there are one thing that I do not get. What are the __ signs and how shall I interpret it? Why do u refer to the DATA as <DATA>.
Also I found loops like while(<>) that is in infinite loop similar to for(;. What is the background of it? I am no perl programmer (yet) but I am eager to learn this language but I cant go to the next step as long as I bump into such things.
It turned out that I have got more than one problems, heh?
Yup... that __DATA__ thing is the one that works that best. The file is now ready to be used. Low quality code but it does what it is supposed to do. thanx guys for the help
I use it quite a lot, it's also very good for example data
for filter programs,
so when 6 months later you go back and say "what the hell does this do?"
you'll have an example to run.
Maybe, I would post, the entire code here so that u can comment it and say what are the thing that u would do in a different way, and why is ur solution better. U think u could do this for me?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.