EchoAngel has asked for the wisdom of the Perl Monks concerning the following question:

Hi Monks, Inside this makefile, I have a variable
asdf = aaa bbbb c or asdf = ddddd ee asdfg
I want to use a single perl command to generate
bbbb_aaa_c or asdfa_ddddd_ee
where this output is based on the length of the longest element to the shortest (if equal then, alphabet order). How to do this?

Replies are listed 'Best First'.
Re: Single Line Perl Command and Makefile
by ccn (Vicar) on Sep 14, 2004 at 18:17 UTC

    perl -0777pe '/asdf = ((?:\w+ ?)+)/ and $_ = join "_", sort {length $b <=> length $b or $a cmp $b } split /\s+/, $1'  makefile

Re: Single Line Perl Command and Makefile
by BUU (Prior) on Sep 15, 2004 at 01:04 UTC
    I've noticed a trend in your paste nodes, where you paste some data and then ask us to do all your work for you. This is rude. You will receive much more help if you tell us *what* you have tried so far and th exact problem you are having with it. Perlmonks is a site devoted to helping people who know how to program perl learn and extend their skills, not to do people's work for them.
Re: Single Line Perl Command and Makefile
by mifflin (Curate) on Sep 14, 2004 at 18:12 UTC
    Here is a quick stab at it (untested)...
    erickn@cosmora01d:/home/erickn/mi> cat x my $asdf = 'ddddd ee asdfg'; my $new = join('_',(sort {length($b) <=> length($a) || $a cmp $b} spli +t /\s/, $asdf)); print "$new\n"; my $asdf = 'aaa bbbb c'; my $new = join('_',(sort {length($b) <=> length($a) || $a cmp $b} spli +t /\s/, $asdf)); print "$new\n"; erickn@cosmora01d:/home/erickn/mi> perl x asdfg_ddddd_ee bbbb_aaa_c
Re: Single Line Perl Command and Makefile
by Anonymous Monk on Sep 14, 2004 at 18:16 UTC