Results 1 to 7 of 7
  1. #1

    need some perl help

    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

  2. #2
    Join Date
    Jan 2005
    Location
    USA
    Posts
    1,379
    hi,

    Code:
    open(DOMAINS, "<domains.txt") || die "Could not open domains.txt. $!";
    while (<DOMAINS>)
    {
    chomp;
    # Now your domain is in $_
    }
    close(DOMAINS);

  3. #3
    ive replaced
    $DomainName = 'UNITEDARABEMIRATES.COM';


    with

    open(DOMAINS, "<domains.txt") || die "Could not open domains.txt. $!";
    while (<DOMAINS> )
    {
    chomp;
    # Now your domain is in $_
    }
    close(DOMAINS);


    when i run the script it shows
    Warning: DomainName variable not defined!

  4. #4
    Join Date
    Jan 2005
    Location
    USA
    Posts
    1,379
    Hi,

    I gave the script so you can change it around to your needs, it simply showed how you can read the lines from the file. You need some knowledge of perl to make it work though.

  5. #5

    Unhappy


    i know .


    just one question.

    your script doesnt pass the variable $DomainName =

    how do i do that?

    hope you dont mind

  6. #6
    Join Date
    Jan 2005
    Location
    USA
    Posts
    1,379
    Hi,

    In every iteration of the loop, after the line that says chomp, the domain name will be in the variable $_

  7. #7
    Join Date
    Feb 2002
    Location
    Vestal, NY
    Posts
    1,381
    You don't seem to know much (or any) perl, so I will try and simplify things for you. I made a modification to the code to push the domain names into an array called "@DomainName"
    Code:
    my @DomainName;
    open(DOMAINS, "<domains.txt") || die "Could not open domains.txt. $!";
    while (<DOMAINS> )
    {
    chomp;
    # Now your domain is in $_
    push @DomainName, $_;
    }
    close(DOMAINS);
    You can now access the domain name strings like so:
    $DomainName[0] is the first domain name
    $DomainName[1] is the 2nd domain name
    etc
    H4Y Technologies LLC .. Since 2001!!
    "Smarter, Cheaper, Faster" - SMB, Reseller, VPS, Dedicated, Colo hosting done right.

    ZERO PACKETLOSS, ZERO DOWNTIME Dedicated and Colo - USA: IA, CA, NC, OR, NV
    **http://h4y.us** **http://iwfhosting.net**
    Voice: (866)435-5642. *** askus at host4yourself d0t com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •