in reply to Re: How to find SELECT tag in HTML and print its values?
in thread How to find SELECT tag in HTML and print its values?

$file_name="index.htm"; open FILE, "$file_name" or die "can't read file: $!"; $char = getc FILE; while($char=<MYFILE>) { $pattern1="select class=form"; if(/$pattern1/i)#search for the string { $pattern2="option"; if(/$pattern2/i)#search for the options { $pattern3="value"; if(/$pattern3/i)#search if the options has value associa +ted with it { print $pattern4="/select"; open (MYFILE, ">save.txt") or die "no such file"; ............. .......... }//end first if statement }//end second if statement }//end while

edit (broquaint): added <code> tags

Replies are listed 'Best First'.
Re^3: How to find SELECT tag in HTML and print its values?
by Roy Johnson (Monsignor) on Mar 24, 2004 at 17:58 UTC
    You've really got a lot of nonsense in your code. The getc, for example -- what's that about?

    It looks like you're expecting to find everything on the same line (select class, option, and value). If so, you might as well construct one pattern to extract what you want, rather than doing the nested ifs.

    For real HTML, using the modules that are designed to parse real HTML is the only sensible choice. If this is a learning exercise, you need to get a really clear idea of what you want your program to do, step-by-step, and then review your code to ensure that it is actually doing that.


    The PerlMonk tr/// Advocate
Re: How to find SELECT tag in HTML and print its values?
by Abigail-II (Bishop) on Mar 24, 2004 at 17:20 UTC
    Why do you read a single character from 'index.htm', which you then discard? Where's MYFILE coming from? Why are you opening the same handle you read from in your condition for writing in the body of the while?

    Abigail

Re: Re: Re: How to find SELECT tag in HTML and print its values?
by Jasper (Chaplain) on Mar 24, 2004 at 17:32 UTC
    I know Perl

    You might want to brush up on the basics.