in reply to Re^2: Has anyone attempted to create a PHP to Perl converter?
in thread Has anyone attempted to create a PHP to Perl converter?

Why would you want to use sed when the Perl regexes are far far far more powerful?

If you feel limited in your command of Perl regexes, I really think that the first thing you want to do is to really start mastering the Perl regexes. Perhaps reading Mastering Regular Expressions, by Jeff Friedl. BTW, this book also shows some of the limitations of regexes, and you project will necessarily meet these limitations. I think that most people on this forum agree that you should not use regexes for parsing HTML or XML, using regexes for parsing PHP would be even worse.

Although regexes might certainly do part of the work, I doubt that you can go anywhere without using a real parser.

One final note on the English-Russian translation anecdote, I personally tried several translating software packages over the years (I was a translator before I became a CS professional) between 1988 and 1996. The results were really bad. On the first one I tried, i gave the following sentence: "Time flies like an arrow". The French translation I obtained was: "Les mouches du temps aiment une flèche", which can be translated back into English as follows: "The flies (the insect) of time love an arrow". I tried other packages at the time, the results were possibly not as funny, but not much better. A lot of improvements have been made since, but the basic problem of implicit context understanding is still there.

  • Comment on Re^3: Has anyone attempted to create a PHP to Perl converter?

Replies are listed 'Best First'.
Re^4: Has anyone attempted to create a PHP to Perl converter?
by taint (Chaplain) on Nov 13, 2013 at 20:25 UTC
    Greetings Laurent_R, and thank you for your reply.

    "Why would you want to use sed when the Perl regexes are far far far more powerful?

    If you feel limited in your command of Perl regexes, I really think that the first thing you want to do is to really start mastering the Perl regexes.

    In my humble defense; I made note of this on two occasions early in this thread.

    But yes. Agreed.

    My choice of referring to SED in this case, is because I can think further with it, because I'm more familiar with it. But assumed that I could (with greater knowledge) accomplish / achive as much with the Perl RE.

    Which is why I thought this strategy would work, the way I indicated.

    Best wishes, and thanks again for responding.

    --Chris

    #!/usr/bin/perl -Tw
    use Perl::Always or die;
    my $perl_version = (5.12.5);
    print $perl_version;

      In my humble defense; I made note of this on two occasions early in this thread.

      I fully appreciate that, and this part of my answer was solely based on your own comments on the subject, I have absolutely no personal opinion on your mastery of regexes.

      Just in case I did not explain clearly what I meant, my comment on Perl regexes was really meant to be a friendly advise to your attention with the idea that first spending a couple of weeks working on Perl regexes should probably save you more time in the longer run, on the PHP project especially, but also more generally. I sincerely hope that you did not understand it as me chastising you with something like "do your leaning work and come back once you know it", as nothing could have been further from my mindset. Again, what I said was really meant as a friendly advise, please pardon me if anything I said might have led you to think or suspect otherwise.

      I have been using sed and awk and grep, etc. for more than 20 years (although I am certainly not a sed expert the way you are, but more simply a decently trained user), and I still use these utilities quite frequently (I even maintain at my company an intranet wiki with numerous recipes using these utilities), but I have been using these much less than before in the last 5 to 7 years, because I am really convinced that Perl regexes are far more powerful and that Perl one-liners or in-line longer scripts can do (almost) everything that sed can do and much more.

      One final point: you might want to look at s2p (sed to Perl) and psed (and a2p, awk to Perl), I would think that they might help you do in Perl what you know how to do in sed and don't yet know how to do in Perl. In addition, looking at the code of these conversion utilities may give you some ideas for your own PHP to Perl project (even though this a much more ambitious project).

        Greetings, Laurent_R.

        Thank you for your greater elaboration, and kind words, Laurent_R.
        I'm afraid it is me, that should excuse myself. Indeed, I did misinterpret your meaning. It seems my skills in the Laurent_R language, need improvement. ;)
        Seriously, I'm terribly sorry for misinterpreting your intent. I hope you will not think ill of me, because of it.

        "One final point: you might want to look at s2p (sed to Perl) and psed (and a2p, awk to Perl), I would think that they might help you do in Perl what you know how to do in sed and don't yet know how to do in Perl. In addition, looking at the code of these conversion utilities may give you some ideas for your own PHP to Perl project (even though this a much more ambitious project)."
        Greatly appreciated advise. Thank you very much, Laurent_R. I look forward to spending a great deal of time with them -- soon!

        Thank you again, Laurent_R, for taking the time to respond.

        --Chris

        #!/usr/bin/perl -Tw
        use Perl::Always or die;
        my $perl_version = (5.12.5);
        print $perl_version;