Help for this page

Select Code to Download


  1. or download this
    @data = (
      'buy 1/23/01 100 12.625 50 25.25',
    ...
      'buy 10/23/01 100 12.625 50 25.25',
      'buy 10/25/01 100 12.625 50 25.25',
    );
    
  2. or download this
    sub get_date {
      my $string = shift;
      my $date = (split ' ', $string)[1];  # second field
      return $date;
    
  3. or download this
    for $line (@data) {
      push @dates, get_date($line);
    }
    
  4. or download this
    for $line (@data) {
      push @dates, [ get_date($line), $line ];
    }
    
  5. or download this
    sub get_date {
      my $string = shift;
    ...
      my ($d, $m, $y) = split '/', $date;
      return sprintf "%02d%02d%02d", $y, $m, $d;
    }
    
  6. or download this
    @dates = sort { $a->[0] <=> $b->[0] } @dates;
    
  7. or download this
    @data = map $_->[1], @dates;
    
  8. or download this
    @data =
      restore(
        sort { $a->[0] <=> $b->[0] }
          extract(@data)
      );
    
  9. or download this
    # extract(@data)
    # becomes
    map [ get_date($_), $_ ], @data
    
  10. or download this
    # restore(...)
    # becomes
    map $_->[1], ...
    
  11. or download this
    @data =
      map $_->[1],
      sort { $a->[0] <=> $b->[0] }
      map [ get_date($_), $_ ],
      @data;
    
  12. or download this
    @data =
      map  { restore($_) }
      sort { ... }
      map  { extract($_) }
      @data;