Hi again. First, no way you should be producing your output like that. That kind of manual jiggery-pokery is fraught with pitfalls and error vectors. You need to build up a data structure known as an array of arrays representing your output, and then convert it to the delimited file using Text::CSV or Text::CSV_XS.
As to your problem: you are building a lookup table from the wrong structure. If what you want to do is check all fields in @csvfieldlist to see which are present in @fields, and record a null value for those that are not, you need to make the lookup table from @fields and loop through the larger list.
use Text::CSV_XS; my @rows; for my $line ( @something ) { if ( $line =~ /NRG\ location/) { my @row; my @fields; foreach my $bline (@blocklines) { my ($k, $v) = split '=', $bline; push @fields, $k; } my %lookup = map { $_ => 1 } @fields; for my $field ( @csvfieldlist ) { if ( exists $lookup{ $field } ) { push @row, 'yes'; } else { push @row, undef; } } push @rows, \@row; } } csv (in => \@rows, out => "file.csv", sep_char=> ";");
Hope this helps!
In reply to Re^3: Determine if array value in string results
by 1nickt
in thread Determine if array value in string results
by ImJustAFriend
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |