Re: use string in "use"
The use function happens at compile time and must take a bareword, but it is functionally equivalent to BEGIN { require Module; Module->import( LIST ); } And the require function allows you to pass a string, but be aware there are lots of differences in behavior when passing a string vs a bareword: https://perldoc.perl.org/functions/require On Mon, Dec 14, 2020, 10:57 Jim Gibson wrote: > I have not used it myself, but the ‘if’ module allows one to load modules > conditionally: > > use if CONDITION, MODULE => ARGUMENTS; > > See ‘perldoc if’ for more details. > > > > On Dec 14, 2020, at 7:23 AM, Gary Stainburn < > gary.stainb...@ringways.co.uk> wrote: > > > > I've written my first re-usable modules in Perl, and all goes well. > However, I want to know if / how I can use a string variable in the 'use' > clause. > > > > In PHP I have a simple system of turning on/off debugging and version > control. Any file *1.html is development version. I then have > > > > $DEBUG=(preg_match('/1.htm/',$_SERVER['REQUEST_URI'])) ? '1' : ''; > > include_once("sql$DEBUG.inc"); > > include_once("security$DEBUG.inc"); > > > > This way I have a live and a development version of every HTML and every > inc file, and putting any one file is simply a case of copying that file > over. > > > > I'm looking to replicate this in Perl. How can I do the following? > > > > #!/usr/bin/perl -w > > > > use warnings; > > use strict; > > > > my $DEBUG=($0=~/1$/) ? '1' : ''; > > use RW::Sql$DEBUG; > > use RW::Docs$DEBUG; > > > > I've found that you can use "require" and pass a path. I understand > that require is run time, while use is compile time. Are there any > down-sides to using require? > > > > -- > > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > > For additional commands, e-mail: beginners-h...@perl.org > > http://learn.perl.org/ > > > > > > Jim Gibson > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > >
Re: threds question with Tk
If nobody responds, please supply a stripped down version of the script that produces the problem. Maybe get rid of use threads; use threads::shared; use IO::Socket::INET; Mike On 12/14/20 7:00 AM, stefano cerbioni wrote: hi guys i have created a script because i want a listbox and inside of them i want visualize a stream data , i understand for do that is necessary use threads first create a stream and second manages a Tk the problem is in Tk listbox appear only one time a data stream why ??, if anyone have some idea is welcome thanks at all this is a my code (perl 5 strawbaerry in windows 10 64bit ) use threads; use threads::shared; use Perl::Tidy; use Tk; use Tk::LabFrame; use Tk::ROText; use strict; use IO::Socket::INET; my$x:shared=1; my$data :shared; my@workerThreads; my@otherThreads; push@workerThreads , threads->create (\&threadSub1) for (1..10); push@otherThreads , threads->create (\&threadSub2) ; $_->join() for@workerThreads ; $_->join() for@otherThreads ; print("$x\n"); subthreadSub2 { my$mw = MainWindow->new ; $mw->geometry( "600x600" ); my$lbox = $mw->Listbox(-height =>500, -width =>500)->pack(); $lbox->insert('end', $data ); MainLoop; } subthreadSub1 { # auto-flush on socket $| = 1; # creating a listening socket my$socket = new IO::Socket::INET ( LocalHost => '127.0.0.1', LocalPort => '23456', Proto => 'tcp', Listen => 5, Reuse => 1 ); die"cannot create socket $!\n"unless$socket; print"server waiting for client connection on port 23456 \n"; while(1) { # waiting for a new client connection my$client_socket = $socket->accept(); # get information about a newly connected client my$client_address = $client_socket->peerhost(); my$client_port = $client_socket->peerport(); print"connection from $client_address:$client_port\n"; # read up to 1024 characters from the connected client #my $data = ""; $client_socket->recv($data, 1024); print"received data: $data\n"; my@data_array = split(/;/,$data); foreach (@data_array) { return"$_\n"; print"$_\n"; } # write response data to the connected client $data = "ok"; $client_socket->send($data); # notify client that response has been sent shutdown($client_socket, 1); } $socket->close(); }