Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^4: Parsing problem

by MB123 (Initiate)
on Nov 08, 2012 at 10:48 UTC ( #1002872=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Parsing problem
in thread Parsing problem

Using your exact code and the data posted here, I get "Coordinates No of Strains AA Change" printed in my command line, and no output file created.

I don't understand how I am getting different results!


Comment on Re^4: Parsing problem
Re^5: Parsing problem
by kcott (Abbot) on Nov 08, 2012 at 19:00 UTC

    I now have some inkling of what the problem might be. I suspect you're missing some very fundamental knowledge. Don't panic about this: none of us was born with this information and you just haven't learned it yet. I can probably take you through this step-by-step but first I'll need some information. Please type

    perl -v

    at your command prompt and then post the full output (within <code>...</code> tags). Here's an example from my system (my command prompt is "$ " - you don't type this):

    $ perl -v This is perl 5, version 14, subversion 2 (v5.14.2) built for darwin-th +read-multi-2level Copyright 1987-2011, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 source ki +t. Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access to + the Internet, point your browser at http://www.perl.org/, the Perl Home Pa +ge.

    -- Ken

      I suspect I am missing a lot of fundamental knowledge! Here is my output -
      This is perl 5, version 16, subversion 1 (v5.16.1) built for MSWin32-x +64-multi-thread Copyright 1987-2012, Larry Wall Perl may be copied only under the terms of either the Artistic License + or the GNU General Public License, which may be found in the Perl 5 +source kit. Complete documentation for Perl, including FAQ lists, should be found +on this system using "man perl" or "perldoc perl". If you have access + to the Internet, point your browser at http://www.perl.org/, the Per +l Home Page.

        In the code I posted above, everything between the text "Here's exactly what I used to test your code and data:" and the [download] link is part of the one script. I suspect you tried to separate that into two files (script and data). Also, on this site, when code lines don't fit on one line they wrap to the next line - this is indicated by the addition of a plus (+) sign (which is coloured red by default). You don't want these additional plusses in your code; so, use the [download] link to get a plain text version. Save this plain text to a file - the usual filename extension for Perl scripts is ".pl" - the filename I used was pm_gene_uninit.pl (the following assumes you've used the same name). You can now run

        perl pm_gene_uninit.pl

        and, hopefully, you'll now get the expected output (displayed on the screen - not in a file).

        Lines in Perl code that start with a hash (#) sign are comments: they are ignored by Perl when the script is run. [Exception: if the first line begins with #! it's not actually a comment - I think you can safely ignore that for now - see perlrun - #! and quoting on non-Unix systems for more information.] Adding a # to the start of a line of code is referred to as commenting out that line of code. Where I earlier referred to "removing the debug print statements", I actually commented them out, e.g.

        #say qq(DEBUG: Line = "$line");

        I also commented out all the lines relating to external files:

        #my $file = "BSAC.pl"; ... #open my $in, "<", "$file"; #open my $out, ">", "output.txt";

        and also changed these three lines:

        say $out "Coordinate No of Strains AA Change"; ... while ( my $line = <$in> ) { ... printf $out "%-12.12s %-15.15s %s\n", $SNP, $count, $change;

        to

        say "Coordinate No of Strains AA Change"; ... while ( my $line = <DATA> ) { ... printf "%-12.12s %-15.15s %s\n", $SNP, $count, $change;

        Removing $out from the say and printf statements means output now goes to the screen instead of a file (that's an oversimplification but will suffice for this discussion). Changing $in to DATA means the input is now everything following __DATA__ - see perldata (under Special Literals) for more details about this. Assuming that you did put everything after __DATA__ in a separate file, all of this explains "I get "Coordinates No of Strains AA Change" printed in my command line, and no output file created.".

        That should get us back to: "Try running this. Assuming it works, try changing the data to something you know will generate the warnings - keeping the data to an absolute minimum.".

        Going all the way back to your original posting, you have an input file called BSAC.pl and a script called Script.txt. I don't have a Perl running under MSWin to test this; however, I expect MSWin will interpret your input file as a Perl script and your actual Perl script as a plain text file. It's possible one (or both) of these may be related to your original problem. Try renaming your input file to BSAC.txt and your Perl script to Script.pl and see if you get better results.

        I'd also recommend you read perlintro (a brief introduction and overview of Perl) and bookmark perl (which has links to all the Perl documentation).

        -- Ken

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2014-09-18 03:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (105 votes), past polls