Running script on Unix. Created on DOS.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Shrutisinha
    New Member
    • Feb 2007
    • 25

    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
    Last edited by Shrutisinha; Apr 20 '07, 01:47 PM. Reason: put signature
  • ghostdog74
    Recognized Expert Contributor
    • Apr 2006
    • 511

    #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.

    Comment

    • Shrutisinha
      New Member
      • Feb 2007
      • 25

      #3
      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_parser 1.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_passe d = $ARGV[0];^M
      $FilePath = "E:/shru/WOC1200/";^M
      $FileName = $variable_passe d;^M
      $FullName = "$FilePath$File Name";^M
      ^M
      open (WOC1200, "<$FilePath$Fil eName") || die "couldn't open the file $FilePath$FileN ame";^M
      open (OutPutFile, ">E:/shru/WOC1200/WOC1200.txt");^ M
      ^M
      print "Parsing file $FilePath$FileN ame ... $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_passe d = $ARGV[0];^M
      $FilePath = "E:/shru/WOC1200/";^M
      $FileName = $variable_passe d;^M
      $FullName = "$FilePath$File Name";^M
      ^M
      open (WOC1200, "<$FilePath$Fil eName") || die "couldn't open the file $FilePat
      h$FileName";^M
      open (OutPutFile, ">E:/shru/WOC1200/WOC1200.txt");^ M
      ^M
      print "Parsing file $FilePath$FileN ame ... $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($re cord,1,9)) > int(0)){^M
      $balance=trim(s ubstr($record,5 0,15));^M
      $balance=~ tr/,//d; ^M
      ^M
      print OutPutFile trim(substr($re cord,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($re cord,67,5)); # as Curr_CR_CL,
      ^M
      print OutPutFile $Delimiter;^M
      print OutPutFile trim(substr($re cord,12,9)); # as EAS,^M
      print OutPutFile $Delimiter;^M
      print OutPutFile trim(substr($re cord,74,10)); # as Last_Actvy,
      ^M
      print OutPutFile $Delimiter;^M
      print OutPutFile trim(substr($re cord,86,10)); # as Last_Actvy_
      DT,^M
      print OutPutFile $Delimiter;^M
      print OutPutFile $balance; # as balance,^M
      #print OutPutFile trim(substr($re cord,50,15)); # as Balance,^M
      print OutPutFile $Delimiter;^M
      print OutPutFile trim(substr($re cord,140,10)); # as STATUS_DT ,
      ^M
      print OutPutFile "\n";^M
      }^M
      }^M
      ^M
      close(WOC1200); ^M
      close(OutPutFil e);
      close(OutPutFil e);

      Comment

      • Shrutisinha
        New Member
        • Feb 2007
        • 25

        #4
        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 :)

        Comment

        Working...