Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Re^2: question for perl book & magazine authors

by holli (Monsignor)
on Oct 19, 2005 at 21:06 UTC ( #501430=note: print w/replies, xml ) Need Help??

in reply to Re: question for perl book & magazine authors
in thread question for perl book & magazine authors

The hash trick is a nice way if the array is small enough. for huge arrays the algorhitmical/runtime trade may be worth the price to save memory.

holli, /regexed monk/

Replies are listed 'Best First'.
Re^3: question for perl book & magazine authors
by sauoq (Abbot) on Oct 19, 2005 at 21:18 UTC

    Sure... if memory is so tight that you have to choose an O(n * m) time complexity over O(n + m) then I guess you gotta do what you gotta do.

    Of course, in that case (and especially if this is a routine task) you are almost certainly going to win by throwing more RAM at the problem because the larger your dataset the more (time) you are saving with the linear algorithm.

    Update: Also note that the additional memory you need will be relative to the smaller of your two arrays. (As a possible optimization depending, of course, on your data.)

    "My two cents aren't worth a dime.";

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://501430]
[Cosmic37]: greetings earthlings please can someone improve my pathetic perl knowledge
[Cosmic37]: I have 2 files each with datetime and other data in unknown order and I want to find rows from both files matching by datetime and output them combined/ concatenated
[Corion]: Sure
[Corion]: Do you have any specific interests or general Perl knowledge?
[Cosmic37]: should I slurp? should I grep? Noble Lords I wish you good karma and beg your advice
[Corion]: Cosmic37: Ah, see perlfaq4, about How do I compute the intersection of two arrays
[Cosmic37]: I am out of practice; I use Perl for scientific programming for number crunching
[Corion]: Cosmic37: Basically, you read one file into a hash, keyed by your key, and then match the lines from the second file to that hash
[Cosmic37]: note that the two files only have datetimes which may match whereas other data per line is different format in file1 and file2 - is that really intersection?
[jedikaiti]: Hi Monks

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (8)
As of 2017-06-29 16:18 GMT
Find Nodes?
    Voting Booth?
    How many monitors do you use while coding?

    Results (672 votes). Check out past polls.