LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-14-2014, 02:25 AM   #1
rajinirajas88
LQ Newbie
 
Registered: Aug 2014
Posts: 1

Rep: Reputation: Disabled
Use of uninitialized value in split at ..... line 83


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.

Last edited by TobiSGD; 08-25-2014 at 05:42 AM. Reason: Moderator: added code-tags
 
Old 08-25-2014, 05:44 AM   #2
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Moved: This thread is more suitable in <Programming> and has been moved accordingly to help your thread/question get the exposure it deserves.

I also added code-tags to your post to preserve the formatting of the code. Please make use of them in th future when posting code or output.
 
Old 08-25-2014, 09:06 AM   #3
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,006

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
So what do you not understand as far as the errors are concerned?

I see you have the warning flag on ... I would suggest also adding:
Code:
use strict;
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl: Why do I get an error: 'use of uninitialized value in split' ? vjx242 Programming 4 04-22-2011 12:06 PM
[SOLVED] bash: Split a text file into an array? (NOT line-by-line) DJCharlie Programming 9 09-19-2010 09:22 PM
[bash] Read file line by line and split on whitespace tskuzzy Programming 4 07-06-2009 03:24 PM
help with c program to read each line from text file, split line , process and output gkoumantaris Programming 12 07-01-2008 12:38 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration