in reply to WARNING!! Possible Brainbench spoilers (do NOT read unless you've taken and passed the cert)

a) Perl Idioms Explained - @ary = $str =~ m/(stuff)/g covers this but in essence you are assigning the return value of m// (yes /.../ == m/.../ ) to a scalar. What is the return value? See perlre but it is 1 (true) if there is a match and false (null string) if there is no match. $data *is not altered* - it was never set to 'Hello World' due to precedence ie the expression parses as $data = ( 'string' =~ m/stuff/ );

b) BEGIN executes at the begining ie compile time before CHECK, INIT and of course END. These four block types run in this order:

Congrats on the payrise. Who says these sorts of tests are pointless!

cheers

tachyon

  • Comment on Re: WARNING!! Possible Brainbench spoilers (do NOT read unless you've taken and passed the cert)
  • Download Code

Replies are listed 'Best First'.
Re^2: WARNING!! Possible Brainbench spoilers (do NOT read unless you've taken and passed the cert)
by dragonchild (Archbishop) on Jul 02, 2004 at 11:49 UTC
    That is one of the goofiest context-things I've ever seen. Must mean why if you want the number of matches, you need to do
    my $data = () = "Hello World" =~ /(.*) (.*)/;

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

    I shouldn't have to say this, but any code, unless otherwise stated, is untested

      Perhaps it is because of the difficulty in defining matches? For example I would call this example one match that *returns* a two element array ( $1, $2 ). I might well expect it to return 1, you evidently expect 2. I do agree that it is non intuitive.

      cheers

      tachyon