http://www.perlmonks.org?node_id=564952


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

Where did the slashes go? That would assemble URIs such as http://example.net/appadminjoebobdoc rather than http://example.net/app/admin/joebob/doc.

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 = ( 'http://example.net/app' . ( !! $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.

  • Comment on Re^2: Secret Perl Operators: the boolean list squash operator, x!!
  • Download Code

Replies are listed 'Best First'.
Re^3: Secret Perl Operators: the boolean list squash operator, x!!
by ioannis (Abbot) on Aug 01, 2006 at 10:24 UTC
    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.)