hello monks! Below I have posted my code. I am getting an error which says "Undefined subroutine &main::fields called at test.pl line 34, <$data> line 2." Can anyone help me?

#Written by Prasuna Dahal use warnings; use XML::Simple; use LWP::UserAgent; use HTTP::Request::Common; use URI::Escape; use Text::CSV; use Data::Dumper; my $i = 0; my @keystr; my @kwrds = {"inhibitors", "activity", "complex", "activator", "activi +ty", "activities", "activated", "proteins", "deficiency", "levels", " +functions", "reductions", "protease", "proteases"}; my $file = "proteinlist.csv"; my $ua = LWP::UserAgent->new; my $csv = Text::CSV->new({sep_char => ','}); #Open the result in a CSV file open (my $fh, ">", "test1.csv"); print $fh "Valid Proteins\n"; #open file containig protein_name #open(my $data1, '<', "proteinlist.csv"); #Open the file containing the PubMed IDs open(my $data, '<', "test.csv"); while (my $line = <$data>) { chomp $line; if ($csv->parse($line)) { #Skip 1st line next if ($. == 1); my @fields = $csv-fields(); #Replace (-) with (,) $fields[0] =~ tr/-/,/; my $id = $fields[0]; #Initialize http request my $args = "db=pubmed&id=$id&retmode=text&rettype=abstract"; my $req = new HTTP::Request POST => 'https://eutils.ncbi.nlm.nih.g +ov/entrez/eutils/efetch.fcgi'; $req->content_type('application/x-www-form-urlencoded'); $req->content($args); #Get response my $response = $ua->request($req); my $content = $response->content; $fields[0] =~ tr/,/-/; my @abstract = split (/[.]/, $content); for $abstract(@abstract){ @var1 = split ((/[ ]|[,]/), $abstract); foreach $var1(@var1){ open(my $data1, "<", $file); while (my $line1 = <$data1>) { chomp $line1; my @fields1 = split ",", $line1; $keystr[$i] = $fields1[0]; $i++; if ($var1=~ /\b$keystr[$i]\b/i){ foreach $kwrds(@kwrds){ if ($var1=~ /\b$kwrds\b/i){ my $valid_prot = $var1; } } print $fh "$valid_prot\n"; print "$valid_prot\n"; } } } } } } close($fh);

In reply to Undefined Subroutine error by pdahal

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.