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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Use of uninitialized value in join or string at arraydef.pl
# 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
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  
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.

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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Lot of services in non-global zones, in uninitialized after reboot

Hello, This is Solaris-10 server, running with 4 non-global zones. This server was hung today and I had to reboot it forcefully from console. Then root file-system was not clean and I had to run fsck from failsafe mode. After it came back in run-level-3, lot of services are showing in... (3 Replies)
Discussion started by: solaris_1977
3 Replies

2. Shell Programming and Scripting

PERL - Use of uninitialized value in pattern match (m//)

I have written a PERL script to read files from directory that the filename contains OT. It then takes each line of each file and prints the first 5 characters before the first occurence of a /. Currently I am getting the error: Use of uninitialized value in string at rowGrab.pl line 43.... (3 Replies)
Discussion started by: chris01010
3 Replies

3. Solaris

Telnet uninitialized

HI I need help regarding telnet as I try to run the service it gives error #svcs -xv svc:/network/telnet:default svc:/network/telnet:default (Telnet server) State: uninitialized since Wed May 15 16:46:41 2013 Reason: Restarter svc:/network/inetd:default is not running. See:... (14 Replies)
Discussion started by: smazshah
14 Replies

4. UNIX for Dummies Questions & Answers

awk - How to join the string with values

Hi, I'm a beginner in awk script. I've been trying to figure how to concatenate two string in input file using awk after the value is calculated. I'm trying to get this format Apple 5.2(10) Orange 4.4(8) Watermelon 3.10(30) Berries 10.2(20) The input file with the format fruit... (2 Replies)
Discussion started by: KCApple
2 Replies

5. UNIX for Dummies Questions & Answers

Join On A String

Is is possible to join on unsorted files by a string? Don't want to sort because there is other text that is already in a good format. File1 has this text string: ABCD-123 FGH File2 has this text string: ABCD-123 I want to replace or join ABCD-123 in file 2 with ABCD-123 FGH in file... (11 Replies)
Discussion started by: jimmyf
11 Replies

6. Shell Programming and Scripting

Join lines with the same start string

I have the text like: DN11-001 Thats the first line which needs to be DN11-001 joined with the second line and also to DN11-001 the third line as they all begin with the same DN11-001 document number. DN11-002 The number of lines differ DN11-002 among the documents. DN11-005 It can also be... (10 Replies)
Discussion started by: andrejm
10 Replies

7. Shell Programming and Scripting

use of uninitialized value in subtraction

Hallo all i am trying to execute this script ............... But this is throwing the error...... use of uninitialized value in subtraction in at icd_convert.pl line 156 use of uninitialized value in subtraction in at icd_convert.pl line 157 use of uninitialized value in subtraction in at... (1 Reply)
Discussion started by: suvenduperl
1 Replies

8. UNIX for Dummies Questions & Answers

Join 2 files with multiple columns: awk/grep/join?

Hello, My apologies if this has been posted elsewhere, I have had a look at several threads but I am still confused how to use these functions. I have two files, each with 5 columns: File A: (tab-delimited) PDB CHAIN Start End Fragment 1avq A 171 176 awyfan 1avq A 172 177 wyfany 1c7k A 2 7... (3 Replies)
Discussion started by: InfoSeeker
3 Replies

9. Solaris

How to clear STATE - uninitialized in solaris 10

Helloo Frd's, How to clear uninitialized state in solaris 10 Services, the fallowing inetadm shows on my server. I tried svcadm clear, enable... not worked. And also i can't change to enable some of service on that. sara4@root# inetadm ENABLED STATE FMRI disabled ... (6 Replies)
Discussion started by: madhu548
6 Replies

10. Programming

bss(uninitialized data) segment allocation

Hi 1) Please go through the following code : char string2; char string1; main() { memcpy(string2,"SENDER ",12); strcpy(string1,"******"); printf("%s\n%s\n",string1,string2); } 2) and the output of... (7 Replies)
Discussion started by: karimulla_sha
7 Replies
Login or Register to Ask a Question