See comments below.

On Feb 11, 2004, at 2:55 PM, James Edward Gray II wrote:

On Feb 11, 2004, at 1:27 PM, Michael S. Robeson II wrote:

[snip]

Anyway, though it works great I am having a tough time trying to figure out WHY it works.

See comments below, in the code.


[snip]

I think if I can understand the mechanics behind this script it will only help me my future understanding of writing PERL scripts.

Perl. The language you are learning is called Perl, not PERL. :)


Hehe, thanks. :-)

[snip]

[snip]

$/ = '>'; # Set input operator

Here's most of the magic. This sets Perl's input separator to a > character. That means that <INFILE> won't return a sequence of characters ending in a \n like it usually does, but a sequence of characters ending in a >. It basically jumps name to name, in other words.


while ( <INFILE> ) {
    chomp;

chomp() will remove the trailing >.

OK that makes pretty good sense. I understand that now, I hope. See next comment.




    next unless s/^\s*(\S+)//;
    my $name = $1;

Well, if we're reading name to name, the thing right a the beginning of our sequence is going to be a name, right? The above removes the name, and saves it for later use.

OK, I think this is were my problem is. That is how does it know that the characters as in "bob" or "fred" are the names and not mistaking the sequence of letters "agtcaccgatg" to be placed in memory ($name). Basically I am reading the following:


next unless s/^\s*(\S+)//;

as "Go to the next line unless you see a line with zero or more whitespace characters followed by one or more non-whitespace characters and save the non-whitespace characters in memory." If this is correct then how can perl tell the difference between the lines containing "bob" or "fred" (and put then in memory) and the "acgatctagc" (and not put these in memory) because both lines of data seem to fit the expression pattern to me. I think it has something to do with how perl is reading through the file that makes this work?

So, there is something I am "missing", not noticing or realizing here.
Maybe I've been staring at the code for far to long and should take a break! :-)




my @char = ( /[a-z]/ig, ( '-' ) x $len )[ 0 .. $len - 1 ];

If I may, yuck! This builds up a list of all the A-Za-z characters in the string, adds a boat load of extra - characters, trims the whole list to the length you want and stuffs all that inside @char. It's also receives a rank of "awful", on the James Gray Scale of Readability. ;)



Yeah, I need to clean that up a bit!


[snip]

-Mike


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to