CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
How to give input files as loop inside perl script?

 



lecria
New User

Jul 26, 2012, 9:55 AM

Post #1 of 3 (1056 views)
How to give input files as loop inside perl script? Can't Post

I am using below script to compare two files UEDP35.txt and BB_UEDP35.txt. This script work well if i give inputs manually. Now i need something more. anyone please help.

Inside one folder i have n numbers of files same like UEDP35.txt. for eg: UEDP1.txt,UEDP2.txt,UEDP3.txt... Same like another file BB_UEDP35.txt for eg: BB_UEDP1.txt,BB_UEDP2.txt,BB_UEDP3.txt... here UEDP is common is both files name. If this UEDP are same, then i want to give those two files as inputs. If any different occur while comparing then that has to export into another new file. This has to be done as loop.

use warnings;

use strict;

open AIN, "<UEDP35.txt ";

open BIN, "<BB_UEDP35.csv";

my %seen;

while (<ain>) {

my $v = (split(/,/))[0];

$seen{$v}++;

}

while (<bin>) {

my $v=(split)[0];

print "$vn" if not $seen{substr($v, 0, 5)};

}

close AIN;

close BIN;

(This post was edited by lecria on Jul 26, 2012, 9:57 AM)


wickedxter
User

Jul 26, 2012, 6:29 PM

Post #2 of 3 (1034 views)
Re: [lecria] How to give input files as loop inside perl script? [In reply to] Can't Post

One thing how big are the files? if they are small enough you can load them in to memory and check one against the other at the same time. This is a shot in the dark as I dont know what kinda data are in the files...


Code
use warnings; 

use strict;

open my $AIN, "<",UEDP35.txt ";

open my $BIN, "<",BB_UEDP35.csv";

#my %seen;

while (<$AIN>) {

my $v = (split(/,/))[0];
#$seen{$v}++;

for my $file (<$BIN>){
my $vv = (split(/,/,$file))[0];

print "$vv" if $vv ne $v;
}

}

close $AIN;

close $BIN;



itsbaskar
Novice

Jul 31, 2012, 8:45 PM

Post #3 of 3 (961 views)
Re: [lecria] How to give input files as loop inside perl script? [In reply to] Can't Post

If maximum number of UDEPX.txt file is constant and known. Use the below logic.


Code
use warnings; 
use strict;

my $filecount=2;
my $ainput;
my $binput;
my $cinput;

for(my $i=1; $i<=$filecount; $i++)
{
$ainput="UEDP".$i .".txt";
$binput="BB_UEDP". $i .".csv";
$cinput="COMPAREFAILED_UEDP".$i."txt";

print "\nComparing files $ainput vs $binput";


# Compare logic. Give the input files as $ainput and binput.

# if compare logic failed. write to the file $cinput


}


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives