home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / perl / 7939 < prev    next >
Encoding:
Text File  |  1993-01-22  |  2.8 KB  |  87 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!gatech!concert!uvaarpa!mmdf
  3. From: "G.W.Bultman" <bultman@dgw.rws.nl>
  4. Subject: Multiple matches & spaces in optionstring
  5. Message-ID: <1993Jan22.085428.20597@uvaarpa.Virginia.EDU>
  6. Sender: mmdf@uvaarpa.Virginia.EDU (Mail System)
  7. Reply-To: bultman@dgw.rws.nl
  8. Organization: The Internet
  9. Date: Fri, 22 Jan 1993 08:54:28 GMT
  10. Lines: 75
  11.  
  12. Hi, 
  13.  
  14. I have a simple script that extracts information from the World Factbook
  15. (1991) as made available by project Gutenberg. 
  16.  
  17. The file is organised as follows:
  18.  
  19. ::     Some tags useful for searching the factbook are as follows:
  20. :: 
  21. ::          _@_   the first three characters in each country heading;
  22. ::                   for example, _@_Afghanistan
  23. ::                                _@_Albania
  24. ::          _*_   the first three characters in each section heading;
  25. ::                   for example, _*_Geography
  26. ::                                _*_People
  27. ::          _#_   the first three characters in each individual entry;
  28. ::                   for example, _#_Total area
  29. ::                                _#_Comparative area
  30. ::          _%_   the first three characters in the first line following
  31. ::                   the end of a country section or an appendix
  32.  
  33. I have a simple script that extract certain categories from the file
  34. (Currency & Exchange rate). 
  35. I would like to modify this scripts so that it takes as an option 
  36. one or more countries to do this for and one or more categories. 
  37. I'm thinking of an interface such as: 
  38.  
  39. worldfact -c Netherlands,Belgium,Albania -e Currency,Total area
  40.  
  41. which would give me the data on Currency and Total area for the 3 countries 
  42. mentioned.
  43.  
  44. My first problem is that I'm not sure how to store these multiple entries 
  45. (maybe in an array?) and how to match against them. 
  46. My second problem is that I do not know how to handle spaces (such as in 
  47. <Total area> when passing options to the script.
  48.  
  49. The script I use so far is included below.
  50.  
  51. :: #!/usr/local/bin/perl
  52. :: 
  53. :: $printing = 0;
  54. :: 
  55. :: while ( <> ) 
  56. ::      {
  57. ::      chop;
  58. ::      if ( /^_\@_([^\s]+)\s*$/ )
  59. ::           {
  60. ::           print $_ . "\n"; 
  61. ::           }
  62. :: 
  63. ::      if ( /^_#_/ ) 
  64. ::           {
  65. ::           $printing = 0;
  66. ::           $printing++ if /^_#_Currency:/;
  67. ::           $printing++ if /^_#_Exchange rates:/;
  68. ::           }
  69. ::      
  70. ::      if ( $printing > 0 ) 
  71. ::           {
  72. ::           print $_ . "\n";
  73. ::           }         
  74. ::      }
  75.      
  76. Any & all help is appreciated,
  77. Gert.
  78.  
  79. --
  80.  
  81.     o                                                                o   
  82.   / | \    Gert Bultman <bultman@dgw.rws.nl>   Koningskade 4       / | \  
  83.  o--o--o   Tidal Waters Division               2596 AA The Hague  o--o--o 
  84.   \ | /    Rijkswaterstaat                     The Netherlands     \ | /  
  85.     o                                                                o    
  86.  
  87.