Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] Need SORT & SUBSTR help please

Expand Messages
  • Rob Biedenharn
    ... @sorted = sort { substr($a,8) cmp substr($b,8) } @Keys The characters of a string are indexed from 0, so the 9th character is at index 8. -Rob Rob
    Message 1 of 4 , Nov 21, 2006
    • 0 Attachment
      On Nov 21, 2006, at 2:36 PM, Paul Archer wrote:

      > 7:25pm, Luinrandir Hernsen wrote:
      >
      >> @Keys = sort {$a cmp $b} substr(@Keys,9,);
      >>
      >> I want to sort an array starting at the 9th character
      >> of each string in the array.
      >> I have a feeling i'm missing a delimiter, maybe????
      >>
      >
      > substr returns a string, not a list--so using on a list (array)
      > isn't going
      > to get you anywhere. You want to use it on the $a and $b variables
      > instead.
      >
      > Paul

      @sorted = sort { substr($a,8) cmp substr($b,8) } @Keys

      The characters of a string are indexed from 0, so the 9th character
      is at index 8.

      -Rob

      Rob Biedenharn http://agileconsultingllc.com
      Rob@...
    • Lou Hernsen
      Ahhh man I acxtually understand what you wrote! I wrote: @Keys = sort {$a cmp $b} substr(@Keys,9,); ... I wrote: Sort is the command and you set the area of
      Message 2 of 4 , Nov 21, 2006
      • 0 Attachment
        Ahhh
        man I acxtually understand what you wrote!
        I wrote:
        @Keys = sort {$a cmp $b} substr(@Keys,9,);
        You wrote:
        > @sorted = sort { substr($a,8) cmp substr($b,8) } @Keys
        I wrote:
        Sort is the command and you set the area of the string to alphabatize in the
        Comparision part of
        the command. I didn't know that could be done.

        Thanks so much... man.. I really see the beauty of it!
        thanks!
        Lou
      Your message has been successfully submitted and would be delivered to recipients shortly.