Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Converting short perl script to php

Posted on 2006-11-06
2
Medium Priority
?
240 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 375 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
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.
Suggested Courses

886 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