Created
September 7, 2017 13:49
-
-
Save xtetsuji/6c319b9be190dae7d958564e0e2e860d to your computer and use it in GitHub Desktop.
How to write subroutine which gives reference of its argument.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
# chomp2 | |
# Is this chomp? | |
# chomp erases only ONE "\n" on end of scalar. | |
# chomp2 erases ALL continuous "\n" on end of scalar. | |
sub chomp2 (\$) { | |
my $str_ref = shift; | |
warn "chomp2: arg is $str_ref\n"; | |
$$str_ref =~ s/(\n+)\z//; | |
return $1; | |
} | |
my $text = "mogemoge\nfuga\n\n"; | |
chomp2 $text; | |
print qq{"$text"\n}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment