Unix/Linux Go Back    


Shell Programming and Scripting 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

Shell Programming and Scripting


Tags
perl, perl array, perl shift, shift, shift perl

Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 08-30-2007   -   Original Discussion by praveen_b744
praveen_b744 praveen_b744 is offline
Registered User
 
Join Date: Aug 2007
Last Activity: 24 August 2010, 9:15 AM EDT
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
Unix or Linux 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
2
3 use strict;
4
5 my @a = ( 1...10 );
6
7 print " Original array : @a \n ";
8
9 #DELETE Function
10
11 my $size=@a;
12
13 print "size of arry before deleting 1st element : $size \n ";
14
15
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.
20
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 ";
Sponsored Links
    #2  
Old Unix and Linux 08-30-2007   -   Original Discussion by praveen_b744
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 22 November 2017, 2:26 PM EST
Location: NM
Posts: 11,240
Thanks: 571
Thanked 1,117 Times in 1,031 Posts
delete (something) makes "something" undefined
Sponsored Links
    #3  
Old Unix and Linux 08-31-2007   -   Original Discussion by praveen_b744
Yogesh Sawant's Unix or Linux Image
Yogesh Sawant Yogesh Sawant is offline Forum Advisor  
Full Time Dad
 
Join Date: Sep 2006
Last Activity: 21 November 2017, 5:36 AM EST
Location: Rossem, Tazenda
Posts: 1,213
Thanks: 7
Thanked 18 Times in 17 Posts
praveen, try shift function on that array
    #4  
Old Unix and Linux 08-31-2007   -   Original Discussion by praveen_b744
praveen_b744 praveen_b744 is offline
Registered User
 
Join Date: Aug 2007
Last Activity: 24 August 2010, 9:15 AM EDT
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
but how to get rid of that error?
Sponsored Links
    #5  
Old Unix and Linux 08-31-2007   -   Original Discussion by praveen_b744
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 22 November 2017, 2:26 PM EST
Location: NM
Posts: 11,240
Thanks: 571
Thanked 1,117 Times in 1,031 Posts
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...
Sponsored Links
    #6  
Old Unix and Linux 08-31-2007   -   Original Discussion by praveen_b744
cbkihong cbkihong is offline Forum Advisor  
Advisor
 
Join Date: Sep 2002
Last Activity: 4 May 2014, 6:22 AM EDT
Location: Hong Kong, China
Posts: 1,622
Thanks: 0
Thanked 11 Times in 10 Posts
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.

Quote:
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.
Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Join lines with the same start string andrejm Shell Programming and Scripting 10 10-02-2011 03:26 PM
use of uninitialized value in subtraction suvenduperl Shell Programming and Scripting 1 04-16-2010 08:21 AM
Join 2 files with multiple columns: awk/grep/join? InfoSeeker UNIX for Dummies Questions & Answers 3 12-01-2009 08:45 PM
How to clear STATE - uninitialized in solaris 10 madhu548 Solaris 6 03-10-2009 07:31 AM
bss(uninitialized data) segment allocation karimulla_sha Programming 7 04-26-2005 02:46 PM



All times are GMT -4. The time now is 01:41 AM.