Re: use FileHandle;

2008-04-17 Thread Eric Amick
On Thu, 17 Apr 2008 12:00:12 -0700, you wrote:

I have a basic project in which I need to break a larger file down into
35 separate files.  I was under the impression that use FileHandle would
store the object in $fh.  I could then create a a copy of my file, save
the associated object in a hash array and print some header information
for the files all in a simple loop.  So, joyfully, I wrote the
following:

use FileHandle;
 
foreach my $key (0 .. 34) {
 
 $fh = new FileHandle  VTOL$key;
 $flist{$key} = $fh;
 print $flist{$key} Header info\n;

Since FileHandle gives you object-oriented access to the filehandle, you
can use

$flist{$key}-print(Header info\n);

as well as the

print {$flist{$key}} Header info\n;

already suggested.
-- 
Eric Amick
Columbia, MD
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Reading 'Little Endian - UCS-2' text to perl

2007-02-15 Thread Eric Amick
 Hello,
 
 I'm having difficulties reading a log file from ADMT using ordinary perl
 5.8.7 open command.
 After opening the file (apparently in little endian format, according to
 my notepad++) i'm printed it and i get spaces everywhere (space between each
 char!).
 when i convert the file to UTF8 (again, manually with my notepad++) it
 prints out file just fine.
 
 anyone knows how to handle this encoding in perl, or how can i convert it to
 UTF8?

If i've read perluniintro correctly, you can use an open statement like this to 
process the file directly:

open FH, :encoding(ucs2), $filename or die Can't open $filename $!\n;

--
Eric Amick
Columbia, MD

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


Re: Japanese chars and ARGV

2006-12-02 Thread Eric Amick
On Sat, 02 Dec 2006 12:00:12 -0800, you wrote:

On a Japanese version of Windows when you execute a Perl to run a script, the 
length() fcn returns
the wrong number of characters for anything you pass in as @ARGV[0], and the 
split() fcn seems to
work the same way.

Using some of the samples shows in perluniintro we do not get the same 
results, so something is wrong.

Using ActivePerl 5.8.8 Build 819. Using Win2003 Server, Japanese. No 
emulation, all default Japanese
installation.

Here is what we are doing:

perl script.pl #12486;#12473;#12488;

(there are three characters for @ARGV[0], the Japanese word for 'test')

The perl script does this:

print length(@ARGV[0]);  # returns 6

If one tries to use split(\\, @ARGV[0]) there are 6 iterations.

Tried use encoding UTF8, the -C6 flag and a ton of other stuff.
Oddly, if one does 'print @ARGV[0]' the output is #12486;#12473;#12488;.

Even used something from perluniintro:
$Unicode_string = pack(U*, unpack(W*, $ARGV[0]));
print $Unicode_string # returns #12486;#12473;#12488;
print length($Unicode_string) # returns 6

We need to capture each character in #12486;#12473;#12488; (3 of them) and 
get the HEX or UNICODE value for the
character. Since Perl thinks the length is 6 we cannot get correct hex/unicode 
values using
pack/unpack or anything else for that matter.

I may be missing something, but wouldn't -CA or -C32 do what you want?
According to perlrun, it means the elements of @ARGV are strings
encoded in UTF-8.
-- 
Eric Amick
Columbia, MD
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Flip-flop operator help

2006-07-14 Thread Eric Amick
On Fri, 14 Jul 2006 12:00:08 -0700, you wrote:

I have something like this:

while (FILE)
{
   if (/TAG/ .. /\/TAG/)
   {
   # process line
   }
}

I got this from http://www.perl.com/pub/a/2004/06/18/variables.html.

My special wrinkle is, I want to process certain sections of a file, but 
only if that section passes certain criteria.

I want to be able to begin processing lines, but I want to be able to 
turn processing off and jump to the next TAG should the script 
encounter a line containing, say, the tag PDF.

There's no magic way to reset the range operator. You could add some
sort of flag, such as this (untested):

my $skip;
while (FILE)
{
   if (my $tags = /TAG/ .. /\/TAG/)
   {
   $skip = 0 if $tags == 1;   # reset flag upon seeing TAG
   $skip = 1 if /PDF/;
   next if $skip;
   # process line
   }
}

Read the description in perlop for further details.

You could also not use the range operator at all; I'll leave the code
for that to you.
-- 
Eric Amick
Columbia, MD
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Issue w Daylight Saving Time on german win2k machine

2006-03-30 Thread Eric Amick
On Thu, 30 Mar 2006 12:05:09 -0800, you wrote:

Oliver Thieke wrote:

 Hi out there,
 
 I'm having issues with retrieving the correct
 time on my machine. In Germany it's now DST -

Kinda early for DST isn't it ?

Much of Europe switches on the last Sunday in March.

-- 
Eric Amick
Columbia, MD
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: How to best count the number of words in a sentence?

2006-03-24 Thread Eric Amick
On Thu, 23 Mar 2006 12:05:07 -0800, you wrote:

This is probably a fun trivial question: I'd like to count the number of 
words in a string. My command:
my $count = split(/\s+/,$line);

works. But Perl complains about:
Use of implicit split to @_ is deprecated

It works, but it's deprecated. I can assign split to an array, then do a 
scalar() on it. But this cannot be the best method (too much work!).

Your take guys?

This works, but it strikes me as a bit *too* clever:

my $count = () = split(/\s+/, $line, -1);

If you've forgotten, a negative third argument forces split to produce
all of the possible fields, keeping trailing null fields. In particular,
it ignores the size of the destination list. I've more often seen this
empty list idiom in conjunction with m//g--not that it's tremendously
common there, either.
-- 
Eric Amick
Columbia, MD
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Hash return value

2006-03-17 Thread Eric Amick
On Fri, 17 Mar 2006 12:05:07 -0800, you wrote:

# Using subroutine that returns a hash doesn't work
while (($key, $value)= each( mkhash() ))
{
print($key = $value\n);
}

sub mkhash
{
 my %hash=('one'=1, 'two'=2, 'three'=3);
 return %hash;
}

The each() function expects its argument to start with %. As perlsub
explains, your function actually returns a list, not a hash; arrays and
hashes are flattened when returned from a function, just as they're
flattened when passed to a function. You can return a reference to a
hash instead and then dereference it in the caller:

while (($key, $value)= each( %{ mkhash() }))
{
print($key = $value\n);
}

sub mkhash
{
 my %hash=('one'=1, 'two'=2, 'three'=3);
 return \%hash;
}
-- 
Eric Amick
Columbia, MD
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Perl Bug (again)

2006-02-17 Thread Eric Amick
On Fri, 17 Feb 2006 12:05:08 -0800, you wrote:

OK, then, consider this program. Notice that there's a global $i 
which has the value 5. Now, when func() is called, if the my $i did 
not create a new lexically scoped variable, then the print line would 
print i = 5. But it doesn't - obviously because the lexical 
variable was created, but is undefined because $b is false.

our $i = 5;
our $b = 0;

func();

sub func {

my $i = 3 if $b;
print(i = $i\n);
}

If you look in perldoc perlsub, you'll see the section on my() variables
specifically mentions that putting statement modifiers on my() has
undefined results, so all of this discussion is moot.
-- 
Eric Amick
Columbia, MD
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Use of uninitialized value in string eq ERROR

2006-01-15 Thread Eric Amick
On Sun, 15 Jan 2006 12:05:08 -0800, you wrote:

my $missingPatch = no;
foreach $patch (@patches)
{
$showrev = `showrev -p | grep \Patch: $patch\`;
if ( length ($showrev) == 0 )  # meaning the patch isn't installed
{
  ...
if ( exists $installedPatch[1] )
{($instPatchID, $instPatchVer) = split(/-/,
$installedPatch[1]); }

if ( ( exists $patchName[1] )  ($patchName[1] lt $instPatchVer
) )
{
   
}
else
{
   ..
  $missingPatch = yes;
}
}
}
if (  $missingPatch =~ m/yes/  )   ---  this is where the error occurs.

Count your braces. The right brace immediately above this if statement
closes the scope of your my variable, so the $missingPatch in the if
is a different (and obviously uninitialized) variable.
-- 
Eric Amick
Columbia, MD
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: perldoc

2005-12-18 Thread Eric Amick
On Sun, 18 Dec 2005 12:05:07 -0800, you wrote:

At 09:03 PM 12/15/2005 -0800, Suresh Govindachar wrote:
 1) What does the following line do? 
   
   eval 'exec C:\opt\perl\bin\perl.exe -S $0 ${1+$@}'
   if 0;

In perl it does nothing.  Under bash it executes perl with itself as an
argument.  Although my tests indicate that double backslashes (C:\\...) and
-x are required to make that trick work.  So I'm not sure what they were
trying to accomplish with that.  In unix, 0 is true and  0 is false. :)
The number represents the error level of the last exiting process.  No
error.  Keep in mind that normally this line will *never* be executed.
Personally I think it's just left over development code that nobody deleted.

According to the Camel Book, those lines allow Perl scripts to be run
naturally (i.e., with scriptname instead of perl scriptname) on
Unix systems that don't support #!. I don't imagine there are many of
those these days. There's no real point to it on Windows, unless your
system doesn't associate whatever extension you use on Perl scripts with
perl.exe.
-- 
Eric Amick
Columbia, MD
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Hash limits? (Was: Re: rand() not so random)

2005-12-01 Thread Eric Amick
On Thu, 1 Dec 2005 12:05:11 -0800, you wrote:

[EMAIL PROTECTED] (Chris Wagner) graced perl with these words of 
wisdom:

 Just for fun I did a little test.
 for (1 .. 1) {
  my $fn = rand();
 ++$dup and next if exists $num{$fn};
  $num{$fn} = 1;
 }
 print scalar keys %num,  unique numbers. $dup duplicates produced\n;
 

Just for fun, I changed one of the lines in that to 

for (1 .. 100) {

When I ran the modified script, I got 32768 unique numbers, with 967232 
duplicates!  As 32768 is a power of 2, I'm wondering if there's a limit on 
the number of keys one may have in a hash.

No, it's a limit on the number of values rand() produces on Windows, as
this one-liner shows:

perl -MConfig -e print $Config{randbits}

randbits is the number of bits in the value produced by rand(); the
value is 15 in ActiveState Perl for Windows. If you want a better random
number generator, there are modules available on the PPM repositories;
search for random.
-- 
Eric Amick
Columbia, MD
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: RegEx

2005-08-28 Thread Eric Amick
On Sun, 28 Aug 2005 12:05:07 -0700, you wrote:

Newbie to RegEx so though I would start with something really easy. My big 
mistake

 

Problem

If the string does not contain a trailing \ then add one.

$string .= \\ unless $string =~ /\\$/;
or, if you prefer,
$string .= \\ if $string !~ /\\$/;
-- 
Eric Amick
Columbia, MD

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


Re: help with defined and !not defined

2005-07-23 Thread Eric Amick
On Fri, 22 Jul 2005 12:05:16 -0700, you wrote:

You want to check if it's null, not if it's defined.  Defined means that the
variable exists.  

Almost. Defined means the variable exists AND its value is not undef, as
this snippet demonstrates:

my $foo;
print !defined $foo;

As for the OP's question, substr() does indeed return undef if the
offset and length specification refers to something completely outside
the string argument. I suspect that the elements of @ARGV have newlines
or other whitespace at the end that are causing a problem.

-- 
Eric Amick
Columbia, MD

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


Re: help with getting file stats

2005-07-21 Thread Eric Amick
On Thu, 21 Jul 2005 12:05:08 -0700, you wrote:

loris reply:
yes I did try stat ($dir/$file)  it would not work , and I tried many 
variation
here is what I finally got to work:

print Opening $dir \n;
 
  opendir DH, $dir  or die Can't open the current dir $!\n;
  while(my $file = readdir(DH)){
 
if(-d $dir/$file){ 
  print \n Dir: $file \n;
  my $pic_year = substr($file,0,4);
  my $pic_month = substr($file,4,2);
  print Year: $pic_year,Month: $pic_month\n;
 
  $dir_ctr++;
}
elsif(-e $dir/$file){ 
  print \n File: $dir/$file ;
  #this wont work for me
  #my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,$atime, 
$mtime, $ctime, $blksize, $blocks) = stat($dir/$file); 
  #print Ctime:$ctime ,Mtime: $mtime\n;
  my $now = ctime();
  print \n Nowtime: $now\n;
  #this works
  my $file_moddate = ctime(stat($dir/$file)-mtime);
  my $file_create_date = ctime(stat($dir/$file)-ctime);

Clearly you directly or indirectly use'd the File::stat module, which
overrides the built-in stat() with an object-oriented version. If you
really want to call the built-in version, try

  my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,$atime, 
$mtime, $ctime, $blksize, $blocks) = CORE::stat($dir/$file); 


-- 
Eric Amick
Columbia, MD

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


Re: Use works but require does not!

2005-07-09 Thread Eric Amick
On Fri, 8 Jul 2005 12:05:08 -0700, you wrote:

Why does the use find the file and the require does not?

The Win32.pm is located in, C:\Perl\lib\Win32.pm

Can't locate Win32::OLE qw(in with) in @INC (@INC contains:
/package0/filpods/loaders . C:\Program Files\ActiveState Komodo
3.1\dbgp\perllib C:\perl\lib C:\perl\site\lib C:\Program
Files\ActiveState Perl Dev Kit 6.0\lib\ C:/Perl/lib C:/Perl/site/lib) at
Y:\FILPODS\DB\loaders\factsheet_extract.pl line 30.

Code example cause error:

$win32ole = 'Win32::OLE qw(in with)';
$winconst = Win32::OLE::Const 'Microsoft Outlook';

if ($^O eq 'MSWin32'){
  require $win32ole;
  require $winconst;
  $Win32::OLE::Warn = 3;  # die on errors...
}

There are two problems:

1) When you pass a string to use or require, Perl expects a file path,
not the :: format. 
2) The arguments after the module name are not processed by require when
you pass a string.

The simplest fix is

eval require $win32ole;

If this code will be executed many times in a single run of the program,
a better way would be

$win32ole = 'Win32/OLE.pm';  # extension is required too!
require $win32ole;
Win32::OLE-import('in', 'with');

All this obviously applies to the Win32::OLE::Const as well.

-- 
Eric Amick
Columbia, MD

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


Re: mystery

2005-06-30 Thread eric-amick

"use constant" defines constants something like this:

sub NAME() { return 42;}

The prototype prevents anything following a reference to the constant from being accepted as an argument. What's more, Perl will inline the function call if the return value is a constant _expression_ in most cases. The Posix module is almost entirely in XS, and clearly the part that defines the constants does not use prototypes.

--Eric Amick Columbia, MD

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


Re: assigned array to keys of hash?

2005-06-05 Thread Eric Amick
On Sun, 5 Jun 2005 12:05:08 -0700, you wrote:

At 07:05 PM 6/4/05 -0700, $Bill Luebkert wrote:
One more using the hash slice suggestion:

my %hash2;
@hash2{grep /$something/, @array} = (1) x @array;

I wasn't aware that u could take a slice of a hash.  Interesting.  I had to
try it out to see if it actually worked and I came up with another little
benefit of doing it.  You can keep track of the insert order into the hash
and the match from the grep array.

If tracking the insert order is really important, it would probably be
better to take advantage of the Tie::IxHash module, which is available
on CPAN and many PPM repositories, including ActiveState's. It has a
number of handy features, and you can treat the hash almost like an
ordinary array. The documentation explains it quite well.

-- 
Eric Amick
Columbia, MD

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


Re: assigned array to keys of hash?

2005-06-04 Thread Eric Amick
On Sat, 4 Jun 2005 12:05:06 -0700, you wrote:

Hopefully quick syntax/philosophy question:

I have a array grep like this: 
   my @newArray = grep ($something, $maybeBiggerOriginalArray);

but would much prefer to take greps list and use it as the keys of a hash. Now
the keylist of a hash cannot be modified, i.e.
   (keys $newHash) = grep (...) 
is rightly forbidden nonsense.

obviously you can do this in a 2-step by e.g. do the first grep, and then
   foreach (@newArray) { $newHash{$_} - {thing} = $_; } # or assign
whatever 

but thats hideous. any tips on how to dump a list to the keys of a hash
directly? once again i'm sure i'm missing something.

Without knowing precisely what values you wish to assign to the hash
elements, I believe you should be able to use a hash slice:

@newHash{grep $something, $MaybeBiggerOriginalArray} = @ValuesArray;


-- 
Eric Amick
Columbia, MD

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


Re: regexp question

2004-12-15 Thread eric-amick


 I seem to be missing a piece of the puzzleI want to define a character  class ([])  with atoms to (not) match involve negative look-ahead assertions.but no  joy.   I am reading a stream of text that may contain the two segments \\n and \"   I want to define a regexp that will match up to the first of either of  these. 
I would suggest a slightly different approach, especially since you apparently might not have either sequence. Try

if ($str =~ /n|\\"/)
{
$mytext = substr($str, 0, $-[0]);
# do whatever with $mytext
}

The arrays @- and @+ contain the starting and ending offsets within a string of the portion successfully matched by a regular _expression_; the 0th elements refer to the whole regex, and other elements to the portions captured by parentheses.

See perlvar in the docs and the description of substr under perlfunc.

--Eric AmickColumbia, MD
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: some error with the code

2004-11-27 Thread eric-amick
 As you can see, perl simplified your unquoted numerical strings 
 by dropping the 
 leading zeros *before* stringifying them to use as hash keys. Quoting them 
 explicitly solves the problem.

Actually, Perl interprets the values with leading zeros as octal numbers; 
that's why 00056 became 46.

 I admit I'm a little surprised by this behavior. 
 The auto-quoting function of = 
 doesn't work quite as literally as I thought.

It's working exactly as documented; = automatically quotes barewords, i.e., 
words that have no other meaning in the language. Strings of digits represent 
numbers in Perl, hence the hash keys must be quoted explicitly to be treated as 
text strings. In general, if your hash key is text that does not start with a 
letter or underscore, you should quote it yourself. If the hash key is text 
that contains anything but letters, digits, and underscores, you *must* quote 
it yourself. (There are some exceptions, but this approach is much less 
error-prone.)

--
Eric Amick
Columbia, MD



___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: why doesn't this work?

2004-09-27 Thread Eric Amick
On Mon, 27 Sep 2004 12:05:10 -0700, you wrote:


test script:

use strict;
use testlib;

print(Env Var 'Oracle' is set to '$ENV{Oracle}'\n);
callme();


test library (testlib.pm):

use strict;

if ($ENV{Oracle}) {
   sub callme {print(Version 1\n);}
   }
else {
   sub callme {print(Version 2\n);}
   }

Normal subroutine definitions occur at compile time, so the second
definition overrides the first before the code even executes. You can do
this instead:

if ($ENV{Oracle}) {
eval 'sub callme {print(Version 1\n);}'
}
else {
eval 'sub callme {print(Version 2\n);}'
}

or this:

if ($ENV{Oracle}) {
$callme = sub {print(Version 1\n);}
}
else {
$callme = sub {print(Version 2\n);}
}

or even this:

if ($ENV{Oracle}) {
*callme = sub {print(Version 1\n);}
}
else {
*callme = sub {print(Version 2\n);}
}

In any case, you will need either an argument list or an ampersand when
calling callme(), since Perl won't know the type at compile time. (The
second case would need $callme-() or $callme.)

-- 
Eric Amick
Columbia, MD

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: using Perl's index function

2004-08-03 Thread Eric Amick
On Tue, 3 Aug 2004 12:05:10 -0700, you wrote:

The logic I am using may be summarized like so:

if(
($textarea_line =~ m/^\s*(Exhibit\s+[\d.]+(\s*\([0-9a-zA-Z]+\))*)\s*$/i) ||
($textarea_line =~ m/^\s*(FORM\s+10\-K)\s*$/i) ||
($textarea_line =~ m/^\s*(FORM\s+10\-K[A-Z]*\/*[A-Z]*)$/i) ||
($textarea_line =~ m/^\s*(FORM\s+8\-K)\s*$/i) )

I was using the index function to get the position of the particular 
heading that triggered the match:

   $heading = $1;
   $heading_offset = index($textarea, $heading);

Being the rocket scientist I am, it took me all morning to figure out 
why I was getting inaccurate results. Then I finally went back to the 
manual and re-discovered that index returns the position of the FIRST 
occurrence of substring within string.

First occurrence doesn't help me. I need, naturally, the exact 
occurrence (whether the fifth or the hundredth) that triggered the match.

The @+ and @- arrays should do the job. See perldoc perlvar.

-- 
Eric Amick
Columbia, MD

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: converting dates..

2004-06-11 Thread Eric Amick
On Fri, 11 Jun 2004 12:05:07 -0700, you wrote:

#   Ensure year is four digits
 if ($year = 1900)
 {
 if ($year  05)
 {
 $year += 1900;
 }
 else
 {
 $year += 2000;
 }
 }

If $year is 1900, your code converts it to 3800. I think you meant

if ($year  100)

-- 
Eric Amick
Columbia, MD

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Win32::Daemon::Simple -install question

2004-04-03 Thread Eric Amick
On Sat, 3 Apr 2004 12:00:12 -0800, you wrote:

When I install a newly compiled script as a service, I see the following
at the command line:

C:\Development\soapwelagent -install
Sagiss Windows Event Log Agent 0.1
Use of uninitialized value in concatenation (.) or string at
/PerlApp/Win32/Daem
on/Simple.pm line 239.
Installed successfully
C:\Development\soap\welagent.exe
Use of uninitialized value in concatenation (.) or string at
/PerlApp/Win32/Daem
on/Simple.pm line 240.

===
The 'use' statement I've got in my script is as follows:

use Win32::Daemon::Simple
Service = 'welagent',
Name = 'Sagiss Windows Event Log Agent',
Version = '0.1',
Info = {
display =  'Sagiss Windows Event Log Agent',
description = 'Polls local Windows event logs and sends events
to remote server',
interactive = 0,
},
Params = { # the default parameters
Tick = 0,
Talkative = 0,
Interval = 10, # minutes
LogFile = undef,
Description = '*END*',
Tick : (0/1) controls whether the service writes a tick message to
the log once a minute if there's nothing to do
Talkative : controls the amount of logging information
Interval : how often does the service look for new or modified files
(in minutes)
LogFile : the path to the log file
...
*END*
};


===
Did I leave something off that '-install' needs?  I tried starting off
with a very pared-back 'use' statement (including just the Service,
Name, Version, and Info options), but found that it wouldn't run at all
without 'Params = {Tick = 0}'.  So I added the 'Params' back, but I'm
wondering if I need to add back some more.  What are the minimum
parameters I need to specify?

It appears to be working OK, but I'd like to eliminate the complaining
it does when I install the service.

I looked in the source, and it appears the print statement is printing
the value of the 'parameters' key stored in the Info hash without
checking to see if it exists. When you use the module with a compiled
file, no value is stored for that hash key. If I've interpreted the code
correctly, adding

parameters = ,

to the Info hash should keep it quiet. In that case, reporting a bug
would be a good idea.

-- 
Eric Amick
Columbia, MD

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: 16b hex conversion

2004-03-03 Thread eric-amick
  It looks like you're doing this. Say if I'm way off-beam.
 
  sub d2h16 {
sprintf %04.4X, shift;
  }
 
 I don't believe it. That's amazing. That's not off-beam, 
 that's nail on the head. Is there a way of returning that
 as a value instead of printing it? 

sprintf() already returns it as a string; it's printf() that prints to the default 
filehandle. (As an aside, %.4X will produce the same result.)

--
Eric Amick
Columbia, MD
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: opening sh

2003-11-16 Thread Eric Amick
On Sun, 16 Nov 2003 12:04:18 -0800, you wrote:

im looking to access the unix 'fortune' program and need to iterate through
it several times but dont want to open a new shell process for each and
every call.  id like to open a single shell then pass 'fortune' to it over
some iteration and retrieve its output.  its simple enough to do:

for (0 .. 100)
{
my $fortune = `/usr/games/fortune`;
print;
}

but it appears to create a bit of overhead in opening and closing a new
process for each call.  it would be better to open a pipe or something and
just pass the handle the command if possible???

You can pass anything recognized by the shell within backquotes, so you
could always write a shell script that runs fortune some number of times
and then use

my $fortune = `/my/fortune/script`;

to get the output.  You could even forego the separate script and enclose
the necessary shell commands in the backquotes instead.  Since fortune
produces only one fortune each time it's run, this will only reduce the
number of processes created a little.

-- 
Eric Amick
Columbia, MD


___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Problem with if statement

2003-09-10 Thread eric-amick
 If($FORM{membername ne  }) {

if($FORM{membername} ne  ) {

--
Eric Amick
Columbia, MD
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: How do I avoid the DOS window when starting a perl script

2003-06-25 Thread Eric Amick

  Have you tried using Windows Perl instead (wperl) ?  You should find
  it in your perl/bin dir.

 This was posted a few months ago. :-)
 Someone pointed why there's no document on it. I think so too.

But it *is* documented, though perhaps not as prominently as it should 
be.  Read perlwin32.

Eric Amick
Columbia, MD

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Is SOAP::Lite with Perl for ISAPI Possible?

2003-06-18 Thread Eric Amick
I've been trying to run a SOAP server with SOAP::Lite 0.55 under Perl
5.8.0 using Perl for ISAPI.  The necessary extension mappings exist, but
the debug trace always says something about no output being produced,
and it apparently sends back a CGI header with a content type of
text/html, which the client doesn't like at all.  Is there some
additional configuration required?  The code produces the desired
results when run as a normal CGI with perl.exe; it's just perlis.dll
that has problems.
-- 
Eric Amick
Columbia, MD

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Reverse of Chomp

2003-06-13 Thread Eric Amick
On Fri, 13 Jun 2003 13:49:45 +, you wrote:

Is there a way to reverse chop/chomp

I'm reading STDIN into an array, then
   chomping off the last character of each of the
   array elements.

Now I'd like to write the array back out
  to STDOUT, but I want to put the \n's back between
  each of the lines.

You've gotten a number of good suggestions.  Let me throw out another
idea:

$ = \n;
print @array\n;

No doubt someone will tell me how dreadful that is. :-)  I also agree
with the poster who asked why you chomped in the first place; is there
really no way to work with the data with the newlines present?

-- 
Eric Amick
Columbia, MD

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: regex expressions

2003-04-12 Thread Eric Amick
On Sat, 12 Apr 2003 19:01:28 +, you wrote:

Got a quick (simple??) question. I can't seem to find an example of how to
do it!!

I have the following string:

$test = my brother is not ok today and i want milk for food

I'd like to be able to place is not ok today in $1 and want milk in $2.
Should be pretty easy, you simply start the search on my brother, place
is not ok today in $1, skip the and, place want milk in $2 and you're
done

sort of like -$test =~ /my brother([ ])/
the result would be placed in $1, and $2

I'm trying to get a better understanding as to how one can quickly get to a
group of chars that match a given term, do something, and then search for a
subsequesnt group of chars

All the examples I see use a single char as opposed to a group. In other
words, how does one put a group of chars in a [] such that they will be used
for an exact match???

I'm not terribly clear on what you're after.  I *think* you want

$test =~ /^my brother (.+) and i (.+) for food$/;

The .+ matches one or more characters other than newline.  The ^
requires the match to start at the beginning of the string, and the $
requires the match to go to the end of the string.

You can also put any arbitrary list of characters in [], such as

[A-Z,.;]

This matches one uppercase letter, comma, period, or semicolon.  As you
can see, ranges can be used to save typing.  There is plenty of
information available if you use the command perldoc perlre; you might
also have perldoc perlretut as well.

-- 
Eric Amick
Columbia, MD

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs