Course of Raku / Objects, I/O, and exceptions / Input and output / Standard streams / Exercises / Note a warning
Solution: Note a warning
Here is a possible solution to the task.
Code
my $value = -3;
note 'Warning: the value is negative' if $value < 0;
say $value.abs;🦋 You can find the source code in the file note-a-warning.raku.
Output
Warning: the value is negative
3Comments
notesends the warning to standard error, and only when the value is actually negative.saysends the real result — the absolute value3— to standard output.Keeping the diagnostic on standard error means it does not pollute the program’s real output: discarding standard error with
2>/dev/nullleaves just the3behind.