fork download
  1. use warnings;
  2. my @iparray=("the","the");
  3. my @sortedarray=sort(@iparray);
  4. my @oparray;
  5. my $lowerlimit=0;
  6. my $upperlimit;
  7. my $count=0;
  8. my $inc=1;
  9. my $mat=0;
  10. my $matchedstring;
  11. sub splitter
  12. {
  13. if($mat==0)
  14. {
  15. $lowerlimit=$lowerlimit+1;
  16. $count=$lowerlimit;
  17. func();
  18. }
  19. else
  20. {
  21. $matchedstring=substr($sortedarray[$count-1],0,$mat);
  22. my $temp=$upperlimit;
  23. while($temp>=$lowerlimit)
  24. {
  25. $word=substr($sortedarray[$temp],$mat,length($sortedarray[$temp]));
  26. if($word eq "")
  27. {
  28. push @oparray,"\\s";
  29. }
  30. else
  31. {
  32. push @oparray ,$word;
  33. }
  34. $temp--;
  35. }
  36. print @oparray;
  37. if($upperlimit==scalar(@sortedarray))
  38. {
  39. print "All the words are parsed";
  40. last;
  41. }
  42. else
  43. {
  44. $lowerlimit=$upperlimit+1;
  45. $count=$lowerlimit;
  46. $inc=1;
  47. func();
  48. }
  49. }
  50. }
  51. sub func
  52. {
  53. if(($count+1)>(scalar(@sortedarray)))
  54. {
  55. last;
  56. }
  57. $base=substr($sortedarray[$count],0,$inc);
  58. if (def $sortedarray[$count+1])
  59. {
  60. $match=substr($sortedarray[$count+1],0,$inc) ;
  61. }
  62. else
  63. {
  64. $count = $lowerlimit;
  65. $inc++;
  66. func();
  67. }
  68. print("\n",$base," ",$match);
  69. $count++;
  70. if($base ne $match)
  71. {
  72. if(($count-1) == $lowerlimit)
  73. {
  74. $mat=$inc-1;
  75. print $mat;
  76. splitter();
  77. }
  78. else
  79. {
  80. $inc++;
  81. unless (($count-1) == $upperlimit)
  82. {
  83. $count=$lowerlimit;
  84. func();
  85. }
  86. }
  87. }
  88. else
  89. {
  90. $upperlimit=$count;
  91. func();
  92. }
  93. }
  94. func();
  95.  
Runtime error #stdin #stdout 0s 4724KB
stdin
Standard input is empty
stdout
Standard output is empty