Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not pass special variables to subroutines directly #222

Open
KES777 opened this issue May 21, 2022 · 5 comments
Open

Do not pass special variables to subroutines directly #222

KES777 opened this issue May 21, 2022 · 5 comments

Comments

@KES777
Copy link

KES777 commented May 21, 2022

Why:

#!/usr/bin/env perl

sub test {
	'asdf' =~ m/.*/; # This destroys received arguments
	print ">>@_<<\n";

}

my $z =  'abcd';
$z =~ m/(ab)(cd)/;
test( $1, $2 );                # >> <<
test( my $x=$1, my $y=$2 );    # >>ab cd<<

How regular expression could be executed when sub is called? This could occur under debugger. For example some module define sub sub and used regex inside that sub

@perlpunk
Copy link
Collaborator

This is an issue tracker for the perl module YAML.pm.
How is your code related to that?

@perlpunk
Copy link
Collaborator

I have the habit to quote these variables when passing them. I did that in #223 too.
Not sure what you mean with sub sub, though.

@KES777
Copy link
Author

KES777 commented May 22, 2022

@perlpunk I mean this sub: https://perldoc.perl.org/perldebguts#Environment-Variables

{
  package DB;
  sub DB  {}
  sub sub {
     # At this debugger sub 
     # call_something(); # we can call something that uses regex
     'asdf' =~ /.*/; # or use regex directrly. And this will break parameter passed to subroutine
     &$sub
  }
}

@KES777
Copy link
Author

KES777 commented May 22, 2022

Thank you for fixing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants