The grep command can do the kinds of things you're looking to do.

#!/usr/bin/perl use warnings; use strict; my @isbn = (); my %hash = (); for ( 0 .. 100) { $isbn[$_] = &gen_isbn_13; } push @isbn, "9780523456789"; push @isbn, "9780523412345"; while(my $pattern = <DATA>) { chomp($pattern); print "Testing pattern = $pattern\n"; $hash{$pattern} = &isbn_exists( $pattern, \@isbn ); print "Matches found! ISBN = $_ \n" for ( @{$hash{$pattern}} ); } sub isbn_exists { my $pattern = shift; my $isbn_arrayref = shift; my @answer = grep { /\Q$pattern\E$/ } @{ $isbn_arrayref }; return \@answer; } sub gen_isbn_13 { my $num = "978"; for ( 1 .. 10 ) { my $digit = int(rand(10)); $num .= $digit; } return $num } __DATA__ 12345 97833 97810 97805
One run of the program looks like:

C:\Code>perl isbncheck.pl Testing pattern = 12345 Matches found! ISBN = 9780523412345 Testing pattern = 97833 Testing pattern = 97810 Testing pattern = 97805
Update: More exact match to original pattern

In reply to Re: Possible to use an expression as the hash key with exists? by dwm042
in thread Possible to use an expression as the hash key with exists? by wenD

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.