473,385 Members | 1,535 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

need advice on this - hash

Hi,

I think i saw a solution of this problem on this forum but i can't find that post, so i'll ask again.
my problem is that i have a table that i converted to hash, the table looks something like this:

x => y
23 32
12 45
12 35
12 67
45 34
34 90
34 55
35 53
35 44
44 41
...
now when i try to search for #12 it returns only the #67 but not 35 and 45.
why is that, and how can i solve this problem,that, at the end of my search it returns all the matching results.

also i'm having problems with creating a loop that would find for example #12, return the result(s) for #12 and start the search again with that result(s) (example: 12=>35, 35=>44, 44=>41). and that it writes down the results of each search.

thank you ,

robert
Aug 20 '07 #1
7 1174
KevinADC
4,059 Expert 2GB
please post your existing perl code.
Aug 20 '07 #2
this is only the working version with some artefact's that were left behind. the actual code for the problem I don't have jet.

Expand|Select|Wrap|Line Numbers
  1. use warnings;
  2. use strict;
  3.  
  4. use Getopt::Long;
  5.  
  6. my $a;
  7. my $b;
  8. my $nods;
  9. my $error = "\n Use it like -i nods.txt \n";
  10. my @nods;
  11. my %nods;
  12. my @nodss;
  13. my $tax;
  14. my $taxx;
  15. my $c;
  16. my $d;
  17. GetOptions('i=s' => \$nods );
  18.  
  19. if (!$nods) {
  20.     print $error
  21. }
  22.  
  23. open(NODS, "<", $nods) || die "can't finde the $nods";
  24.  
  25. while ($a = <NODS>) {
  26.     @nods = split(/\t\|\t/, $a);
  27.     $tax=$nods[0];
  28.     $taxx = $nods[1] ;
  29.     $nods{$taxx} = $tax;
  30. }
  31.  
  32. print "enter tax:";
  33. chomp(;
  34.  
  35. ######    this is wher the main part of the program should go!!!!!
  36.  
  37. exit;
  38.  
  39.  
Aug 20 '07 #3
could this be resolved through sql. i mean it would be nice to save some memory, because the files are pretty big .

thanks
Aug 20 '07 #4
i don't know if this is realy hard question or there is no interest for answering it but, i came up with a solution for a part of my question. using code:
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. use warnings;
  4. use strict;
  5. use Getopt::Long;
  6.  
  7.  
  8. my $a;
  9. my $b;
  10. my $nods;
  11. my $error = "\n Use it like -i nods.txt -o query.txt \n";
  12. my @nods;
  13. my %nods;
  14. my @nodss;
  15. my $tax;
  16. my $taxx;
  17. my $c;
  18. my $d;
  19. my $out;
  20. my @e;
  21.  
  22. GetOptions('i=s' => \$nods, 'o=s' => \$out );
  23.                  if (!$nods || !$out) {
  24.                  print $error
  25.                  }
  26.  
  27. open(NODS, "<", $nods) || die "can't finde the $nods";
  28. open(OUT, "<", $out) || die "can't finde the";
  29. open(OUTT, ">>", $out) || die "can't finde the";
  30.  
  31.  
  32. while ($a = <NODS>) {
  33.  
  34.  
  35.  
  36.           @nods = split(/\t\|\t/, $a);
  37.           $tax=$nods[0];
  38.           $taxx = $nods[1] ;
  39.           $nods{$taxx} = $tax;
  40. }
  41.  
  42.  
  43. #this is wher the main part of the program should go!!!!!
  44.  
  45. while (open(OUT, "<", $out) || die "can't finde it"){
  46.  
  47.       while ($b = <OUT>){
  48.                 @e = split(/\n/, $b);
  49.                 }
  50. $c = $#e;
  51.  
  52. print OUTT "\n" . $nods{$e[$c]};
  53. close OUT;
  54. }
  55.  
  56. close OUTT;
  57.  
  58.  
  59.  
  60. close NODS;
  61.  
  62.  
  63. exit;
  64.  
  65.  
this code works with a big bug in it, it does what i want but it repeats a result couple of times before it changes a search. it is like, the opening and closing a file is to slow for the 'while' loop.
to test the program you can save this text as file that goes into the -i

32 | 23 |
45 | 12 |
35 | 12 |
67 | 12 |
34 | 45 |
90 | 34 |
55 | 34 |
53 | 35 |
44 | 35 |
41 | 44 |

watch for the format (##^t|^t##^t|^t)

and # 45 in file that goes into -o.
and tun it : perl program.pl -i xxx.txt -o xxx.txt

that is it , please help, ask questions so that i can bi more specific in defining the problem

thanks

robert
Aug 21 '07 #5
ok i fixed the second part of the problem , it works through hashes, but now still the first part remains:


my problem is that i have a table that i converted to hash, the table looks something like this:

x => y
23 32
12 45
12 35
12 67
45 34
34 90
34 55
35 53
35 44
44 41
...
now when i try to search for #12 it returns only the #67 but not 35 and 45.
why is that, and how can i solve this problem,that, at the end of my search it returns all the matching results.

any ideas on how to do this, i could try to do this through mysql but i need the advice on this . shoul i do it in this way or is there a better way to do it.

robert

ps
please don't let me talk to myself
Aug 21 '07 #6
KevinADC
4,059 Expert 2GB
a simplified example of what I think you are trying to do:

Expand|Select|Wrap|Line Numbers
  1. use warnings;
  2. use strict;
  3. my %nods;
  4. while (my $line = <DATA>) {
  5.    my ($tax,$taxx) = split(/\s/, $line);
  6.    push @{$nods{$tax}},$taxx;
  7. }
  8. my $tax = 12;
  9. print "$tax = ", join(',',@{$nods{$tax}});
  10. exit;
  11.  
  12. __DATA__
  13. 23 32
  14. 12 45
  15. 12 35
  16. 12 67
  17. 45 34
  18. 34 90
  19. 34 55
  20. 35 53
  21. 35 44
  22. 44 41
  23.  
  24.  
Aug 22 '07 #7
thank you that is it, i just needed an idea. i think i have all the ingredients now to resolve my problem.

thanks

robert
Aug 27 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Randell D. | last post by:
Folks, My internet access is intermitent until I get my own connection inside the next ten days - I say this so that I can thank in advance who ever gives a few seconds to read/answer my...
3
by: ChadDiesel | last post by:
Hello everyone. I need some advice on table structure for a new project I've been given. One of our customers sends us an Excel spreadsheet each week containing their order. Currently, someone...
11
by: Bonj | last post by:
Hello I am making a syntax highlighter for T-SQL, and I am going to hardcode the words into it for speed's sake (I will probably have thought up enough new features for a new version when the next...
1
by: Charles | last post by:
Hi all, I need C# code for Implementing MD5 Algorithm.. Hope all would have heard of MD5 Algorith... Does any one have the C# coding for that Algorithm.. please Send... ITs URgent..... Thanks...
24
by: kdotsky | last post by:
Hello, I am using some very large dictionaries with keys that are long strings (urls). For a large dictionary these keys start to take up a significant amount of memory. I do not need access to...
21
by: Johan Tibell | last post by:
I would be grateful if someone had a minute or two to review my hash table implementation. It's not yet commented but hopefully it's short and idiomatic enough to be readable. Some of the code...
4
by: naknak4 | last post by:
Introduction This assignment requires you to develop solutions to the given problem using several different approaches (which actually involves using three different STL containers). You will...
6
by: naknak | last post by:
Introduction This assignment requires you to develop solutions to the given problem using several different approaches (which actually involves using three different STL containers). You will...
8
by: Jim Cobban | last post by:
I am writing a program in which I need a hash table implementation of a Map. The version of g++ available for Windo$e does not yet include the TR1 support for this. It just has the original SGI...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.