Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Hi Juerd,

You make some excellent points about PHP, (and having spent much of the last 2 years as a PHP programmer, I agree with many of your points). In particular the namespace issue is a killer (although using OO techniques you can avoid the problem to a degree). You have also made some errors in your comments.

>>> Heck, it doesn't even have anonymous functions.

Yes it does.

>>> That's another thing: how will you be rewriting that hash of coderefs? A hash of strings that are evaled at runtime?

#!/usr/bin/php -q <?php error_reporting(E_ALL); $dispatch_table = array( # create some anonymous functions 'foo' => create_function('$a', 'return "foo got $a\n";'), 'bar' => create_function('$a', 'return "bar got $a\n";'), 'baz' => create_function('$a', 'return "baz got $a\n";') ); print $dispatch_table['foo']('hello'); print $dispatch_table['bar']('hi'); print $dispatch_table['baz']('yo'); ?> # outputs foo got hello bar got hi baz got yo

>>> Also, don't think $foo = bar() || $baz does the same in PHP. In PHP, you end up with true or false. So you must write it in two separate expressions.

$baz = "DEFAULT VALUE"; function bar(){return "Assigned value";} function quux(){return false;} $foo = bar() ? bar() : $baz; print "$foo\n"; $foo = quux() ? quux : $baz; print "$foo\n"; # outputs Assigned value DEFAULT VALUE

I'm not sure if you could consider that as two separate expressions, but it seems a concise enough idiom for me.

While PHP does not have closures, I have used static variables in functions to emulate some of the behaviours I have used closures for in Perl.

Perl remains, by far, my language of choice, but I thought it would only be fair to point these things out

cheers

thinker


In reply to Re^3: Is Perl a good career move? by thinker
in thread Is Perl a good career move? by Mutant

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others examining the Monastery: (7)
    As of 2014-04-20 16:30 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (485 votes), past polls