#!/usr/bin/perl # # Print a file backwards # open( FILE, "test.txt" ) or die( "Can't open file file_to_reverse: $!" ); @lines = reverse ; foreach $line (@lines) { $line = reverse $line; print $line; } #### #!/usr/bin/perl # # Convert DNA to bits and see what comes out # use strict; use warnings; open my $fh, "<:encoding(UTF-8)", "Homo_sapiens.GRCh38.dna.chromosome.2.fa" or die "$!\n"; # open my $fh, "<:encoding(UTF-8)", "test.txt" or die "$!\n"; my $bit = "0"; my $byte = ""; my $i = 0; while (read($fh, my $char, 1)) { # ignore all other characters, escpecially those annoying NNNNNNNN, what are they anyway? if ($char =~ m/[ACGT]/ ) { # convert bases to bits, 6 possible way to do this if ($char eq "A") { $bit = "0"; } if ($char eq "C") { $bit = "1"; } if ($char eq "G") { $bit = "0"; } if ($char eq "T") { $bit = "1"; } # add one bit at a time up to a byte if ($i < 7) { $i++; $byte .= $bit; } else { $i = 0; # convert the byte to a string my $chars = length($byte); my @packArray = pack("B$chars",$byte); my $print = "@packArray"; # only print alphanumeric characters if ($print =~/[a-z]|[A-Z]/) { print "$print"; } $byte = ""; } } } print "\n";