Solved

Converting short perl script to php

Posted on 2006-11-06
2
228 Views
Last Modified: 2006-11-18
For a perl script I made a while ago for a highcore table for games, I would like to convert to PHP to hold a database of web addresses for an entirely seperate purpose, but it's still among the same lines. I just changed some text down below from highscore to address.  I'm just curious how I'm going to change a lot of the code.  For instance, chomp and recalling a database from a text file.

#!perl
print "Expires: -1\n";
print "Content-type: text/html\n\n";
$filename = "addresses.txt";
open(DATABASE, $filename);
@addresses = <DATABASE>;
close DATABASE;
print "addresses=";
foreach (@addresses){
      @address_entry = split('-',$_);
      chomp @address_entry[0];
      chomp @address_entry[1];
      print ++$couner . ". ";
      printf "%-9s", @address_entry[1];
      printf "%9i\r", @address_entry[0];
}
exit;




Thanks.
0
Comment
Question by:bostoncybertech
2 Comments
 
LVL 19

Accepted Solution

by:
VoteyDisciple earned 125 total points
ID: 17885385
By a "database" in a text file, this is a '-' delimited file?

How 'bout...

$filename = 'addresses.txt';
$addresses = file($filename);
foreach($addresses as $address) {
    $entries = explode('-', $address);

    // I'm guessing this is what chomp does?  I don't know Perl...
    $entries[0] = trim($entries[0]);
    $entries[0] = trim($entries[0]);

    echo ++$counter . '. ';

    // ... and here I don't know the formatting strings.
}

?>


A partial solution, anyway...
0
 

Author Comment

by:bostoncybertech
ID: 17885594
The dash will seperate the numbers from the words.  It used to hold the score and the persons name.  The "score" numbers eventually will not be usefull, but the list numbers may.  The "names" will be useful because they'll contain addresses instead.  I just have to figure out how a flash movie is going to read from a list, and figure out which address in the list to play, and to write to the list.  That all comes later though..
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now