Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re^2: How can one get the correct results of all combinations with bigger input files?

by supriyoch_2008 (Scribe)
on Apr 29, 2013 at 05:22 UTC ( #1031153=note: print w/ replies, xml ) Need Help??


in reply to Re: How can one get the correct results of all combinations with bigger input files?
in thread How can one get the correct results of all combinations with bigger input files?

Hi hdb,

As per davido's advice and your suggestions, I have written a script c.pl that takes a list of file names and calculates number of lines in each text file and finally the total number of combinations. I have observed that the number of combinations will be very large i.e. 644972544 with files s1.txt, s2.txt and s3.txt (each with 864 lines). But I have written a line to remove white space and empty lines,if any, at the end of each text file i.e $fh=~s/\s+$//g;. I am not sure whether it works or not.

Here goes the c.pl;

#!/usr/bin/perl use strict; use warnings; my $entry; my @a; do { print"\n Press 1 to enter a File or 2 to count Total Combinations: + "; $entry=<STDIN>; chomp ($entry); if ($entry==1) { print"\n\n Enter File Name to count number of LINES (.txt): "; + my $filename = <STDIN>; chomp $filename; open my $fh, "<", $filename or die "Cannot open $filename.\n"; $fh=~s/\s+$//g; # To remove white space & empty # lines after end of each text file my $count = 0; while ( <$fh> ) {$count++;} print"\n Lines in File $filename: $count\n\n"; push @a, $count; } } until ($entry==2); my $product=1; $product *= $_ foreach @a; print"\n\n Total Combinations: $product\n"; exit;

I have got the following results:

C:\Users\x\Desktop>c.pl Press 1 to enter a File or 2 to count Total Combinations: 1 Enter File Name to count number of LINES (.txt): s1.txt Lines in File s1.txt: 864 Press 1 to enter a File or 2 to count Total Combinations: 1 Enter File Name to count number of LINES (.txt): s2.txt Lines in File s2.txt: 864 Press 1 to enter a File or 2 to count Total Combinations: 1 Enter File Name to count number of LINES (.txt): s3.txt Lines in File s3.txt: 864 Press 1 to enter a File or 2 to count Total Combinations: 2 Total Combinations: 644972544 C:\Users\x\Desktop>


Comment on Re^2: How can one get the correct results of all combinations with bigger input files?
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1031153]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2014-10-01 23:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    What is your favourite meta-syntactic variable name?














    Results (41 votes), past polls