473,386 Members | 1,798 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,386 software developers and data experts.

perl script help needed

hi all...
i need to write a perl program which does the following:

it connects to the database and retrieves the rows from a table, which i am able to do.

For example, the table looks like this :
Name PID CID LID
a1 0 0 10
a1 0 0 20
a1 0 1 30
a2 0 2 40
a2 1 1 50
a3 0 1 10


so, here i need to check for duplicates and the rule is as folows:

eliminate duplicate rows which has the same CID, same PID and same name.
SO in the above example, i need to eliminate either row 1 or row 2. LID is NOT an issue here, i mean it does not matter if they are same or different.

I am storing all columns in separate arrays and then trying to sort based on columns. I just have an idea but I would like to have the perfect working code.

I will be grateful if some1 could provide me with one.
Thankyou.
Regards,
Abhilash
Oct 26 '07 #1
4 1199
numberwhun
3,509 Expert Mod 2GB
hi all...
i need to write a perl program which does the following:

it connects to the database and retrieves the rows from a table, which i am able to do.

For example, the table looks like this :
Name PID CID LID
a1 0 0 10
a1 0 0 20
a1 0 1 30
a2 0 2 40
a2 1 1 50
a3 0 1 10


so, here i need to check for duplicates and the rule is as folows:

eliminate duplicate rows which has the same CID, same PID and same name.
SO in the above example, i need to eliminate either row 1 or row 2. LID is NOT an issue here, i mean it does not matter if they are same or different.

I am storing all columns in separate arrays and then trying to sort based on columns. I just have an idea but I would like to have the perfect working code.

I will be grateful if some1 could provide me with one.
Thankyou.
Regards,
Abhilash
First, Welcome to TSDN!!

As for your issue, you have not posted any code so that we can see what you have tried thus far. If you could please post the code you have been working on, enclosed in the necessary [code] [/code] tags.

I understand that you would just like someone to provide you code to do what you want, but please know that this is not a code writing service. Someone may provide you snippets, but not all of the code. Being a learning forum, you are required to do a lot of the coding for your project(s).

Regards,

Jeff
Oct 26 '07 #2
hello... sorry i did not know that..

anyways here is my code...

Expand|Select|Wrap|Line Numbers
  1. $sql="select ed.HostIndex, ed.CPUNum, ed.GenErrCode, ed.Interpretation, sm.CorePerPhys, sm.LogPerCore, sm.PhysID, sm.CoreID, hf.TotalDownTime, (hf.Deathtime-hf.Birthtime-hf.TotalDownTime) as TotalUpTime from emmaDecode_WINtable ed, SMTinfo_WINtable sm, HostLifetime_WINtable hf where ed.HostIndex = sm.HostIndex and ed.CPUNum = sm.CPUNum and ed.HostIndex = hf.HostIndex and sm.HostIndex = hf.HostIndex and ed.GenErrCode between 2048 and 4095 limit 10;";
  2.  
  3. $dbh=DBI->connect($dsn,$user,$pass);
  4. $sth=$dbh->prepare($sql);
  5. $sth->execute;
  6.  
  7. sub bubble_sort;
  8. sub swap;
  9.  
  10. my @HostIndexArray;
  11. my @CPUNumArray;
  12. my @CodeArray;
  13. my @InterpretationArray;
  14. my @CPPArray;
  15. my @LPCArray;
  16. my @PIDArray;
  17. my @CIDArray;
  18. my @DownTimeArray;
  19. my @UpTimeArray;
  20.  
  21. while(($HostIndex, $CPUNum, $Code, $Interpretation, $CPP, $LPC, $PID, $CID, $DownTime, $UpTime) = $sth->fetchrow_array())
  22. {
  23.        $numrows=$sth->rows;
  24.        push(@HostIndexArray, $HostIndex);
  25.        push(@CPUNumArray, $CPUNum);
  26.        push(@CodeArray, $Code);
  27.        push(@InterpretationArray, $Interpretation);
  28.        push(@CPPArray, $CPP);
  29.        push(@LPCArray, $LPC);
  30.        push(@PIDArray, $PID);
  31.        push(@CIDArray, $CID);
  32.        push(@DownTimeArray, $DownTime);
  33.        push(@UpTimeArray, $UpTime);
  34. }
  35.  
  36. for($a1 = 0; $a1 <= $numrows; $a1++)
  37.         {
  38.          print "$HostIndexArray[$a1] \t $CPUNumArray[$a1] \t $CodeArray[$a1] \t $InterpretationArray[$a1] \t $CPPArray[$a1] \t $LPCArray[$a1] \t $PIDArray[$a1] \t $CIDArray[$a1] \t $DownTimeArray[$a1] \t $UpTimeArray[$a1] \n";
  39.         }
  40.  
  41.  
  42. sub swap
  43. {
  44.   my($index1, $index2) = @_;
  45.  
  46.   ($HostIndexArray[$index1], $HostIndexArray[$index2]) = ($HostIndexArray[$index2], $HostIndexArray[$index1]);
  47.   ($CPUNumArray[$index1], $CPUNumArray[$index2]) = ($CPUNumArray[$index2], $CPUNumArray[$index1]);
  48.   ($CodeArray[$index1], $CodeArray[$index2]) = ($CodeArray[$index2], $CodeArray[$index1]);
  49.   ($InterpretationArray[$index1], $InterpretationArray[$index2]) = ($InterpretationArray[$index2], $InterpretationArray[$index1]);
  50.   ($CPPArray[$index1], $CPPArray[$index2]) = ($CPPArray[$index2], $CPPArray[$index1]);
  51.   ($LPCArray[$index1], $LPCArray[$index2]) = ($LPCArray[$index2], $LPCArray[$index1]);
  52.   ($PIDArray[$index1], $PIDArray[$index2]) = ($PIDArray[$index2], $PIDArray[$index1]);
  53.   ($CIDArray[$index1], $CIDArray[$index2]) = ($CIDArray[$index2], $CIDArray[$index1]);
  54.   ($DownTimeArray[$index1], $DownTimeArray[$index2]) = ($DownTimeArray[$index2], $DownTimeArray[$index1]);
  55.   ($UpTimeArray[$index1], $UpTimeArray[$index2]) = ($UpTimeArray[$index2], $UpTimeArray[$index1]);
  56. }
  57.  
  58. sub bubble_sort
  59. {
  60.       for ($i=0; $i < $numrows; ++$i)
  61.         {
  62.                 for ($j=0; $j < $numrows-$i; ++$j)
  63.                  {
  64.                         if($PIDArray[$j] > $PIDArray[$j+1])
  65.                            {
  66.                                 swap($j, $j+1);
  67.                            }
  68.                  }
  69.         }
  70. }
  71.  
  72. bubble_sort();
  73.  
  74. for($a2 = 0; $a2 <= $numrows; $a2++)
  75.         {
  76.          print "$HostIndexArray[$a2] \t $CPUNumArray[$a2] \t $CodeArray[$a2] \t $InterpretationArray[$a2] \t $CPPArray[$a2] \t $LPCArray[$a2] \t $PIDArray[$a2] \t $CIDArray[$a2] \t $DownTimeArray[$a2] \t $UpTimeArray[$a2] \n";
  77.         }
  78.  
  79.  
  80. for ($i=0; $i < $numrows ; $i++)
  81.  {
  82.     my @temparr;
  83.     print "\n \n Value of i = $i.......$PIDArray[$i]......... $CIDArray[$i]";
  84.     print "\n Value of (i+1) = ($i+1) ....... $PIDArray[$i+1]....... $CIDArray[$i+1]";
  85.     if(($PIDArray[$i] == $PIDArray[$i+1]) && ($CIDArray[$i] == $CIDArray[$i+1]))
  86.           {
  87.         print " \n Going... ";
  88.         $temparr[$i] =  0;
  89.       }
  90.     print "\n Temparr = $temparr[$i]";
  91.  }
  92.  
  93.  


Here , the I am sorting based only on the PID array, but not able to sort the PID based sorted array based on the CID array.

Somehow, I am overwriting it if I am consecutively sorting the arrays in the fol loop.

I need to remove duplicates , and so I would like to do this.

Any other better idea... please let me know.
thank you.
Regards,
Abhilash
Oct 26 '07 #3
eWish
971 Expert 512MB
Do you administer the database and can you create tables? If, so then I would recommend that you normalize tables. With the proper use of indexes, primary keys you could eliminate duplicates before they are inserted into the database.

An Introduction to Database Normalization
Oct 26 '07 #4
Hello...
No I am not administering the database.....
i have no other options but do the sorting thing... could you please help me with it??
regards,
abhilash
Oct 27 '07 #5

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

Similar topics

1
by: Robert V | last post by:
Hi all, I could use some help programming on of my Perl script to handle different submit buttons within the same form. Here is what I have so far. A user goes to a Web form and inputs some data...
6
by: Richard Trahan | last post by:
I want a js function to call a Perl script residing on a server. The Perl script will return a string, to be used by the js. Pseudo code: <script> stringvar = perlfunc_on_server(stringarg)...
0
by: Kirt Loki Dankmyer | last post by:
So, I download the latest "stable" tar for perl (5.8.7) and try to compile it on the Solaris 8 (SPARC) box that I administrate. I try all sorts of different switches, but I can't get it to compile....
3
by: Nathan Gilbert | last post by:
I am wanting to use javascript to select between different *.css files dependent on the user's browser. I am also wanting to generate the html document containing this javascript dynamically using...
5
by: Karyn Williams | last post by:
I am new to Pyton. I am trying to modify and understand a script someone else wrote. I am trying to make sense of the following code snippet. I know line 7 would be best coded with regex. I first...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
223
by: Pilcrow | last post by:
Given that UNIX, including networking, is almost entirely coded in C, how come so many things are almost impossible in ordinary C? Examples: Network and internet access, access to UNIX...
10
by: happyse27 | last post by:
Hi All, I got this apache errors(see section A1 and A2 below) when I used a html(see section b below) to activate acctman.pl(see section c below). Section D below is part of the configuration...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.