How to share/export a global variable between two different perl scripts?

前端 未结 3 1455
你的背包
你的背包 2020-12-14 07:08

How do we share or export a global variable between two different perl scripts.

Here is the situation:

first.pl

#!/usr/bin/         


        
3条回答
  •  时光取名叫无心
    2020-12-14 08:10

    They will share global variables, yes. Are you seeing some problem with that?

    Example:

    first.pl:

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    our (@a, @b);
    
    @a = 1..3;
    @b = "a".."c";
    

    second.pl:

    #!/usr/bin/perl
    
    use strict;
    use warnings;
    
    require "first.pl";
    
    our (@a,@b);
    print @a;
    print @b;
    

    Giving:

    $ perl second.pl
    123abc
    

提交回复
热议问题