-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
243 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/perl | ||
use warnings; | ||
use strict; | ||
|
||
my $favorite_color = 'green'; | ||
my @colors = ('red', $favorite_color, 'cornflower blue', 5); | ||
|
||
my $org = join ("--" , @colors ); | ||
|
||
## push changes the array | ||
push (@colors , 'black'); | ||
my $new = join ("--" , @colors ); | ||
|
||
print "org: $org\n"; | ||
print "new: $new\n"; | ||
|
||
my $last = pop @colors; | ||
|
||
# while tests for truth | ||
# a list is true if it is not empty ( len > 0 ) | ||
# a list is false when it is empty ( len == 0) | ||
while (my $last = pop @colors){ | ||
print "last is $last\n"; | ||
} | ||
|
||
# example of scope and my | ||
print "$last\n"; ## this will be 'black' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/perl | ||
use warnings; | ||
use strict; | ||
|
||
my $favorite_color = 'green'; | ||
my @colors = ('red', $favorite_color, 'cornflower blue', 5); | ||
|
||
$favorite_color = 'black'; | ||
my $second = $colors[1]; | ||
|
||
print "fc:$favorite_color\tsecond:$second\n"; | ||
|
||
my $length = scalar @colors; | ||
#my $length = length @colors; #this is wrong, returns 1 | ||
print "len = $length\n"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/perl | ||
use warnings; | ||
use strict; | ||
|
||
my $favorite_color = 'green'; | ||
my @colors = ('red', $favorite_color, 'cornflower blue', 5); | ||
my @colors2 = ('red', $favorite_color, 'cornflower blue', 5); | ||
|
||
my $string = join ("\t" , @colors); | ||
my $string2 = join ("--" , @colors , @colors2); | ||
|
||
print $string , "\n"; | ||
print $string2 , "\n"; | ||
## @colors is still the same, not changed by join | ||
print $colors[0] , "\n"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/perl | ||
use warnings; | ||
use strict; | ||
|
||
my @words = qw(I do not like green eggs and ham); | ||
|
||
#foreach my $word (sort {uc($a) cmp uc($b)}@words){ | ||
|
||
foreach my $word (@words){ | ||
next if $word eq "and"; | ||
print "$word\n"; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/perl | ||
use warnings; | ||
use strict; | ||
|
||
my @words = qw(I do not like green eggs and ham); | ||
|
||
#foreach my $word (sort {uc($a) cmp uc($b)}@words){ | ||
|
||
foreach my $word (@words){ | ||
next if $word eq "and"; | ||
print "$word\n"; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#!/usr/bin/perl | ||
use strict; | ||
use warnings; | ||
|
||
my @array = qw (a f gf t ffffh j ); | ||
my @map_array = | ||
map { my $elem = $_ ; length $elem } @array; | ||
print "@map_array\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/perl | ||
use warnings; | ||
use strict; | ||
|
||
my $favorite_color = 'green'; | ||
my @colors = ('red', $favorite_color, 'cornflower blue', 5); | ||
|
||
## no quotes no spaces | ||
## quotes, array will print with spaces | ||
print "no quotes: " , @colors , "\n"; | ||
print "quotes: @colors\n"; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/perl | ||
use warnings; | ||
use strict; | ||
|
||
my @seqs = qw ( ATGGTGCA TTTTTAA CCCGGG TTTATATATAT ); | ||
|
||
while (my $seq = shift @seqs){ | ||
print "seq: $seq\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/perl | ||
use warnings; | ||
use strict; | ||
|
||
my @seqs = qw ( ATGGTGCA TTTTTAA CCCGGG TTTATATATAT ); | ||
|
||
## length of the array is one more than the last index | ||
for (my $i = 0 ; $i < scalar @seqs ; $i++){ | ||
print "seq: $seqs[$i]\n"; | ||
} | ||
|
||
print "\n-------\n"; | ||
|
||
foreach my $seq (@seqs){ | ||
print "seq: $seq\n"; | ||
} | ||
|
||
print "before while: @seqs\n"; | ||
print "\n-------\n"; | ||
|
||
##after this while loop, @seqs is empty, len = 0 | ||
while (my $seq = shift @seqs){ | ||
print "seq: $seq\n"; | ||
} | ||
print "after while: @seqs\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/perl | ||
use warnings; | ||
use strict; | ||
|
||
my @seqs = qw ( ATGGTGCA TTTTTAA CCCGGG TTTATATATAT ); | ||
|
||
## length of the array is one more than the last index | ||
for (my $i = 0 ; $i < scalar @seqs ; $i++){ | ||
print "seq: $seqs[$i]\n"; | ||
} | ||
|
||
print "\n-------\n"; | ||
|
||
foreach my $seq (@seqs){ | ||
print "seq: $seq\n"; | ||
} | ||
|
||
print "before while: @seqs\n"; | ||
print "\n-------\n"; | ||
|
||
##after this while loop, @seqs is empty, len = 0 | ||
while (my $seq = shift @seqs){ | ||
print "seq: $seq\n"; | ||
} | ||
print "after while: @seqs\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/perl | ||
use warnings; | ||
use strict; | ||
|
||
my @seqs = qw ( ATGGTGCA TTTTTAA CCCGGG TTTATATATAT ); | ||
|
||
foreach my $seq (@seqs){ | ||
print "seq: $seq\n"; | ||
} | ||
|
||
print "before while: @seqs\n"; | ||
print "\n-------\n"; | ||
|
||
##after this while loop, @seqs is empty, len = 0 | ||
while (my $seq = shift @seqs){ | ||
print "seq: $seq\n"; | ||
} | ||
print "after while: @seqs\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/perl | ||
use warnings; | ||
use strict; | ||
|
||
my @seqs = qw ( ATGGTGCA TTTTTAA CCCGGG TTTATATATAT ); | ||
|
||
foreach my $seq (@seqs){ | ||
print "seq: $seq\n"; | ||
} | ||
|
||
print "before while: @seqs\n"; | ||
print "\n-------\n"; | ||
|
||
##after this while loop, @seqs is empty, len = 0 | ||
while (my $seq = shift @seqs){ | ||
print "seq: $seq\n"; | ||
} | ||
print "after while: @seqs\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/perl | ||
use strict; | ||
use warnings; | ||
|
||
my $seq = "ATGCGACCGGTTAA"; | ||
my @nts = split('',$seq); | ||
print "seq/array len = " , scalar @nts , "\n"; | ||
print "@nts\n"; | ||
print join("--",@nts),"\n"; | ||
|
||
my @sorted_nts = sort (@nts); | ||
print join("--",@sorted_nts),"\n"; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/perl | ||
use warnings; | ||
use strict; | ||
|
||
my $num1 = 10; | ||
my $num2 = 2; | ||
my $num3 = 100; | ||
my $num4 = 5; | ||
my $num5 = 0; | ||
|
||
### bad idea ## my $result_2 = $num1 <=> $num2; | ||
|
||
## good idea ## | ||
my @nums = ($num1 , $num2 , $num3, $num4 , $num5); | ||
my @sorted_num = sort {$a <=> $b} @nums; | ||
|
||
print "@sorted_num\n"; | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/perl | ||
use strict; | ||
use warnings; | ||
|
||
my $string = "I do not like green eggs and ham"; | ||
my @words = split("green",$string); | ||
print "@words\n"; | ||
print join("--",@words),"\n"; | ||
|