Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: Secret Perl Operators: the boolean list squash operator, x!!

by ioannis (Abbot)
on Aug 01, 2006 at 07:39 UTC ( #564940=note: print w/replies, xml ) Need Help??

in reply to Secret Perl Operators: the boolean list squash operator, x!!

Instead of using the x operator, we could have used the the && operator. The advantage here is that it codes simpler, and the disadvantage is it has no movable parts (since it is not an array).
no strict; no warnings; my $part = '' . ($admin && $is_admin_link) . (defined $subsite && $subsite) . $mode . (defined $id && $id) . (defined $submode && $submode) ; print $part;

Replies are listed 'Best First'.
Re^2: Secret Perl Operators: the boolean list squash operator, x!!
by Aristotle (Chancellor) on Aug 01, 2006 at 09:25 UTC

    Where did the slashes go? That would assemble URIs such as rather than

    You also broke down on my ornery $is_admin_link requirements. First of all the clause is the wrong way around, it would have to be ( $is_admin_link && $admin ) – but since $is_admin_link is always 0 or 1, that would leave spurious zeroes in the output, so you need to boolify: ( !! $is_admin_link and $admin ).

    All things considered, we get this:

    my $part = ( '' . ( !! $is_admin_link && '/' . $admin ) . ( defined $subsite && '/' . $subsite ) . '/' . $mode . ( defined $id && '/' . $id ) . ( defined $submode && '/' . $submode ) );

    I definitely feel like a broken record now.

    Not to mention that all of this misses my point because it’s specific to join, and I’ve needed to pass a variable list to some function or method often enough where really needed the sub-list to be empty depending on the condition – winging it by combining && and the false evaluates to the empty string factoid wouldn’t have done me any good.

    Makeshifts last the longest.

      Indeed, the substring related to $is_admin_link should have been written to reflect both boolean states, like this:

      (($is_admin_link||'') && $admin)

      Whether this form is preferable than using the trenary operator, the issue props our individual taste.

      ( The missing slashes were already prepended on my variables -- you had no way of knowing this; which in turn reminds us of the better clarity of join(), another subject and one more issue to consider.)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://564940]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2022-07-01 10:03 GMT
Find Nodes?
    Voting Booth?
    My most frequent journeys are powered by:

    Results (98 votes). Check out past polls.