Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

using the split command

by deano (Initiate)
on Jan 26, 2012 at 22:56 UTC ( #950237=perlquestion: print w/replies, xml ) Need Help??
deano has asked for the wisdom of the Perl Monks concerning the following question:


I have file A.txt and B.txt

File A A.txt contains the following:


File B B.txt contains the following:


My task is to create a script to do the following:

1. Read contents of file A and B, load the content of the first column only into individual array.

ex. @arry={A,F};

2. compare elements of both arrays and print out the differences lines.

I need this for my work! the idea is to pull csv file from database and load it into an archive database then remove archived data from production database. I have spent hours today with no luck working on this

Your help is highly appreciated!

Thank you

newbie monk!

Replies are listed 'Best First'.
Re: using the split command
by ww (Archbishop) on Jan 27, 2012 at 04:31 UTC
    "I need this for my work!"

    Then I need your paycheck.

    Seriously, this is not code-o-matic (and even there, I think, you have to drop your nickle in the slot.)

    The Monastery exists for many reasons, but doing your work isn't one of them. OTOH, we will -- and gladly -- help you over a problem, when you show you've tried to solve it (by posting your code, your sample data -- you did well there-- and any error messages or an explicit, detailed description of how your program failed and what it was supposed to do -- good job on that part, as well.

    So really, all you need to do is:

    • Open and read A.txt
    • Do the same for B.txt
    • a. Read the FAQ on comparing arrays... or Super_Search for related threads here
      b. Read File::Compare and understand it
      c. Implement based on what you've learned
    • Hand in finished project; collect paycheck; go home and study some more.

    P.S. re your "ex" code: it's not at all what's recommended above. See On asking for help and How do I post a question effectively?... and it's not in markup, <c>...code and data should be bracketed with code tags....</c> like those.

    Fixed link for compare

Re: using the split command
by InfiniteSilence (Curate) on Jan 26, 2012 at 23:35 UTC

    Maybe my brain's just not working, but I don't see how what you are proposing to do will help you with your goal. If you are looking to take data from a production database and archive it and then subsequently remove that data from the production data there is no need to convert to CSV. Database tables should have keys. Move the data from A->B and then cache all of the keys using DBM. Confirm all data was moved to B. If true, then go ahead and iterate through all of the keys and delete them from the production database. That's if you need to do this in Perl.

    I wouldn't do this in Perl at all however. I would create a backup database or schema in my database and use SQL in a transaction to do this work.

    create table foo; create table foo (id text, name varchar(15)); insert into foo values ('a','foo'); insert into foo values ('b','foo'); insert into foo values ('c','foo'); create table backupfoo (id text, name varchar(15)); insert into backupfoo (select * from foo); delete from foo; -- you would obviously use a WHERE clause to restrict + what you are deleting >>> 3 records copied
    Now, you can just push everything from the backup table to an archive offline (example uses PostgreSQL).

    pg_dump -d YOURDATABASE -t backupfoo > mybackup.sql

    Then you can reload that data in a different database entirely.

    psql -d YOURDATABASEARCHIVE -f mybackup.sql

    You could script this or use a CPAN module to script this.

    Celebrate Intellectual Diversity

Re: using the split command
by kielstirling (Scribe) on Jan 26, 2012 at 23:32 UTC

    Post the code you have. You'll get more help that way..

    -Kiel R Stirling.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://950237]
Approved by GrandFather
[Discipulus]: my father sometimes gives the same result.. good fellow

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2018-02-21 14:02 GMT
Find Nodes?
    Voting Booth?
    When it is dark outside I am happiest to see ...

    Results (280 votes). Check out past polls.