my $data = "Hello World" =~ /(.*) (.*)/;

Is two statements in one. Look at it as:

my $data = ("Hello World" =~ /(.*) (.*)/);

or more clearly. Assign the output of

"Hello World" =~ m/(.*) (.*)/);

to

my $data

The expression

"Hello World" =~ m/(.*) (.*)/;

says to "run the match (m//) operator against the fixed string "Hello World". The output of the match operator is whether it matched: 1 (yes) 0 (no). Since Hello World matches 0 or more characters, a space, followed by 0 or more characters it returns 1 and the output of that is assigned to $data hence it has a value of 1.

From "man perlop"

"In scalar context, each execution of "m//g" finds the next match, returning true if it matches, and false if there is no further match.

That one is from the man pages too. "man perlmod"

A "BEGIN" subroutine is executed as soon as possible, that is, the moment it is completely defined, even before the rest of the containing file is parsed.


In reply to Re: WARNING!! Possible Brainbench spoilers (do NOT read unless you've taken and passed the cert) by Anonymous Monk
in thread WARNING!! Possible Brainbench spoilers (do NOT read unless you've taken and passed the cert) by Anonymous Monk

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.