in reply to if array contain push another array

Hi, what is the syntax error according to the error message?

The code you posted produces:

Global symbol "$element" requires explicit package name (did you forge +t to declare "my $element"?) at 1203983.pl line 14. Global symbol "@element" requires explicit package name (did you forge +t to declare "my @element"?) at 1203983.pl line 16. Global symbol "@element" requires explicit package name (did you forge +t to declare "my @element"?) at 1203983.pl line 17. Missing right curly or square bracket at 1203983.pl line 21, at end of + line syntax error at 1203983.pl line 21, at EOF Execution of 1203983.pl aborted due to compilation errors.
Note that the last line of the message tells you exactly where one of the errors is.

I assume you also didn't have the undeclared variable error in your real code, but it was a typing error here. See:

You have a number of unneeded loops and variables in your script. Meanwhile the main error is in your attempt to match one of a list of values against a string. Please see perlrequick for a beginner's intro to regular expressions. You might have to go on to perlretut for character classes, which is what's used below.

Here's a version that does what you want, with sample data and a Test::More test to verify that the code is working correctly.

use strict; use warnings; use feature 'say'; use Test::More tests => 1; # my $filename = 'gff.annotated.gtf'; # open(my $fh, '<:encoding(UTF-8)', $filename) # or die "Can't open $filename: $!"; my $fh = \*DATA; my @transcript_ids; while ( my $line = <$fh> ) { my @columns = split / /, $line; if ( $columns[16] =~ /^[uxis]$/ ) { push @transcript_ids, $columns[10]; } } is_deeply( \@transcript_ids, [qw/ bb cc dd ee /], 'the right lines were matched' ); __DATA__ 1: 01 02 03 04 05 06 07 08 09 aa 11 12 13 14 15 a 2: 01 02 03 04 05 06 07 08 09 bb 11 12 13 14 15 u 3: 01 02 03 04 05 06 07 08 09 cc 11 12 13 14 15 x 4: 01 02 03 04 05 06 07 08 09 dd 11 12 13 14 15 i 5: 01 02 03 04 05 06 07 08 09 ee 11 12 13 14 15 s 6: 01 02 03 04 05 06 07 08 09 ff 11 12 13 14 15 z
Note that I am using the _DATA_ section but you can read from a file just as well.

Update: While I was updating this node to show some helpful links and an example, Brother Athanasius composed his excellent reply (although note that he and I came to different conclusions about what your actual problem spec is).

Hope this helps!


The way forward always starts with a minimal test.