473,385 Members | 1,944 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.

How to Compare two tables in perl script

Hello,

Can we compare two tables in perl? I mean How can we do it for database tables.

I would like to know the solution for below scenario in perl script.

Here are 2 tables:
Table 1
Names City
aaaaa hyd
bbbbb bang
ccccc chen
dddddd noida
eeeeeee hyd
ffffffffffff chen

Table: 2
Names Organization
aaaaa TCS
bbbbb Infosis
sssss TCS
dddddd Infosis
eeeeeee NTT
ccccc NTT


When i compare this tables: When i compare Names of two columns, the result should be like this:
Name City Organization
aaaaa hyd TCS
bbbbb bang Infosis
ccccc chen NTT
dddddd noida Infosis

I need organization details from table 2 which has same name in both table 1 and 2.

Thank you for help !
Jul 30 '15 #1
5 4704
RonB
589 Expert Mod 512MB
What have you tried?

What part of the task is giving you trouble?

What errors/warnings are you receiving?

I have a feeling that this is some sort of homework assignment, so I'll hold off providing a full solution. However, I will give you a hint.

Load one of the files into a hash to be used as a lookup table.
Jul 30 '15 #2
Hello Ron,

I am planning to do automation for macros which is in MS Access DB into Perl Scriot. There in Access DB, we used to compare IP column which is same in both tables and will retrive details whatever required. I got struck at comparing tables. I am not getting idea how to compare. Asking for help this.

Thank you
Jul 31 '15 #3
RonB
589 Expert Mod 512MB
The sql statement you need would be:
Expand|Select|Wrap|Line Numbers
  1. SELECT t1.Names, t1.City, t2.Organization FROM table1 as t1 INNER JOIN table2 as t2 ON t1.Names = t2.Names;
As a personal preference in coding style, I prefer to break long statements (greater that 80 characters) like that into multiple lines to make it more readable and maintainable.

Expand|Select|Wrap|Line Numbers
  1. SELECT t1.Names, t1.City, t2.Organization
  2. FROM table1 as t1
  3. INNER JOIN table2 as t2 ON t1.Names = t2.Names;
  4.  
Here's the actual query and it's results.
Expand|Select|Wrap|Line Numbers
  1. mysql> SELECT t1.Names, t1.City, t2.Organization
  2.     -> FROM table1 as t1
  3.     -> INNER JOIN table2 as t2 ON t1.Names = t2.Names;
  4. +---------+-------+--------------+
  5. | Names   | City  | Organization |
  6. +---------+-------+--------------+
  7. | aaaaa   | hyd   | TCS          |
  8. | bbbbb   | bang  | Infosys      |
  9. | ccccc   | chen  | NTT          |
  10. | dddddd  | noida | Infosys      |
  11. | eeeeeee | hyd   | NTT          |
  12. +---------+-------+--------------+
  13. 5 rows in set (0.04 sec)
  14.  
If you need help in using that statement in your script, then you will need to post your script.
Jul 31 '15 #4
Thank you for the reply RonB. Appreciated.

I have one more question.

I just created a script with db tables and output was moved to excel sheets.
Below are two sheets:

Sheet1:

IP address Status
x.x.x.x success
y.y.y.y No Access
z.z.z.z Retired
a.a.a.a Success

Sheet2:
IP address Status
x.x.x.x success
y.y.y.y Success
z.z.z.z NoAccess
a.a.a.a NoAccess

Now, I have to compare and update sheet1 status with sheet2. Sheet1 has oen IP with retired status and for same IP sheet2 has NoAccess. In result the retired status should not change:

The output seems to be like this:

IP address Status
x.x.x.x success
y.y.y.y Success
z.z.z.z Retired
a.a.a.a NoAccess.

If its in database, we can write update and where clause as not like.

But how to compare and update in Perl script ?

Thank you for the help !
Aug 4 '15 #5
RonB
589 Expert Mod 512MB
What have you tried?

Your question is not very clear. Please post your script and explain how it fails to do what you need. Include any errors/warnings it produces.
Aug 4 '15 #6

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

Similar topics

3
by: dpackwood | last post by:
Hello, I have two different scripts that do pretty much the same thing. The main perl script is on Windows. It runs and in the middle of it, it then calls out another perl script that then...
9
by: Martin Foster | last post by:
Hi. I would like to be able to mimic the unix tool 'uniq' within a Perl script. I have a file with entries that look like this 4 10 21 37 58 83 111 145 184 226...
3
by: PzYon | last post by:
Hey 2gether! I'm trying to execute a PERL script on the web server when the user presses a button in an ASP.NET Web Application using Visual Basic. The most obvious solution for me seemed to be...
9
by: 8anos | last post by:
Hello, I am new at the community and newbie at programming :) As you may know rapidshare provides a perl script for linux, to upload files at their servers. You can find the original scripts at...
2
by: gwigg | last post by:
Hi, am am having a problem with extracting all the data I want using a perl script the data being in a mysql database. The script works fine until row 59101 is reached in the 1st table, anyone aware...
3
by: tundal45 | last post by:
Hey Guys, I am trying to automate the process of loading data in our oracle server. As a part of that process, I am working on a perl script that loads external tables from data files. What I am...
24
by: Peter Michaux | last post by:
I have a Perl script that I want to run as a set-user-ID program. Many OSes don't allow scripts run as set-user-ID. To make this script portable, it seems I need to write a C wrapper program that...
1
by: krus | last post by:
Hi All, I am relatively new to HTML and perl scripts. I am writing a HTML page which has a form. It takes two inputs. Now I want pass these two inputs from the HTML form to the perl script. I want...
6
by: optimusprime | last post by:
Hi All, am very new to perl, I have to shell script which compares 2 files line by line and get the difference (am using sdiff command) #!/bin/bash # cmp_dir - program to compare two...
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:
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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.