RE: TK Listbox problem; need help
From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Daniel Burgaud Sent: Wednesday, May 08, 2013 12:11 AM To: Perl-Win32-Users Subject: TK Listbox problem; need help > Hi, > Below is the script I have. > 1. Listbox is suppose to have 0-99 lines. working > 2. when user clicks on a line, it will highlight the line. working > 3. when user clicks on a particular line, script will display the value of that line to STDout. not working. > What happens is, it prints the value of the previous click!!! > Why? What is wrong? > > Dan. > > > > use strict; > use Tk; > require Tk::BrowseEntry; > require Tk::ROText; > > my $mw = MainWindow->new( -bg=> "#404040", -borderwidth=> 0); > $mw->minsize( 100, 200 ); > > > my $LB = $mw->Scrolled( > "Listbox", > -bg=> "#C0C0C0", > -fg=> '#00', > -relief=> 'raised', > -scrollbars=> 'e', > -cursor=> 'top_left_arrow', > )->pack( -side => 'top', -expand => 1, -fill => 'both', ); > $LB->bind('', sub { DoThis( $LB->get('active') ); } ); > > for (my $x=0; $x<100; $x++) { > $LB->insert('end',$x); > } > > sub DoThis { > my $this = shift; > print $this,"\n"; > } > > MainLoop; > It appears that the button callback is called before the 'active' member has been updated. You would be better off using something like: $LB->bind('', sub { DoThis( $LB->get($LB->curselection())); } ); HTH, Ken ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Isn't there a way to set variables in a loop?
>From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf >Of Rothenmaier, Deane C. >Sent: Friday, January 27, 2012 2:08 PM >To: perl-win32-users@listserv.ActiveState.com >Subject: Isn't there a way to set variables in a loop? > >Gurus, all > >Im sure theres a way to do it using some kind of for, or foreach, loop, but for the life of me, Im not seeing it. What I >want to do is stick the same drive letter/directory path on the front of several filenames. Right now, Im doing it like this: > > $ap_data_file = join '\\', $in_path, $ap_data_file; > $ck_data_file = join '\\', $in_path, $ck_data_file; > $cs_data_file = join '\\', $in_path, $cs_data_file; > $ct_data_file = join '\\', $in_path, $ct_data_file; > $ie_data_file = join '\\', $in_path, $ie_data_file; > $mr_data_file = join '\\', $in_path, $mr_data_file; > $ts_data_file = join '\\', $in_path, $ts_data_file; > >Where $in_path has a value like E:\\. So, for example, $cs_data_file would end up like E:\Training\CS_Values.txt, usw. > >Somebody have a spare moment to show me the light? > >Thanks! >Deane Rothenmaier >Programmer/Analyst IT-StdCfg >Walgreens Corp. >2 Overlook Point #N51022D >MS 6515 >Lincolnshire, IL 60069 >224-542-5150 There are probably many ways to do it. I think setting up a hash might be the way to go: use strict; use warnings; my %fileHash = ( apData => 'Dir1\ap_data.txt', ckData => 'Dir2\ck_data.txt', csData => 'Dir3\cs_data.txt', ); my $in_path = 'E:'; foreach my $type ( keys %fileHash ) { $fileHash{$type} = "$in_path\\$fileHash{$type}"; print "$fileHash{$type}\n"; } - You can always loop over the variables: Use strict; Use warnings; my $ap_data_file = 'Dir1\ap_data.txt'; my $ck_data_file = 'Dir2\ck_data.txt'; my $cs_data_file = 'Dir3\cs_data.txt'; foreach my $file ( $ap_data_file, $ck_data_file, $cs_data_file ) { $file ="$in_path\\$file"; print "$file\n"; } print $ap_data_file . "\n"; -- You could just store the names in an array, but I'm assuming you need to access a specific file at some point. HTH, Ken ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: File::Find::Rule problem
> -Original Message- > From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl- > win32-users-boun...@listserv.activestate.com] On Behalf Of Brian Raven > Sent: Tuesday, December 13, 2011 8:36 AM > To: perl-win32-users@listserv.ActiveState.com > Subject: RE: File::Find::Rule problem > > > -Original Message- > > From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl- > > win32-users-boun...@listserv.activestate.com] On Behalf Of Ken Slater > > Sent: 13 December 2011 12:57 > > To: arvinport...@lycos.com; perl-win32-users@listserv.ActiveState.com > > Subject: RE: File::Find::Rule problem > > > > > -Original Message- > > > From: perl-win32-users-boun...@listserv.activestate.com > > > [mailto:perl- win32-users-boun...@listserv.activestate.com] On > > > Behalf Of arvinport...@lycos.com > > > Sent: Friday, December 09, 2011 4:33 PM > > > To: perl-win32-users@listserv.ActiveState.com > > > Subject: File::Find::Rule problem > > > > > > I have a real head scratcher trying to exclude directories with > > > File::Find:Rule version 0.32. > > > > > > I have made a small test directory on my Windows XP machine with > the > > > following two files: > > > > > > D:\My Documents\projects\dave\test\log.txt > > > D:\My Documents\projects\dave\test\84_33 (Kland, Dan)\test.pl > > > > > > I want to exclude the Kland directory and just return log.txt (I > > > know I can set the depth of the find - this is just an illustrative > > problem > > > for a much larger directory structure). > > > > > > Here is my test program: > > > > > > use File::Find::Rule; > > > use strict 'vars'; > > > > > > my $rule = new File::Find::Rule (); my @exclude = (qr/Kland, > Dan/); > > > $rule->or( > > >$rule->new->directory->name(@exclude)->prune->discard, > > >$rule->new > > > ); > > > > > > my @files = $rule->file->in('D:\My Documents\projects\dave\test'); > > > > > > foreach my $file (@files) { > > >print STDERR "$file\n"; > > > } > > > > > > It works as it should, only returning log.txt > > > > > > However if I make certain changes to the exclude regex it fails > > (i.e., > > > the program runs fine but returns both files, including test.pl > > > which it should not). > > > > > > This works: my @exclude = (qr/\(Kland, Dan\)/); This works: my > > > @exclude = (qr/84_33/); So does this (with a space at the end): my > > > @exclude = > > > (qr/84_33 /); This does not: my @exclude = (qr/84_33 \(Kland, > > Dan\)/); > > > This doesn't work either (adding a single space in front): my > > @exclude > > > = (qr/ \(Kland, Dan\)/); And this crashes with a lengthy > > > File::Find::Rule compile error: my @exclude = (qr/84_33 \(/); > > > > > > So, it's not the spaces, it's not the parentheses, it's ... > > something. > > > > > > Can anyone see what I'm doing wrong, or at least replicate the > > problem? > > > > > > Arvin > > > > > > This is perl, v5.10.0 built for MSWin32-x86-multi-thread (with 5 > > > registered patches, see perl -V for more detail) > > > > > > Copyright 1987-2007, Larry Wall > > > > > > Binary build 1004 [287188] provided by ActiveState > > > http://www.ActiveState.com Built Sep 3 2008 13:16:37 > > > ___ > > > > Hello, > > I had never used File::Find::Rule before, but I gave it a try. > > ActivePerl 5.8.9 Build 826. > > > > I set up a test with 3 files in the directory hierarchy: > > > > D:/My Documents/projects/dave/test/should-print.txt > > D:/My Documents/projects/dave/test/84-33 (Kland, Dan)/test.pl D:/My > > Documents/projects/dave/test/84-33 Kland, Dan/test2.pl > > > > Then ran the following code: > > > > use strict; > > use warnings; > > > > use File::Find::Rule; > > my $ctr = 1; > > > > print "\n\n== START =\n"; while (my > > $pattern = ) { > >chomp $pattern; > > > >my $rule = new File::Find::Rule (); > > > >my $subctr = 'a'; > >foreach my $modifiedPattern ( qr/\Q$pattern\E/, $pattern ) > >{ > > my @exclude
RE: File::Find::Rule problem
> -Original Message- > From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl- > win32-users-boun...@listserv.activestate.com] On Behalf Of > arvinport...@lycos.com > Sent: Friday, December 09, 2011 4:33 PM > To: perl-win32-users@listserv.ActiveState.com > Subject: File::Find::Rule problem > > I have a real head scratcher trying to exclude directories with > File::Find:Rule version 0.32. > > I have made a small test directory on my Windows XP machine with the > following two files: > > D:\My Documents\projects\dave\test\log.txt > D:\My Documents\projects\dave\test\84_33 (Kland, Dan)\test.pl > > I want to exclude the Kland directory and just return log.txt (I know I > can set the depth of the find - this is just an illustrative problem > for a much larger directory structure). > > Here is my test program: > > use File::Find::Rule; > use strict 'vars'; > > my $rule = new File::Find::Rule (); > my @exclude = (qr/Kland, Dan/); > $rule->or( >$rule->new->directory->name(@exclude)->prune->discard, >$rule->new > ); > > my @files = $rule->file->in('D:\My Documents\projects\dave\test'); > > foreach my $file (@files) { >print STDERR "$file\n"; > } > > It works as it should, only returning log.txt > > However if I make certain changes to the exclude regex it fails (i.e., > the program runs fine but returns both files, including test.pl which > it should not). > > This works: my @exclude = (qr/\(Kland, Dan\)/); This works: my @exclude > = (qr/84_33/); So does this (with a space at the end): my @exclude = > (qr/84_33 /); This does not: my @exclude = (qr/84_33 \(Kland, Dan\)/); > This doesn't work either (adding a single space in front): my @exclude > = (qr/ \(Kland, Dan\)/); And this crashes with a lengthy > File::Find::Rule compile error: my @exclude = (qr/84_33 \(/); > > So, it's not the spaces, it's not the parentheses, it's ... something. > > Can anyone see what I'm doing wrong, or at least replicate the problem? > > Arvin > > This is perl, v5.10.0 built for MSWin32-x86-multi-thread (with 5 > registered patches, see perl -V for more detail) > > Copyright 1987-2007, Larry Wall > > Binary build 1004 [287188] provided by ActiveState > http://www.ActiveState.com Built Sep 3 2008 13:16:37 > ___ Hello, I had never used File::Find::Rule before, but I gave it a try. ActivePerl 5.8.9 Build 826. I set up a test with 3 files in the directory hierarchy: D:/My Documents/projects/dave/test/should-print.txt D:/My Documents/projects/dave/test/84-33 (Kland, Dan)/test.pl D:/My Documents/projects/dave/test/84-33 Kland, Dan/test2.pl Then ran the following code: use strict; use warnings; use File::Find::Rule; my $ctr = 1; print "\n\n== START =\n"; while (my $pattern = ) { chomp $pattern; my $rule = new File::Find::Rule (); my $subctr = 'a'; foreach my $modifiedPattern ( qr/\Q$pattern\E/, $pattern ) { my @exclude = ($modifiedPattern); print "\n=\n"; print "== $ctr$subctr >>$exclude[0]<<\n\n"; $rule->or( $rule->new->directory->name(@exclude)->prune->discard, $rule->new ); my @files = $rule->file->in('D:/My Documents/projects/dave/test'); foreach my $file (@files) { print "$file\n"; } $subctr++; } $ctr++; } __DATA__ Kland, Dan (Kland, Dan) 84-33 84-33 84-33 (Kland, Dan) 84-33 Kland, Dan 84-32 This produced the output listed below == START = = == 1a >>(?-xism:Kland\,\ Dan)<< D:/My Documents/projects/dave/test/should-print.txt = == 1b >>Kland, Dan<< D:/My Documents/projects/dave/test/should-print.txt = == 2a >>(?-xism:\(Kland\,\ Dan\))<< D:/My Documents/projects/dave/test/should-print.txt = == 2b >>(Kland, Dan)<< D:/My Documents/projects/dave/test/should-print.txt = == 3a >>(?-xism:84\-33)<< D:/My Documents/projects/dave/test/should-print.txt = == 3b >>84-33<< D:/My Documents/projects/dave/test/should-print.txt = == 4a >>(?-xism:84\-33\ )<< D:/My Documents/projects/dave/test/should-print.txt = == 4b >>84-33 << D:/My Documents/projects/dave/test/should-print.txt = == 5a >>(?-xism:84\-33\ \(Kland\,\ Dan\))<< D:/My Documents/projects/dave/test/should-print.txt D:/My Documents/projects/dave/test/84-33 (Kland, Dan)/test.pl D:/My Documents/projects/dave/test/84-33 (Kland, Dan)/test.pl~ = == 5b >>84-33 (Kland, Dan)<< D:/My Documents/projects/dave/test/should-print.
RE: Non-blocking keyboard?
Hi, I also thought of Term::ReadKey and gave it a shot, but it reports that non-blocking mode does not work under windows. Also looked at the 'select' statement, but that appears to only work for sockets under windows. Ken > From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl- > win32-users-boun...@listserv.activestate.com] On Behalf Of JONES, > ROBERT E CTR USAF AETC TTMS/TTMS > Sent: Friday, October 07, 2011 1:06 PM > To: Barry Brevik; perl-win32-users@listserv.activestate.com > Subject: RE: Non-blocking keyboard? > > > You might want to look into the Term::Readkey module. > > > Robert Jones, BSP, BSCS > Keesler AFB > > -Original Message- > From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl- > win32-users-boun...@listserv.activestate.com] On Behalf Of Barry Brevik > Sent: Friday, October 07, 2011 11:46 AM > To: perl-win32-users@listserv.activestate.com > Subject: Non-blocking keyboard? > > I'm writing a program where a process runs in a loop. I want to process > keyboard input without disturbing the main process in the loop. I'm > trying to use the Win32::Console module for this task (see code below), > but the module blocks on the Input statement. > > Is there some way to make this non-blocking, or maybe even use a > different technique entirely that does not block? I tried whipping an > IOCTL statement on it, but I either did it wrong, or it does not work. > > use strict; > use warnings; > use Win32::Console; > > my $STDIN = new Win32::Console(STD_INPUT_HANDLE); > $STDIN->Mode(ENABLE_PROCESSED_INPUT); > > # Un-buffer STDOUT. > select((select(STDOUT), $| = 1)[0]); > > while (1) > { > my @input = $STDIN->Input(); > if (defined $input[0] and $input[0] == 1) > { > if ($input[1]) > { > last if $input[5] == 27; # ESC key. > if ($input[5] == 8) {print "\x08", ' ', "\x08"; next;} # > Backspace key. > print chr($input[5]); > } > } > } > > As an aside, I think we need to get more traffic on this list somehow. > > Barry Brevik ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Help with Win32::Process::Create()
> -Original Message- > From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl- > win32-users-boun...@listserv.activestate.com] On Behalf Of Barry Brevik > Sent: Tuesday, August 23, 2011 2:08 PM > To: perl-win32-users@listserv.ActiveState.com > Subject: Help with Win32::Process::Create() > > I'm working on an app that periodically needs to execute outside > procedures. Ideally, I want to launch the outside procedure in "fire > and > forget" mode; that is, I do not want to wait for the outside process to > terminate. > > I ALREADY HAVE some code that does this (see below). My question is- is > there a way to periodically poll the outside process to determine if it > is still running? I've tried a few things already and none of them > work. > > = the code = > use strict; > use warnings; > use Win32::Process; > > # Parameters for the Win32::Process::Create function: > # > # Process This is an empty string that will receive > #a process ID used to address the child process. > #Returns a string that looks like this: > #"Win32::Process=SCALAR(0x235478)". > # > # fullPath The full path to the program including the > #program name and extension. Can be UNC. > # > # newArg The name of the program itself with an extension, > #but no path. Also, command line arguments go here. > # > # inheritHndls Should the child process inherit the parent's file > handles? > # > # flagsx OR'd combination of the flags listed above. > # > # dirx Startup directory for the child process. > # > my $process = ''; > my $dirx = '.'; > my $inheritHndls = 0; > my $newArg = 'notepad.exe'; > my $fullPath = "c:\\windows\\system32\\$newArg"; > my $flagsx = DETACHED_PROCESS | NORMAL_PRIORITY_CLASS; > > if (my $spawnhndl = Win32::Process::Create($process, $fullPath, > $newArg, > $inheritHndls, $flagsx, $dirx)) > { > my $pid = $process->GetProcessID(); > print "Child process returned PID: $pid\n"; > } > else > { > my $errormsg = Win32::FormatMessage(Win32::GetLastError()); > print "Failed to launch process $fullPath: $errormsg\n"; > } > ___ Take a look at the GetExitCode method for Win32::Process. HTH, Ken ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: Determining if a file is open
Hi, Someone may have a better option, but one way to do it would be to use the external program 'handle' available from sysinternals (http://technet.microsoft.com/en-us/sysinternals/bb896655.aspx) . You could see if the file was open using this command - of course you could encounter a race condition if the other process then opens the file before you open it (not sure if this is a possibility or not). Ken -Original Message- From: perl-win32-users-boun...@listserv.activestate.com [mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Jason Lowder Sent: Thursday, February 18, 2010 9:38 AM To: perl-win32-users@listserv.ActiveState.com Subject: Determining if a file is open Hello, Is there anyway to determine if a file is currently open by another process? I want to look at a file that is being generated by another program (sometimes a very large file) and determine when it is finally closed. I see the file attributes for things like size, owner, type etc. but nothing to really determine it's state. Thanks, Jason ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs