Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Converting short perl script to php

Posted on 2006-11-06
2
Medium Priority
?
238 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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…
The viewer will learn how to dynamically set the form action using jQuery.

721 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