Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
laziness, impatience, and hubris
 
PerlMonks  

Re: Entering the land of Perl

by choroba (Abbot)
on Apr 04, 2013 at 21:38 UTC ( #1027037=note: print w/ replies, xml ) Need Help??


in reply to Entering the land of Perl

Hello manbroski, welcome to the Monastery!
Prototypes are seldom used in Perl. It is usually enough to pass a reference as the argument directly:

sort_and_print_hash_keys(\%letters);
Moreover, counting characters in a string is idiomatically done via the tr operator. We know in advance that the possible characters are A, C, T and G only, so you can write:
#!/usr/bin/perl use strict; use warnings; use feature qw(say); my $s = shift; say join " ", map eval "$s =~ tr/$_//", qw/A C G T/;
Which was exactly my solution to the DNA problem on Rosalind :-)
لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ


Comment on Re: Entering the land of Perl
Select or Download Code
Re^2: Entering the land of Perl
by manbroski (Initiate) on Apr 04, 2013 at 21:51 UTC

    That, sir, is a beauty.

    Anything functional (in the map-reduce sense) makes me quite happy. You have my thanks.

    EDIT: what version is this? 5.16 'use strict' returns all zeros for each count. Does that provide the function return code?

      The shift requires the string as an argument of the script. If you want to read it from a file, you have to use
      $s = <>;
      instead and provide the input file as the argument.
      لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (12)
As of 2014-04-21 16:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (496 votes), past polls