Home Man
Today's Posts

BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Use of uninitialized value in join or string at arraydef.pl

perl, perl array, perl shift, shell scripts, shift, shift perl

Login to Reply

Thread Tools Search this Thread
# 1  
Old 08-30-2007
Question Use of uninitialized value in join or string at arraydef.pl

When try to execute the following script, its throwing this error:
" Use of uninitialized value in join or string at arraydef.pl line 17. "

The script is [ i am pasting with line numbers]:

1 #!/usr/bin/perl
3 use strict;
5 my @a = ( 1...10 );
7 print " Original array : @a \n ";
9 #DELETE Function
11 my $size=@a;
13 print "size of arry before deleting 1st element : $size \n ";
16 delete($a[0]); #Deleting 1st element
17 print " Array after deleting first element : @a \n ";
18 $size=@a;
19 print "size of arry after deleting 1st element : $size \n "; # size dont differ wen we delete 1st or middle ,,. It differs only wen we delete last element.
21 delete($a[$size-1]);
22 print " Array after deleting last element : @a \n ";
23 $size=@a;
24 print "size of arry after deleting last element : $size \n ";
# 2  
Old 08-30-2007
delete (something) makes "something" undefined
# 3  
Old 08-31-2007
praveen, try shift function on that array
# 4  
Old 08-31-2007
but how to get rid of that error?
# 5  
Old 08-31-2007
Yogesh gave you the answer. shift the array. If you don't like that then tell us what your requirements are. IN other words what are you trying to do with the perl code...
# 6  
Old 08-31-2007
According to the POD, for an array element, delete() sets the element to undef. So $a[0] will be undef. print @a will then give a warning (not error) if warnings are enabled.

Deleting an array element effectively returns that position of the array to its initial, uninitialized state. Subsequently testing for the same element with exists() will return false. Also, deleting array elements in the middle of an array will not shift the index of the elements after them down. Use splice() for that.
Login to Reply

« Previous Thread | Next Thread »
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Lot of services in non-global zones, in uninitialized after reboot solaris_1977 Solaris 2 4 Weeks Ago 02:39 PM
PERL - Use of uninitialized value in pattern match (m//) chris01010 Shell Programming and Scripting 3 03-18-2015 07:03 AM
Telnet uninitialized smazshah Solaris 14 05-28-2013 04:51 PM
awk - How to join the string with values KCApple UNIX for Dummies Questions & Answers 2 05-14-2013 01:37 AM
Join On A String jimmyf UNIX for Dummies Questions & Answers 11 10-12-2012 02:37 PM
How to use the the join command to join multiple files by a common column evelibertine UNIX for Dummies Questions & Answers 5 07-05-2012 04:15 PM
Join lines with the same start string andrejm Shell Programming and Scripting 10 10-02-2011 02:26 PM
use of uninitialized value in subtraction suvenduperl Shell Programming and Scripting 1 04-16-2010 07:21 AM
How to clear STATE - uninitialized in solaris 10 madhu548 Solaris 6 03-10-2009 06:31 AM
bss(uninitialized data) segment allocation karimulla_sha Programming 7 04-26-2005 01:46 PM

All times are GMT -4. The time now is 10:53 AM.

Unix & Linux Forums Content Copyright©1993-2018. All Rights Reserved.
Show Password