Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Hello:

Im trying to do a web directory similar to Yellow Pages based in a flat file database.

My script saves info in a folder named COUNTRIES in the following manner.

$Country-$State.txt

OK, now I need to use this data to present it on the browser. I want to make a one column table so each row in the column will be a different Country. Inserted between countries, in the same column I want to display the respective States registered.

Imagine for USA and Mexico would be:

USA
california
new york
florida
MEXICO
cuernavaca
veracruz
yucatan
FRANCE
etc

I went OK as far as the first step (Countries) and ran into trouble when trying to display States as follows:

opendir LOGDIR, "COUNTRIES"; @logfiles = readdir (LOGDIR); closedir (LOGDIR); if (@logfiles) { foreach $filename (@logfiles) { $filename =~ s/.txt/ /; push (@countries, "$filename"); } } foreach $country_data (@countries) { @splitted_country_name = split(/\-/,$country_data ); push (@single_countries, "$splitted_country_name[0]"); } undef %saw; @unique_countries = grep(!$saw{$_}++, @single_countries); print"<table>" foreach $final_country (@unique_countries) { #### Countries like EL_Salvador or Costa_Rica need #### to have underscores removed $no_line_country = "$final_country"; $no_line_country =~ s/_/ /g; foreach $Country_File (@countries) { @splitted_country_name = split(/\-/,$Country_File ); if($final_country =~ /$splitted_country_name[0]/){#1 $final_state = "$splitted_country_name[1]"; $no_line_state = "$final_state"; $no_line_state =~ s/_/ /g; $State_Row ="<tr><td>$no_line_state</td></tr>"; push (@single_states, "$State_Row"); } } print"<tr><td>$no_line_country</td></tr>" print "@single_states"; } print"</table>"

OK the above code displays a single column table with each country in a row and inserts the states of the first country right below it. Then displays the states of the first and second country right below the second country. Then all the states of the first three countries below the third country,etc. I only need to display the states corresponding to each country right below the country name.

What am I doing wrong..??

VirtualWeb


In reply to Problem with push() Function by virtualweb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-24 17:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found