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.

In reply to Re: if array contain push another array by 1nickt
in thread if array contain push another array by zw

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.