Help for this page

Select Code to Download


  1. or download this
    # Do this using GREP
    
    my @people = ('Jacob Smith', 'Michael Brown', 'Joshua Smith', 'Matthew
    Cope');
    @smiths = grep(/smith/i, @people);
    
  2. or download this
    No!
    
    my $first = (grep /smith/i, @people)[0];
    
    But inefficient, because it will grep more than necessary.
    
  3. or download this
    my ( $first) = grep ...;
    
  4. or download this
    my @l = qw( foo bar baz);
    ( my ( $first) = grep /ba/ => @l ) > 1 and warn "not unique\n";
    print "first: $first\n";