+ Reply to Thread
Results 1 to 4 of 4

Thread: Perl - string is in array question

  1. #1
    chienbinhbattu
    Guest

    Perl - string is in array question

    This is dead simple in PHP but I'm doing a small script in perl, and simple perl




    Code:

    #I have 2 arrays with very similar content
    #@pids
    #@outs
    #I need to know which values don't exist in the other array

    print "Orphaned Processes\n";
    foreach $pid (@pids){
    #$found = grep/$pid/@outs;
    $found = grep(/$pid/, @outs);
    if ($found > 0)
    {
    print "proc: $pid\n";
    }
    }

    print "Orphaned Out Files\n";
    foreach $thisout (@outs){
    $found = grep(/$thisout/, @pids);
    if ($found > 0)
    {
    print "$thisout\n";
    }
    }

    The grep doesn't seem to be working. Any ideas?



    thanks



    Sarah

    More:


  2. #2
    OffenoDeevecy
    Guest

    I found this page: http://www.comptechdoc.org/independe...unctarray.html



    Is exists the right thing to use? Performance isn't really an issue.

  3. #3
    bachkim257
    Guest

    I havn't had to use perl for a *long* time, but you might want to try this: (Not tested but should work)


    Code:

    my $found = 0;
    # Loop thru @pids
    print "Orphaned processes \n";
    foreach $pid(@pids){
    $found = 0;
    # For each $pid, loop thru all @outs
    foreach $out(@outs){
    # Does $out contain $pid ?
    if ($out =~ /$pid/) {
    # $out contains $pid
    $found = 1;
    } else {
    # $out does not contain $pid
    }
    }
    if ($found == 0) {
    print "$pid \n";
    }
    }


+ Reply to Thread

Similar Threads

  1. highlighting an array of keywords
    Code: Function Highlight(strText, strFind) '// Check that at least one search term has been submitted If Len(strFind) < 1 Then '// no...
  2. Anyone know Perl
    Hi anyone know what causes this to happen when i click on it i see double headers its from my forum post I asked the owner from who i...
  3. Anyone here program in perl?
    If so, I have a small snippet of code I need to get modified and I don't have a clue as to how to make the change. Please pm if you have a few...
  4. Newbie Perl Question #2
    Ok, probably not a huge difference between and this but I'll start a new thread anyway. I have a site hosted locally which doesn't allow cron...
  5. Newbie Perl question
    My webhost has cPanel which only accepts Perl scripts, aargh So I'm using this to get Perl to call my real PHP scripts which do all the work ...

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Automatic Translations (Powered by Powered by Google):
Afrikaans Albanian Arabic Belarusian Bulgarian Catalan Chinese Croatian Czech Danish Dutch English Estonian Filipino Finnish French Galician German Greek Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Taiwanese Thai Turkish Ukrainian Vietnamese Welsh Yiddish