LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-23-2005, 06:07 AM   #1
jrtayloriv
Member
 
Registered: Jun 2004
Location: Inland NW, US
Distribution: Ubuntu
Posts: 363
Blog Entries: 1

Rep: Reputation: 44
perl: concatenate arrays


pertaining to perl:

I have have two arrays and would like to append the elements of one of them to the end of the other. What is the syntax for this?

Thanks,
jrtayloriv
 
Old 01-23-2005, 06:40 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,373

Rep: Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962Reputation: 1962
push(@array1, @array2)
 
Old 01-23-2005, 07:13 AM   #3
jrtayloriv
Member
 
Registered: Jun 2004
Location: Inland NW, US
Distribution: Ubuntu
Posts: 363
Blog Entries: 1

Original Poster
Rep: Reputation: 44
Question

Thanks, kewpie, that's what I thought I was supposed to do, but I am not getting the results I expected. Basically I am trying to write a script that parses HTML files that are grabbed from URLs listed in a text file for IP addresses and emails, removes all duplicate results and places the results into a text file. Here is my code, can you tell me what I have done wrong?

Code:
#!/usr/bin/perl

#Given a text file containing URLs, this script will extract any IP addresses or email address from said URLs

use LWP::Simple;


print "Enter location of URL list file: ";
chomp($infile=<STDIN>);
open INFILE, $infile
   or die "Could not open file $infile";

print "Enter location at which to create output file: ";
chomp($outfile=<STDIN>);
open OUTFILE, ">$outfile"
   or die "Could not open/create $outfile";

while($url=<INFILE>)
{
   chomp($url);
   $html=get("$url")
      or die "Couldn't open page located at $url";
    
   #find and store IP addresses
   @ips = $html =~ /(\d{1,3}[0-255]\.\d{1,3}[0-255]\.\d{1,3}[0-255]\.\d{1,3}[0-255])/g; 
   
   #find email addresses and store
   @emails = $html =~ /(\w+\@\w+\.\w+)/g;

   push(@allips, @ips);
   push(@allemails, @emails);

}
####remove duplicate array members####

for($i=0; $i<(scalar @allips); $i++)
{
   for ($j=0; $j<(scalar @allips); $j++)
   {
      if ($allips[$i]==$allips[$j] && $i!=$j)
      {
         splice(@allips, $j, 1);
      }
   }
}

####remove duplicate array members####

for($i=0; $i<(scalar @allemails); $i++)
{
   for ($j=0; $j<(scalar @allemails); $j++)
   {
      if ($allemails[$i]==$allemails[$j] && $i!=$j)
      {
         splice(@allemails, $j, 1);
      }
   }
}

####Store data in output file####

print OUTFILE "IP Addresses: \n";
foreach (@allips)
{
   print OUTFILE "$_\n";
}

print OUTFILE "\nEmail Addresses: \n";

foreach (@allemails)
{
   print OUTFILE "$_\n";
}

close(INFILE);
close(OUTFILE);
Thanks a bunch,
jrtayloriv

Last edited by jrtayloriv; 01-23-2005 at 04:34 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PERL : Arrays confusing? fredgt Programming 3 12-19-2004 08:24 AM
merging arrays suing perl pantera Programming 1 06-03-2004 08:51 AM
dereferencing anonymous arrays in Perl coolman0stress Programming 6 10-27-2003 10:17 PM
arrays in perl BBQ_Matt Programming 3 09-23-2003 07:45 AM
Perl question re arrays/variable names Jon- Linux - Software 1 09-19-2003 10:29 AM


All times are GMT -5. The time now is 07:56 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration