perl script

Discussion in 'Programming' started by ssimon171078, Apr 9, 2010.

  1. #1
    i need help to filter result in $link that i need to receive url like :
    "http://website/Registration.aspx?returnUrl= " all another urls need be deleted.

    my perl script:

    
    #!/usr/bin/perl -w
    use HTML::LinkExtor;
    use Data::Dumper;
    $content=0;$line=0;
    open(SALES,"email.txt");
    
    while ($line= <SALES>)
    {
     $content= $line.$content;
    
    }
     close SALES;
    
    my $parser = HTML::LinkExtor->new(); #create LinkExtor object with no callbacks
    $parser->parse($content); #parse content
    my @links = $parser->links; #get list of links
    print Dumper \@links;  #print list of links out.   
    
    Code (markup):

     
    ssimon171078, Apr 9, 2010 IP
  2. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #2
    As with perl, there is more than one way to do it..... a regex inline would be simple enough but depends
    on what you are doing with the urls afterwards.

    #!/usr/bin/perl -w
    use HTML::LinkExtor;
    use Data::Dumper;
    
    $content=0;$line=0;
    my $url ="http://website/Registration.aspx?returnUrl=";
    
    open(SALES,"email.txt");
    
    while ($line= <SALES>)
    {
     $content= $line.$content;
    
    }
     close SALES;
    
    my $parser = HTML::LinkExtor->new(); #create LinkExtor object with no callbacks
    $parser->parse($content); #parse content
    my @links = $parser->links; #get list of links
    
    foreach my $link (@links)
      {
      if(index($url, $link))
        {
        print "success\n";
        }
      }
    Code (markup):
    By the way, you should really "use strict" too.
     
    lukeg32, Apr 10, 2010 IP