Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Length of strings in an array

by GrandFather (Saint)
on Sep 20, 2020 at 21:31 UTC ( [id://11121974]=note: print w/replies, xml ) Need Help??


in reply to Length of strings in an array

If you really want a fixed number of entries then this variation of NewWalla's reply may help.

use strict; use warnings; my @seq; # DNA sequence strings for my $count (1 .. 4) { print "Please enter DNA sequence $count:"; push @seq, scalar <STDIN>; } chomp @seq; # Remove line endings on all entries printf "%2d: %s\n", length $_, $_ for sort {length $a <=> length $b} +@seq;

Prints (for some arbitrary input):

Please enter DNA sequence 1:asdf Please enter DNA sequence 2:zvasdfasf Please enter DNA sequence 3:asd Please enter DNA sequence 4:asdfasg 3: asd 4: asdf 7: asdfasg 9: zvasdfasf

You can visit PerlDoc to find out what scalar does.

Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-24 03:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found