Uninitialised value error stumping me..

L

Len

Hi

I am a newbie so be kind ;) The code below is used to process the data
below it. The code works fine on some larger data of identical (I
believe) format, however on this small data it throws the error:

"Use of uninitialized value in join or string at report13a.txt line
16, <> line 7"

Any help would be great - I'm sure it's something easy but it's
driving me crazy...

Thanks
Len

----------

#! perl -w
use strict;

my ($line, @fields, $refdes, @symbol, $count);
$refdes = "NEW"; #refdes enables symbol count
$symbol[0] = "EMPTY";

while ($line = <>){

chomp($line);
next if $line =~ /(^A|^J|MECHANICAL)/; #drop out if begins with A or
J or includes Mechanical
@fields = split /!/, $line; #Change separator

if (($refdes eq "new")||($fields[1] ne $refdes)){ #New refdes
$count = 0; #Reset counter
print "$refdes array is:mad:symbol\n"; #Print previous refdes symbol
array
$refdes = $fields[1]; #Reset refdes
@symbol = (); #Reset symbol array
$symbol[0] = $fields[2]; #Put symbol name at front of array
}

else{
$count++;
$symbol[$count] = $fields[4];
}
}

print "Final $refdes array is: @symbol\n"; #Print final symbol array

-------------

A!REFDES!SYM_NAME!GRAPHIC_DATA_7!
J!C:\PCB_DATA_DUMP\test.brd!Mon Jan 31 12:46:35
2005!-75.000!-170.000!425.000!190.000!0.001!millimeters!TOP_LEVEL!31.496063
mil!2!UP TO DATE!
S!CN5!MTG_2_40CP1_70!used:01BAiss2/USB programmer!
S!CN5!MTG_2_40CP1_70!rev:1,NJH,28/09/04!
S!CN5!MTG_2_40CP1_70!1.700!
S!CN5!MTG_2_40CP1_70!2.400!
S!CN6!CONN_UMP_3MM_SMT!PACKAGE!sym.req:0554!
S!CN6!CONN_UMP_3MM_SMT!PACKAGE!lib.name:conn_ump_3mm_smt!
S!CN6!CONN_UMP_3MM_SMT!PACKAGE!height:3.00mm!
S!CN6!CONN_UMP_3MM_SMT!PACKAGE!used:01ATiss1/Whitney RF!
S!CN6!CONN_UMP_3MM_SMT!PACKAGE!rev:2,NJH,26/05/04!

--------------
 
A

Atlantis

Len said:
Hi

I am a newbie so be kind ;) The code below is used to process the data
below it. The code works fine on some larger data of identical (I
believe) format, however on this small data it throws the error:

"Use of uninitialized value in join or string at report13a.txt line
16, <> line 7"

Any help would be great - I'm sure it's something easy but it's
driving me crazy...

Thanks
Len

----------

#! perl -w
use strict;

my ($line, @fields, $refdes, @symbol, $count);
$refdes = "NEW"; #refdes enables symbol count
$symbol[0] = "EMPTY";

while ($line = <>){

chomp($line);
next if $line =~ /(^A|^J|MECHANICAL)/; #drop out if begins with A or
J or includes Mechanical
@fields = split /!/, $line; #Change separator

if (($refdes eq "new")||($fields[1] ne $refdes)){ #New refdes
$count = 0; #Reset counter
print "$refdes array is:mad:symbol\n"; #Print previous refdes symbol
array
$refdes = $fields[1]; #Reset refdes
@symbol = (); #Reset symbol array
$symbol[0] = $fields[2]; #Put symbol name at front of array
}

else{
$count++;
$symbol[$count] = $fields[4];
}
}

print "Final $refdes array is: @symbol\n"; #Print final symbol array

-------------

A!REFDES!SYM_NAME!GRAPHIC_DATA_7!
J!C:\PCB_DATA_DUMP\test.brd!Mon Jan 31 12:46:35
2005!-75.000!-170.000!425.000!190.000!0.001!millimeters!TOP_LEVEL!31.496063
mil!2!UP TO DATE!
S!CN5!MTG_2_40CP1_70!used:01BAiss2/USB programmer!
S!CN5!MTG_2_40CP1_70!rev:1,NJH,28/09/04!
S!CN5!MTG_2_40CP1_70!1.700!
S!CN5!MTG_2_40CP1_70!2.400!
S!CN6!CONN_UMP_3MM_SMT!PACKAGE!sym.req:0554!
S!CN6!CONN_UMP_3MM_SMT!PACKAGE!lib.name:conn_ump_3mm_smt!
S!CN6!CONN_UMP_3MM_SMT!PACKAGE!height:3.00mm!
S!CN6!CONN_UMP_3MM_SMT!PACKAGE!used:01ATiss1/Whitney RF!
S!CN6!CONN_UMP_3MM_SMT!PACKAGE!rev:2,NJH,26/05/04!

--------------

I think the origin of your problem is in the "else" part of your "if"
statement. I'd add some debug (before/after) to see what values and
elements are being set by the $symbol[$count] = $field[4]; assignment.
 
P

Paul Lalli

Len said:
I am a newbie so be kind ;) The code below is used to process the data
below it. The code works fine on some larger data of identical (I
believe) format, however on this small data it throws the error:

"Use of uninitialized value in join or string at report13a.txt line
16, <> line 7"

In the future, it would be helpful to know exactly which line is line
16, without us having to guess where your line breaks actually are.
#! perl -w
use strict;

my ($line, @fields, $refdes, @symbol, $count);

Don't do this. Define your variables in the smallest scope possible.
$refdes = "NEW"; #refdes enables symbol count
$symbol[0] = "EMPTY";

while ($line = <>){

chomp($line);
next if $line =~ /(^A|^J|MECHANICAL)/; #drop out if begins with A or
J or includes Mechanical
@fields = split /!/, $line; #Change separator

if (($refdes eq "new")||($fields[1] ne $refdes)){ #New refdes
$count = 0; #Reset counter
print "$refdes array is:mad:symbol\n"; #Print previous refdes symbol
array

Here, you are interpolating @symbol - that is, printing each element of
@symbol.
$refdes = $fields[1]; #Reset refdes
@symbol = (); #Reset symbol array

Here, you clear @symbol (which would likely not be needed if you'd
declared it in the correct scope.
$symbol[0] = $fields[2]; #Put symbol name at front of array

Here you add one element to @symbol, so it's size is now 1.
}

else{
$count++;
$symbol[$count] = $fields[4];

In the else statement, you are setting some unknown element of @symbol.
Say for example that at this stage, $count is 2. Then you would be
setting the 3rd element of @count. Assuming @symbol still has the same
single value it had in the if statement, @symbol now contains:
($fields[2], undef, $fields[4])

Then when you go back to the top of the if statement, you attempt to
again print out all the elements of @symbol. One of those elments is
undefined. That is the cause of the warning message.

From the looks of things, I'd guess your algorithm needs a little work.
}
}

print "Final $refdes array is: @symbol\n"; #Print final symbol array

<input data snipped>

Paul Lalli
 
I

ioneabu

Len said:
Hi

I am a newbie so be kind ;) The code below is used to process the data
below it. The code works fine on some larger data of identical (I
believe) format, however on this small data it throws the error:

"Use of uninitialized value in join or string at report13a.txt line
16, <> line 7"

Any help would be great - I'm sure it's something easy but it's
driving me crazy...

Thanks
Len

----------

#! perl -w
use strict;

my ($line, @fields, $refdes, @symbol, $count);
$refdes = "NEW"; #refdes enables symbol count
$symbol[0] = "EMPTY";

while ($line = <>){

chomp($line);
next if $line =~ /(^A|^J|MECHANICAL)/; #drop out if begins with A or
J or includes Mechanical
@fields = split /!/, $line; #Change separator

if (($refdes eq "new")||($fields[1] ne $refdes)){ #New refdes
$count = 0; #Reset counter
print "$refdes array is:mad:symbol\n"; #Print previous refdes symbol
array
$refdes = $fields[1]; #Reset refdes
@symbol = (); #Reset symbol array
$symbol[0] = $fields[2]; #Put symbol name at front of array
}

else{
$count++;
$symbol[$count] = $fields[4];

How do you know @fields has 5 elements to address? Your first line of
data only has 4 items. You could check it like this:

$symbol[$count] = $fields[4] if $fields[4];

but that may not solve your overall problem.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top