Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Re: Re: Re: Re: grepping

by dws (Chancellor)
on Mar 25, 2001 at 11:37 UTC ( [id://66985]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: Re: Re: grepping
in thread grepping

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.)

Replies are listed 'Best First'.
Re: Re: Re: Re: Re: Re: grepping
by Anonymous Monk on Mar 25, 2001 at 12:36 UTC
    Actually I've got a login, but sometimes I refrain because monks will get annoyed at how many times I post a question...lol. Anyway, please tell me where you get lost in my post so I can get better at writing these situations.

    Now, let me explain in detail what's happening.

    @data is read from a file containg many rows such as:
    1,comp1,type1
    2,comp2,type2
    3,comp3,type3

    @data2 is read from a file containing many rows such as:
    1,comp1,type1,doc1,ref1
    2,comp2,type2,doc2,ref2
    3,comp3,type3,doc3,ref3
    4,comp4,type4,doc4,ref4
    5,comp5,type5,doc5,ref5

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

    it matches all five values from each line in @data2 to all 3 values in @data line by line. So basically every line in @data2 gets printed when that script is run. What I want to do is match the first value from @data2 to the first value from @data and return the results based on values in @data2 that are not in @data.

    I also want to know how I can match the second value from @data2 to the first value in @data and return the results that are not in @data.

    I hope this makes better senses. I'll keep trying if it doesn't. Thanks for all your help.
      This sounds like the kind of operations that a relational database is intended for.

      I would suggest using DBI together with DBD::CSV if you want to keep on using flatfiles. And then when you get tired of bad performance you can just use a real database instead. :-)

      I agree. You're heading in a direction that relational databases and SQL cover quite well.

      If you choose to continue on in Perl, you might get some mileage out of mapping your data rows into hashes.

      while ( <DATA2> ) { chomp; my %record; @record{qw(ID COMP TYPE DOC REF)} = split; pushd @data2, \%record; }
      will give you an array of (references) to hashes that hold records from your second data file. (You'll need to fill in some code around this, but that should be obvious.) Then, to get an array of IDs you would do something like @ids = map { $_->{'ID'} } @data2; I'll leave the queries as an exercise. You should be able to piece them together based on information given so far in this thread.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-19 11:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found