SPUG: Correction to Sample Program

Tim Maher/CONSULTIX tim at consultix-inc.com
Wed Sep 22 10:47:53 CDT 1999


>> Message submitted at: Wed Sep 22 08:47:53 PDT 1999
X-Mailer: ELM [version 2.4 PL25]
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Length: 1400      

SPUGers,

As pointed out by a few sharp-eyed participants at last night's
SPUG show, the joining of input lines in the program below needs
to use the TAB character, rather than the NULL string as shown in
last night's version, in converting program input into a scalar.

(I had been modifying the program right up to "showtime",
and as sometimes happens a discrepancy had arisen between the
published version and the one I had actually tested.)

Here's the corrected version:

#! /usr/local/bin/perl -w
# emp_ids2: associate employee surnames with employee-ids  
# This version loads hash directly from matches, without
#	using any intervening variables
# Tim Maher, 6/1/99

# Sample input line:
# Richard Simmons	312-45-8679

$_=join "\t", <>;	# put all input into scalar

# Equivalent to: %emps=( 'key1', 'value1', 'key2', 'value2', etc.)
%emps=/[^\t]+/g;	# returns matches, order interpreted as (key, value)

END{ 
	print "\nEmployee ID of Simmons is: $emps{'Richard Simmons'}\n";
}
*==================================================================*
| Tim Maher, PhD  CEO, Consultix &    (206) 781-UNIX/8649          |
|      Pacific Software Gurus, Inc.   Email: tim at consultix-inc.com |
| "The UNIX/Perl Training Experts"    http://www.consultix-inc.com |
|      FALL SCHEDULE OF PUBLIC UNIX/Perl CLASSES COMING SOON!      |
*==================================================================*

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    POST TO: spug-list at pm.org        PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
        Email to majordomo at pm.org: ACTION spug-list your_address





More information about the spug-list mailing list