SPUG: Dup'ing STDIN from DATA?

Tim Maher/CONSULTIX tim at consultix-inc.com
Thu Mar 15 11:57:50 CST 2001


On Thu, Mar 15, 2001 at 09:43:54AM -0800, Tim Maher/CONSULTIX wrote:
> SPUGsters,
> 
> I'm writing a little program that will eventually read input from
> SDTIN, but initially I want to test it using the DATA filehandle.
> I thought the following would work, but it doesn't; it just reads from
> STDIN.  Anybody know the way to accomplish this?
> 
> #! /usr/bin/perl -wn
> 
> BEGIN {
> 	open STDIN, "<&DATA";	# comment-out after testing
> }
> 
> s/^(.*?:)//;
> defined $1  and  print "Extracted $1\n";
> 
> __DATA__
> Data: right here

For those put off by the AWKisness (-n usage) of the above program,
the following one doesn't work any better:

#! /usr/bin/perl -w

open STDIN, "<&DATA";

while (<>) {	# no arguments provided to script
	<do fun stuff with $_>
}

__DATA__
Stuff here

*==========================================================================*
|  Dr. Tim Maher, CEO, Consultix        (206) 781-UNIX/8649;  ask for FAX# |
|  Email: tim at consultix-inc.com         Web: http://www.consultix-inc.com  |
|  TIM MAHER: Unix/Perl   DAMIAN CONWAY: Adv. Perl   COLIN MEYER: Perl/DBI |
|  *We are currently scheduling On-Site Classes on UNIX and Perl topics!*  |
*==========================================================================*

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/





More information about the spug-list mailing list