Advertisement
Guest User

Untitled

a guest
Dec 26th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.92 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings qw(FATAL all);
  5.  
  6. use constant MSG_FMT => 'CQ<';
  7. use constant MSG_SIZE => length pack(MSG_FMT, 0, 0);
  8.  
  9. scalar @ARGV or die "Usage: $0 type [args]\n";
  10. my $type = shift @ARGV;
  11.  
  12. if ($type == 0) {
  13.   scalar @ARGV or die "fibonacci: n not specified\n";
  14.   my $n = shift @ARGV;
  15.   my $msg = pack 'CQ<Q<', $type, 8, $n;
  16.   print STDERR "fibonacci n=$n\n";
  17.   print $msg;
  18. }
  19. if ($type == 1) {
  20.   scalar @ARGV or die "pow: n not specified\n";
  21.   my $n = shift @ARGV;
  22.   my $msg = pack 'CQ<Q<', $type, 8, $n;
  23.   print STDERR "pow n=$n\n";
  24.   print $msg;
  25. }
  26. if ($type == 2) {
  27.   scalar @ARGV or die "bubble-sort: len not specified\n";
  28.   my $len = scalar @ARGV;
  29.   print STDERR "bubble-sort len=$len";
  30.  
  31.   my $msg = pack 'CQ<', $type, $len * 8;
  32.   print $msg;
  33.  
  34.   while (@ARGV) {
  35.     my $num = shift @ARGV;
  36.     print STDERR " $num";
  37.     print pack 'Q<', $num;
  38.   }
  39.   print STDERR "\n";
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement