home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!gatech!concert!uvaarpa!mmdf
- From: "G.W.Bultman" <bultman@dgw.rws.nl>
- Subject: Multiple matches & spaces in optionstring
- Message-ID: <1993Jan22.085428.20597@uvaarpa.Virginia.EDU>
- Sender: mmdf@uvaarpa.Virginia.EDU (Mail System)
- Reply-To: bultman@dgw.rws.nl
- Organization: The Internet
- Date: Fri, 22 Jan 1993 08:54:28 GMT
- Lines: 75
-
- Hi,
-
- I have a simple script that extracts information from the World Factbook
- (1991) as made available by project Gutenberg.
-
- The file is organised as follows:
-
- :: Some tags useful for searching the factbook are as follows:
- ::
- :: _@_ the first three characters in each country heading;
- :: for example, _@_Afghanistan
- :: _@_Albania
- :: _*_ the first three characters in each section heading;
- :: for example, _*_Geography
- :: _*_People
- :: _#_ the first three characters in each individual entry;
- :: for example, _#_Total area
- :: _#_Comparative area
- :: _%_ the first three characters in the first line following
- :: the end of a country section or an appendix
-
- I have a simple script that extract certain categories from the file
- (Currency & Exchange rate).
- I would like to modify this scripts so that it takes as an option
- one or more countries to do this for and one or more categories.
- I'm thinking of an interface such as:
-
- worldfact -c Netherlands,Belgium,Albania -e Currency,Total area
-
- which would give me the data on Currency and Total area for the 3 countries
- mentioned.
-
- My first problem is that I'm not sure how to store these multiple entries
- (maybe in an array?) and how to match against them.
- My second problem is that I do not know how to handle spaces (such as in
- <Total area> when passing options to the script.
-
- The script I use so far is included below.
-
- :: #!/usr/local/bin/perl
- ::
- :: $printing = 0;
- ::
- :: while ( <> )
- :: {
- :: chop;
- :: if ( /^_\@_([^\s]+)\s*$/ )
- :: {
- :: print $_ . "\n";
- :: }
- ::
- :: if ( /^_#_/ )
- :: {
- :: $printing = 0;
- :: $printing++ if /^_#_Currency:/;
- :: $printing++ if /^_#_Exchange rates:/;
- :: }
- ::
- :: if ( $printing > 0 )
- :: {
- :: print $_ . "\n";
- :: }
- :: }
-
- Any & all help is appreciated,
- Gert.
-
- --
-
- o o
- / | \ Gert Bultman <bultman@dgw.rws.nl> Koningskade 4 / | \
- o--o--o Tidal Waters Division 2596 AA The Hague o--o--o
- \ | / Rijkswaterstaat The Netherlands \ | /
- o o
-
-