Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: pre-texted <STDIN>

by bart (Canon)
on Apr 04, 2020 at 12:15 UTC ( [id://11115037] : note . print w/replies, xml ) Need Help??

in reply to pre-texted <STDIN>

I'm going to take your title as a question, irrespective of any interpretation of what you really want to achieve. Can you instert extra text, say, from a text file, into the perl input via STDIN? Well, yes you can.

If you set @ARGV to the paths of a number of files, while(<>) will read the files instead of STDIN. But add "-" (that's a minus sign) as a file namen, and perl will also read from normal STDIN.

In summary: the following snippet will read a saved text file and input from STDIN.

@ARGV = ('grocery_list.txt', '-'); while(<>) { print " * $_"; }

This will read from STDIN until you somehow terminate it: read from a finite pipe, or enter ctrl-D or ctrl-Z interactively, depending on the platform.

Replies are listed 'Best First'.
Re^2: pre-texted <STDIN>
by ShainEdge (Novice) on Apr 04, 2020 at 12:39 UTC

    Not exactly. What I want to do, within the perl program, is take a $string, insert it into a STDIN-like function, have it user editable, and then save it back as a $string.

    So, what we are looking at is: $string = "this is a list". Insert that string in a real-time user-editable buffer. Then, have that edited string returned... such as "this is an 'edited' list." now in the $string variable

      So you're talking about the console, not about STDIN.

      The module RL can, theoretically, do that; see insert_test and stuff_char.

      However, I've not yet succeeded in installing it using CPAN on Windows, as it's missing "readline.h", so I'd have to get a port of "readline" (GNU?) to Windows first. MinGW might have it, but that's about all I know.