Hi friends,
I have issues with my perl script used to merging files upto 8 MB. I run this script in my linux server and got below errors
Code:
Use of uninitialized value in split at /apps/wdr/psm_hkp/script/merge_file.pl line 83.
Use of uninitialized value in split at /apps/wdr/psm_hkp/script/merge_file.pl line 90.
Use of uninitialized value in split at /apps/wdr/psm_hkp/script/merge_file.pl line 94.
Use of uninitialized value in concatenation (.) or string at /apps/wdr/psm_hkp/script/merge_file.pl line 95.
Use of uninitialized value in concatenation (.) or string at /apps/wdr/psm_hkp/script/merge_file.pl line 95.
Use of uninitialized value in concatenation (.) or string at /apps/wdr/psm_hkp/script/merge_file.pl line 111.
cat: -: Bad file descriptor
Use of uninitialized value in concatenation (.) or string at /apps/wdr/psm_hkp/script/merge_file.pl line 112.
Use of uninitialized value in concatenation (.) or string at /apps/wdr/psm_hkp/script/merge_file.pl line 111.
cat: -: Bad file descriptor
Use of uninitialized value in concatenation (.) or string at /apps/wdr/psm_hkp/script/merge_file.pl line 112.
Use of uninitialized value in concatenation (.) or string at /apps/wdr/psm_hkp/script/merge_file.pl line 111.
cat: -: Bad file descriptor
Use of uninitialized value in concatenation (.) or string at /apps/wdr/psm_hkp/script/merge_file.pl line 112.
Use of uninitialized value in concatenation (.) or string at /apps/wdr/psm_hkp/script/merge_file.pl line 114.
touch: missing file operand
Try `touch --help' for more information.
Use of uninitialized value in concatenation (.) or string at /apps/wdr/psm_hkp/script/merge_file.pl line 120.
read error onstdin: Bad file descriptor
Use of uninitialized value in concatenation (.) or string at /apps/wdr/psm_hkp/script/merge_file.pl line 120.
read error onstdin: Bad file descriptor
Use of uninitialized value in concatenation (.) or string at /apps/wdr/psm_hkp/script/merge_file.pl line 120.
read error onstdin: Bad file descriptor
mv: cannot stat `*.Z': No such file or directory
------------------------------------------------
my script is below - script name : merge_file.pl
------------------------------------------------
Code:
#!/usr/bin/perl -w
#!/usr/local/bin/perl -w
my $data_dir="/apps/wdr/MNP/prod/data";
my $archive_dir="/apps/wdr/data/archive_data/mnpcis";
my $log_dir="/apps/wdr/psm_hkp/log";
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
my $ymd = sprintf("%04d%02d%02d",$year+1900,$mon+1,$mday);
my $log_file=$log_dir."/MNP_CAT_".$ymd.".log";
my $REPORTING_ONLY=0; # Flag to just simulate the CAT. Will not cat or compress
the files
open(LOG,">>$log_file") || die "$!";
chdir($data_dir) or printf LOG "Could not change to data directory\n";
if (-e "stop_mnp_cat.txt")
{
printf LOG ("CONCAT will not progress due to presence of stop_mnp_cat.tx
t in data folder\n");
}
else
{
my $file_pattern="MNP_RAW_*.txt";
@arr=`ls -l $file_pattern`;
foreach $a (@arr)
{
chomp($a);
@var=split(/ +/,$a);
push(@size,$var[4]/ (1024 * 1024));
push(@file,$var[8]);
}
#Remove first 2 files for the stack
shift @size;
shift @size;
shift @file;
shift @file;
# Check which files can be cat to less than 4 MB
$max_size=8;
$lenght=scalar(@size);
$T_size=0;
$start_index=0;
for ($i=0;$i<$lenght;$i++)
{
if ($size[$i]+$T_size > $max_size)
{
$T_size=$size[$i];
$j=$i-1;
merge_function($start_index,$j);
$start_index=$i;
}
else
{
$T_size=$size[$i]+$T_size;
}
}
if ($start_index != $i)
{
$j=$i-1;
merge_function($start_index,$j);
}
#######################
sub merge_function
{
local ($start,$end) = @_;
if ($start != $end)
{
## Create file name, the pattern is MNP_RAW_20100713113502_6369.txt. Create the file with proper timestamp touch -r merge_orig cde.txt
# 2 Cases (i) the file can be MNP_RAW_20100713113502_6369.txt or MNP_RAW_20100713113502_6369-6370.txt.
# Finding the first part of the new file
$start_file=$file[$start];
$end_file=$file[$end];
@arr=split(/-/,$start_file);
if (scalar(@arr) > 1)
{
$first_part_string=$arr[0];
}
else
{
@arr=split(/\./,$start_file);
$first_part_string=$arr[0];
}
@arr=split(/_/,$end_file);
$new_file=$first_part_string."-".$arr[3];
if ($REPORTING_ONLY)
{
printf LOG ("Files :\n");
for($k=$start;$k<=$end;$k++)
{
printf LOG ("$file[$k]\n");
}
printf LOG ("will be cat into $new_file\n\n");
}
else
{
## Cat the file
for($k=$start;$k<=$end;$k++)
{
`cat $file[$k] >> $new_file`;
printf LOG ("Merged $file[$k] whose size is $size[$k] MB into $new_file\n");
}
`touch -r $end_file $new_file`;
## Zip and move to archive
for($k=$start;$k<=$end;$k++)
{
#the file is created with .Z at the end
`compress $file[$k]`;
}
`mv *.Z $archive_dir/`;
$ls_new_size=`ls -al $new_file`;
@temp_size=split(/ +/,$ls_new_size);
$new_size=$temp_size[4]/ (1024 * 1024);
printf LOG ("Final size of $new_file is $new_size MB\n\n");
}
}
}
}
#printf LOG ("\n\n");
close(LOG);
-------------
Please some one help me to rectify the error.