in reply to Re^2: socket checker in multiple hosts for multiple destination
in thread socket checker in multiple hosts for multiple destination

... in Perl 6 you can use a module in the middle of code and it is only valid within that block

Does that mean that Perl6 unloads the module when the block is exited ? ... in which case if there's a second block later on that wants to use the same module then that second block has to load that module all over again ?

Note that in Perl5 you can also require a module in a block of code, such that the module doesn't get loaded until that block is executed ... but once loaded that module stays loaded even after the block is exited.

Cheers,
Rob
  • Comment on Re^3: socket checker in multiple hosts for multiple destination (Perl 6)
  • Download Code

Replies are listed 'Best First'.
Re^4: socket checker in multiple hosts for multiple destination (Perl 6)
by raiph (Deacon) on Feb 16, 2016 at 19:20 UTC
    I don't think Rakudo yet unloads the module in the sense of freeing up the space it takes but it does unload it in the sense the symbols that the module added go away again (become unavailable to non-mop code).

    If multiple blocks want to use the same module then you'll typically `use` that module in an outer scope:

    use foo; # foo's and waldo's symbols available { use bar; # foo's, waldo's, and bar's symbols available } # foo's and waldo's symbols available { use qux; # foo's, waldo's, and qux's symbols available } # foo's and waldo's symbols available use waldo;

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re^4: socket checker in multiple hosts for multiple destination (Perl 6)
by u65 (Chaplain) on Feb 16, 2016 at 00:31 UTC

    I can't say definitively, but I think the module stays loaded and can only be used in the scope where it is used. The gory details are described here.

Re^4: socket checker in multiple hosts for multiple destination (Perl 6)
by Bams (Initiate) on Feb 16, 2016 at 05:19 UTC

    Use of uninitialized value $servername in printf at ./new.pl line 42. This is the error message I am getting when I executed the code after modifying change suggested by "poj" Please help. Any guidance would be greatly appreciated

      Use this basic program to check your input files

      #!/usr/bin/perl use strict; use Data::Dumper; $Data::Dumper::Useqq = 1; if( @ARGV < 2 ) { print "Usage: new.pl source destination\n"; exit; } my $file1 = $ARGV[0]; my $file2 = $ARGV[1]; open my $fh1,'<',$file1 or die "Could not open $file1: $!"; my @src = <$fh1>; chomp(@src); close $fh1; open my $fh2,'<',$file2 or die "Could not open $file2: $!"; my @dest = <$fh2>; chomp(@dest); close $fh2; # check data print Dumper(\@src,\@dest); for my $src (@src){ print "Source [$src]\n"; for my $dest (@dest){ my ($servername, $portnumber) = split ',', $dest; print "Destination [$servername:$portnumber] \n"; } }
      poj

        Hi POJ, Thanks for your response.

        $: cat source.csv 123.com 456.com 789.com $: cat destination.csv bc.com,3080 def.com,4560 $: ./new2.pl source.csv destination.csv $VAR1 = [ "123.com", "456.com", "789.com" ]; $VAR2 = [ "bc.com,3080", "def.com,4560" ]; Source [123.com] Destination [bc.com:3080] Destination [def.com:4560] Source [456.com] Destination [bc.com:3080] Destination [def.com:4560] Source [789.com] Destination [bc.com:3080] Destination [def.com:4560]
        Here is the output of the program you gave . This works fine, the problem occurs when I try to connect to remote server and execute that socket, the result doesn't stop printing. It goes into endless loop.