Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Perl Array

by kcott (Archbishop)
on Oct 11, 2015 at 03:49 UTC ( [id://1144411]=note: print w/replies, xml ) Need Help??


in reply to Perl Array

G'day baconyluv5,

Welcome to the Monastery.

Firstly, I can see without even running it, that the code you've posted won't compile! So you'll need to deal with whatever messages Perl gives you and fix the problems.

While you're learning, you'll find the diagnostics pragma will provide a lot more information for warning and error messages. It's a developer tool: don't leave it in your production code (that includes the code you hand in for marking/assessment/whatever).

The first problem that stood out was that you've used $i without declaring it. I thought that was maybe a typo and you'd meant $j; however, you've used both of those variables in more than one line, so my initial guess wasn't right.

Another problem occurs in various comparisons. Perl uses different operators for numeric and string comparisons. You've used numeric comparison operators throughout: I'm pretty sure those (or, at least, a fair number of them) should be string comparisons. perlop documents all the operators. For this specific issue, you'll want the Equality Operators and Relational Operators sections.

I also see code like this in two places:

for (my$j=0;$j<$n;$j=$j+1)

That looks more like C than Perl. Try writing those lines more like:

for my $j (0 .. $n - 1)

The .. is a range operator. You may have already noticed it if you followed the perlop link I provided earlier. It's in the Range Operators section.

There's other parts of your code that look like they probably need attention; although, what that might be may change after you deal with the issues I've already pointed out. In fact, they may become apparent to you as you apply fixes: a good learning exercise. You can always ask later if you find yourself stumped.

I'd recommend you take a step back and read through "perlintro -- a brief introduction and overview of Perl". It's not that long: you'd do well to read it all but do at least read down to, and including, the Builtin operators and functions section.

"... and I'm sorry for my bad English!"

Actually, I wish more native English speakers made as few mistakes and you've done here. "alignement" (which should be: alignment) was the only spelling mistakes I noticed. Perl (capitalised) is the name of the language; perl (all lowercase) is the filename of the program (as you have in your shebang line: /usr/bin/perl).

There are however two things you omitted. You should show the error and warning messages and also tell us about the expected output. Take a look at "How do I post a question effectively?" - it explains these things in more detail.

Finally, you talked about "an alignement table for sequences" [sic]. That's something that's technical and not directly related to Perl. Many monks, who could answer the coding part of your question, may read no further than your first sentence because they don't know what that is. Either describe it in a few short sentences or provide a link that will help us understand the concept sufficiently to help with your question.

— Ken

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (9)
As of 2024-04-23 09:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found