Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^4: reading and working with grow.out files

by rmgzsm9 (Novice)
on Apr 29, 2012 at 14:00 UTC ( #967935=note: print w/ replies, xml ) Need Help??


in reply to Re^3: reading and working with grow.out files
in thread reading and working with grow.out files

I made this program, but it is giving so many errors. Can you help me in debugging it.

use strict; use warnings; use Carp qw(croak); { my $input_file = "input_file.txt"; my @lines = slurp($input_file); for my $line (@lines){ my ($filename, $ligand) = split(/\t/, $line); open(FILE, '<', $filename) or die "Cannot open file: $!"; while (my $line = <FILE>) { if ($line =~ /$ligand/) { $count++; $first=substr($line, 0,1); if($first=='H'); { $sum++; } } print "Total No. of interactions are $count"; print " No. of Hydrogen bonds are $sum"; } close(FILE); } } ##Slurps a file into a list sub slurp { my ($file) = @_; my (@data, @data_chomped); open IN, "<", $file or croak "can't open $file\n"; @data = <IN>; for my $line (@data){ chomp($line); push (@data_chomped, $line); } close IN; return (@data_chomped); }


Comment on Re^4: reading and working with grow.out files
Download Code
Re^5: reading and working with grow.out files
by marto (Bishop) on Apr 29, 2012 at 14:10 UTC

    The messages you receive tell exactly what's wrong:

    Global symbol "$count" requires explicit package name at test.pl line +14. Global symbol "$first" requires explicit package name at test.pl line +15. Global symbol "$first" requires explicit package name at test.pl line +16. syntax error at test.pl line 16, near ");" Global symbol "$sum" requires explicit package name at test.pl line 18 +. Global symbol "$count" requires explicit package name at test.pl line +21. Global symbol "$sum" requires explicit package name at test.pl line 22 +.

    Define $count, $first and $sum, like the other variables in your script. For example, add the following line in the appropriate place:

    my ($count, $first, $sum);

    Next, No semi colon required here:

    if ($first=='H'); {

    Should be:

    if ($first=='H') {

    I suggest spending some time working on the basics:

      Thanks. It worked. Not exactly I wanted, but it worked

        Telling you how to fix the code you provided wasn't exactly what you wanted, or your code doesn't do what you want?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://967935]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (9)
As of 2015-07-01 23:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (25 votes), past polls