Update: I went with tilly's suggestion to use unpack, however I'm not sure that I did this efficiently. I first did an unpack into 2 columns, then broke it up from there, unpacking each column. This actually runs slower than my regex version, but it is a little nicer on the eyes. Suggestions are very welcome!
#!/usr/bin/env perl use strict; use Text::Soundex; my $PHONE_LIST = "$ENV{HOME}/phone_list"; my %seen; my $cntr; if(@ARGV == 0 || $ARGV[0] eq '-?' || $ARGV[0] eq '-h') { print "\nUsage: $0 <last name> ...\n\n"; exit 1; } open(PL, "$PHONE_LIST") || die "Can't open $PHONE_LIST: $!"; while(<PL>) { foreach my $name (@ARGV) { my $code = soundex($name); my @name_list; undef @name_list; my ($column_one, $column_two) = unpack("a40a40", $_); if($code eq soundex(split(/,/, $column_one))) { @name_list = unpack("a18a5a7", $column_one); } elsif($code eq soundex(split(/,/, $column_two))) { @name_list = unpack("a18a5a7", $column_two); } if(defined(@name_list)) { $seen{$name}++; if(++$cntr == 1) { printf("\n %-24s %-9s %-5s\n ", "Last, First M", "Ext", "Rm#"); print "=" x 40, "\n"; } printf("%-25s %-8d %-5s\n", @name_list); } } } foreach my $name (@ARGV) { if(! exists($seen{$name})) { print "\nNot found: $name"; } } print "\n"; close(PL);

In reply to Re: Need help with regex by BastardOperator
in thread Need help with regex by BastardOperator

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.