I have a perl script that works fine on my windows XP and a vmware W2003 server... but when I install it on the customer hardware, i get the following errors.

Use of uninitialized value $setpub in substitution iterator at C:\scsinput\SaxoOTF.pl line 133.
Use of uninitialized value $setpub in substitution iterator at C:\scsinput\SaxoOTF.pl line 133.
Use of uninitialized value $target in string at C:\scsinput\SaxoOTF.pl line 143.
Use of uninitialized value $target in concatenation (.) or string at C:\scsinput\SaxoOTF.pl line 143
.
Couldn't open file OUT  at C:\scsinput\SaxoOTF.pl line 143.

The perl script basically opens a file, searches for a value and inserts a value based on an ini file that translates a 4 character code to a two-letter code and inserts it in a specific location in the file.

Works fine on my local device, works fine on a local VMWare server.. put on clients W2003 Server or XP workstation, get error messages above.

Is there some environment variable that I can set to make this run.

Complete script below:

#!c:\perl\bin
#
# SaxoOTF.pl - Saxotech Outtext Filtering on the fly 
# This script depends on SaxoOTF.ini #
# Filter through files in specified input directory
# Modify lines starting with PAGE to include the 
# 2-digit code for publication edition 
#
# Save modified file to destination folder which may
# be determined by Filename or by search string in Header
# original directory filter script from la press 
# 20090315 - cld
#
use warnings;
use File::Copy;
#
# Grab settings from ini file
#
open(INI, "SaxoOTF.ini") || die("Couldn't open file INI SaxoOTF");
@file = <INI>;
close(INI);
$i = 1;
foreach $line (@file){
   if ( $line =~ /InputFolder=(.*)/ ) {
      $input_folder = $1;
   } elsif ( $line =~ /OsSlash=(.*)/ ) {
      $slashstring = $1;
   } elsif ( $line =~ /PrintConfig=(.*)/ ) {
      $print_config = $1;
   } elsif ( $line =~ /Debug=(.*)/ ) {
      $debug = $1;
   } elsif ( $line =~ /FileString=(.*)/ ) {
      $filestring[$i] = $1;
   } elsif ( $line =~ /Header=(.*)/ ) {
      $header[$i] = $1;
   } elsif ( $line =~ /PubName=(.*)/ ) {
      $pubname[$i] = $1;
   } elsif ( $line =~ /OutputFolder=(.*)/ ) {
      $output_folder[$i] = $1;
      $i++;
   }
}
#
# Output the settings
#
if( $print_config ) {
 print "Input folder: $input_folder\n";
 print "Number of Output publications: $#filestring\n\n";
 for ($i = 1; $i <= $#filestring; $i++) {
  print "Filestring: $filestring[$i]\n";
  print "Header: $header[$i]\n";
  print "Publication Name: $pubname[$i]\n";
  print "Output folder: $output_folder[$i]\n";
  print "--------------\n";
 }
}
#
# Create filelist from source folder
#
opendir (DIR,$input_folder) || die("Could not open input directory.$!");
@filelist = sort(grep(/\.txt$/,readdir(DIR)));
closedir(DIR);
$count = @filelist;
print "Number of files to process: $count \n\n";
$tmppub = "TEMPPUBLICATIONEDITION";
#
# Loop through files   
#
foreach $file (@filelist) {
   print "Current File: $file \n";
   $getpub = substr($file, 3, 4);
   $source_path = $input_folder . $slashstring . $file;
   open(IN, "$source_path") || die("Couldn't open file IN $source_path");
   @source_file = <IN>;
   close(IN);
   $linenum = 0;
   $newfile = "";
   $newline = "";
   foreach $line (@source_file){
         $linenum++;
  $linelen = length($line);
         # Get the edition number within publication
         if( $linenum == 1 ) {
            $geted = substr($line, 8, 4);
            $geted =~ s/ /0/g;
         }
  # Search for PAGE lines to manipulate characters
         if(substr($line, 0, 4) =~ "PAGE") { 
            $spaces7 = "       ";
     $str1 = substr($line, 0, 30);
     $str2 = substr($line, 41, $linelen-41);
     $newline = $str1 . $tmppub . $spaces7 . $str2;
         }else{ 
            $newline = $line . "\n";
  }
         $newfile = $newfile . $newline;
   }
   $match_found = 0;
   for ($i = 1; $i <= $#filestring; $i++) {
      if( $geted =~ $filestring[$i] ) { 
         if( $debug ) { 
   print "Search " . $filestring[$i] . " = ED " . $geted . "\n";
   print "Output: " . $output_folder[$i] . "\n";
         }
         $match_found = 1;
  $setpub = $pubname[$i];
         $target_path = $output_folder[$i];
         $target = $target_path . $slashstring . $file;
      } 
      if( $getpub =~ $filestring[$i] ) { 
  $pub = $pubname[$i];
         $pub_target_path = $output_folder[$i];
         $pub_target = $pub_target_path . $slashstring . $file;
      } 
   }
   if( $match_found == 0 ) { 
      $setpub = $pub; 
      $target_path = $pub_target_path;
      $target = $pub_target;
   } 
   $newfile =~ s/$tmppub/$setpub/g; 
   #
   # Check for target folder, if directory doesn't exist, create it 
   #
   #mkdir($target_path,"0755");
   #opendir (DIR,$tartget_path); 
   #closedir(DIR);
   open(OUT, "+>", "$target") || die("Couldn't open file OUT $target");
   print OUT "$newfile";
   close(OUT);
   #
   # Delete the original source file from input folder 
   #
   unlink($source_path);
   print "Match found on Publication : " . $setpub . "\n";
   print "Processed Source: " . $source_path . "\n";
   print "Moved to Destination: " . $target_path . "\n";
   print "--------------\n";
}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Chnage this line:

open(OUT, "+>", "$target") || die("Couldn't open file OUT $target");

change to:

open(OUT, "+>", "$target") || die("Couldn't open file OUT $target: $!");

and see what $! reports. I suspect file paths need to be adjusted for the computer the script does not run on correctly.

it tells me "no such file or directory at saxoOTF.pl line 142.. which means that it's either not seeing the cirectory or not writing out the files on the device where running

There you go. Its a place to start. Nobody here can help with that part besides telling you to try and figure out what the problem is. Check that the directory does exist, the file does exist, etc etc etc.

This article has been dead for over six months. Start a new discussion instead.