Re: Regex
The string $body (Library Card: 0240740) does not end in \D (not a number). You might want to add a * to that if you want to make sure it matches strings that _do_ end in \D (ie. \n or \r\n or whatever stuff comes behind the ID) and those that end in the ID itself. - Original Message - From: David Budd [EMAIL PROTECTED] To: perl-win32-users@listserv.ActiveState.com Sent: Tuesday, September 20, 2005 4:57 PM Subject: Regex I thought this was working, but my logs just showed a case where it seems not to do what I want. Why does: $OK_body=($body=~/library\s*?card\D*?(\d{7})\D/i) ; Not become true when $body contains: Library Card: 0240742 Just possibly there's some dodgy html or something in the original that doen't make it through to my logs, but right now I'm perplexed -- David Budd, Applications section, IT Services Kilburn Building, University of Manchester Tel 56033 Email [EMAIL PROTECTED] http://www.its.man.ac.uk/applications ___ 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
Re: references
Why not make it a hash? my $sub = { ref = \test, params = [$sockethandle] }; $sub-{ref}-(@{$sub-{params}}); sub test { my $socket = shift; # ... } - Original Message - From: [EMAIL PROTECTED] To: $Bill Luebkert [EMAIL PROTECTED] Cc: perl-win32-users@listserv.ActiveState.com Sent: Monday, July 25, 2005 8:19 PM Subject: Re: references hello again, hello all, here is a ref/deref problem I need to take a socket handle, convert it to a socket ref, then a scaler string A bit later in the same script, I need to take that scaler string and turn it back to a socket ref, and deref it back to the socket handle. Maybe instead of asking for the way to implement your solution, you should describe the complete problem and see if we can come up with an alternate solution that is a little less convoluted. :) let me clarify my problem. I have a reference of a subroutine. eg. $sub = test; ..deref and execute $sub; ... sub test { my ($sockethandle,$blah...) = @_; ..do something } in order to pass the paramenters, i decided to do this : sub main { my $sub = test|$sockethandle; ($sub,@_) = split(/\|/,$sub); $sub; } if this is to work correctly, I need to take a socket handle, convert it to a socket ref, then a scaler, so i can pass it as a parameter. in order to use the socket later, i have to take the scaler, convert it to the socket ref, then dereference it. Is there an easier way to pass parameters with a subroutine reference? ___ 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
Re: Test if string is a number?
Title: Re: Test if string is a number? How about regexp? /^\-?(\d+\.?\d*|\.\d+)$/ - Original Message - From: Joe Discenza To: Chris Wagner ; perl-win32-users Sent: Thursday, June 30, 2005 4:48 PM Subject: RE: Test if string is a number? Chris Wagner wrote, on Thu 6/30/2005 08:48 : Wow there's been a lot of heavy duty code proposed to do something so: simple. The answer is in how Perl converts between the two.:: print "is a number" if $var eq $var + 0;: print "not a number" if $var ne $var + 0; Except if $var is, say, '0.00'. Then $var + 0 is '0', and won't eq $var. Joe == Joseph P. Discenza, Sr. Programmer/Analyst mailto:[EMAIL PROTECTED] Carleton Inc. http://www.carletoninc.com 574.243.6040 ext. 300 fax: 574.243.6060Providing Financial Solutions and Compliance for over 30 Years ___Perl-Win32-Users mailing listPerl-Win32-Users@listserv.ActiveState.comTo 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
Re: Win32::API and Unicode filenames
Thanks all for the feedback. I've fixed my implementation with a little bit of help with Jan Dubois (he indirectly tipped me off to use a null character at the end of the string, which worked). I've improved my module a bit with some things from Bill Luebkert's implementation. Also, as Jan pointed out to me, it might be smart to have the module also work on Perl filehandle level. Therefor I've also added a perlify() subroutine which seems to work. Thanks all! - Original Message - From: $Bill Luebkert [EMAIL PROTECTED] To: Siebe Tolsma [EMAIL PROTECTED] Sent: Saturday, June 18, 2005 2:42 PM Subject: Re: Win32::API and Unicode filenames Siebe Tolsma wrote: Hello! Considering Perl cannot open files with Unicode filenames by default I decided to create a Win32 module which imports functions like CreateFileW from kernel32.dll and let it write/read files through that. The OS I am writing this for will always be Windows, and in all cases = 2K (so 2K, XP, 2K3, etc). I have no interest in supporting older systems like 9x and NT (yet?). I've already implemented a some of the functions (fopen, fclose, fread, fwrite, fseek) and the basic thing works, but, there is one slight problem/oddity. I have the following code: I'm on XP Pro with FAT32, so my version may not work for you, but it creates the file (with boxes for characters in explorer). use strict; use warnings; use Encode qw (encode decode); use Data::Dumper; $Data::Dumper::Indent=1; $Data::Dumper::Sortkeys=1; our ($CreateFile, $ReadFile, $WriteFile, $CloseHandle); import_APIs (); # currently using the wide version of CreateFile here import_constants (); # filename: e6 8a a5 e7 ba b8 2e 70 6c # filename: . p l my $fname = pack 'H*', 'e68aa5e7bab82e706c'; $fname = decode ('utf8', $fname); # $fname = encode ('UTF-16LE', $fname); $fname = encode ('UTF-16', $fname); # doesn't like UTF-16LE unless path parsing off for fopen # my $path_parsing = '?\\'; # turn off path parsing with this my $path_parsing = ''; my $fh; if ($fh = fopen (\$fh, '', $fname)) { print open '$fname' worked\n; fwrite ($fh, Line 1\nLine 2\nLine 3\n); fclose ($fh); } exit; #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - sub fopen { # $ret = fopen ($fh, $mode, $filename); my $sref = shift; # Reference my $mode = shift; #+ + + my $file = shift; # Filename my %file_perms = ( '' = GENERIC_READ, '' = GENERIC_WRITE, '' = GENERIC_WRITE, '+' = GENERIC_READ | GENERIC_WRITE, '+' = GENERIC_READ | GENERIC_WRITE, '+' = GENERIC_READ | GENERIC_WRITE, ); my $fmode = $file_perms{$mode} || 0; my %file_cr_dist = ( '' = OPEN_EXISTING, '' = CREATE_ALWAYS, '' = OPEN_ALWAYS, '+' = OPEN_EXISTING, '+' = TRUNCATE_EXISTING, '+' = OPEN_ALWAYS, ); my $fcd = $file_cr_dist{$mode}; die Illegal mode '$mode'\n if $fmode = 0; my $lpFileName = pack 'a*', $path_parsing . $file; my $dwDesiredAccess = $fmode; my $dwShareMode = 0; my $lpSecurityAttributes = 0; my $dwCreationDisposition = $fcd; my $dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL; my $hTemplateFile = 0; my $fh = $CreateFile-Call($lpFileName, $dwDesiredAccess, $dwShareMode, $lpSecurityAttributes, $dwCreationDisposition, $dwFlagsAndAttributes, $hTemplateFile); print Data::Dumper-Dump([$fh, $lpFileName, $dwDesiredAccess, $dwCreationDisposition, $dwFlagsAndAttributes], [qw($fh $lpFileName $dwDesiredAccess $dwCreationDisposition $dwFlagsAndAttributes)]) if $debug; if ($fh != INVALID_HANDLE_VALUE) { return $fh; } else { die CreateFile '$file': $! ($^E); } } #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - sub fread { my $fh = shift; my $str = shift; my $lpBuffer = pack 'a*', \000 x 32768; my $nNumberOfBytesToRead = 32768; my $lpNumberOfBytesRead = pack 'L', 0; my $lpOverlapped = 0; print Data::Dumper-Dump([$fh, $nNumberOfBytesToRead, $lpOverlapped], [qw($fh $nNumberOfBytesToRead $lpOverlapped)]) if $debug; my $bytes; my $ret = $ReadFile-Call($fh, $lpBuffer, $nNumberOfBytesToRead, $lpNumberOfBytesRead, $lpOverlapped); if ($ret) { $bytes = unpack 'L', $lpNumberOfBytesRead; print Data::Dumper-Dump([$ret, $bytes], [qw($ret $bytes)]) if $debug; $$str = unpack 'a*', $lpBuffer; return $bytes; } else { warn Error reading file: $! ($^E); return 0; } } #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - sub fwrite { my $fh = shift; my $str = shift; my $lpBuffer = pack 'a*', $str; my $nNumberOfBytesToWrite = length $str; my $lpNumberOfBytesWritten = pack 'L', 0; my $lpOverlapped = 0; print Data::Dumper-Dump([$fh, $lpBuffer, $nNumberOfBytesToWrite, $lpOverlapped], [qw($fh $lpBuffer $nNumberOfBytesToWrite $lpOverlapped)]) if $debug; my $bytes; my $ret = $WriteFile-Call($fh, $lpBuffer, $nNumberOfBytesToWrite, $lpNumberOfBytesWritten, $lpOverlapped); $bytes
Re: Win32::API and Unicode filenames
I've uploaded the modules Win32::Unicode::File and Win32::Unicode::File::Ops, you can get a copy (zipped) right here: http://siebe.bot2k3.net/perl/Win32.zip. The modules themselves are pretty simple, but do the job I needed to do very well. The perlify() code is largely (if not entirely) based on a solution given to me by Jan. There are only a couple of slight adjustments because I already had a normal CreateFile() handle open. I'm still working on it (adding some more things like fstat()). If anyone knows of functions in the Win32 API that I could extend it with, please be my guest and tip me off. Other comments improvements are welcome as well :) Siebe Tolsma BOT2K3 Team [ http://bot2k3.net ] - Original Message - From: $Bill Luebkert [EMAIL PROTECTED] To: Siebe Tolsma [EMAIL PROTECTED] Sent: Saturday, June 18, 2005 4:50 PM Subject: Re: Win32::API and Unicode filenames Siebe Tolsma wrote: Thanks all for the feedback. I've fixed my implementation with a little bit of help with Jan Dubois (he indirectly tipped me off to use a null character at the end of the string, which worked). I've improved my module a bit with some things from Bill Luebkert's implementation. Also, as Jan pointed out to me, it might be smart to have the module also work on Perl filehandle level. Therefor I've also added a perlify() subroutine which seems to work. Give us alook at the 'perlify' code. -- ,-/- __ _ _ $Bill LuebkertMailto:[EMAIL PROTECTED] (_/ / )// // DBE CollectiblesMailto:[EMAIL PROTECTED] / ) /-- o // // Castle of Medieval Myth Magic http://www.todbe.com/ -/-' /___/__/_/_http://dbecoll.tripod.com/ (My Perl/Lakers stuff) ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Win32::API and Unicode filenames
Hello! Considering Perl cannot open files with Unicode filenames by default I decided to create a Win32 module which imports functions like CreateFileW from kernel32.dll and let it write/read files through that. The OS I am writing this for will always be Windows, and in all cases = 2K (so 2K, XP, 2K3, etc). I have no interest in supporting older systems like 9x and NT (yet?). I've already implemented a some of the functions (fopen, fclose, fread, fwrite, fseek)and the basic thing works, but, there is one "slight" problem/oddity. I have the following code: my $fname = pack("H*", "e68aa5e7bab82e706c"); $fname = decode("utf8", $fname); $fname = encode("UTF-16LE", $fname); # Open a file handle to the file :)if(fopen(\my $fh, "", $fname)) { # Fails! This however fails miserably, with an error that it cannot create the file (even though it is UTF-16LE, which is supposely the encoding used on NTFS). But, when I bump in a "print" in the middle it works like a charm (creates the file, then later on in the if() block writes "Hello World!" to it).. This, to me, is very odd because "print" shouldn't do anything with the variable (but when using non-Unicode filenames the print is not required and everything runs OK!): my $fname = pack("H*", "e68aa5e7bab82e706c"); $fname = decode("utf8", $fname); $fname = encode("UTF-16LE", $fname); print "$fname\n"; # Open a file handle to the file :)if(fopen(\my $fh, "", $fname)) { # Works?! Does anyone have a solution to this of the top of their head? I've included the fopen() subroutine for reference. The __mode() subsimply converts the mode types like "" and "" to their corrosponding LONG values. $apis is an array reference filled with the APIs I use (I didn't want the imported functions directly into the modules namespace). Any help would be appreciated! :) Siebe Tolsma BOT2K3 Team [ http://bot2k3.net ] -- sub fopen { # open FILEHANDLE,MODE,EXPR my $sref = shift; # Reference my $mode = shift; #+ + + my $file = shift; # Filename # Check what mode we want.. my $fmode = __mode($mode); # Valid mode? if($fmode 0) { # HANDLE CreateFile( LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, # LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, # HANDLE hTemplateFile ); # Determine how to open (and create if necessary) the filemy $fop = ($mode =~ // ? OPEN_ALWAYS : ($mode =~ // ? OPEN_EXISTING : CREATE_ALWAYS)); # Open the file with the API.. my $fh = $apis-[0]-Call($file, $fmode, 0, 0, $fop, FILE_ATTRIBUTE_NORMAL, 0); if($fh != INVALID_HANDLE_VALUE) { # Bless the object and pass it back return bless($$sref = [$fh,$mode,$fmode], __PACKAGE__); } else { cluck("Could not create handle to file \"$file\"\n"); }} else { cluck("Could not determine mode for opening from \"$mode\"\n"); } return 0;} ___ Perl-Win32-Users mailing list Perl-Win32-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs