Re: find words not in an array
From: mbstevens (NOXwebmasterx_at_xmbstevensx.com)
Date: 03/28/05
- Previous message: Jürgen Exner: "Re: About Encryption Question"
- In reply to: r: "find words not in an array"
- Next in thread: Joe Smith: "Re: find words not in an array"
- Reply: Joe Smith: "Re: find words not in an array"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 28 Mar 2005 07:46:14 GMT
#!/usr/local/bin/perl -w
use strict;
#-----------------------------------------------
# Q: if I have 2 arrays,
# @wordlist and @testlist,
# how can I create a third
# array that contains the words from
# @testlist that are not common to
# @wordlist?
#--------------------------------------------
# A: I like a subroutine version for clarity.
#--------------------------------------------
use subs qw (is_in_wordlist);
my @testlist = ( 'a', 'e', 'i', 'o', 'u');
my @wordlist = ('zot', 'pook', 'e', 'vee', 'u');
my @newlist = ();
#-----------------------------------------
foreach my $t (@testlist) {
if ( !is_in_wordlist($t) )
{push @newlist, $t;}
}
foreach my $n (@newlist)
{print "$n\n";}
#-------------------------------------------
sub
is_in_wordlist {
my $sought = shift;
foreach my $w (@wordlist) {
if ($sought eq $w)
{ return 1; } # found
}
return 0; # not found
}
- Previous message: Jürgen Exner: "Re: About Encryption Question"
- In reply to: r: "find words not in an array"
- Next in thread: Joe Smith: "Re: find words not in an array"
- Reply: Joe Smith: "Re: find words not in an array"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|