•
•
•
•
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
![]() |
•
•
Join Date: Oct 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
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
thanks and regards
R
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;
}
R
•
•
Join Date: May 2006
Location: ★ ijug.net ★
Posts: 929
Reputation:
Rep Power: 5
Solved Threads: 66
visit perl.org, go through perl tutorials
you can not learn perl on the fly
you can not learn perl on the fly
•
•
Join Date: Oct 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 0
atleast pls tell me dii between
i know they are vector and scalar
i need what difference between vector and scalar
and the way we use those variables
my @FileNames; # my $FileName;
i need what difference between vector and scalar
and the way we use those variables
•
•
Join Date: May 2006
Location: ★ ijug.net ★
Posts: 929
Reputation:
Rep Power: 5
Solved Threads: 66
filenames is an array of scalars(files)
vector -> multiple values (i.e. array, which this one is)
scalar -> a single value.
Read the tutorials laready linked to!
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
----------------------------------------------
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
![]() |
•
•
•
•
•
•
•
•
DaniWeb Perl Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Change output in cgi script (Perl)
- CGI perl to java script (Perl)
- Perl Output Formatting (Perl)
- Download manager script needed (Existing Scripts)
- Script Installation, Server Administration (Post your Resume)
- perl script help re: scope/structure for noob (Perl)
- Perl/CGI (Checking For Data) (Computer Science and Software Design)
- help with my perl code (Perl)
- Safe Perl (Perl)
Other Threads in the Perl Forum
- Previous Thread: Process manager with perl
- Next Thread: Reading Keyboard Data Direct From Port



Linear Mode