The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk, join or sed jkl_jkl Shell Programming and Scripting 1 04-15-2008 05:55 AM
Join jazz8146 UNIX for Dummies Questions & Answers 5 01-29-2008 11:42 AM
join (pls help on join command) summer_cherry Shell Programming and Scripting 1 12-31-2007 05:19 AM
bss(uninitialized data) segment allocation karimulla_sha High Level Programming 7 04-26-2005 01:46 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 08-30-2007
praveen_b744 praveen_b744 is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 49
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 ";
  #2 (permalink)  
Old 08-30-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,643
delete (something) makes "something" undefined
  #3 (permalink)  
Old 08-31-2007
Yogesh Sawant's Avatar
Yogesh Sawant Yogesh Sawant is offline Forum Staff  
Part Time Moderator and Full Time Dad
  
 

Join Date: Sep 2006
Location: Rossem, Tazenda
Posts: 1,086
praveen, try shift function on that array
  #4 (permalink)  
Old 08-31-2007
praveen_b744 praveen_b744 is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 49
but how to get rid of that error?
  #5 (permalink)  
Old 08-31-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,643
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 (permalink)  
Old 08-31-2007
cbkihong cbkihong is offline Forum Advisor  
Advisor
  
 

Join Date: Sep 2002
Location: Hong Kong, China
Posts: 1,624
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

Bookmarks

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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 03:21 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language translation by Google.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0