Re: Variable scoping
On 2/19/2010 3:29 PM, Barry Brevik wrote: I was under the impession that when I use the keyword our when declaring a variable, that the variable was then available to subroutines called from the routine that declared the variable. However, the code shown below fails with the following message: Variable $clr is not imported at test5.pl line 17. Global symbol $clr requires explicit package name at test5.pl line 17. What gives? -Barry Brevik === use strict; use warnings; my $color = 'blue'; setColor($color); sub setColor { our $clr = $_[0]; adjustColor(); } sub adjustColor { print $clr\n; } http://perldoc.perl.org/functions/our.html -- In other words, our has the same scoping rules as my, but does not necessarily create a variable. ...so, it's more like a static variable from the c world. I think you might be thinking of 'local'. ___ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Module name with dash (or is it hypen?)
Does anyone know if/how module names with dashes are supported in perl? I just happened to name one of my packages with a dash in it and I wasn't able to load it (use my-package; fails with a strange error). I wonder if there is some special trick to load modules with names like this or is it simply not allowed? Thanks, Mike Ellery ___ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Help with socket timeout
Barry Brevik wrote: I am using Active Perl 5.8.8 on Windows. I am writing an app that opens a TCP socket to a network printer, and then prints barcode labels on it. When the app starts up, it tries to determine if the specific printer is reachable or not. If the printer is on the network and online, then the test goes well. However, if the printer is not reachable for some reason, there is a lengthy timeout before the connect function fails. I would like to make that timeout much shorter than it is, so I wonder if anybody knows how to do that. My sample program is shown below: use Socket; use Warnings; $printPort = 9100; $printHost = '10.18.0.30'; $printProtocol = (getprotobyname('tcp'))[2]; # The print host can be expressed as either a host name, or an # IP address, but it has to end up as a binary IP address. if ($printHost =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/) { $printHost = pack('C4', split(/\./, $printHost)); } else {$printHost = (gethostbyname($printHost))[4];} $printHostReadable = join('.', unpack('C4', $printHost)); print \n\nConnecting to printer $printHostReadable... ; if (socket(BARCODE, AF_INET, SOCK_STREAM, $printProtocol)) { if (connect(BARCODE, pack('Sna4x8', AF_INET, $printPort, $printHost))) { print ok \n\n; close BARCODE; } else { print offline \n\n; } } the IO::Socket package has an optional timeout value for connect (http://perldoc.perl.org/IO/Socket/INET.html). Looking briefly at that module, it seems to be implemented using select. You can try to do something like that yourself...or just use the IO::Socket package and be done with it. -Mike ___ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Help with $_
I would recommend either (1) don't chomp in the first place or (2) just do print $_\n. -Mike Barry Brevik wrote: I am aware that there are a number of Perl operations that will use the system variable $_ as the default variable if one is not supplied. Consider the following snippet (where XMLIN is a previously opened file handle): foreach (XMLIN) { chomp; # Do some stuff to the contents of the line. print; } OK, what I really want to do here is print the (possibly changed) line, AND a CR/LF, but to do that, I have to add a separate print statement like this: print \n; So after all these years, I'm wondering, is there a PERLish way to add a \n in the same line of code that prints the default $_ variable? Barry Brevik ___ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Help with unpack
Have you tried reading it as BigEndian (using the N template)? It kinda looks like BigEndian to me, but I get easily turned around by endianness... -Mike Barry Brevik wrote: I am writing an app which, at a certain point, needs to read a .PNG graphics file. The .PNG file is always small, so I read the whole file (binmode) into a scalar, and this works well. if ($gfilesize = -s $gfilespec) { $GRAPHFILE = $gfilespec; if (open GRAPHFILE) { binmode GRAPHFILE; read GRAPHFILE, $gbuffer, $gfilesize; close GRAPHFILE; The size of the file ($gfilesize) matches the size of the scalar ($gbuffer). This is good. Then I proceed to paw through the buffer. The 1st 8 bytes of the file is a signature, which I read and deal with. Then, the file is a series of chunks where the 1st 4 bytes is a 32 bit number representing the size of the chunk, and the 2nd 4 bytes is an ASCII chunk name, such as IHDR. So, after the signature, the next 8 bytes look like this: 00 00 00 0d 49 48 44 52. . . . I H D R I am trying to decode this with the following: $bufptr = 8; ($chunksize, $chunkname) = unpack L a4, substr($gbuffer, $bufptr, 8); Actually, I've tried every permutation of unpack template that I can think of. The problem is that the 2nd scalar ($chunkname) comes out fine as IHDR, but the first scalar comes out as 218103808 which is wrong as you can see above, it should be 13. I thought I was starting to understand unpack, but what am I doing wrong?? Barry Brevik ___ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Archive::Tar
Has anyone had success using this module with activeperl on windows XP? I've tried to run this simple script: my $tar = Archive::Tar-new(c:/myfile.tgz); $tar-extract(); ..and it just seems to consume 100% of the CPU and never complete. I also tried a plain tar file (not gzipped) and had similar results. Any experience out there with this? Thanks, Mike Ellery ___ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Archive::Tar
Serguei Trouchelle wrote: Michael Ellery wrote: Has anyone had success using this module with activeperl on windows XP? I've tried to run this simple script: my $tar = Archive::Tar-new(c:/myfile.tgz); $tar-extract(); Try this: my $arc = Archive::Tar-new('c:/myfile.tgz', 1); $arc-extract($arc-list_files()); It works for me just fine with most of CPAN tar.gz distributions. hmmm - I tried this and get the same results (so far I've let it run for 20 minutes max). I wonder if this archive is simply too big for this library to handle (it's about 40 mb, which doesn't seem particularly large to me, but who knows...) ___ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Archive::Tar
Serguei Trouchelle wrote: Michael Ellery wrote: my $arc = Archive::Tar-new('c:/myfile.tgz', 1); $arc-extract($arc-list_files()); It works for me just fine with most of CPAN tar.gz distributions. hmmm - I tried this and get the same results (so far I've let it run for 20 minutes max). I wonder if this archive is simply too big for this library to handle (it's about 40 mb, which doesn't seem particularly large to me, but who knows...) Actually, yes. It is PP and it stores file contents in memory. Even 1MB can too big for Archive-Tar's extract if there's a lot of files in it. You may want to try extract_file method, it should be faster, or even tar.exe from MinGW or UnxUtils. okay - thanks for the advice. My archive actually contains a single large file (exe image), so I might still have problems with extract_file. My current fall-back plan is to use 7-zip to extract in a shell command, which seems to work fine. ___ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: help with dispatch array
So, something like: my %functionTable = ( 'string_1' = sub { }, 'string_2' = sub { }, ); invocation via: $functionTable{'string_1'}(ARGLIST); ..is that what you had in mind? -Mike Barry Brevik wrote: I am running Active Perl 5.8.8 on Windows. I'm coding an app right now where it would be advantageous to be able to look up a text string in an array (or hash) and be able to branch to a subroutine that is somehow associated with that string. Am I dreaming, or is this possible? Barry Brevik ___ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Net::XMPP
Anyone know if there is a ppm repo for Net::XMPP ... or perhaps another module with equivalent functionality? I've tried installing this module using the cpan shell, but I just get hanging tests which require me to kill perl. TIA, Mike Ellery ___ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Net::XMPP
sorry, I probably should have given some information about my environment. I'm running ActiveState perl 5.10.0, build 1004. I see that one of the repos for 5.8.x seems to have it. I might consider downrev-ing, but I'd prefer not to (even if it mean manually building the packages...) Michael Ellery wrote: Anyone know if there is a ppm repo for Net::XMPP ... or perhaps another module with equivalent functionality? I've tried installing this module using the cpan shell, but I just get hanging tests which require me to kill perl. TIA, Mike Ellery ___ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
XML::Stream test hanging with ActivePerl 5.10.0 on winxp
Does anyone have experience installing XML::Stream on ActivePerl 5.10 (win32) ? I'm trying to make/install from source and I'm getting hanging tests currently... -Mike Ellery ___ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Working with XML in Perl
Wayne Simmons wrote: Curtis Leach said: Is there a preferred module for use when working with XML in Perl? I use: XML::DOM; snip #save it back. not sure how to do this... honestly haven't done it before. that's the easy part: $maindoc-printToFile($file); -Mike ___ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: UTC time conversion to local time
use DateTime; use DateTime::Format::HTTP; ??? -Mike Bilashi Sahu wrote: Hi, I am trying to convert UTC (In seconds) time to local Time. I will appreciate if anybody has some hints to do this. I have code like this, it does not work properly Here cds_date is in UTC seconds and $cmpn_date is in local time Just comparing if both of the same Thanks, Bilashi #check date sub checkDate () { my ($cds_date, $cmpn_date, $fhlog, $result) = @_; my ($g_day, $g_mon, $g_year, $g_hr, $g_min, $g_sec, $g_msec, $g_ampm) = split(/[-\s\.]/, $cmpn_date);$g_year += 2000; my @abbr = qw( JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC ); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($cds_date); $year += 1900; if($g_ampm eq PM) { $g_hr += 12; } $g_hr = 0 if($g_ampm eq AM $g_hr == 12); $hour = ($hour + 7) if ($g_hr 17);; if ($g_year == $year ($g_day == $mday) ($abbr[$mon] eq $g_mon) $g_hr == $hour $g_min == $min $g_sec == $sec) { #$g_hr == $hour $g_min == $min $g_sec == $sec) { } else { $$result = F; } ___ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: getting undefined subroutine main::sLogData after calling successfully multiple times in script.
Labelle, Marc S wrote: Periodically and *not* at the same point in the program each time the script will fail with an undefined subroutine main::sLogData, this after it's successfully called it 20 or 30 times before... sub sLogData(@) I notice you are using protypes here. Is it possible that coercion is mucking things up in some calling cases? I have zero experience with prototypes in perl, thus I'm only speculating. Have you tried removing the prototype? -Mike ___ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Communication between Perl and VB script
Jenda Krynicky wrote: It's also quite often better to wrap the functionality in a DLL using ActiveState's Perl Development Kit's PerlCtrl. VB is generaly more happy working with COM/OLE objects than with external applications. Another similar approach would be to create a scriplet that contains the perl code you want to make available. Just search for Windows Script Components and you should find enough information to get started. The only complaint I have about WSCs is that errors are not reported via COM exceptions, but rather as pop-up messages from the engine (and that only when the ?component error=true? PI is in your scriptlet). -Mike ___ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: [Fwd: Net::SSH::W32perl /Net:SSH::Perl on activeperl win32]
I've been trying to use Net::SFTP recently, without luck. When I try to execute a simple fetch with code like: use strict; use Net::SFTP; my $scp = new Net::SFTP( 'SOMEHOST', user = 'SOMEUSER', password = 'SOMEPASS', ) or die Unable to create host connection; my @list = $scp-ls('/tmp'); print HERE IS /tmp\n:; map {print \t$_\n;} @list; my $stat = $scp-get('/tmp/InstalledDB', 'c:/s2/InstalledDB'); print get status is $stat\n; ...I get the error: The getpwuid function is unimplemented at C:/Perl/site/lib/Net/SSH/Perl.pm line 110. I know it can be pretty difficult getting SSH related packages working on Win32. Can anyone out there summarize the steps required to make this stuff work? I've seen various references to packages supplied at soulcage.net, but I think that site has fallen away. Any advice is appreciated. I'm using perl 5.8.8, BTW. Thanks, Mike Ellery listmail wrote: Just an update. Some debugging that I've done shown that my ssh connection was actually hung and looping between $ssh-client_loop and $ssh-drain_outgoing and never exiting . My assumption was wrong with how things had been fixed up. I seen many Google hits on this problem and allot of the fixes were older and stating to use the soulcage repo! After many hours I made a copy of my working installations' site/lib/Net/SSH folder and pasted into a fresh perl install and then installed the Crypt modules and other dependencies from uwinnipeg.ca. Not the most ideal solution, but performance is good. If I don't get any solution for the existing packages I'll probably end up doing diffs on the files between two site folders and see if I can create a fix. Original Message Subject: Net::SSH::W32perl /Net:SSH::Perl on activeperl win32 Date: Fri, 13 Jun 2008 00:59:29 -0500 From: listmail [EMAIL PROTECTED] To: activeperl@listserv.ActiveState.com I've been using Net::SSH::W32perl 0.06 originally provided by a repo on http://www.soulcage.net/ (Scott Scecina) for a few years now. And my install still works great. Unfortunately this site is down and I can no longer find that specific version and dependencies. I believe Scott had hacked some parts of that package or any of its dependencies so as to make it work without Math::BigInt::GMP but not falling back to the slowest math libs. Without fast math routines using Net::SSH::Perl is incredibly slow (10 minutes or more to connect). A couple years back I solved this problem on Solaris by building against libgmp, but I haven't created a working solution on Windows using a clean development machine. This concerns me since I have applications in production which rely on the continue development and availability of this functionality.I've been testing the packages provided at http://theory.uwinnipeg.ca/ppms/ with no luck on the performance issue so far. I will be testing against Net::SSH:Perl v1.23 (instead of 1.30) next. If anyone has any tips or suggestions, I would appreciate it. ___ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs ___ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: [Fwd: Net::SSH::W32perl /Net:SSH::Perl on activeperl win32]
Jenda Krynicky wrote: Net::SSH2 works fine for me under Windows. ..and sure enough, it does! Who knew it could be so easy. Thanks. -Mike ___ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: Counting occurences?
Barry Brevik wrote: I can't believe this has me stymied, but here goes... I'm processing a string of chars in a loop, and the string can contain multiple lines; that is, the string has embedded \n chars in it. For display purposes, I need to count the number of \n chars in each string. Is there a simple way to do this? scalar(split(/\n/, $string)) - 1 ...does that work for you? ___ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
getopt long
I've been under the impression that Getopt::Long is included with most (if not all) distributions of perl. Recently I've encountered a few Activestate versions that don't seem to have it installed. What the current policy with this package - is it included? As of which version did it become standard? Thanks, Mike Ellery ___ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: getopt long
Michael Ellery wrote: I've been under the impression that Getopt::Long is included with most (if not all) distributions of perl. Recently I've encountered a few Activestate versions that don't seem to have it installed. What the current policy with this package - is it included? As of which version did it become standard? ..and it gets worse. For those versions that seem to have Getopt::Long but that don't have the minimum version I require (2.36), I've tried installing the latest (using ppm), but at runtime perl always loads the builtin version and not my upgraded version in site/lib. Any ideas how I can fix this? Thanks, Mike Ellery ___ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: getopt long
Bill Luebkert wrote: Michael Ellery wrote: Michael Ellery wrote: I've been under the impression that Getopt::Long is included with most (if not all) distributions of perl. Recently I've encountered a few Activestate versions that don't seem to have it installed. What the current policy with this package - is it included? As of which version did it become standard? ..and it gets worse. For those versions that seem to have Getopt::Long but that don't have the minimum version I require (2.36), I've tried installing the latest (using ppm), but at runtime perl always loads the builtin version and not my upgraded version in site/lib. Any ideas how I can fix this? I have version 2.37 in my site/lib (not sure if that's usable or not). Try posting the output of this script: use strict; use warnings; use Getopt::Long; print $_\n foreach @INC; print \n; print $_ = $INC{$_}\n foreach keys %INC; __END__ OUTPUT from a 5.8.7 installation: C:\Documents and Settings\testuser.S2TECHperl //s2server1/infrastructure/libpath.pl C:/Perl/lib C:/Perl/site/lib . warnings/register.pm = C:/Perl/lib/warnings/register.pm Carp.pm = C:/Perl/lib/Carp.pm warnings.pm = C:/Perl/lib/warnings.pm Exporter/Heavy.pm = C:/Perl/lib/Exporter/Heavy.pm vars.pm = C:/Perl/lib/vars.pm Exporter.pm = C:/Perl/lib/Exporter.pm strict.pm = C:/Perl/lib/strict.pm constant.pm = C:/Perl/lib/constant.pm Getopt/Long.pm = C:/Perl/lib/Getopt/Long.pm My local 5.8.8 installation works fine because it appears to have 2.37 built-in, so I never had to install or upgrade. Older distributions seem to have either not Getopt::Long or an antiquated version (I'm relying on a function in 2.36+). Thanks, Mike ___ ActivePerl mailing list ActivePerl@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs