CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Script Error

 



sumnerdu
New User

Jul 21, 2011, 9:02 AM

Post #1 of 2 (790 views)
Script Error Can't Post

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:

Use of uninitialized value $var8 in substr at test.pl line 24, <IN> line 2.
Use of uninitialized value $var8 in substr at test.pl line 24, <IN> line 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> line 20.
Use of uninitialized value $var8 in substr at test.pl line 24, <IN> line 21.

Script:

#!/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 by 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;

Could use some assistance getting past this error. Thanks ahead of time!


kwatts59
Novice

Jul 21, 2011, 11:23 AM

Post #2 of 2 (781 views)
Re: [sumnerdu] Script Error [In reply to] Can't Post

Maybe the problem is with the line

my $line = IN;

I dont know what version of PERL you are using but I typically use

$line = $_;

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives