#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    71
    Rep Power
    14
    Hi !

    What am I trying to do is extracting all six-digit numbers from html and writing them to another array (@numbers). Html document is contained in @messages array.

    This is what I tried to do and it didn't work:
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    sub output_status {
    my (@messages) = @_;
    my $message;
    my @numbers = ("Start");
    foreach $message (@messages) {
    if ($message =~ /d{6}/) {
    $broj = ($message =~ /(d{6})/);
    push (@numbers,$broj);
    }
    }
    print "Content-type: text/htmlnn";
    foreach $line (@numbers) {
    print "Number: $line<BR>";
    }
    }
    [/code]
    Output of this code looks like this:

    Number: Start
    Number: 1


    But there is lots of six-digit numbers on html page which should be printed

    [This message has been edited by Pepe (edited December 09, 2000).]
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2000
    Posts
    0
    Rep Power
    0
    I have found way to go around this by splitting html code to rows and I used </TR> as delimiter. But I have felling that there is much simpler way to do it.
    Now it works like this:
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    sub output_status {
    my (@messages) = @_;
    my $message = $messages[0];
    @pairs = split(/</TR>/, $message);
    my @numbers = ("Start");
    foreach $message (@pairs) {
    if ($message =~ /d{6}/) {
    $message =~ /(d{6})/;
    push (@numbers,$1);
    }
    }
    print "Content-type: text/htmlnn";
    foreach $line (@numbers) {
    print "Number: $line<BR>";
    }
    }

    [/code]
    Could someone please tell me how to extract specific string from one array and push it to another?
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Southern California
    Posts
    73
    Rep Power
    14
    In your code, you're only fetching the first match. You need to use a loop with the 'g' option to fetch all matches:

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    sub output_status {
    my @messages = @_;
    my @numbers = ("Start");

    for (@messages) {
    chomp;
    push(@numbers,$1) while /(d{6})/g;
    }

    print "Content-type: text/htmlnn";
    for (@numbers) {
    print "Number: $_<br>n";
    }
    }
    [/code]


    [This message has been edited by vpopper (edited December 09, 2000).]
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2000
    Posts
    0
    Rep Power
    0
    Thanks. I have one more problem: How do I exclude some 6-digit numbers from that loop. I'm trying to prevent these numbers to be pushed to new array "000000" "666666" "501117" (html color code)

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
    for (@messages) {
    chomp;
    push(@numbers,$1) while /(d{6})/g;
    }

    [/code]


    [This message has been edited by Pepe^ (edited December 10, 2000).]

    [This message has been edited by Pepe^ (edited December 11, 2000).]
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Location
    Southern California
    Posts
    73
    Rep Power
    14
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by Pepe^:
    I have one more problem: How do I exclude some 6-digit numbers from that loop. I'm trying to prevent these numbers to be pushed to new array "000000" "666666" "501117" (unwanted part of html file)[/quote]

    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>

    %skip = map { $_ => 1 } qw(000000 666666 501117);

    for (@messages) {
    chomp;
    push(@numbers,$1) while /(d{6})/g and not $skip{$1};
    }

    [/code]

  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2000
    Posts
    0
    Rep Power
    0
    I changed this code but now nothing gets pushed to @numbers array

IMN logo majestic logo threadwatch logo seochat tools logo