How do you pass (and dereference) an array of hashes to a Perl subroutine?

I though the code below would work but I think it is not dereferencing the array:

#!/usr/bin/perl

# ARRAY OF HASHES
$val[0]{‘CELL1′} = "0cell1";
$val[0]{‘CELL2′} = "0cell2";
$val[1]{‘CELL1′} = "1cell1";
$val[1]{‘CELL2′} = "1cell2";

for my $i (0..$#val) {
print "$val[$i]{‘CELL1′} $val[$i]{‘CELL2′}\n";
}

$res = &mysub(\@val);
print "RESULT: $res\n";

sub mysub {
my $ref = shift ; # $ref is a reference to an array of HASHES
my @valIN=@{$ref}; # try to dereference it

for my $i (0..$#valIN) {
print "$valIN[$i]{‘CELL1′} $valIN[$i]{‘CELL2′}\n";
}

return "DONE";
}

I Need Perl Programming Help!?

the question is:
Write a Perl program that scores an alignment using the scoring matrix in the file
"matrix.txt". Assume that the alignment is stored in FASTA format in the file
"dna.fasta". The program should print the alignment score as output.

The file matrix.txt contains this input:
10 -1 2 1
-1 9 1 2
2 1 11 -1
1 2 -1 12

The file dna.fasta contains this input:
>human
ACCGTTAAG
>mouse
–CGTTCA-

(the dashes ‘-’ represents blanks or spaces)

I think what they are basically asking is to I use the following input in matrix.txt:
A C G T
A 10 -1 2 1
C -1 9 1 2
G 2 1 11 -1
T 1 2 -1 12

to score the input in dna.fasta, and then print out the alignment score. Also, they want these done in a subroutine.

I have the main code and the subroutine, but they seem to be combined all wrong and so cant perform the whole task.

@matrix=();
&getmatrix("matrix.txt",\@matrix);
@sequences=(); @names=();
&get_dna_score("dna.fasta", \@sequences, \@names);
$score=$score(\@sequences, \@matrix);
print $score;

@matrix= ( );
&getmatrix ("matrix.txt",\@matrix );
for(my$i=0; $i<4; $i++)
{
for (my$j=0; $j<4; $j++)
{
print $matrix[$i][$j] ." ";
}
print "\n";
}

sub getmatrix
{
open (IN, $_[0]);
my $ref=$_[1];
$i=0;
while(<IN>)
{
@s=split(/\s+/, $_);
for (my$j=0; $j<@s; $j++)
{
$$ref[$i][$j]=$s[$j];
}
$i++;
}
close(IN);
return;
}

use strict;
use warnings;

open(IN, "dna.fasta");
my @file1=<IN>;
chomp($file1[1]);
chomp($file1[3]);
close IN;

sub get_dna_score {
my @first_arr = split //, shift;
my @second_arr = split //, shift;
my $match = shift;
my $miss = shift;
my $gap = shift;
my $score = 0;
my ($i, $len);
if (scalar @first_arr != scalar @second_arr) {
die "Can’t compare strings with different length!\n";
}
for ($i = 0, $len = scalar @first_arr; $i < $len; ++$i) {
if ($first_arr[$i] eq $second_arr[$i]) {
$score += $match;
} elsif ($first_arr[$i] eq " " || $second_arr[$i] eq " ") {
$score += $gap;
} else {
$score += $miss;
}
}
return $score;
}

print get_dna_score($file1[1], $file1[3], 2, -1, -2), "\n";

Please Help!!!

I didn't learn jack with an information systems degree?

Ok I just started a job as a computer programmer and it is very apparent I am no where need the level needed to start at the entry level.

The job description said extensive knowledge of perl, PHP, XML, HTML and it is very apparent to me now that I know a lot less than I thought I knew.

I had done an internship monitoring a small web page for my local university. There wasn’t much code on it. I had added a small questbook using perl, but it wasn’t anything fancy.

I am completely overwelmed in my new job. Trying to read the code my project manager has is like trying to decipher greek. It is way above my head. I have spent two days looking up commands I don’t know, but I can’t learn this all until the project is due.

I have read and worked on small projects in classes, but nothing this large. It is huge! I am tearing my hair out trying to sift through 100+ pages of code and trying to fiqure out how each module and subroutine fits into the big picture. What should I do?

Simple code but wierd Perl behavior. Why does this happen?

Hello. I have a very simple subroutine that opens a file and reads the lines into an array, then prints out the array text. (I’m experimenting with arrays – not planning to print out all the lines directly so please don’t tell me how to do that).

sub printFile{
my ($file) = @_;
open(HANDLE, "< $file") || die("Failed to open file!");
while(@line = <HANDLE>){
chomp(@line);
print @line;
}
close(HANDLE);
}

So when I run the code it shows only one line of it that changes as it prints out the text and then it finishes with the last line shown. I would have expected it to fill the whole console window with text, but all it does is update a single line.

I want to write a subroutine to comparing the length of two sequences ( return 1 if 1st seq longer than 2nd se?

programming in perl
i write it this way but its not working i dont know why :( … and i didnt under stand your way of doing it

use strict;

# i am just writing this as an example to test my subroutine

my $firstSeq = "AGTUUUU";
my $secondSeq = "AGGG";
print "my result =", comparing ($firstSeq,$secondSeq),"\n";

sub comaring {

my $firstSeq = @_;
my $secondSeq = @_;
my $firtslength = length($firstSeq);
my $secondlength = length($secondSeq);

# can i do this? if (length($firstSeq) > length($secondSeq)){

if ($firtslength > $secondlength){
print "1 \n";
}

elsif ($firtslength == $secondlength){
print "0 \n";

}

elsif ($firtslength < $secondlength){
print "-1 \n";

}

}