Thank you, the following worked:
{ no warnings qw(uninitialized); ... } ----- Original Message ----- From: Jim Gibson <jimsgib...@gmail.com> To: perl list <beginners@perl.org> Cc: Sent: Monday, January 9, 2012 1:14 PM Subject: Re: supressing error message Use of uninitialized value in concatenation.... On 1/9/12 Mon Jan 9, 2012 10:53 AM, "Rajeev Prasad" <rp.ne...@yahoo.com> scribbled: > Hello, > > I have a lot of fields being concatenated to form a string and sometimes the > values are empty, so i am getting this error: > > Use of uninitialized value in concatenation (.) or string at ./script.pl line > 144, <$IN_FH> line 1. > > how can i suppress this? > > my logic flow: > > > $string1 = "a,b,c,d,e,f,........ a very long record" > > i only want few fields from this record of hundreds of fields, so > > @array = split(/,/,$string1) > > then reassemble the array elements into the new string: > > $string2 = $array[3]." ".$array[7]." ".$array[24].... and so on.... > > so whenever anything like $array[24] is empty and it occurs in concatenation > above i get this error: > > Use of uninitialized value in concatenation (.) or string at ./script.pl line > 144, <$IN_FH> line 1. > > how to suppress or avoid this error? You can use the 'no warnings uninitialized' pragma within a block to suppress the warnings: { no warnings uninitialed; $string2 = $array[3] . " " . $array[7] . " " . $array[24]; } You could also assign empty strings to undefined array members before the concatenation: $_ = (defined $_ ? $_ : '') for @array; For later Perls: $_ //= '' for @array; If elements of the array returned by split are really undefined, then you must be processing lines that do not have as many fields as you think they do. You could add tests to see how many elements are in @array and process them appropriately if they are short some fields. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/