Jump to content

Perl Question


SonicDragon

Recommended Posts

Is there a way to convert text into subscript in Perl? I haven't been able to find anything in any of the books i have here, or turn up much on the web, but i'm still looking.Thanks everyone

Link to comment
Share on other sites

Hi SonicDragonI'm not a Perl expert by any means, but I do know that with the latest Perl versions that anything between the pipes as in this example:PRINT qq| HTML &/or JavaScript, etc. code here\n|;will be displayed as coded as in this example:PRINT qq|<input type="text" name="foo" value="$foo">\n|;Or you could use the \ to escape any quotes, etc. as in this example:PRINT "<input type=\"text\" name=\"foo\" value=\"$foo\">\n";Note: If the pipes do not work for you, try using parenthesis like this:PRINT qq(HTML &/or JavaScript, etc. code here \n); as I have seen some references to using that.One of the 2 should work for you :lol:

Link to comment
Share on other sites

I think this is (something like) what you are looking for. For more information look for "hash". This is how perl does associative arrays:

%hash1 = ('fred' => 'landlord',           'ethel' => 'landlady',           'lucy' => 'lady tenant',          'ricky' => 'guy tenant');$key = 'fred';# the following prints 'landlord'print "$hash1{$key}\n";# the following prints 'landlord'print "$hash1{'fred'}\n";$key = lucy;# the following prints 'lady tenant'print "$hash1{$key}\n";# the following prints 'guy tenant'print "$hash1{'ricky'}\n";# the following prints 'male tenant'$hash1{"ricky"} = 'male tenant';print "$hash1{'ricky'}\n";# prints a blank line (due to \n) because 1 is not a key of the table as defined by# %hash1 definitionprint "$hash1{1}\n";# print the array keys and associated data. Note that the order is # not the order that the data were defined.foreach $key (keys %hash1) { print "$key => $hash1{$key}\n";}
Link to comment
Share on other sites

Thanks. Sluggo: That sounds like it would work. I'll have to try that it the morning though... i'm very tired. I just got back from a drum circle. I hadn't been to one in months and I forgot for tiring they are :D. littlebone: I'm a little confused. What do hashes have to do with subscripts? By subscrips i meant litty tiny letters, sort of offset below the line. Sorry for the confusion.

Link to comment
Share on other sites

Hmmm, i can't get it to work.$foo="<sub>asdf</sub>";print qq(<input type="html" name="foo" value="$foo">\n);Is that what you're talking about, or am i way off? That only prints this for me:<input type="html" name="foo" value="<sub>asdf</sub>">Oh... i just thought of something. Are you talking about putting perl on a webpage? or just through the console ('cause that's what i've been doing).I was talking to a guy at work, and he said that he didn't think it could be done becuase the terminal can't display subscipt characters. Subscripts would be a display property of what you're running the code in, not perl it self. Any thoughts? If we can't figure out how to do it, it's no big deal, i was just playing around with stuff. It's not really that important.

Link to comment
Share on other sites

Hi SonicDragonMaybe I shouldn't have used a form input code as an example as that might be confusing, however to have regular text displayed as subscript text on a web page that's being served up in HTML format (I can't say about a console though) you would need the normal opening and closing set of HTML tags coded into the Perl script somewhere before and after the line(s) for the subscript text that you want to insert.That can be done using the examples that I posted but with the normal HTML coding for those lines such as this:PRINT qq|<html><head></head><body rest of any body code here>Your <sub>subscript text here</sub> remainder of text here.</body></html>\n|;You do not need to write an individual line for each line of HTML code as some will use, you could write an entire page's HTML code between the pipes if you wanted to as well as insert any CSS code (or use the usual <link rel="stylesheet" href="style.css" type="text/css"> in the head section.In other words, using the pipes allows you to write normal code that would otherwise not be possible without escaping the quotes, etc.

I was talking to a guy at work, and he said that he didn't think it could be done because the terminal can't display subscript characters. Subscripts would be a display property of what you're running the code in, not perl it self.
That seems to be a fair statement on the surface, but I can't say for sure as I've not had any experience using any type of console with Perl.
Link to comment
Share on other sites

You're welcome, did you get it to work ?
Sorry i left you hanging. I didn't have time to test it out last night.I'm still really new to perl (and programing) and i don't have any idea for to integrate it with HTML :lol: I tried uploading the .pl file and typing www.sonicdragon.net/asdf.pl and got a 500 error. I assume i'm doing this wrong?
Link to comment
Share on other sites

Hi SonicDragon

I tried uploading the .pl file and typing www.sonicdragon.net/asdf.pl and got a 500 error. I assume i'm doing this wrong?
It sounds like you've got an error in the script somewhere, if the script ran OK without the section that you're trying to add it has to be in that section, so try using the backslash \ in front of any quote marks as in this example"<img src=\"mygif.gif\">You can PM me with the section of code that you're trying to use if you want to ?
Link to comment
Share on other sites

#!/usr/bin/perl -wprint "first element: ";$first=<STDIN>;chomp($first);print "second element: ";$second=<STDIN>;chomp($second);print qq(<html><head></head><body><sub>$first $second</sub></body></html>\n);
There's the code i'm playing around with. Lol, not much to look at ;)Do i need to change the /usr/bin/perl part to match the server? I'll look for perl's locating there.<edit>Yea, it's /usr/bin/perl on the server</edit>
Link to comment
Share on other sites

You're welcome, did you get it to work ?
Sorry i left you hanging. I didn't have time to test it out last night.I'm still really new to perl (and programing) and i don't have any idea for to integrate it with HTML :thumbsup: I tried uploading the .pl file and typing www.sonicdragon.net/asdf.pl and got a 500 error. I assume i'm doing this wrong?
Sonic,your Perl script needs to go whichever folder is aliased for script executions. On an Apache server it is usually in the cgi-bin directory outside of the document root. You would need to construct the URL as www.sonicdragon.net/cgi-bin/asdf.pl. Unless of course your document root for your site can run scripts, which, by the way is a security no-no.
Link to comment
Share on other sites

Hi SonicDragonBesides the obvious requirement of uploading the script in ASCII and setting the permissions, and your using the parenthesis instead of the pipes | I would say that the script is incomplete, but as I said I'm not a Perl expert by any means so I'll have to defer to somebody that is more qualified than I am, sorry :blink:

Link to comment
Share on other sites

Thanks. Ok, i've got it in the cgi-bin, and uploaded in ASCII form, and changed to pipes.Still no luck. What should the permissions be set at? Right now , the User has read and write permissions but not execute and both Group and Other have read permissions, but not write or execute. That's how it uploaded, i didn't change anything. Thanks again!

Link to comment
Share on other sites

What should the permissions be set at? Right now , the User has read and write permissions but not execute and both Group and Other have read permissions, but not write or execute.
Hi SonicDragonI would assume that the script has to set permissions to 755 which is:O=Owner G=Group O=Other O G O 7 5 5rwx r-x r-xSorry for the poor formatting of the above example, the board wouldn't allow the proper spacing.Here is a link to a site that explains File Permissions:http://www.hostingmanual.net/other/permissions.shtmlI'm sure that there are many more similar sites out there though.
Link to comment
Share on other sites

Sorry for the poor formatting of the above example, the board wouldn't allow the proper spacing.
SluggoWhen you want your spacing to not be altered - try using a "code" tag. I have found that if you have long links or other things that you don't want the forum software to change then you need to put it inside a code tag. Give it a try sometime. B)
Link to comment
Share on other sites

From iPowerWeb (my host).

One of the most common errors is "500 Internal Error". The chances are that you will experience it many times. The worst thing about it, is that it doesn't actually tells you what's wrong with the script. It only tells you that something isn't right. There are several possibilities that make up 99% of this error. Here they are: * Incorrect path to PERL. See the next question for more information * Syntax error. Check and see if you didn't accidentally deleted a command or a word that the instructions didn't tell you to. * Incorrect CHMOD command. Make sure that you chmod the file exactly as the instructions say. Most of the times it will be either 755 or 777 (not always!).
I have the correct path to perl, and i changed the permissions, so it must be my code. Thanks everyone.
Link to comment
Share on other sites

Sorry for the poor formatting of the above example, the board wouldn't allow the proper spacing.
SluggoWhen you want your spacing to not be altered - try using a "code" tag. I have found that if you have long links or other things that you don't want the forum software to change then you need to put it inside a code tag. Give it a try sometime. ;)
Hi TeacherOK thanks, I'll try it again with the code tags
  O     G        O  7      5        5rwx   r-x     r-x

Now lets see how it looks ?OK, I think it looks pretty good :)I should have thought to use it after seeing it in the toolbar for so long, but............

Link to comment
Share on other sites

Glad it worked for you. It's one of those things you see but never think about it until you are forced to look at options. ;) It is the best way to post some things without any changes!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...