sumnerdu has asked for the wisdom of the Perl Monks concerning the following question:
Hello,
This is my first stab at writing a Perl script and could use another set of eyes. My current script is below and the error message I am getting.
Basically I am trying to get all the txt files from a directory, read through each file line by line, and then separate the records into separate files. Each record is pipe delimited with 13 items in each record. Separation of the records is determined by the value of the first three characters of the 8th item in each record.
Error Messages:
Script:Use of uninitialized value $var8 in substr at test.pl line 24, <IN> li +ne 2. Use of uninitialized value $var8 in substr at test.pl line 24, <IN> li +ne 17. ksh: IN: cannot open server: Use of uninitialized value $var8 in substr at test.pl line 24, + <IN> line 3. ksh: IN: cannot open servername: Use of uninitialized value $var8 in substr at test.pl line + 24, <IN> line 4. ksh: IN: cannot open servername: Use of uninitialized value $var8 in substr at test.pl line + 24, <IN> line 5. ksh: IN: cannot open servername: Use of uninitialized value $var8 in substr at test.pl line + 24, <IN> line 6. ksh: IN: cannot open servername: Use of uninitialized value $var8 in substr at test.pl line + 24, <IN> line 7. ksh: IN: cannot open servername: Use of uninitialized value $var8 in substr at test.pl line + 24, <IN> line 8. ksh: IN: cannot open servername: Use of uninitialized value $var8 in substr at test.pl line + 24, <IN> line 9. ksh: IN: cannot open servername: Use of uninitialized value $var8 in substr at test.pl line + 24, <IN> line 10. ksh: IN: cannot open servername: Use of uninitialized value $var8 in substr at test.pl line + 24, <IN> line 11. ksh: IN: cannot open servername: Use of uninitialized value $var8 in substr at test.pl line + 24, <IN> line 12. ksh: IN: cannot open servername: Use of uninitialized value $var8 in substr at test.pl line + 24, <IN> line 19. Use of uninitialized value $var8 in substr at test.pl line 24, <IN> li +ne 20. Use of uninitialized value $var8 in substr at test.pl line 24, <IN> li +ne 21. <br><br>
Could use some assistance getting past this error. Thanks ahead of time!#!/usr/bin/perl -w @files = </myhome/incoming/*.txt>; foreach $file (@files) { print $file . "\n"; open(IN,$file) || die ("Could not open file"); open(OUT131,'>>/myhome/outgoing/data131.txt'); open(OUT186,'>>/myhome/outgoing/data186.txt'); open(OUT999,'>>/myhome/outgoing/data999.txt'); while (<IN> ne "") { my $line = IN; chomp($line); my $firstchar = substr($line,0,1); if($firstchar eq "#") { next; } my ($var1,$var2,$var3,$var4,$var5,$var6,$var7,$var8,$var9,$var10 +,$var11,$var12,$var13)=split(/\|/, $line); #variables are separated b +y commas. my $type = substr($var8,0,3); if($type eq 131) { print OUT131 $line . "\n"; } elsif($type eq 186) { print OUT186 $line . "\n"; } else { print OUT999 $line . "\n"; } } close(IN); close(OUT131); close(OUT186); close(OUT999); my $newfile='/roamdev/htdocs/RIEFID/incoming/processed/new_file.txt +'; #use File::Copy; #move($file, $newfile) or die "The move operation failed: $!"; } exit 0;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: New to Perl - Script Error
by toolic (Bishop) on Jul 21, 2011 at 16:26 UTC | |
by sumnerdu (Initiate) on Jul 21, 2011 at 17:14 UTC | |
by toolic (Bishop) on Jul 21, 2011 at 17:22 UTC |