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: Intermediate: Re: [BillKSmith] Open file command with Sort and sub function call: Edit Log



FishMonger
Veteran / Moderator

Mar 11, 2015, 10:56 AM


Views: 9901
Re: [BillKSmith] Open file command with Sort and sub function call

Sorry Bill but that's not correct. Only 1 process is writing to the file.

Here's the "corrected version" of the OP's code.

First, the contents of the input file.

Quote
Step 5 ..!
Step 3 ..!
Step 4 ..!
Step 6 ..!
Step 1 ..!
Step 7 ..!
Step 2 ..!


"Corrected" module code. I adjusted it slightly to work on Linux because my Windows box just had a HD crash.

Code
package Extraction; 

#use strict;
#use warnings;

sub ReceiveFile()
{
print "Step 1 ..! \n";
open $fOut,"| sort | perl -MExtraction -e 'Extraction::WriteFile(\'OutputFile.txt\')'";

print "Step 3 ..! \n";
open $fIn, "<Input.txt" or die("Unable to open the file"); #-Step2

while(<$fIn>)
{
print "Step 4 ..! \n";
print $fOut "$_"; #-Step3
}
print "Step 5 ..! \n";
close($fIn);

print "Step 6 ..! \n";
close($fOut);
}

sub WriteFile
{

my $out_file_name = shift;
print "Step 2 ..! \n";

print "Step 7 ..! \n";
open OUT,">$out_file_name" or die ("$! $out_file_name");

while(<STDIN>)
{
print OUT "$_";
}

close(OUT);
}

1;


Contents of output file.

Quote
Step 1 ..!
Step 2 ..!
Step 3 ..!
Step 4 ..!
Step 5 ..!
Step 6 ..!
Step 7 ..!


EDIT: Here's the console output.

Quote
./ExtractionMain.pl is used to Extract the workfiles...
Step 1 ..!
Step 3 ..!
Step 4 ..!
Step 4 ..!
Step 4 ..!
Step 4 ..!
Step 4 ..!
Step 4 ..!
Step 4 ..!
Step 5 ..!
Step 6 ..!
Step 2 ..!
Step 7 ..!



(This post was edited by FishMonger on Mar 11, 2015, 11:02 AM)


Edit Log:
Post edited by FishMonger (Veteran) on Mar 11, 2015, 10:59 AM
Post edited by FishMonger (Veteran) on Mar 11, 2015, 11:02 AM


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

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