Hi,
Well I am getting this warning while running my script which is attached:Use of uninitialized value in concatenation (.) or string at aj.pl
in this line : print OUTFILE"$address[$k]|" as when i remove this line I don't get any warnings:
Can someone please tell me what is wrong with it:
Thanks
Aj
Here is my code:
#!/usr/bin/perl
use warnings;
use strict;
my $input = 'try_file.txt';
my $output = 'try_file_pipe.txt';
my $i=0;
my $lines="";
our(@aj1,@aj2,@aj3,@aj4,@aj5);
my @id=();
my @author= ();
my @text=();
my @address=();
open (INFILE, "$input") or die "Couldn't open $input for reading: $!\n";
open (OUTFILE, "> $output") or die "Couldn't open $output for writing: $!\n";
my @file1 =<INFILE>;
foreach $lines(@file1)
{
chomp($lines);
if($lines =~m/ID:/)
{
$lines=~s/\s+$//g;
@aj1=split(/:/,$lines);
push(@id,$aj1[1]);
}
elsif ($lines =~m/Author/)
{
$lines=~s/\s+$//g;
@aj4=split(/:/,$lines);
push(@author,$aj4[1]);
}
elsif ($lines =~m/Address/)
{
$lines=~s/\s+$//g;
@aj5=split(/:/,$lines);
push(@address,$aj5[1]);
}
elsif ($lines =~m/^\\/)
{
$i=$i+1;
}
else
{
push(@text,"$lines");
}
if ($i==1)
{
$i=0;( #no warnings 'uninitialized'; #of course when I am using this I don't get any warnings, still I am curious to know what is wrong with it.)
print OUTFILE"@id|";
my $n = scalar @author;
for($k=0;$k<$n;$k++)
{
print OUTFILE"$author[$k]|";
print OUTFILE"$address[$k]|";
}
print OUTFILE"@text";
@id=();
@text=();
@address=();
@author=();
}
}
close (INFILE);
close(OUTFILE);
exit;