home *** CD-ROM | disk | FTP | other *** search
/ Netrunner 2004 October / NETRUNNER0410.ISO / regular / ActivePerl-5.8.4.810-MSWin32-x86.msi / _e2a6cd850c78d7df29c31dfc5cf2c4cf < prev    next >
Encoding:
Text File  |  2004-06-01  |  1.4 KB  |  70 lines

  1. #! /usr/bin/perl -w
  2.  
  3. use Text::Reform qw(form columns);
  4.  
  5. # Easy when data already in columns...
  6.  
  7. @name  = qw(Tom Dick Harry);
  8. @score = qw( 88   54    99);
  9. @time  = qw( 15   13    18);
  10.  
  11. print form
  12. '-----------------------------',   
  13. 'Name             Score   Time',   
  14. '-----------------------------',   
  15. '[[[[[[[[[[[[[[   |||||   ||||',
  16. \@name,          \@score,\@time;
  17.  
  18. print "\n"x2;
  19.  
  20. # Not so easy when data in rows...
  21.  
  22. @data = (
  23.     { name=>'Tom',   score=>88, time=>15 },
  24.     { name=>'Dick',  score=>54, time=>13 },
  25.     { name=>'Harry', score=>99, time=>18 },
  26. );
  27.  
  28.  
  29. # The ugly way...
  30.  
  31. print form
  32. '-----------------------------',   
  33. 'Name             Score   Time',   
  34. '-----------------------------',   
  35. '[[[[[[[[[[[[[[   |||||   ||||',
  36. [map $$_{name},  @data],
  37. [map $$_{score}, @data],
  38. [map $$_{time} , @data];
  39.  
  40. print "\n"x2;
  41.  
  42. # The nice way...
  43.  
  44. print form
  45. '-----------------------------',   
  46. 'Name             Score   Time',   
  47. '-----------------------------',   
  48. '[[[[[[[[[[[[[[   |||||   ||||',
  49. columns qw(name score time), @data;
  50.  
  51.  
  52. @data = (
  53.     [ 15, 'Tom',   88 ],
  54.     [ 13, 'Dick',  54 ],
  55.     [ 18, 'Harry', 99 ],
  56. );
  57.  
  58. print "\n"x2;
  59.  
  60.  
  61. # Works for arrays too, and multiple lists...
  62.  
  63. print form
  64. '--------------------------------------',   
  65. 'Name             Score   Time  | Total',   
  66. '--------------------------------------',   
  67. '[[[[[[[[[[[[[[   |||||   ||||  | |||||',
  68. columns 1,2,0, @data,
  69.         2, @data;
  70.