in reply to Re: sorting inside specific
in thread sorting inside specific

mutated,
but it should work

Really? AFAICT it isn't even close. What exactly is sort numerically @array supposed to do? At what point are you storing anything in @array? Even after fixing your coding mistakes (strictures and warnings)++ - all I get for output is:

<sep> <sep>

Cheers - L~R

Update: Even your updated code is broke. I preserved your original code in HTML comments. You would see the problem if you had warnings and strictures on
Update 2: Good job! Not exactly the way I would have done it, but it works ;-)

Replies are listed 'Best First'.
Re^3: sorting inside specific
by mutated (Monk) on Sep 10, 2004 at 13:49 UTC
    No worries, I should have tested before I posted in the first place..too early and no morning coffee..sigh..at any rate it works now :P..it's still not as eloquent as your solution but I'm learning...still trying rap my head around the sort function


    daN.
      mutated,
      at any rate it works now

      No it doesn't. I understand that you are learning and am really not trying to beat you up here but before saying something works you should verify the output against the expected results. I have only slightly modified your code, but I left in your case sensitivity mistake SEP vs sep.

      #!/usr/bin/perl use strict; use warnings; my @array; while( <DATA> ) { @array = (@array,$_); if (/<sep>/) { print join '',sort {$a <=> $b} @array; print "<sep>\n"; @array=(); } } print join '',sort {$a <=> $b} @array; __DATA__ <sep> 22 1 3 <sep> 4 2 44
      Here is the output:
      Argument "<sep>\n" isn't numeric in sort at foo.pl line 14, <DATA> lin +e 8. Argument "<sep>\n" isn't numeric in sort at foo.pl line 14, <DATA> lin +e 8. <sep> <sep> 1 2 3 4 22 44

      Cheers - L~R

        with sort.in
        <SEP> 4 99 63 2 1 <SEP> 8 1 12 <SEP> 3 2 1
        my code produces this now
        <SEP> 1 2 4 63 99 <SEP> 1 8 12 <SEP> 1 2 3
        before it also seemed to be sorting it correctly but when I turned on warnings and strict I saw the errors you where talking about:
        Argument "\x{3c}\x{53}..." isn't numeric in sort at foo.pl line 8, <IN +> line 7. Argument "\x{3c}\x{53}..." isn't numeric in sort at foo.pl line 8, <IN +> line 11. Argument "\x{3c}\x{53}..." isn't numeric in sort at foo.pl line 14, <I +N> line 14.
        I appreciate the helpful critisim, thank you.


        daN.