Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hello,
I am new to perl and I need your help/advise. I have to
do the following:
1. Download a webpage that has currency rates against the
U.S. dollar (I was able to do this successfully).
2. Grep for the countries desired from a list.
3. Strip the sorrounding html tags from the desired name.
4. List and strip the subsequent five lines that have the
data related to that country.

For example,
html-tag html-tagEURhtml-tag html-tag
html-tag html-tagEurope (Euro)html-tag html-tag
html-tag html-tag1.1356html-tag html-tag
html-tag html-tag0.8806html-tag html-tag
html-tag html-tag0.7142html-tag html-tag
html-tag html-tag1.4002html-tag html-tag
html-tag html-tagCANhtml-tag html-tag
html-tag html-tagCanada (Dollar)html-tag html-tag
html-tag html-tag1.5901html-tag html-tag
html-tag html-tag0.6289html-tag html-tag
html-tag html-tag1.0000html-tag html-tag
html-tag html-tag1.0000html-tag html-tag

How do make it so that I pattern match for "EUR",
and get the next 5 lines of data, then strip away
the html tags to make the output look like this:

EUR,1.1356,0.8806
CAN,1.5901,0.6289



Thanks,
bembe0417

Replies are listed 'Best First'.
Re: How to match pattern and next 5 lines?
by Ovid (Cardinal) on Apr 06, 2002 at 17:54 UTC

    Two words: "stepwise refinement."

    I understand that you are having some difficulty figuring this out, but starting from a top-down approach and doing stepwise refinement will allow you to arrive at your answer. Then, if your code does not work, you can post what you have and monks would be much more willing to help. If this sounds unfamiliar, you should read about stepwise refinement in this famous introduction by Niklaus Wirth.

    In the meantime, this kind of looks like a homework problem. My suspicions are aroused.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

      I don't know if it sounds like homework either. This task was one of the first tasks given to me when I started at my current position. They found out I knew perl, handed me some legacy code that was really slow, and said - "Here, fix this, and make it faster."

      I ended up re-writing an intranet application that retrieved stock information since many corporate employees weren't allowed internet access, but they still wanted to know certain, company related stock info (competitors, customers, etc...).

      Companies like Reuters have subscription services, but they are really costly, especially if you aren't using the information for trading.

      As far as content ripping goes, *shrug* I suppose if the anonymonk above was making the data available publically it couldbe a more severe issue, that's for his morals to decide.

      C-.

      I don't know about "homework" but it sounds a lot like content ripping...
Re: How to match pattern and next 5 lines?
by cjf (Parson) on Apr 06, 2002 at 17:55 UTC

    Have a look at HTML::Parser. For more specific help try posting some of your code and making it look a little less like homework :)

      ... or if you don't feel like rolling your own, you can (ab)use the Finance::Currency (alt.) modules. :)

          --k.


Re: How to match pattern and next 5 lines?
by cacharbe (Curate) on Apr 06, 2002 at 22:27 UTC
    All nodes above are excellent ideas. You could also use something that I wrote that "eschewed Finance::Currency::Convert::Yahoo " (as merlyn put it) at: Yahoo Currency Exchange Interface, just to plug my own code.

    C-.