Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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

by Jenda (Abbot)
on Jul 31, 2006 at 17:20 UTC ( [id://564809]=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!!

I don't think I get it. First I thought you mean

@a = ( 1, 2 x!! exists($h{ahoj}), 3 );
but that does not autovivify anything in %h (perl 5.8.7). Could you post and example?

Replies are listed 'Best First'.
Re^3: Secret Perl Operators: the boolean list squash operator, x!!
by Aristotle (Chancellor) on Jul 31, 2006 at 17:34 UTC

    He probably means something like this:

    exists $hash{ foo } && exists $hash{ foo }{ bar } ? $hash{ foo }{ bar +} : ()

    In this case, switching to x!! will cause $hash{ foo }{ bar } to always be evaluated, which will cause $hash{ foo } to be autovivified even if the condition is false.

    Makeshifts last the longest.

      I see. Actually to prevent confusion ... even this would autovivify:

      @a = ( $hash{foo}{bar} x!! 0);
      I guess we'd need to "fix" the x operator to not evaluate the lefthand operator if the righthand one is <=0.

      Update: Never mind, i see it now ;P)

      Why would that be trouble?

      use strict; use warnings; use Data::Dumper; my $hash = { test => 1}; print Dumper($hash); print "Hello\n" x!! exists($hash->{test}); print Dumper($hash); print "One More\n" x!! exists($hash->{test2}) && exists($hash->{test2} +->{Dude}); print Dumper($hash);

      That works as expected and doesn't autovivify anything...did I miss something?


      ___________
      Eric Hodges

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2024-03-28 09:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found