User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Perl section within the Software Development category of DaniWeb, a massive community of 423,554 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,776 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Perl advertiser: Programming Forums
Views: 1160 | Replies: 5
Reply
Join Date: Oct 2007
Posts: 3
Reputation: ranadheer is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ranadheer ranadheer is offline Offline
Newbie Poster

New to Perl, please explain the script

  #1  
Oct 26th, 2007
hi all
i am a java devoloper need to understand a perl scrip based on a project requirement. as i dont know any thing about the Perl i am posting my script here. some body please look in to it and help me out explaing what the script does
the script follows
#!/usr/bin/perl
#
# This program is called in an Analytics/Sector directory to create
# the Deal run time analytsics files within that sector.
# The script must be called with the proper directory, sector and product as arguments.
#

use warnings;
use strict;
use POSIX qw(strftime);


#
# Test to make sure the script is called with correct arguments.
#

($#ARGV == 0) || die "ERROR: Call with one argument: Input Directory \n";

#
# Define local variables.
#

my $InputDir = $ARGV[0]; 
my $FileNamePattern = $InputDir . "/*.txt";		# Pattern to match for input files.
my @FileNames;						# 
my $FileName;						#
my $FileNameFlag;					#
my $Count;						#
my $DistribYearMonth;					#
my $Header;						# Header line of the input file.
my $Line;						# Non-header line from the input file.
my @LineArray;						# Non-header line from the input file.
my $OutLine;						# Output line.
my $DealName;						# Deal name, used to create the output directory.
my @DealNameDirs;					# List of deal name directories.
my $OutFileName;					# Output file name.
my $OutHeader;						# 
my $HeaderValue;
my @HeaderArray;
my %HeaderHash=();
my $now = strftime("%Y-%m-%d %R", localtime(time));
 
#
# Set up the output header.
#

	$OutHeader=	"LoanID" . "\t" . 
			"FICO" . "\t" . 
			"Occupancy" . "\t" .
			"Purpose" . "\t" .
			"Documentation" . "\t" .
			"SFUnit" . "\t" .
			"OrigRate" . "\t" . 
			"CurrRate" . "\t" .
			"Margin" . "\t" .
			"OrigLTV" . "\t" .
			"CombLTV" . "\t" .
			"OrigBalance" . "\t" .
			"CurrBalance" . "\t" .
			"FirstReset" . "\t" .
			"IOTerm" . "\t" .
			"PPTerm" . "\t" .
			"DTI" . "\t" .
			"LoanAge" . "\t" .
			"Lien" . "\t" .
			"PMILevel" . "\t" .
			"ZipCode" . "\t" .
			"StateBucket" . "\t" .
			"PayStatus" . "\t" .
			"PayHistory" . "\t" .
			"Term" . "\t" .
			"AmTerm" . "\t" .
			"LoanNo" . "\n";

#
# Get a list of current deal name directories.
#

@DealNameDirs = glob "*";

foreach $DealName ( @DealNameDirs ){
	chdir($DealName);
	@FileNames = glob("*.txt");
	foreach $FileName ( @FileNames ){
		$FileNameFlag = $FileName . ".flag";
		open(FlagHANDLE,">$FileNameFlag");
		close(FlagHANDLE);
	}
	@FileNames = glob("*.old");
	foreach $FileName ( @FileNames ){
		unlink($FileName);
	}
	chdir("../.");
}

#
# For each .txt file in the New data directory, process the file.
#

@FileNames = glob $FileNamePattern;

foreach $FileName ( sort alphabetically @FileNames ){
print("$FileName \n");
	open(InputHANDLE,$FileName) || die "Could not open $FileName";
	# Get and process the header information
	$Header=<InputHANDLE>;
	chop($Header);
	@HeaderArray=split(/\t/,$Header);
	$Count=0;
	foreach $HeaderValue (@HeaderArray){
		$HeaderHash{$HeaderValue}=$Count;
		$Count++;
	}

	# For each non-header line, process the data.
	while ($Line = <InputHANDLE>) {
		# Grab the deal name and distrib year month fields for this line.
		chop($Line);
		@LineArray=split(/\t/,$Line);
		$DealName=$LineArray[$HeaderHash{'Deal Name'}];
		$DistribYearMonth=$LineArray[$HeaderHash{'Distrib Year Month'}];
		# If the deal name directory does not exist, create it.
		(-d $DealName) || mkdir($DealName,0755);
		# Create the output file name.
		$OutFileName=$DealName . "/" . "DataRT" . $DistribYearMonth . ".txt";
		# If the file name flag is set, move the old run-time file and delete the flag file.
		$FileNameFlag = $OutFileName . ".flag";
		if(-e $FileNameFlag){
			unlink($FileNameFlag);
			rename($OutFileName,$OutFileName . ".old");
		}


		# If the run-time file does not exist, create it and write header line.
		if(!(-e $OutFileName)){ 
			open(OutputHANDLE,">$OutFileName");
			print OutputHANDLE "<HEAD>\n";
			print OutputHANDLE "Version\t1.2\n";
			print OutputHANDLE "Deal\t" . $DealName . "\n";
			print OutputHANDLE "As Of\t" . $DistribYearMonth . "\n";
			print OutputHANDLE "<LOG>\n";
			print OutputHANDLE "Created\tCreator\n";
			print OutputHANDLE $now . "\tPaul Check\n";
			print OutputHANDLE "</LOG>\n";
			print OutputHANDLE $OutHeader;
			print OutputHANDLE "</HEAD>\n";
			close(OutputHANDLE);
		}


		$OutLine=	$LineArray[$HeaderHash{'Numeric Loan ID'}] . "\t" . 
		$LineArray[$HeaderHash{'FICO'}] . "\t" . 
		$LineArray[$HeaderHash{'Occupancy'}] . "\t" . 
		$LineArray[$HeaderHash{'Purpose'}] . "\t" . 
		$LineArray[$HeaderHash{'Document'}] . "\t" . 
		$LineArray[$HeaderHash{'SFUnit'}] . "\t" . 
		$LineArray[$HeaderHash{'Init Coupon'}] . "\t" . 
		$LineArray[$HeaderHash{'Curr Coupon'}] . "\t" . 
		$LineArray[$HeaderHash{'Margin'}] . "\t" . 
		$LineArray[$HeaderHash{'LTV'}] . "\t" .
		$LineArray[$HeaderHash{'Comb LTV'}] . "\t" .
		$LineArray[$HeaderHash{'Orig Amt'}] . "\t" .
		$LineArray[$HeaderHash{'Balance'}] . "\t" .
		$LineArray[$HeaderHash{'Reset Month'}] . "\t" .
		$LineArray[$HeaderHash{'IO Term'}] . "\t" .
		$LineArray[$HeaderHash{'PP Term'}] . "\t" .
		$LineArray[$HeaderHash{'DTI'}] . "\t" .
		$LineArray[$HeaderHash{'Loan Age'}] . "\t" .
		$LineArray[$HeaderHash{'Lien'}] . "\t" .
		$LineArray[$HeaderHash{'PMI Level'}] . "\t" .
		$LineArray[$HeaderHash{'ZipCode'}] . "\t" .
		$LineArray[$HeaderHash{'State Bucket'}] . "\t" .
		$LineArray[$HeaderHash{'Delinq Stat'}] . "\t" .
		$LineArray[$HeaderHash{'Pay History'}] . "\t" .
		$LineArray[$HeaderHash{'Term'}] . "\t" .
		$LineArray[$HeaderHash{'Amort Term'}] . "\t" .
		$LineArray[$HeaderHash{'Loan No'}] . "\n";

		open(OutputHANDLE,">>$OutFileName");
		print OutputHANDLE $OutLine;
		close(OutputHANDLE);
	}
	close(InputHANDLE);
}
 
#
# Delete the flag files.
#

foreach $DealName ( @DealNameDirs ){
	chdir($DealName);
	@FileNames = glob("*.txt.flag");
	foreach $FileName ( @FileNames ){
		unlink($FileName);
	}
	chdir("../.");
}

#
# Subroutine to compare alphbetically, used in sorting.
#

sub alphabetically {
  my ($aa, $bb) = ($a, $b);
  $aa =~ tr/A-Z/a-z/;
  $bb =~ tr/A-Z/a-z/;
  return $aa cmp $bb;
}
thanks and regards
R
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2006
Location: ★ ijug.net ★
Posts: 929
Reputation: ithelp will become famous soon enough ithelp will become famous soon enough 
Rep Power: 5
Solved Threads: 66
ithelp ithelp is offline Offline
Posting Shark

Re: New to Perl, please explain the script

  #2  
Oct 26th, 2007
visit perl.org, go through perl tutorials
you can not learn perl on the fly
Reply With Quote  
Join Date: Oct 2007
Posts: 3
Reputation: ranadheer is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
ranadheer ranadheer is offline Offline
Newbie Poster

Re: New to Perl, please explain the script

  #3  
Oct 26th, 2007
atleast pls tell me dii between
my @FileNames;						# 
my $FileName;	
i know they are vector and scalar
i need what difference between vector and scalar
and the way we use those variables
Reply With Quote  
Join Date: May 2006
Location: ★ ijug.net ★
Posts: 929
Reputation: ithelp will become famous soon enough ithelp will become famous soon enough 
Rep Power: 5
Solved Threads: 66
ithelp ithelp is offline Offline
Posting Shark

Re: New to Perl, please explain the script

  #4  
Oct 26th, 2007
filenames is an array of scalars(files)
Reply With Quote  
Join Date: Feb 2006
Posts: 1,454
Reputation: masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice 
Rep Power: 9
Solved Threads: 129
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Virtuoso

Re: New to Perl, please explain the script

  #5  
Oct 26th, 2007
vector -> multiple values (i.e. array, which this one is)
scalar -> a single value.

Read the tutorials laready linked to!
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Join Date: Mar 2006
Posts: 618
Reputation: KevinADC is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 33
KevinADC's Avatar
KevinADC KevinADC is offline Offline
Practically a Master Poster

Re: New to Perl, please explain the script

  #6  
Oct 26th, 2007
It's a poorly written perl script. You would be better off starting from scratch.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Perl Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Perl Forum

All times are GMT -4. The time now is 6:19 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC