Solved

Converting short perl script to php

Posted on 2006-11-06
2
234 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP Syntax Error 4 32
Could you point a way on how to connect to a remote DB from a MySQL stored function? 3 48
What's wrong with this PDO query? 5 27
MVC - procedural PHP 10 36
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

860 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