diff options
| author | lakpatashi <lakpatashi@gmail.com> | 2021-05-10 13:34:52 +0530 |
|---|---|---|
| committer | lakpatashi <lakpatashi@gmail.com> | 2021-05-10 13:34:52 +0530 |
| commit | 68c882dadc90c61bb61c2ba47482a9afc8552f22 (patch) | |
| tree | 6ef11df145fe3343327411443beef768edb67227 | |
| parent | 2d54689b0c64905cfe62c534d22a9b6b84141fbf (diff) | |
| download | perlweeklychallenge-club-68c882dadc90c61bb61c2ba47482a9afc8552f22.tar.gz perlweeklychallenge-club-68c882dadc90c61bb61c2ba47482a9afc8552f22.tar.bz2 perlweeklychallenge-club-68c882dadc90c61bb61c2ba47482a9afc8552f22.zip | |
Finished challenge-019 ch-1 only with perl
| -rw-r--r-- | challenge-019/lakpatashi/README | 1 | ||||
| -rwxr-xr-x | challenge-019/lakpatashi/perl/ch-2.pl | 24 |
2 files changed, 25 insertions, 0 deletions
diff --git a/challenge-019/lakpatashi/README b/challenge-019/lakpatashi/README new file mode 100644 index 0000000000..bc153bd576 --- /dev/null +++ b/challenge-019/lakpatashi/README @@ -0,0 +1 @@ +Solution by lakpatashi diff --git a/challenge-019/lakpatashi/perl/ch-2.pl b/challenge-019/lakpatashi/perl/ch-2.pl new file mode 100755 index 0000000000..ed7e298875 --- /dev/null +++ b/challenge-019/lakpatashi/perl/ch-2.pl @@ -0,0 +1,24 @@ +#!/usr/bin/perl + +use warnings; +use strict; +use Data::Dumper; +use List::Util qw(sum); +use feature qw(switch); + +#part 2 +my $str = "This is random string to be formatted and wrap to given length"; +my $LineWidth = 10; +my $SpaceLeft = $LineWidth; +my $SpaceWidth = 1; + +for my $word (split / /,$str){ + if ( length($word) + $SpaceWidth > $SpaceLeft ){ + #insert line break before Word in Text + print "\n$word"; + $SpaceLeft = $LineWidth - length($word); + }else{ + print " $word"; + $SpaceLeft -= (length($word) + $SpaceWidth); + } +} |
