I think you've got the meaning right, you're just mistaken about the syntax of && and //.

The correct translation of the if() statement, using your $line variable would be

if ($line =~ /a/i && $line =~ /e/i && $line =~ /i/i && $line =~ /o/i +&& $line =~ /u/i) {

Where you're going wrong is that && does not combine matches into a single match, it just does a logical AND of the results of the matches.

And any // match without a preceding $variable =~ statement matches on $_, the "implicit"/"default"/"this" variable.

So your original translation boils down to *) - see update 2

if ($line =~ /a/i && $_ =~ /e/i && $_ =~ /i/i && $_ =~ /o/i && $_ =~ +/u/i) {

update: personally, I find the PP book's version much easier on the eyes, and it's definitely more readable once you're used to seeing // matches without explicit $variable =~ parts, but I agree it crams a lot of meaning into a very short line.

The Camel book tends to be like that: it favours idiom over explicitness. IMHO the 3rd edition is a little gentler in this regard, especially in the beginning of the book.

update 2: Sidhekin pointed out that your line actually does something else. Here is your line:

$line =~ (/a/i && /e/i && /i/i && /o/i && /u/i)
Note that you're trying to use the result of (/a/i && /e/i && /i/i && /o/i && /u/i) (which will probably 1 or undef) as a match on $line.


In reply to Re: Long Versions by Joost
in thread Long Versions by BoulderBum

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.