in reply to Trying to get fancy...

*blink* *blinkblink*

Wow. That takes my vote for most obfuscated-but-didn't-mean-to code of the day.

First, a rewrite of the code, so we can start to see what's going on:

$listA[0] = [qw(1 foo bar)]; $listB[0] = [qw(1 bar baz)]; print "First record from \@listA: $listA[0][0]\n"; @listToExpire = grep { } @listB;
The {} say that you need to do some stuff on each element of @listB. However, your code is of the form grep ( @listB ); Are you sure this is what you want?

Update: Try the following:

my @listToExpire = grep { my $a = $_; (grep /$a/, @listA) ? () : ($a); + } @listB;
Interestingly enough, you can substitute map for the grep. Of course, I wrote it initially with map, cause that's how I think. TMTOWTDI.

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Replies are listed 'Best First'.
Re: Re: Trying to get fancy...
by Purdy (Hermit) on Nov 28, 2001 at 20:36 UTC
    Yep - for each element in @listB, I want to pry out the first element, assign it to $b and then do another nested grep on all elements of @listA and see if $b is in there. If it isn't, then I want it assigned to the overall @listToExpire array.

    I rewrote the line to use the { }'s:

    @listToExpire = grep { $b = (@{$_})[0] && grep { $a = (@{$_})[0] && $b != $a } @listA } @listB;

    Still the same result:
    Use of uninitialized value in numeric ne (!=) at ./listMgr.pl line 62.
    Use of uninitialized value in numeric ne (!=) at ./listMgr.pl line 62.

    I know I could do it in a more readable foreach loop (or a lookup hash), but thought I would take on a challenge, instead. :)

    Jason

    Update: I got it to work! Thanks, dragonchild! Here's the final version:

    @listToExpire = grep { $b = (@{$_})[0]; grep { $a = (@{$_})[0]; $b != +$a } @listA } @listB;

    It was those '&&''s ... I still don't understand them outside of the typical boolean EXPR. Need to grok that & the 'and|or' stuff, too.

      Though readability may not be a high priority for you in this excercise, consider changing this:

      (@{$_})[0]

      to this

       $_->[0]
        *laugh* ... thanks. Lord help whomever adopts my code whenever that happens. Fortunately, this exercise is for a temporary utility script, but with my success, I will prolly adopt it more often. Hermmmm...

        Jason

        If I could have voted this up twice, I would have. :)