Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

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

by Aristotle (Chancellor)
on Aug 01, 2006 at 09:25 UTC ( #564952=note: print w/ replies, xml ) Need Help??


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
Re^3: Secret Perl Operators: the boolean list squash operator, x!!
by ioannis (Vicar) 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.)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (8)
As of 2015-07-03 03:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (48 votes), past polls