Perl array get value outside loop -
i have created 1 script in storing existing records in array , comparing record latest file record , if exists remove records array. able compare , print record when trying debug/print remaining list @ last. once loops gets closed it's throwing error requires global syntax. means script unable read remaining list present in array outside array.
for example: have 100 records put in array. when new record process if value matched in array remove record array. @ last ever records matches removed , remaining_record array remained record not exists in new record file.
if ( grep { $new_record eq $current_record } @array ) { debug( "debug: record found in existing array" ); @remaining_record = splice(@array, $new_record, 1); }
now when trying debug remaining record @ end of script , script looking global variable , looks empty.
my @remaining_record; $size = @remaining_record; ($n=0; $n < $size; $n++) { debug( "debug: remaining records $remaining_record[$n][0]" ); }
my @remaining_record; $size = @remaining_record;
either remove my
@remaining_record;
otherwise create new empty array name @remaining_record
.
or assign old array remaining data remaining_record
like
my @remaining_record = @array_with_remaining_data;
modify program below.
my @remaining_record; if ( grep { $new_record eq $current_record } @array ) { debug( "debug: record found in existing array" ); @remaining_record = splice(@array, $new_record, 1); } $size = @remaining_record; (my $n=0; $n < $size; $n++) { print "debug: remaining records $remaining_record[$n]"; }
Comments
Post a Comment