Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Helping Beginners (continued)

by japhy (Canon)
on Oct 30, 2001 at 07:54 UTC ( #122028=note: print w/replies, xml ) Need Help??

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;
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (1)
As of 2019-08-21 04:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?