Connecting Tech Pros Worldwide Help | Site Map

Running script on Unix. Created on DOS.

Newbie
 
Join Date: Feb 2007
Posts: 25
#1: Apr 20 '07
Hi
please anybody can help me again !!!

I created a code in perl(which parse my current file) but using dos evniornment , now want to run same code made in perl but in Unix
do i have to change any coding ??

I can put the code if somebody can help me plzz
Expert
 
Join Date: Apr 2006
Posts: 512
#2: Apr 20 '07

re: Running script on Unix. Created on DOS.


first, the modules you used should be able to run on Unix perl. Say if you have use Win32com module, then i guess you can't use it on Unix..
second, ensure that when you bring your script over to Unix, check for ^M in your file, use an editor like vi or something to view the script. If there are ^M, use dos2unix ( or code your own ) to remove all the ^M.
thirdly, take note of the #!/usr/bin/perl line on top of the script....you can include it or not, its entirely up to you. if you don't include it, then you have use the perl interpreter to run the script.
i think that's about it.
Newbie
 
Join Date: Feb 2007
Posts: 25
#3: Apr 20 '07

re: Running script on Unix. Created on DOS.


Quote:

Originally Posted by ghostdog74

first, the modules you used should be able to run on Unix perl. Say if you have use Win32com module, then i guess you can't use it on Unix..
second, ensure that when you bring your script over to Unix, check for ^M in your file, use an editor like vi or something to view the script. If there are ^M, use dos2unix ( or code your own ) to remove all the ^M.
thirdly, take note of the #!/usr/bin/perl line on top of the script....you can include it or not, its entirely up to you. if you don't include it, then you have use the perl interpreter to run the script.
i think that's about it.

I found dos2unix,but I do not know how to properly implement it
my code is all fallows ... i do have ^M, plz help me

# Declare the subroutines^M
sub trim($);^M
sub ltrim($);^M
sub rtrim($);^M
^M
# Perl trim function to remove whitespace from the start and end of the string^M
sub trim($)^M
{^M
my $string = shift;^M
$string =~ s/^\s+//;^M
$string =~ s/\s+$//;^M
return $string;^M
}^M
# Left trim function to remove leading whitespace^M
sub ltrim($)^M
{^M
my $string = shift;^M
$string =~ s/^\s+//;^M
return $string;^M
}^M
# Right trim function to remove trailing whitespace^M
sub rtrim($)^M
{^M
"woc1200_parser1.pl" [Incomplete last line] 108 lines, 3089 characters
# Declare the subroutines^M
sub trim($);^M
sub ltrim($);^M
sub rtrim($);^M
^M
# Perl trim function to remove whitespace from the start and end of the string^M
sub trim($)^M
{^M
my $string = shift;^M
$string =~ s/^\s+//;^M
$string =~ s/\s+$//;^M
return $string;^M
}^M
# Left trim function to remove leading whitespace^M
sub ltrim($)^M
{^M
my $string = shift;^M
$string =~ s/^\s+//;^M
return $string;^M
}^M
# Right trim function to remove trailing whitespace^M
sub rtrim($)^M
{^M
my $string = shift;^M
$string =~ s/\s+$//;^M
return $string;^M
} ^M
$variable_passed = $ARGV[0];^M
$FilePath = "E:/shru/WOC1200/";^M
$FileName = $variable_passed;^M
$FullName = "$FilePath$FileName";^M
^M
open (WOC1200, "<$FilePath$FileName") || die "couldn't open the file $FilePath$FileName";^M
open (OutPutFile, ">E:/shru/WOC1200/WOC1200.txt");^M
^M
print "Parsing file $FilePath$FileName ... $Timestamp";^M
# dECLARE THE SUBROUTINES

sub trim($);^M
sub ltrim($);^M
sub rtrim($);^M
^M
# Perl trim function to remove whitespace from the start and end of the string^M
sub trim($)^M
{^M
my $string = shift;^M
$string =~ s/^\s+//;^M
$string =~ s/\s+$//;^M
return $string;^M
}^M
# Left trim function to remove leading whitespace^M
sub ltrim($)^M
{^M
my $string = shift;^M
$string =~ s/^\s+//;^M
return $string;^M
}^M
# Right trim function to remove trailing whitespace^M
sub rtrim($)^M
{^M
my $string = shift;^M
$string =~ s/\s+$//;^M
return $string;^M
} ^M
$variable_passed = $ARGV[0];^M
$FilePath = "E:/shru/WOC1200/";^M
$FileName = $variable_passed;^M
$FullName = "$FilePath$FileName";^M
^M
open (WOC1200, "<$FilePath$FileName") || die "couldn't open the file $FilePat
h$FileName";^M
open (OutPutFile, ">E:/shru/WOC1200/WOC1200.txt");^M
^M
print "Parsing file $FilePath$FileName ... $Timestamp";^M
^M
$Delimiter = "|";^M
^M
$ReportDate = "";^M
$AccStatus = "";^M
$AccStatus_Des=""; ^M
$PathCode = "";^M
$WORiskLvl = "";^M
$CurrencyCD = "";^M
^M
$Ban = "";^M
$EAS = "";^M
$Name = "";^M
$Balance = "";^M
$CRCL = "";^M
$LastAct = "";^M
$LastDT = "";^M
$AssColl = "";^M
$CollAge = "";^M
$AssDT = "";^M
$Handled = "";^M
$StatusDT = "";^M
^M
^M
while ($record = <WOC1200>) {^M
$record =~ s/[\r\n]+/ /g; # Remove CR and/or LF and
replace with space ^M
if (substr($record,40,12) eq "Report Date:"){^M
$ReportDate = substr($record,53,10);^M
}^M
if (substr($record,1,16) eq "Account Status :"){^M
$AccStatus = substr($record,18,1);^M
$AccStatus_Des = substr($record,24,23);^M
} ^M
if (substr($record,1,16) eq "Path Code :"){^M
$PathCode = substr($record,18,3);^M
}^M
if (substr($record,1,19) eq "Write-off risk lvl:"){^M
$WORiskLvl = substr($record,21,2);^M
}^M
if (substr($record,1,16) eq "Currency Code :"){^M
$CurrencyCD = substr($record,18,3);^M
}^M
if (int(substr($record,1,9)) > int(0)){^M
$balance=trim(substr($record,50,15));^M
$balance=~ tr/,//d; ^M
^M
print OutPutFile trim(substr($record,1,9)); # AS BAN,^M
print OutPutFile $Delimiter;^M
print OutPutFile trim($AccStatus); # As Account Sta
tus,^M
print OutPutFile $Delimiter;^M
print OutPutFile trim($PathCode); # As Path Code,^
M
print OutPutFile $Delimiter;^M
print OutPutFile trim($WORiskLvl); # As Status Leve
l,^M
print OutPutFile $Delimiter;^M
print OutPutFile trim(substr($record,67,5)); # as Curr_CR_CL,
^M
print OutPutFile $Delimiter;^M
print OutPutFile trim(substr($record,12,9)); # as EAS,^M
print OutPutFile $Delimiter;^M
print OutPutFile trim(substr($record,74,10)); # as Last_Actvy,
^M
print OutPutFile $Delimiter;^M
print OutPutFile trim(substr($record,86,10)); # as Last_Actvy_
DT,^M
print OutPutFile $Delimiter;^M
print OutPutFile $balance; # as balance,^M
#print OutPutFile trim(substr($record,50,15)); # as Balance,^M
print OutPutFile $Delimiter;^M
print OutPutFile trim(substr($record,140,10)); # as STATUS_DT ,
^M
print OutPutFile "\n";^M
}^M
}^M
^M
close(WOC1200);^M
close(OutPutFile);
close(OutPutFile);
Newbie
 
Join Date: Feb 2007
Posts: 25
#4: Apr 20 '07

re: Running script on Unix. Created on DOS.


Quote:

Originally Posted by ghostdog74

first, the modules you used should be able to run on Unix perl. Say if you have use Win32com module, then i guess you can't use it on Unix..
second, ensure that when you bring your script over to Unix, check for ^M in your file, use an editor like vi or something to view the script. If there are ^M, use dos2unix ( or code your own ) to remove all the ^M.
thirdly, take note of the #!/usr/bin/perl line on top of the script....you can include it or not, its entirely up to you. if you don't include it, then you have use the perl interpreter to run the script.
i think that's about it.



its working thanks a lot :)
Reply