473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Running script on Unix. Created on DOS.

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
Apr 20 '07 #1
3 4543
ghostdog74
511 Expert 256MB
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.
Apr 20 '07 #2
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);
Apr 20 '07 #3
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 :)
Apr 20 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Sticks | last post by:
ok... im not quite sure how to describe my problem. i have a php script that runs through my entire php site and writes the resulting output to html files. this is necessary as the nature of the...
3
by: dpackwood | last post by:
Hello, I have two different scripts that do pretty much the same thing. The main perl script is on Windows. It runs and in the middle of it, it then calls out another perl script that then...
5
by: shinma | last post by:
Have anyone tried to code C# in a Unix box running solaris ?? Does it working fine ? or any issue you've found ?
0
by: joeted | last post by:
Hi, I am using system.diagnostic.process with the intention of running a program to communicate with a unix box: The program is "PuTTY", running from a batch script. I know it works because...
17
by: Csaba Gabor | last post by:
Is there a way to determine the path to the php executable (as opposed to the script. In other words, I am looking for the path to php.exe or php-win.exe) that is currently running (ie. how was...
4
by: kriz4321 | last post by:
I just started to learn CGI as I have some Basic knowledge in perl. Iam Just trying to run a simple Hello world program and i face some problems let me know ifthe procedure I followed is correct. ...
2
by: jonathan184 | last post by:
Hi basically what i want this script to do is In a particular dir there are alot of files from today back to 1999 or earlier. So I am trying to have the script search this dir and sort the files...
4
by: jonathan184 | last post by:
Hi I have a perl script, basically what it is suppose to do is check a folder with files. Now the files are checked using a timestamp with the command ls -l so the timestamp in this format is...
0
by: =?Utf-8?B?QW5vbnltb3Vz?= | last post by:
I just posted this in microsoft.public.inetserver.iis but thought this might be a better place for it. I have the following ASP page that simply executes a DIR command on a UNC path and displays...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.