SPUG: Dup'ing STDIN from DATA?

Michael LaGaly lagaly at eskimo.com
Mon May 7 21:41:06 CDT 2001


For the Portability Corner, only the following will work on NT4+Perl 5.005:

#! /usr/bin/perl -w

*STDIN = *DATA ;

# Iterating over <> hangs the script
while (<STDIN>) { # no arguments provided to script
    print "Found: $_";
}


__DATA__
Stuff here

THE FOLLOWING DOES NOT WORK ON NT4/PERL 5.00503:
************************************************
#! /usr/bin/perl -w

# won't hang the script, but won't set STDIN as we want it
open STDIN, "<&DATA";

#doesn't matter how you deal with iteration over STDIN, <> or <STDIN>
while (<STDIN>) { # no arguments provided to script
    print "HERE: $_";
}
************************************************

I'm getting the same results on a Linux SuSE setup with Perl 5.005.03.  We're getting two issues: whether <> works on OS X with Perl Y, and which of two ways of setting STDIN to DATA works on OS X with Perl Y.  
  ----- Original Message ----- 
  From: Lauren Smith 
  To: 'Tim Maher/CONSULTIX' ; spug-list at pm.org 
  Sent: Thursday, March 15, 2001 11:20 AM
  Subject: RE: SPUG: Dup'ing STDIN from DATA?




  > -----Original Message-----
  > From: Tim Maher/CONSULTIX [mailto:tim at consultix-inc.com]
  > Sent: Thursday, March 15, 2001 9:58 AM
  > To: spug-list at pm.org
  > Subject: Re: SPUG: Dup'ing STDIN from DATA?
  > 
  > 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

  Works for me:

  #!perl -w

  open STDIN, "<&DATA";

  while (<STDIN>) { # no arguments provided to script
  s/.*? //;
  print $_;
  }

  __DATA__
  Stuff here

  Output:
  here

  Is Perl making a distinction between "<>" and an explicit "<STDIN>"?

  Lauren

   - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       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/



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/archives/spug-list/attachments/20010507/e652cf42/attachment.htm


More information about the spug-list mailing list