Advertisement
Guest User

Untitled

a guest
Dec 30th, 2011
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.85 KB | None | 0 0
  1. #! /usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. use Data::Dumper qw( Dumper );
  7.  
  8. sub splitlist(@)
  9. {
  10.   [@_[0 .. int((($#_ % 2 ) ? $#_ : $#_ - 1) / 2)]],  [@_[int(($#_ + 1) / 2) .. $#_]]
  11. }
  12.  
  13.  
  14. my @empty;
  15. my @oneelement = qw( 1 );
  16. my @odd = qw( 1 2 3 4 5 );
  17. my @even = qw( 1 2 3 4 5 6 );
  18.  
  19. print "empty:\n";
  20. my ($f,$s) = splitlist(@empty);
  21. print "first: " . Dumper($f) . "\n";
  22. print "second: " . Dumper($s) . "\n";
  23.  
  24. print "oneelement:\n";
  25. ($f,$s) = splitlist(@oneelement);
  26. print "first: " . Dumper($f) . "\n";
  27. print "second: " . Dumper($s) . "\n";
  28.  
  29. print "odd:\n";
  30. ($f,$s) = splitlist(@odd);
  31. print "first: " . Dumper($f) . "\n";
  32. print "second: " . Dumper($s) . "\n";
  33.  
  34. print "even:\n";
  35. ($f,$s) = splitlist(@even);
  36. print "first: " . Dumper($f) . "\n";
  37. print "second: " . Dumper($s) . "\n";
  38. ~
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement