use strict;
use warnings;
#let's write a function that do something and avoid writing similar code everytime when we open a new loop.... 


my $file="example.fasta";
open (FILEHANDLE,$file);
my @array=<FILEHANDLE>;
close FILEHANDLE;


while (@array)
{
my $temp=shift @array; 
chomp $temp; 
#we put the code from regular expression in to test1 and let it do it instead of writing the code
my @out=test1($temp); 
#@out takes the value returned from the 
print "this line is ",$out[0] ,"\n"; 
print "rc sequence is ",$out[1] ,"\n"; 
}

sub test1
{
my @t=@_;
#remember @ARGV?? @_ here is that thing in a subroutine, it takes the value you put in to a function
my $new=shift @t;
#get the first element
my $value;  
#we want to return something to the main part of function so we define $value and $rc --reverse complimentary sequences
my $rc; 
if($new=~ m/\>/)
{
print "it's a sequence ID\n";
$value="ID";

}
else
{
print "it's not a sequence ID\n";
$value="Sequence";
#do a scalar reversion
$rc=reverse $new; 
$rc=~ tr/ATGC/TACG/;  
}

#you can return scalar/array/hash to the main part of function, $value is identifier of the type, $rc is rc sequence when it's sequence. so it would be empty for sequence id lines
# note: "my" variable is only valid in a loop/subroutine when it's defined in it. so when it's inside a pair of curly brackets, it's not reachable in other parts of scripts and will be deleted after the curly brackets are closed 
return ($value, $rc); 
}
