S
Stefan Ram
I want to have the match »something =~ /(.)/g« to be kept in a
separate subroutine, because then, I can keep this at the
start of my script. (I like to collect those parts of my
script that I change often there.)
However, as one can see from the script below, my first attempt
(exhibit 0) does not work, it only prints empty lines.
When I do not use a subroutine (exhibit 1), the behavior is as
wanted: it prints lines with »a«, »b«, and »c«.
Can I put the match »something =~ /(.)/g« in a separate
source code entity that can be moved to the top of my script
(like a subroutine) and still get the behavior of exhibit 1?
#!/usr/bin/perl
#perl 5.8.3
use strict;
use warnings;
my $text = "abc";
# exhibit 0
sub match($){ $_[0] =~ /(.)/g }
while( match( $text ))
{ print $1, "\n"; }
# exhibit 1
while( $text =~ /(.)/g )
{ print $1, "\n"; }
separate subroutine, because then, I can keep this at the
start of my script. (I like to collect those parts of my
script that I change often there.)
However, as one can see from the script below, my first attempt
(exhibit 0) does not work, it only prints empty lines.
When I do not use a subroutine (exhibit 1), the behavior is as
wanted: it prints lines with »a«, »b«, and »c«.
Can I put the match »something =~ /(.)/g« in a separate
source code entity that can be moved to the top of my script
(like a subroutine) and still get the behavior of exhibit 1?
#!/usr/bin/perl
#perl 5.8.3
use strict;
use warnings;
my $text = "abc";
# exhibit 0
sub match($){ $_[0] =~ /(.)/g }
while( match( $text ))
{ print $1, "\n"; }
# exhibit 1
while( $text =~ /(.)/g )
{ print $1, "\n"; }