http://qs321.pair.com?node_id=1127067


in reply to Tie::DBI works in one script... not the other

It seems that you want to show values (and their counts) that appear both in the database and in plain text input data. You process that data word by word, but the assignment to @intersections happens anew on each iteration. Previous assignments are lost and assignment occurs whether or not you find a match. So the final content of @intersections is that of the last word processed, and presumably, for your input data, there is no match for the last word.

I do not have an installed copy of List::Compare to hand, and the documentation doesn't say, but perhaps, even in a list context, it does an explicit return undef which would match the behaviour you see. Use Data::Dumper or similar to confirm what the data is.

Consider pushing your data to @intersections.

Replies are listed 'Best First'.
Re^2: Tie::DBI works in one script... not the other
by liamclimbguy9k (Initiate) on May 19, 2015 at 00:14 UTC
    Also, Dumper did this:
    2015 $VAR1 = '2015'; 3 $VAR1 = '3'; a $VAR1 = 'a'; against $VAR1 = 'against'; all $VAR1 = 'all'; an $VAR1 = 'an'; and $VAR1 = 'and'; angeles $VAR1 = 'angeles'; are $VAR1 = 'are'; at $VAR1 = 'at'; atlanta $VAR1 = 'atlanta'; back $VAR1 = 'back'; be $VAR1 = 'be'; been $VAR1 = 'been'; bulls $VAR1 = 'bulls'; by $VAR1 = 'by'; clippers $VAR1 = 'clippers'; coaches $VAR1 = 'coaches'; coaching $VAR1 = 'coaching'; confirmed $VAR1 = 'confirmed'; contract $VAR1 = 'contract'; deandre $VAR1 = 'deandre'; doc $VAR1 = 'doc'; end $VAR1 = 'end'; far $VAR1 = 'far'; for $VAR1 = 'for'; free $VAR1 = 'free'; from $VAR1 = 'from'; future $VAR1 = 'future'; game $VAR1 = 'game'; had $VAR1 = 'had'; have $VAR1 = 'have'; hawks $VAR1 = 'hawks'; he $VAR1 = 'he'; here $VAR1 = 'here'; his $VAR1 = 'his'; i $VAR1 = 'i'; in $VAR1 = 'in'; irving $VAR1 = 'irving'; is $VAR1 = 'is'; james $VAR1 = 'james'; johnson $VAR1 = 'johnson'; jordan $VAR1 = 'jordan'; kevin $VAR1 = 'kevin'; kyrie $VAR1 = 'kyrie'; left $VAR1 = 'left'; los $VAR1 = 'los'; loves $VAR1 = 'loves'; making $VAR1 = 'making'; mcmenamin $VAR1 = 'mcmenamin'; mod $VAR1 = 'mod'; nba $VAR1 = 'nba'; now $VAR1 = 'now'; of $VAR1 = 'of'; on $VAR1 = 'on'; out $VAR1 = 'out'; play $VAR1 = 'play'; playoffs $VAR1 = 'playoffs'; points $VAR1 = 'points'; post $VAR1 = 'post'; reminder $VAR1 = 'reminder'; rivers $VAR1 = 'rivers'; rockets $VAR1 = 'rockets'; rules $VAR1 = 'rules'; says $VAR1 = 'says'; season $VAR1 = 'season'; series $VAR1 = 'series'; so $VAR1 = 'so'; take $VAR1 = 'take'; that $VAR1 = 'that'; the $VAR1 = 'the'; their $VAR1 = 'their'; they $VAR1 = 'they'; this $VAR1 = 'this'; throws $VAR1 = 'throws'; to $VAR1 = 'to'; today $VAR1 = 'today'; tony $VAR1 = 'tony'; two $VAR1 = 'two'; votes $VAR1 = 'votes'; wall $VAR1 = 'wall'; warriors $VAR1 = 'warriors'; washington $VAR1 = 'washington'; what $VAR1 = 'what'; will $VAR1 = 'will'; winning $VAR1 = 'winning'; with $VAR1 = 'with'; year $VAR1 = 'year';
    I don't understand how those values are undefined...
      None of the code you've posted so far uses Dumper, so seeing all this output from Dumper doesn't help much, since we can't tell what's being Dumped.

      If you haven't tried using the perl debugger on this yet (putting perl -d at the start of the command line when you run your script), that's probably what you should do next. Set a break point at the line that causes the error, so that the debugger stops and prompts for input from you when it reaches (but has not yet tried to execute) that line.

      When you reach the breakpoint, look at the value of $intersection, and confirm whether or not your hash has a matching key. (According to the error message, it doesn't). Then figure out why $intersection has the value that you see, and/or why the hash doesn't have that as a key.

Re^2: Tie::DBI works in one script... not the other
by liamclimbguy9k (Initiate) on May 18, 2015 at 23:27 UTC

    Thanks for the reply. I updated my post. So to explain a little bit further, in my sql table, the key is the word, and the value is the number of times it appears in the rest of the titles. A count of all duplicates, basically. So my database already has a bunch of words.