in reply to Can we do without auxiliary variable here?
Another one:
sub prefix_print { print map $_ ne "\n" ? "$prefix$_":$_, split /(\n)/, join '',@_; }
The split /(\n)/ also returns the newlines, so you can prefix anything that isn't a newline, while passing the newlines through as is. This way, you don't have to take care of boundary cases like trailing newline and initial prefix.
|
|---|