in reply to Re: explanation of passages of a Perl script
in thread explanation of passages of a Perl script

Thank you for answering

I have doubts about all the script because like you I think it is a bit confusing... I'm a new learner of Perl and in general of programming language and as exercise I'm trying to modify this script in order to make it better.

I understand for what it has been done (it is a quality trimming for a FASTQ file) but if I were the programmer I dont' think I would have written the script like that.

Maybe this will be a stupid question but I have serious problems to understand the variables (like $sub) that have been used, in particular when we have the feature "substr". I have to find more info in the manual and I will do that for sure... also the variables -$#qual: why I have to write them like that?

Moreover, I noted the absence of the use strict, use warnings and probably of use diagnostics... In fact I rewrite the script using them and with use script I don't have any problem but when I use warnings and diagnostics I have an error of unitialized value in operation that I can't really resolve (if you prefer I could write you down my script but it is practically the same thing only with "my". I have also changed the way to read the FASTQ file preferring the simple way to write directly in the script the name of the FASTQ file of my interest).

I'm really sorry to annoy all of you with these problems but I would really like to understand how to work with this script and how I could ameliorate it...

Thank you very much
  • Comment on Re^2: explanation of passages of a Perl script

Replies are listed 'Best First'.
Re^3: explanation of passages of a Perl script
by hippo (Archbishop) on Feb 06, 2018 at 15:42 UTC
    I have serious problems to understand the variables (like $sub) that have been used, in particular when we have the feature "substr".

    substr() is a built-in function in perl. All of the built-in functions are documented and if your machine has the perl documentation installed you can simply run perldoc -f substr to read it. Alternatively, it is available online here.

    also the variables -$#qual: why I have to write them like that?

    $#qual is a special syntax, it returns the index of the last element in the array @qual. See the Arrays: A Tutorial/Reference for a discussion of this and many other aspects of using arrays in perl.

    when I use warnings and diagnostics I have an error of unitialized value in operation that I can't really resolve

    You can find the offending term and then surround it with a suitable "if" statement. Suppose $foo might sometimes be undefined, but you want to print it, you might then use:

    if (defined $foo) { print $foo; }

    or, equivalently

    print $foo if defined $foo;

    Perl is a very big language with lots to learn. I think you would benefit from reading some of the Tutorials here covering the areas that you know less well. Stick at it - you will soon be amazed at what you can achieve.

Re^3: explanation of passages of a Perl script
by AnomalousMonk (Archbishop) on Feb 06, 2018 at 16:32 UTC

    Further to hippo's excellent comments, I would add with regard to

    $dna = <FASTQ>; ...; $qual = <FASTQ>; @dna = split ('', $dna); @qual = split ('', $qual);
    and similar from the tidied source that the code uses the same name for variables of different type. IMHO, it's not, in general, good practice to do this; eventually, you'll give yourself a terrible headache. Don't do that. In general, use informative, distinctive names for variables, subroutines, etc.


    Give a man a fish:  <%-{-{-{-<