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

Re: Re: grepping

by Anonymous Monk
on Mar 25, 2001 at 11:15 UTC ( #66979=note: print w/replies, xml ) Need Help??


in reply to Re: grepping
in thread grepping

Okay, question...@data has three variables $id, $name, $ref and @data2 has 5 variables $id, $name, $ref, $type, $owner.

{ my %data; undef @data{@data}; foreach ( @data2 ) { print "This $_ was not found.\n" if not exists $data{$_} } }

This code is matching all 5 variables in @data2 to all 3 variables in @data, thus returning every row in @data2. For a test I took out all but 1 variable from each row in each array and it returned the results I needed. How can I use this code to handle multiple variables or values? And what if I wanted to lookup $name instead of $id.

Thanks!

Replies are listed 'Best First'.
Re: Re: Re: grepping
by dws (Chancellor) on Mar 25, 2001 at 11:21 UTC
    I think you misundertand the relationship between variables and arrays. Arrays hold values; they do not hold variables.

    Consider:

    my $id = 47; my @data = ( $id );
    @data now holds the value 47, and knows nothing whatsoever about where that value came from.

    The script you've asked for (and gotten) mere tells which values appear in one array and not the other.

      At 1:30am they seem the same to me, but I do know the difference. I will be more clear in my future attempts to get help. Nice example, but it still doesn't answer my last question. And in my original post, I specifically asked which ids are in @data2 and not in @data.

      I just need a little more help in understanding how can I do lookups on any value I want instead of every value or just the first value. Please don't think I'm being scarcastic, I'm very frustrated in trying to learn about hashes and arrays. :) Smile on those who read the docs, Perl Cookbook, The Complete Reference to Perl, and even Perl DBI. Yes, I own all three and I'm trying very hard to learn this...phew. Thanks.
        Sorry. I didn't answer your last question because I thought that the first part was based on a flawed premise, and the second part made no sense. It seemed to me that the best response was to point out the misunderstanding, rather than guess at what you might have meant.

        Please restate the question.

        (This is also a good reason to sign up here rather than posting anonymously. Some of this can be hashed out in the Chatterbox.)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2021-01-21 17:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?