LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   perl: concatenate arrays (https://www.linuxquestions.org/questions/programming-9/perl-concatenate-arrays-281145/)

jrtayloriv 01-23-2005 06:07 AM

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

acid_kewpie 01-23-2005 06:40 AM

push(@array1, @array2)

jrtayloriv 01-23-2005 07:13 AM

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


All times are GMT -5. The time now is 05:44 AM.