[11459] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 5058 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 4 20:07:33 1999

Date: Thu, 4 Mar 99 17:00:23 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 4 Mar 1999     Volume: 8 Number: 5058

Today's topics:
    Re: <STDIN> Question (Larry Rosler)
    Re: <STDIN> Question <emschwar@mail.uccs.edu>
    Re: <STDIN> Question <uri@ibnets.com>
    Re: <STDIN> Question (Sean McAfee)
    Re: <STDIN> Question <emschwar@mail.uccs.edu>
        Case of missing cc and re -- a repost asking the correc <m-fuerst@cecer.army.mil>
    Re: Cross Platform DBMs <jeromeo@atrieva.com>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 4 Mar 1999 15:38:35 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: <STDIN> Question
Message-Id: <MPG.1148b959b5fb75c29896e1@nntp.hpl.hp.com>

In article <_vDD2.147$I51.15386@news.shore.net> on Thu, 04 Mar 1999 
22:08:58 GMT, Scratchie <upsetter@ziplink.net> says...
 ...
> I have a program that, in a certain situation, reads a file from STDIN (in
> other words, it's called as 'myscript < myfile').
> 
> Is there a way, once STDIN has been read and stored in an array, to
> "reset" STDIN so I can interact with the user? (a la 'chomp ($response =
> <STDIN>);'). 

Trivial on Windows/DOS, because I know the name of the 'console'.
  
#!/usr/local/bin/perl -w
use strict;

print while <STDIN>; # prints the redirected input file
open STDIN, 'CON' or die "Couldn't open STDIN. $!\n";
print while <STDIN>; # echoes the terminal
__END__

I'm having trouble on Unix, though, because there are many pseudo-files 
named "/dev/tty...".  This C program:

#include <stdio.h>
#include <unistd.h>

main()
{
    char *tty = ttyname(0);
    printf("|%s|\n", tty);
}

prints the name of the attached STDIN tty pseudo-file, *unless* STDIN 
has been redirected, in which case the function returns the null string.

Any other thoughts??? 

-- 
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


------------------------------

Date: 04 Mar 1999 16:56:59 -0700
From: Eric The Read <emschwar@mail.uccs.edu>
Subject: Re: <STDIN> Question
Message-Id: <xkfww0whkqc.fsf@valdemar.col.hp.com>

Scratchie <upsetter@ziplink.net> writes:
> I have a program that, in a certain situation, reads a file from STDIN (in
> other words, it's called as 'myscript < myfile').
> 
> Is there a way, once STDIN has been read and stored in an array, to
> "reset" STDIN so I can interact with the user? (a la 'chomp ($response =
> <STDIN>);'). 

Nope.  By redirecting, myfile *is* stdin.  If you want to interact with
the user, provide a command-line argument, like 'myscript -f myfile', and 
then you can use STDIN to get responses from the user to your heart's
content.

-=Eric


------------------------------

Date: 04 Mar 1999 19:12:07 -0500
From: Uri Guttman <uri@ibnets.com>
To: lr@hpl.hp.com (Larry Rosler)
Subject: Re: <STDIN> Question
Message-Id: <39pv6ohk14.fsf@ibnets.com>

>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:

  LR> In article <_vDD2.147$I51.15386@news.shore.net> on Thu, 04 Mar 1999 
  LR> 22:08:58 GMT, Scratchie <upsetter@ziplink.net> says...
  LR> ...
  >> I have a program that, in a certain situation, reads a file from STDIN (in
  >> other words, it's called as 'myscript < myfile').
  >> 
  >> Is there a way, once STDIN has been read and stored in an array, to
  >> "reset" STDIN so I can interact with the user? (a la 'chomp ($response =
  >> <STDIN>);'). 


  LR> I'm having trouble on Unix, though, because there are many pseudo-files 
  LR> named "/dev/tty...".  This C program:

on (most) unix the device /dev/tty should always be the terminal you are
running on. 

  LR> Any other thoughts??? 

but perl is smarter than you are. this seems to work just fine:

perl -e '@a=<>; print @a; open( STDIN, q(-) ); $l=<>; print "[$l]\n"'

uri

-- 
Uri Guttman                             Hacking Perl for Ironbridge Networks
uri@sysarch.com				uri@ironbridgenetworks.com	


------------------------------

Date: Fri, 05 Mar 1999 00:22:35 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: <STDIN> Question
Message-Id: <ftFD2.10070$Ge3.39450846@news.itd.umich.edu>

In article <_vDD2.147$I51.15386@news.shore.net>,
Scratchie  <upsetter@ziplink.net> wrote:
>I have a program that, in a certain situation, reads a file from STDIN (in
>other words, it's called as 'myscript < myfile').

>Is there a way, once STDIN has been read and stored in an array, to
>"reset" STDIN so I can interact with the user? (a la 'chomp ($response =
><STDIN>);'). 

I don't think you can "reset" STDIN, but if you're on a Unix system you can
reopen it using /dev/tty:

while (<STDIN>) { print }
open(STDIN, "< /dev/tty");
print "Did you like what you saw? ";
chomp($reply = <STDIN>);

-- 
Sean McAfee                                                mcafee@umich.edu
print eval eval eval eval eval eval eval eval eval eval eval eval eval eval
q!q@q#q$q%q^q&q*q-q=q+q|q~q:q? Just Another Perl Hacker ?:~|+=-*&^%$#@!


------------------------------

Date: 04 Mar 1999 17:57:50 -0700
From: Eric The Read <emschwar@mail.uccs.edu>
Subject: Re: <STDIN> Question
Message-Id: <xkfemn4hhwx.fsf@valdemar.col.hp.com>

mcafee@waits.facilities.med.umich.edu (Sean McAfee) writes:
> I don't think you can "reset" STDIN, but if you're on a Unix system you can
> reopen it using /dev/tty:
> 
> while (<STDIN>) { print }
> open(STDIN, "< /dev/tty");
> print "Did you like what you saw? ";
> chomp($reply = <STDIN>);

Note that Bad Things(tm)-- well, the Wrong Thing, anyway--  will happen
if this code is executed in the middle of a program that's being run
without a tty associated with it.  cron is only one example, but I'd
imagine just about anything that works on the same principle would do the 
same.

-=Eric


------------------------------

Date: Thu, 04 Mar 1999 16:58:01 -0600
From: Michael Fuerst <m-fuerst@cecer.army.mil>
Subject: Case of missing cc and re -- a repost asking the correct question.
Message-Id: <36DF0FF8.272D31D3@cecer.army.mil>

*******Question 1
Can someone show me (a new PERL convert)
HOW to RECOGNIZE a a string of comma separated words
 with intervening
spaces, tabs and new lines, form w/i a longer string
(eg a function call or variable declaration)
and put the resulting words into an array?
My interest is learning the intracies of regular expressions.

My attempt below doesn't quite work--and would
like to know where I went wrong.
I obviously am overlooking one or two important principles.
Thanks for any insights you can give me.

# A word must start with a letter or _ and may be surrrounded by
optional white space
$word = '\s*[a-zA-Z_]\w*\s*';
# A word list can be a comma separated list of words or just a word.
# The ?:'s are intended to group w/o filling the array
$wordlist =  "(?:(?:(?:($word),)+($word))|($word))";
# The following puts a zero length string in each of
#   $oo[0] and  $oo[1], and aa into $oo[2]
# I had hoped just to see aa in $oo[0]
@oo  =   'aa' =~ m"$wordlist"smg;
print @oo[0] . " " . length(@oo[0]) . "\n";
print @oo[1] . " " . length(@oo[1]) . "\n";
print @oo[2] . " " . length(@oo[2]) . "\n";
# The following puts aa and bb string in each of
#   $pp[0] and  $pp[1] (as I expected) ,
#   and a zero length string into $pp[2] (I expected
#   pp to have only 2 elements!!)
@pp  =   'aa, bb' =~ m"$wordlist"smg;
print @pp[0] . " " . length(@pp[0]) . "\n";
print @pp[1] . " " . length(@pp[1]) . "\n";
print @pp[2] . " " . length(@pp[2]) . "\n";
# The following puts bb into $qq[0],
#   a space and cc into $qq[1] (both as expected
#   and a zero length string into $qq[2]
# (I expected aa, bb and space cc to be in the the 3 elements of qq
@qq  =   'aa,bb, cc' =~ m"$wordlist"smg;
print @qq[0] . " " . length(@qq[0]) . "\n";
print @qq[1] . " " . length(@qq[1]) . "\n";
print @qq[2] . " " . length(@qq[2]) . "\n";



--
(If this message was posted to a newsgroup,
please reply to both me and the newsgroup.)

Michael Fuerst

Work: Construction Engineering Research Lab
      Box 9005
      Champaign  IL  62826        217-373-7273

Home: 802 N Broadway
      Urbana IL 61801       217-239-5844




------------------------------

Date: Thu, 04 Mar 1999 16:05:35 -0800
From: Jerome O'Neil <jeromeo@atrieva.com>
To: Simeon McAleer <mcaleer@jlab.org>
Subject: Re: Cross Platform DBMs
Message-Id: <36DF1FCF.383F572E@atrieva.com>

Debug::Psychic prognosticates that you are using Any_DBM.  I looks like
it is using sdbm on the Sun and some other dbm (gdmb) on the linux box. 
You need to ensure that they are using the same library. 

Even then, I don't think dbm files are portable between platforms.  I
have problems moving gdbm files from Solaris to SCO and back.

Good Luck!


Simeon McAleer wrote:
> 
> I am trying to use a internal PERL DBM database to record the output of
> some programs I am running. On Sun machines perl database files are
> created in pairs with the file extensions .dir and .pag. On Linux there
> is only one file created with a .db extension. The files created on one
> platform can not be accessed by PERL on the other platform. Does any one
> know how to get around this problem? Thanks in advance.

-- 
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947 
The Atrieva Service: Safe and Easy Online Backup  http://www.atrieva.com


------------------------------

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 5058
**************************************

home help back first fref pref prev next nref lref last post