homepage Welcome to WebmasterWorld Guest from 54.234.0.85
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
need a perl function
indiandomain

10+ Year Member



 
Msg#: 4124 posted 9:28 pm on Jul 3, 2005 (gmt 0)

hi guys

i have a perl script x.pl with this line,.
when i run this script it registers domains.

$DomainName = 'UNITEDARABEMIRATES.COM';

instead of adding domain in this code.. i want it to pickup from txt file

the txt file will have a list of domains like
dd.com
d3.com
df.com

so when i run the script it shud pick each domain from the txt file and run in a loop.

can someone provide a perl function for this?

thanks
sohail

 

tombola

10+ Year Member



 
Msg#: 4124 posted 5:50 am on Jul 4, 2005 (gmt 0)


$textfile = /path/to/textfile.txt

open (INFILE,"$textfile");
@domains = <INFILE>;
close (INFILE);

foreach $DomainName(@domains) {
[code to register this $DomainName]
}

wruppert

10+ Year Member



 
Msg#: 4124 posted 6:36 am on Jul 4, 2005 (gmt 0)

The previous code leaves a newline at the end of the domain name.

This code strips leading and trailing whitespace (including newlines), skips blank lines, and skips lines whose first non-whitespace character is a pound sign. This allows your input text file to have comments, which I find to be very useful.

It picks up a the file name from the command line, or uses a default if there is none.

[pre]
#!/usr/bin/perl

use strict;
use warnings;

my $textfile = shift ¦¦ "your-default-filename";
open IN, "<", $textfile
or die "Unable to open $textfile $@";

while (<IN>) {
s/^\s+//;
s/\s+$//;
next if /^$/;
next if /^\#/;
my $DomainName = $_;
print "Processing: $DomainName\n";
# process domain name.
}

close IN;
[/pre]

The broken bars above (¦¦) should be the unbroken bars.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved