+ Reply to Thread
Results 1 to 5 of 5

Thread: Need help translating 2 lines of Perl code to PHP

  1. #1
    kha tung
    Guest

    Need help translating 2 lines of Perl code to PHP

    It has been a while since I worked with Perl and can't really grasp it. I know how to convert the second line, but I put it there to make it easier to understand.




    php Code:

    my @chars = map {chr $_} (0x20 ... 0x7e);
    $text = $chars[int(rand(@chars))];
    $text =~ s/[<>!&]/./g;

    Any help or pointers appreciated.



    Thanks,
    More Information:
    1. What I'm trying to say is that sometimes programs need to be written in PERL and other times in PHP or ASP for that matter
    2. Perl code which examines lines in a text file, and if the line contains a GenBank ACCESSION, prints out that GenBank ACCESSION
    3. code, perl, java, php, html, visual, xml, basic, delphi, python, project, comment, lines, source, programming, development, count, software, report, c
    4. After howdy you could add <br><br> to produce two lines (standard html code), and then copy in any php script you find on the net, instantly giving your page the
    5. I would prefer Perl as PHP will require a great deal more code to achieve the processing required once I have the email data, but if necessary I can live with PHP or translate the script into Perl
    6. Great, exactly what I was looking for… helped me a lot when digging out perl code and need to extend it

    More:


  2. #2
    nogino
    Guest

    My Perl is kind of rusty, but that's some of the most convoluted rubbish I've seen for generating one random character between space and null.



    Let's go throught that - the first line creates a map, basically an array of characters running from space (0x20/32 DEC) to ~ (0x7E/126)... the next line chooses ONE random character from that set, converts it to an integer to use it as an index of that original array, returning that character... WTF?



    $text=chr(rand(32,126));



    Should be the equivalent of those first two lines. As perl, it should be:



    $text=chr(rand(32..126));



    I'm not sure why the blue blazes the original code is so convoluted... much less why you'd need so complex a regexp on a single character.
    More Information:
    1. I guess this tutorial is not for php beginners (don't know why your try to translate php code to perl)
    2. that is not blank are all depending on the highlight data, and therefore are not very flexible — for example the C Style indenter can not be used with perl or php code
    3. of source code with the following tags: <code> , <blockcode> , <c> , <cpp> , <drupal5> , <drupal6> , <java> , <js> , <perl> , <php> , <python> , <ruby> , <sql>
    4. I've seen more HTML and program code inlined together in PHP then I've ever seen in Perl
    5. Once you have what you want and need to port to a server that may only take Perl or PHP, then translating to a new language will not be nearly so hard as you may imagine
    6. Have you ever needed to do an auto-increment on a letter in Javascript? It's built into PHP and Perl ($a = 'A'; $a++; # $a is now 'B'), but I recently found that
    7. Translate Asp Code To Php; Translate Perl Into PHP; PHP 4

  3. #3
    ducbeo1993
    Guest

    Thank you.



    I tried:



    rand(0x20,0x7e)



    but its giving me numbers. Whats the point of the regular expression if the results are numbers?



    Thanks,
    More Information:
    1. </html> change to Code: <html> <?php $loads_of_stuff = 1231231; ?> </html> There are 000's of lines, so some awk command or something similiar would
    2. 5 posts - 2 authors - Last post: Apr 2, 2008I need read into Perl/PHP variables email that has been forwarded to the module using the cPanel facility
    3. 9 posts - 4 authorsNeed help translating code Computing & Technology discussion
    4. Perl - Translating Foreign HTML Code Im working on this script that grabs a web page from a foreign site, searches it for specific information, and grab
    5. Hey, I need to be able to export a spreadsheet as an htm file (which I have already done) and then using perl code have it automatically e
    6. Does your company need: MODx Website Design? Perl, PHP or MySQL Programming? A LAMP Programmer (Linux, Apache, MySQL, and Perl/PHP)?
    7. PHPXref has very minimal requirements to run; just having a copy of Perl installed is all you need (and the Windows binary supplies that for you)
    8. Coded in Perl 6 - >35000 lines of tests - >10000 lines of examples - >10000 lines in the Rakudo compiler - >1600 lines in the November wiki - (figures from mid
    9. I wrote an (small) AI script for twenty questions in perl, however i need the code translated into C++ (i ahve some knowledge of C++, but not enough to write this program)

  4. #4
    happymieu87
    Guest

    rand will indeed give you numbers, that's why you have to wrap it in chr() to convert those numbers to their ASCII equivalents.



    chr(rand(0x20,0x7e))
    More Information:
    1. Hi I have a little python 2 5 code 1500 lines many comments that I need in adobe actionscript 3 As I can see there are no librarys or includes in the python script
    2. HTML to AnyCode Converter is an interesting tool for web programmers, as it lets you translate source code in HTML directly to JavaScript, ASP, PHP, JSP or Perl
    3. Please note that the Perl, PHP and Python code is all LGPL (or MIT), and any patches you send will also be LGPL (or MIT) :-)
    4. You don't need to know this in order to use this perl code
    5. Ruby and Python qualify (Perl can be beautiful, but it suffers from some of the same problems as PHP, in that much of the existing code is horrible
    6. Seems like all of the new webapps are getting written in PHP and Ruby, we need to write some good ones in Perl!
    7. This feature is particularly useful to embed existing GrADS code without the need to convert to Perl syntax

+ Reply to Thread

Similar Threads

  1. Small Flash Script problem (14 lines of code)
    I am trying to achieve a reverse countdown with flash scripting. I got up to the following code: Code: var counter = 15;...
  2. Help with a few lines of code please
    Hi all need a little help here. I have this code here: Code: if($oow->userlevel != "0"){ print"You cant search staff !"; So here in this...
  3. Translating your site into many languages
    Hi, For adsense related sites, is it a good idea to translate your site into many languages using software ? Will that increase your adsense...
  4. Translating Websites
    I am thinking about offering my website in a few languages and put them on a sub-domain. Is anyone familiar with this? I am looking to hire someone...
  5. Translating web into multiple languages
    Question for those of you with sites in multiple languages Is there worry regarding duplicate content penalty? Thanks for your input. Shannon

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Automatic Translations (Powered by Powered by Google):
Afrikaans Albanian Arabic Belarusian Bulgarian Catalan Chinese Croatian Czech Danish Dutch English Estonian Filipino Finnish French Galician German Greek Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Taiwanese Thai Turkish Ukrainian Vietnamese Welsh Yiddish