Skip to content

Instantly share code, notes, and snippets.

@raiph
Created December 11, 2022 13:20
Show Gist options
  • Save raiph/210f7a14c18e44407bd92e1e9f62f589 to your computer and use it in GitHub Desktop.
Save raiph/210f7a14c18e44407bd92e1e9f62f589 to your computer and use it in GitHub Desktop.
ChatGPT answer on StackOverflow to a Raku question (that of course wasted everyone's time, even if it was easy to spot)

To pipe in a string to a Raku program, you can use the echo command to output the string and pipe it to the Raku program. For example, if your Raku program is called my_program.raku, you can use the following command:

echo "my string" | raku my_program.raku

Alternatively, you can pass the string as an argument to the Raku program by using the -e option with the echo command, like this:

echo -e "my string" | raku my_program.raku

This will pass the string "my string" to the Raku program, which you can then access using the @*ARGS array variable. For example, you can print the string using the following code in your Raku program:

# Print the first argument passed to the program
say @*ARGS[0];

You can also use the $*IN variable to read from the standard input stream in a Raku program, like this:

# Read a line from the standard input stream
my $line = $*IN.get;

# Print the line that was read
say $line;

In this case, you don't need to use the echo command to pipe the string to the Raku program. Instead, you can simply use the | (pipe) operator to redirect the output of the echo command to the Raku program, like this:

echo "my string" | raku my_program.raku

The Raku program will then read the string from the standard input stream and print it using the say function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment