Re: Perl-Win32-Users Digest, Vol 63, Issue 12

2011-11-29 Thread Michael Zeng
 why not use File::Find ?

already written better module for you ,


On Wed, Nov 30, 2011 at 4:00 AM, <
perl-win32-users-requ...@listserv.activestate.com> wrote:

> Send Perl-Win32-Users mailing list submissions to
>perl-win32-users@listserv.ActiveState.com
>
> To subscribe or unsubscribe via the World Wide Web, visit
>
> http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
> or, via email, send a message with subject or body 'help' to
>perl-win32-users-requ...@listserv.activestate.com
>
> You can reach the person managing the list at
>perl-win32-users-ow...@listserv.activestate.com
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Perl-Win32-Users digest..."
>
>
> Today's Topics:
>
>   1. Problem with recursive routine (Barry Brevik)
>   2. RE: Problem with recursive routine (Tobias Hoellrich)
>   3. RE: Problem with recursive routine (Barry Brevik)
>
>
> --
>
> Message: 1
> Date: Mon, 28 Nov 2011 15:38:59 -0800
> From: "Barry Brevik" 
> Subject: Problem with recursive routine
> To: "perl Win32-users" 
> Message-ID:
>
>  <995C029A48947048B3280035B3B5433C010747B3@Stellar2k3-Exch.STELLARMICRO.LOCAL
> >
>
> Content-Type: text/plain;   charset="iso-8859-1"
>
> I'm having a problem with a recursive routine that enumerates a directory
> tree and all of its files. It works well, except when it goes down 1 level
> from the top directory, I get this message: Use of uninitialized value in
> addition (+) at test61.pl line 61.
>
> I've been fighting this thing for a couple of hours, and I thought that it
> was a variable scoping problem, but now I'm not so sure.
>
> The code:
>
> use strict;
> use warnings;
> use Cwd;
>
> # Target directory is the current directory. For consistency,
> # convert '\' into '/' and add a trailing '/' to the directory
> # path if it is missing.
> (my $targetdir = cwd()) =~ s/\\/\//g;
> unless ($targetdir =~ /\/$/) {$targetdir .= '/';}
>
> my $prefixFactor = 0;
>
> enumerateDirectory($targetdir, $prefixFactor);
>
> # -
> # This routine enumerates the files in the target directory
> # and traverses the directory tree downwards no matter how
> # far it goes. The routine does this by being RECURSIVE.
> #
> # While processing directories, maintain a prefix factor which
> # controls the indention of the file and directory display.
> #
> sub enumerateDirectory($$)
> {
>  my ($targetdir, $prefixFactor) = @_;
>  my ($filename, $filesize) = ('', 0);
>  my $fileTotalSize = 0;
>
>  if (opendir(my $currentDir, $targetdir))
>  {
>my $nxtfile = '';
>
># Enumerate each file in the current directory.
>#
>while (defined($nxtfile = readdir($currentDir)))
>{
>  # If the current file is a directory, follow this logic.
>  if (-d $nxtfile)
>  {
># If the directory is '.' or '..' then ignore it.
>if ($nxtfile eq '.' || $nxtfile eq '..') {next;}
>
># If the directory name returned by readdir() is
># missing a trailing '/', add it here.
>unless ($nxtfile =~ /\/$/) {$nxtfile .= '/';}
>
># Display the directory name then increment the prefix factor.
>print "\n", ' ' x $prefixFactor, "$nxtfile\n";
>
>$prefixFactor += 2;
>
># Call ourself with the directory name that we are following down.
>enumerateDirectory($targetdir.$nxtfile, $prefixFactor);
>
># Upon return from the recursive call, de-increment the prefix
> factor.
>$prefixFactor -= 2 if $prefixFactor > 0;
>  }
>  else
>  {
># If here, we have an ordinary file. Display it.
>$fileTotalSize += (-s $nxtfile);# THIS IS LINE 61 REFERRED TO
> IN THE ERROR MSG.
>print ' ' x $prefixFactor, $nxtfile, '  ', (-s $nxtfile), "\n";
>  }
>}
>
># After completely enumerating each directory, be sure to
># close the directory entity.
>close $currentDir;
>print "\n", ' ' x $prefixFactor, "$fileTotalSize)\n";
>  }
> }
>
>
> --
>
> Message: 2
> Date: Mon, 28 Nov 2011 15:46:41 -0800
> From: Tobias Hoellrich 
> Subject: RE: Problem with recursive routine
> To: Barry Brevik , perl Win32-users
>
> Message-ID:
><81cb148a36e8b241a8369338aa528ac385ce852...@nambx02.corp.adobe.com>
> Content-Type: text/plain; charset="us-ascii"
>
> You are not changing the directory while traversing. Whenever you access
> "$nxtfile", you'll need to access it as "$targetdir/$nxtfile". So, this
> (among other things):
>$fileTotalSize += (-s $nxtfile);# THIS IS LINE 61 REFERRED TO
> IN THE ERROR MSG.
> Needs to become:
>$fileTotalSize += (-s "$targetdir/$nxtfile");# THIS IS LINE 61
> REFERRED TO IN THE ERROR MSG.
>
> Cheers - Tobias
>
> -Original Message-
> From: perl-

Re: Perl-Win32-Users Digest, Vol 33, Issue 6

2009-04-19 Thread Michael Zeng
please read some documents related to  perl in Win32

use Win32 ;

On 4/20/09, perl-win32-users-requ...@listserv.activestate.com <
perl-win32-users-requ...@listserv.activestate.com> wrote:
>
> Send Perl-Win32-Users mailing list submissions to
> perl-win32-users@listserv.ActiveState.com
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
> or, via email, send a message with subject or body 'help' to
> perl-win32-users-requ...@listserv.activestate.com
>
> You can reach the person managing the list at
> perl-win32-users-ow...@listserv.activestate.com
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Perl-Win32-Users digest..."
>
>
> Today's Topics:
>
>1. perl to dll? (Daniel Burgaud)
>
>
> --
>
> Message: 1
> Date: Sun, 19 Apr 2009 21:49:37 +0800
> From: Daniel Burgaud 
> Subject: perl to dll?
> To: Perl-Win32-Users 
> Message-ID:
> 
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hi All,
>
> I know there is a perl to exe, but what about a perl to dll?
>
> Dan
> -- next part --
> An HTML attachment was scrubbed...
> URL:
> http://listserv.ActiveState.com/pipermail/perl-win32-users/attachments/20090419/6980567f/attachment-0001.html
>
> --
>
> ___
> Perl-Win32-Users mailing list
> Perl-Win32-Users@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
>
> End of Perl-Win32-Users Digest, Vol 33, Issue 6
> ***
>



-- 
Yours Sincerely
Zeng Hong
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Perl-Win32-Users Digest, Vol 33, Issue 4

2009-04-16 Thread Michael Zeng
i think you can chomp the 'return'

chomp ( my $result =  )  , which is a common practice

or you can use Term::ReadKey /  Term::ReadLine  to control the read the
keyboard input more well





On 4/17/09, perl-win32-users-requ...@listserv.activestate.com <
perl-win32-users-requ...@listserv.activestate.com> wrote:
>
> Send Perl-Win32-Users mailing list submissions to
> perl-win32-users@listserv.ActiveState.com
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
> or, via email, send a message with subject or body 'help' to
> perl-win32-users-requ...@listserv.activestate.com
>
> You can reach the person managing the list at
> perl-win32-users-ow...@listserv.activestate.com
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Perl-Win32-Users digest..."
>
>
> Today's Topics:
>
>1. active perl 5.8.8 build 820 inconsistent behavior with $input
>   = ;  (Greg Aiken)
>2. RE: active perl 5.8.8 build 820 inconsistent behavior with
>   $input=;  (Brian Raven)
>
>
> --
>
> Message: 1
> Date: Thu, 16 Apr 2009 08:25:19 -0700
> From: "Greg Aiken" 
> Subject: active perl 5.8.8 build 820 inconsistent behavior with $input
> =   ;
> To: 
> Message-ID:
> 
> Content-Type: text/plain; charset="us-ascii"
>
> I seem to be experiencing inconsistency when I invoke;
>
>
>
> $user_input = ;
>
>
>
> in some programs the behavior is as expected.  at that point in the program
> I type in some input from keyboard then the moment I press the 'enter' key,
> the program flow returns back to the executing Perl program.
>
>
>
> other times, I get a rather unusual response.
>
>
>
> I type in user input from the keyboard and when I press the 'enter' key,
> instead of having program flow return back to the program, the enter key is
> instead OUTPUT TO THE DOS CONSOLE SCREEN and the cursor drops down one line
> on the console screen!  when this happens, the program flow does NOT return
> back to the program and my program just hangs there.
>
>
>
> any explanation for this?
>
>
>
> more importantly, whats the fix?
>
>
>
>
>
>
>
>
>
> today it just happened again.  the relevant block of code is here.
>
>
>
> sub main_loop {
>
>
>
> while (1) {
>
>
>
> system("cls");
>
>
>
> print "Test tcp/ip client/server request/response from
> server x using port 80\n\n
>
> Press:
>
>
>
>'H' to test HTTP request/reponse
>
>'X' to test XML  request/reponse
>
>'Q' to Quit
>
>
>
> Test which application protocol:\n";
>
>
>
> my $ui = ;
>
>
>
> if  ($ui =~ /x/i) {
>
> my $request = &assign_xml_request_from_xml_file;
>
> &attempt_request_response($request);
>
> } elsif ($ui =~ /h/i) {
>
> my $request = &assign_http_request_from_http_file;
>
> &attempt_request_response($request);
>
> } elsif ($ui =~ /q/i){
>
> print "\nProgram Terminated\n";
>
> close $main::socket;
>
> exit;
>
> } else {
>
> next;   #loop
>
> }
>
>
>
> }
>
>
>
> }
>
>
>
>
>
> the full program is here:
>
>
>
>
>
> use IO::Socket;
>
> use Strict;
>
> use Warnings;
>
>
>
> our $socket;
>
>
>
> &open_tcp_socket;
>
> &main_loop;
>
>
>
>
>
>
>
> ### sub routines
> ###
>
>
>
> sub open_tcp_socket {
>
>
>
> $main::socket = new IO::Socket::INET ( Proto  => "tcp",
>
> PeerAddr =>
> "siteundertest.com",
>
> PeerPort => "80",
>
>) or die "Error: Cannot create tcp/ip socket
> ($!)\n";
>
> $main::socket->autoflush(1);
>
> }
>
>
>
>
>
> sub main_loop {
>
> not duplicated in email - this is found above
>
> }
>
>
>
>
>
> sub assign_xml_request_from_xml_file {
>
> open (IN, "xml.request");
>
> undef $/;
>
> my $xml_request = ;
>
> return $xml_request;
>
> }
>
>
>
>
>
> sub assign_http_request_from_http_file {
>
> open (IN, "http.request");
>
> undef $/;
>
> my $http_request = ;
>
> return $http_request;
>
> }
>
>
>
>
>
> sub attempt_request_response {
>
> my $response;
>
> $main::socket->send($_[0]);
>
> $main::socket->recv($response, 8192);
>
> system("cls");
>
> print "Response =\n\n$response";
>
> sleep(10);
>
> }
>
>
>
> -- next part --
> An HTML attachment was scrubbed...
> URL:
> http://listser