Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: How can I sort my array numerically on part of the string? (updated)

by tybalt89 (Prior)
on Dec 02, 2020 at 03:17 UTC ( #11124499=note: print w/replies, xml ) Need Help??


in reply to Re^2: How can I sort my array numerically on part of the string? (updated)
in thread How can I sort my array numerically on part of the string?

Here's a capture in list context. Prettier?

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11124461 use warnings; my @list = ( '1,cat', '2,dog', '22,mouse', '11,eel', '001,elk', '13,mi +nk'); my @n; @n[ /(\d+),/ ] .= "$_\n" for @list; print grep defined, @n;

This is why perl is fun :)

  • Comment on Re^3: How can I sort my array numerically on part of the string? (updated)
  • Download Code

Replies are listed 'Best First'.
Re^4: How can I sort my array numerically on part of the string? (updated)
by LanX (Cardinal) on Dec 02, 2020 at 11:06 UTC
    > This is why perl is fun :)

    and so memory efficient ...

    > Prettier?

    nope! :)

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery

      TY guys I learned a lot from your suggestions, and no one made me feel "dumb"... LOVE IT..

      Happy Holidays to all may Karma be your friend..

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (4)
As of 2021-03-04 21:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favorite kind of desktop background is:











    Results (108 votes). Check out past polls.

    Notices?