Advertisement
cd62131

split input without function split

Dec 8th, 2018
488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 0.38 KB | None | 0 0
  1. #!/usr/bin/env perl
  2. use strict;
  3. use warnings;
  4. my @ar;
  5. while (<>) {
  6.   chomp;
  7.   my ($i, $j) = (0, 0);
  8.   for (; $i < length; ++$i) {
  9.     my $s = substr $_, $i, 1;
  10.     if ($s eq ' ' || $s eq '.' || $s eq ',') {
  11.       push @ar, substr $_, $j, $i - $j;
  12.       $j = $i + 1;
  13.     }
  14.   }
  15.   if ($i != $j) {
  16.     push @ar, substr $_, $j, $i - $j;
  17.   }
  18. }
  19. print join ' ', @ar;
  20. print "\n";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement