Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Unable to reuse STDIN

by fireblood (Acolyte)
on Jul 05, 2016 at 21:09 UTC ( #1167277=note: print w/replies, xml ) Need Help??


in reply to Unable to reuse STDIN

Hi all, thanks for your replies, I've checked out the Term::ReadLine module and am now close to a solution (still haven't figured out how to suppress the termcap attributes in the prompt yet). Regarding the inquiry from two experts regarding what the big picture is -- what I'm doing is writing a script that I call dir_zip that runs in my department's UNIX (Solaris) environment that compresses old project directories. For each directory, I first use pax to serializes its contents into a single file and then use bzip2 to compress that file. I allow the user to specify any number of target directories on the command line, using any of several different syntaxes:

Usage: The dir_zip script may be invoked using any of the following f +orms: dir_zip (list of directories to be zipped) dir_zip < (name of file containing list of directories to be z +ipped) echo (list of directories to be zipped) | dir_zip cat (name of file containing list of directories to be zipped) + | dir_zip The first and the third form may use wildcard characters, e.g. dir_zip + p08* You can use a file to hold a list of only the directories for which yo +u have update access.

Depending on which form the user chooses I collect the list of target directories either through @ARGV or <STDIN>. Then I loop through them doing a series of checks on each one, e.g. that the user has read permission on the directory, then that the user has write permission on the directory, and finally that there are no nested subdirectories at any level down under the target directory for which the user does not have read access. If all of these checks pass, then I check whether the user is the owner of the target directory. If not, then I add the name of the target directory to an array of directories that the user does own. After the loop has completed examining the list of target directories, I then list the directory or directories that the user does not own and say that if the process continues, the user will become the owner of those directories. Then I prompt for whether or not the user wants to continue.

I could solve the problem by not letting the user identify the target directories through <STDIN> at the beginning, but there are reasons for allowing it. My first version of the script let the user specify the target directory names only via @ARGV, e.g. "dir_zip p08*". But then I realized that in some cases p08* globbed into a list of directories of which one or two might be unreadable by the user. So I updated the script to allow "ls p08* | grep -v p08_unreadable | dir_zip" to enable initial generation of the list from ls and then filtering out of selected individual entries. Being able to do the latter requires pipelining, so I didn't see a way to avoid the use of <STDIN> at the beginning of the script. So then, when <STDIN> or <> needed to be used later to elicit confirmation from the user that it is okay to make him the owner of directories that he currently doesn't own, that's where I ran into the problem.

So it looks as if using the Term::ReadLine module allows me to be able to read the initial directory list from <STDIN> if the user chooses that route, and then still to be able to interact with the user later on.

I greatly appreciate the guidance, thanks much!

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1167277]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2020-04-07 21:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The most amusing oxymoron is:
















    Results (43 votes). Check out past polls.

    Notices?