Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: socket checker in multiple hosts for multiple destination

by u65 (Chaplain)
on Feb 15, 2016 at 16:28 UTC ( #1155267=note: print w/replies, xml ) Need Help??


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

Don't use 'use' in the middle of code

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

Replies are listed 'Best First'.
Re^3: socket checker in multiple hosts for multiple destination (Perl 6)
by syphilis (Bishop) on Feb 15, 2016 at 22:57 UTC
    ... 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
      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.

      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.

      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

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1155267]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (6)
As of 2021-04-11 10:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?