Re: Chomp to trim '\r'

2003-10-08 Thread Carl Jolley
On Wed, 8 Oct 2003, Sisyphus wrote:

 Lee Goddard wrote:

 
  Why not use a regular expression?
 

 I can't find an answer to that question - and, judging by the responses
 so far received, nor can anyone else !!

 ;-)


You know that in perl TAMTOWTDI. However usually there
are some ways that are more-or-less equivalent and then there
are ways that only a veteran of several obfuscated perl contests
could appreciate.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Array question

2003-10-07 Thread Carl Jolley
On Fri, 26 Sep 2003, Michael D. Smith wrote:



   This is perl, arrays start at zero, get used to it.

 Right :)

 And to perl you could add C, and it's offspring C++, and Fortran and COBOL
 and JAVA(Script) and... I didn't even know there was one that didn't. I
 know nothing of pascal but I believe:) pascal only offers the option of
 starting with one (as does perl if you really want to mess with $[ ), but
 it doesn't require that an array start with one only that the beginning and
 the end subscript be specified -- which is unique, as far as I know.

 I don't see the problem. Use foreach instead of for and there's no need
 to ever even think about a subscript. And if you're really nuts about it
 for some reason, this works: $array[1-1]. Just always use the minus one
 when you write it and always ignore it when you're reading it. A little
 self-hypnosis and it'll look just like the array starts with one :)

 ms



 At 10:59 AM 9/26/03, you wrote:
 Right, the Book says its a bad idea, so at least localize the badness:
 my @time;
 {
   local $[ = 1;
 
   open TXT, (' C:\myperl\test.txt') or die no joy $!;
   @time = TXT;
   close TXT;
 }
 
 which means you only clobber a local copy (not 'my' here - this is one of
 the few valid uses of local) of $[ for the duration of the troublesome
 situation.  The reason why the original poster wanted to start at 1
 remains unknown, but most guesses are its a former pascal programmer's
 fear of zero.  This is perl, arrays start at zero, get used to it.  If
 you're doing:
 foreach ($i = 0; $i = $#Array; $i++) {
my $file = $Array[$i];
 ...
 
 and want that to start at one:
 foreach my $file ( @Array ) {
 
 
 solves both problems in a perlish fashion.
 


My memory differs from yours regarding the Fortran initial array
index. I thought it was 1. I also thought it was 1 for Cobol, too.
OTOH its been decades since I last did any coding for either one of them.
BTW you can also add Algol, Java and Newp to your list of arrays
start a 0 languages. If I recall correctly I believe that VisualBasic
offers the same kind of flexibility for both starting and ending array
indices as you mention for Pascal. On-topic comment: Perl has lots of
archaic features and deprecated capabilities that it got early in life
when it tried to be the swiss-army-knife of programming and scripting
languages and it included just about every quirky feature that any of its
predecessors had. Awk and sed programmers die hard. I think that when/if
Perl 6 ever gets released that it will probably kill off a lot of the
stuff that previous versions of perl have been carring around from
the distant past.


 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: array of anon. hashes sorting

2003-10-07 Thread Carl Jolley
On Fri, 26 Sep 2003, Jay Ay wrote:

 hi there

 i want to be able to sort an array of hashes.

 for example, i create each hash like this and push it on to the array.
 push(@senddata,{ 'sender' = $se, 'recip' = $re, 'smtphost' = $svr,
 'number' = $somenbr});

 what i want to do is sort the array by 'number' key value, in order greatest
 number to smallest number.


I'm pretty sure you've gotten lots of replies to the question you asked
so I won't add to the list. I just want to do a little mild course
correction to your termanology. The only thing that can ever be pushed
into an array is a scalar. Every defined element of an array contains
a scalar. What you are actually pushing is a special type of scalar
called a reference. In this case a reference to an anonymous hash.
If you tried to actually push a hash into an array you'd end up
adding one scalar for every key and data element of the hash.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 


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


Re: How to skip unwanted columns in CSV file?

2003-10-06 Thread Carl Jolley
On Fri, 26 Sep 2003, Noushad Dawood wrote:

 I'm trying to read a huge CSV file which got 30 columns separated by comma,
 but i only need to get values of 3rd, 12th and 20th columns. Is there a
 neat and easy way to get this done?


One way would be to use an array slice:
while($row=CSV) {
  chomp($row);
  @data=(split(/,/,$row))[2,11,19];
  .
  .
}

Alternatively if you need those specific column values as separate scalars
instead of three elements of an array then:

($item1,$item2,$item3)=(split(/,/,$row))[2,11,19];

The chomp($row) isn't strictly needed since you are not using
the last column.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


RE: How to skip unwanted columns in CSV file?

2003-10-06 Thread Carl Jolley
On Fri, 26 Sep 2003, Ken Cornetet wrote:

  open FILE blah, blah...
  while(FILE) {
   chomp;
   my @tmp = split /,/;
   my $col3 = $tmp[2];
   my $col12 = $tmp[11];
   my $col20 = $tmp[19];
  }

 I suppose you could get fancy and use DBI and DBD-CSV.


Or you could use a Cray super-computer to discover the value of
the variables by using the Monte Carlo method (a random walk) to
repetively try to guess which ones are the correct ones. Why complicate
a simple task? Unless of course, you're trying to deliberatly make life
difficult for the next person who will have to maintain your code.
Unnecessary fancy is rarely appreciated by other than the party of
the first part OTOH, simplistic elegance is widely admired.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


RE: Perl and MS Publisher

2003-10-06 Thread Carl Jolley
On Fri, 26 Sep 2003, Erich Beyrent wrote:

 Yes I did.  I also checked ppm, and Googled a bit.  I was looking for
 tutorials on how to control Publisher, and was thinking I could probably
 use Win32-OLE to do it, but I found nothing.

 Has anyone tried this?


It would kinda suprise me if MS didn't build Publisher around a COM
(i.e. OLE) interface. You could always just use the OLE Browser program
that is included in all semi-recent versions of perl and scan
all your installed OLE interfaces/Controls to see if Publisher is among
them.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Date manipulation in Perl

2003-09-26 Thread Carl Jolley
On Wed, 24 Sep 2003, ashish srivastava wrote:

 Hi

 I have 2 queries each of which return date in the following format :
 dd=mon-yy:hh:mi
 The results are (say) final_time and start_time.
 I want to get the time difference between the 2 times(in days or hours).
 Any pointers in this regard would be greatly appreciated.

 I just tried to subtract the 2 values and this is what i get :

 init_time : 17-jun-03:01::51 final time : 17-jun-03:02::00 Difference : 0
 init_time : 23-jun-03:10::19 final time : 24-jun-03:02::53 Difference : 1
 init_time : 25-jun-03:06::28 final time : 25-jun-03:02::31 Difference : 0
 init_time : 25-jun-03:11::48 final time : 01-jul-03:10::28 Difference : -24
 init_time : 02-jul-03:01::53 final time : 02-jul-03:08::57 Difference : 0
 init_time : 02-jul-03:11::37 final time : 03-jul-03:04::02 Difference : 1
 init_time : 17-jul-03:02::14 final time : 17-jul-03:07::35 Difference : 0
 init_time : 17-jul-03:07::41 final time : 17-jul-03:08::33 Difference : 0


You got those results due to the leading numeric portion of the
strings. If you want to do date arithmetic then one solution is to
use either Date::Calc or Date::Manip modules.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 


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


Re: Array question

2003-09-26 Thread Carl Jolley
On Thu, 25 Sep 2003, Wong, Danny H. wrote:

 Hi all,
   I was wondering if I can start adding elements into an array
 starting at 1? Here is what I am trying to do. I'm trying to glob all
 files/folders in a directory and assign it to an array, but it start at
 subscript 0. I know I can do a loop and start the subscript at 1. Just
 see if there is an easier way.

 Chdir ('c:\temp');
 @Array = *;

 Is there a shift command?


There's a shift command but it won't do what you want.
Use the unshift command instead. Build the array as
usual and then do a unshift(@array,0) and the 0 will become element
zero with all other elements shifted up one element, i.e. what
was originally element 0 will become element 1, the original
element 1 will become element 2, etc. You can also consider simply
setting $] to 1 so that the base of _all_ arrays will become 1 instead
of 0 but that may cause more problems than it solves.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Array question

2003-09-26 Thread Carl Jolley
On Thu, 25 Sep 2003, Ken McNamara wrote:

 Use opendir, readdir - if $array[0] is really a problem then do
 push(@array2,'',@array) - which will leave a null entry in the
 $array2{0] slot.


 Wong, Danny H. wrote:
 
  Hi all,
  I was wondering if I can start adding elements into an array
  starting at 1? Here is what I am trying to do. I'm trying to glob all
  files/folders in a directory and assign it to an array, but it start at
  subscript 0. I know I can do a loop and start the subscript at 1. Just
  see if there is an easier way.
 
  Chdir ('c:\temp');
  @Array = *;
 
  Is there a shift command?
 

Not hardly. push provides is the oposite action as pop, I.E. push
adds to the end of the array. While pop removes from the end of
the array. To add to the beginning of the array, use unshift. To
remove an element from the beginning of the array use shift. Note,
the splice function can add or delete one or more elements to the start,
end, or at any arbitrary point in an array.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


RE: Regular Expression problem?

2003-09-26 Thread Carl Jolley
On Fri, 26 Sep 2003, Xu, Qiang (XSSC SGP) wrote:

 Ted S. wrote:
  Beckett Richard-qswi266 graced perl with these words of wisdom:
  That should have been s/.*\///
 
  Don't you have to escape the period, too?
 
  s/\.*\///

 No, we shouldn't, because here . stands for any single character except a
 new line.


Well you are correct that a . regex character will match a period
but consider if the matched string was 'aaabcd.txt' the unescaped
period followed by * would match the string 'aaa'. Technically you are
correct, you don't have to escape the . character unless of course you
want the match to work correctly.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Array question

2003-09-26 Thread Carl Jolley
On Fri, 26 Sep 2003 [EMAIL PROTECTED] wrote:


 Hai,

 can any one tell how to pick up a particular pattern of files into that
 array...

 Eg:- files with extension .pl or .cfg


@selected=grep{ /\.(?:pl|cfg)$/ } *.*;

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: newbie hlelp!

2003-09-18 Thread Carl Jolley
On Tue, 16 Sep 2003, alex p wrote:

 Might it be the way i have it set on my computer to read the time?
 I have copied and pasted $Bill's code onto mine and I still get the same
 output!
 code
 foreach $f (@allfiles)
   {
 unless ( ($f eq .) || ($f eq ..) )
   {
 print $f\n;
 my ($dom, $mon, $year) = (localtime ((stat $f)[9]))[3,4,5];
 printf $f: %04d%02d%02d\n, $year+1900, $mon+1, $dom;
 #(undef,undef,undef,$dom,$mon,$year)=localtime((stat($dir/$f))[9]);
 #$mon++;
 #$year += 1900;
 #$dateval = printf(%04d%02d%02d\n,$year,$mon,$dom);}
 /code
 outPUT
 8000839F.LOG: 19691231
 800083BC.LOG: 19691231
 800083D8.LOG: 19691231
 80008401.LOG: 19691231
 80008441.LOG: 19691231
 800084AB.LOG: 19691231
 80008509.LOG: 19691231
 80008560.LOG: 19691231
 8000863E.LOG: 19691231
 /outPUT



 From: $Bill Luebkert [EMAIL PROTECTED]
 To: alex p [EMAIL PROTECTED]
 CC: [EMAIL PROTECTED]
 Subject: Re: newbie hlelp!
 Date: Tue, 16 Sep 2003 11:05:22 -0700
 
 alex p wrote:
 
   Thank you all for replying, I am using the code below and I am still
 unable
   to get the correct date
   code
   opendir (DIR, $server\\c\$\\sys\\data\\LOG\\updates);
 @allfiles = readdir(DIR);
 #print(, readdir(DIR));
 #closedir(DIR);
 foreach $f (@allfiles)
 {
   unless ( ($f eq .) || ($f eq ..) )
 {
   print $f\n;
   (undef,undef,undef,$dom,$mon,$year)=localtime((stat($f))[9]);
   $mon++;
   $year += 1900;
   $dateval = printf(%04d%02d%02d\n,$year,$mon,$dom);
  }
   /code
   the output of printf is: 19691231  for every file?
   what am I doing wrong?
   the date should be yesterdays date 20030915
 
 The following works fine for me (modified the dir for testing):
 
 use strict;
 
 #opendir DIR, $server\\c\$\\sys\\data\\LOG\\updates or die opendir:
 $!;
 opendir DIR, . or die opendir: $!;
 my @allfiles = readdir DIR;
 closedir DIR;
 
 foreach my $f (@allfiles) {
  next if $f =~ /^\.{1,2}$/;
  my ($dom, $mon, $year) = (localtime ((stat $f)[9]))[3,4,5];
  printf $f: %04d%02d%02d\n, $year+1900, $mon+1, $dom;
 }
 
 __END__
 
 Your version also worked with minimal additions for scoping, etc.
 Maybe there's a problem using the share - try a local filesystem and
 see if it makes a difference.
 

If that is your code then it's clear why it doesn't work.

You need to do: stat($dir/$f). The value of $dir divided by $f
also won't work (the part that you commented out). I suggest that
you put the following line immediatedly after your
print $f\n;

print file test, -f $dir/$f,\n;

Note also that you are checking all files AND dirctories in the current
directory. If you just want to check files and not directories then
you might change the initialization of @allfiles to:

@allfiles=grep{ -f } readdir DIR;

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: win32::ODBC insert error

2003-09-18 Thread Carl Jolley
On Tue, 16 Sep 2003, Mark Elliott wrote:

 I get this error:

 [Microsoft][ODBC SQL Server Driver][SQL Server]Could not find stored
 procedure 'insert into hosts (HOST,lastchk)

 When I attempt to insert a bunch of rows into a MSSQL table.  It gets data
 from a text file.

 Here is the code:

 use Win32::ODBC;
 $prox = new Win32::ODBC(DSN=wilma);
 @_ = ;
 foreach $_(@_){
   /(.*)\t(.*)\t(.*)/;
   $strsql = 'insert into hosts (HOST,lastchk) VALUES
 (\''.$1.'\',\''.$3.'\');';
   print $strsql;

   if ($prox-sql($strsql)){$prox-DumpError}
   $prox-sql($strsql);
   $foo = ;}

 $prox-Close();


All your '\' strings need to be changed to '\\'.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Reg Expression missing last char?

2003-09-18 Thread Carl Jolley
On Wed, 17 Sep 2003, Capacio, Paula J wrote:

 I am using $1 and $2 to retain data from a matched regular expression.
 I expect $1 to contain the KEY ID and $2 to contain USER NAME, but $2 is
 missing the last character.  See the code and results below.
 (watch out for text line wrapping)
 Thanks in advance
 Paula
 CODE
 use strict;
 #simulate the output from a back-tick command : @system_out =
 `$command`;
 my @system_out;
 push @system_out,  Alg  Type Size  Flags   Key ID User
 Name\n\n;
 push @system_out, *DSS  pair 1024/1024 [VI---] 0x2BEAF881 American
 Family Insurance\n\n;
 push @system_out,  DSS  pub  2048/1024 [-] 0x8E5DAD1A operator2
 [EMAIL PROTECTED]\n\n;
 push @system_out,  DSS  pub  3072/1024 [-] 0xBE71303F
 another/americanfamily [EMAIL PROTECTED]\n\n;
 push @system_out,  DSS  pub  1024/1024 [-] 0xB04F7DAA
 swisscow\n\n;
 push @system_out,  DSS  pub  2048/1024 [-] 0xAA2F4ABA SLM
 [EMAIL PROTECTED]\n\n;
 push @system_out,  5 found.\n\n;
 foreach my $line (@system_out) {
 next if ($line !~ /DSS  p/);   #eliminate heading/footer lines
 chomp $line;
 print $line;
 if ($line =~ /DSS  p.+\].{1}(.+).{1}(.*)/) {
 print Expression matched and retained: $1 $2\n\n;
 }else{
 print Start Over, expression did not match\n;
 }
 }
 RESULTS
 *DSS  pair 1024/1024 [VI---] 0x2BEAF881 American Family Insurance
 Expression matched and retained: 0x2BEAF881 American Family Insuranc

  DSS  pub  2048/1024 [-] 0x8E5DAD1A operator2
 [EMAIL PROTECTED]
 Expression matched and retained: 0x8E5DAD1A operator2
 [EMAIL PROTECTED]

  DSS  pub  3072/1024 [-] 0xBE71303F another/americanfamily
 [EMAIL PROTECTED]
 Expression matched and retained: 0xBE71303F another/americanfamily
 [EMAIL PROTECTED]

  DSS  pub  1024/1024 [-] 0xB04F7DAA swisscow
 Expression matched and retained: 0xB04F7DAA swissco

  DSS  pub  2048/1024 [-] 0xAA2F4ABA SLM [EMAIL PROTECTED]
 Expression matched and retained: 0xAA2F4ABA SLM [EMAIL PROTECTED]


You are push'ing the header lines not unshifting them. They will be
placed at the end of system_out. Also I believe you probably should
do the unshifts in reverse order. But that is beside the point. I suspect
that $2 matched the empty string at the end of your line, after all
you did capture it with (.*). The last real character was matched
by the preceeding .{1} field. It had to be otherwise the match would
have failed. The empty string following the last real character then
allowed the (.*) to also match.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: OT: Regex humor

2003-09-18 Thread Carl Jolley
On Thu, 18 Sep 2003, Ted Schuerzinger wrote:

 This, I suppose, is proof that computers are only as bright as the people
 who program them, and a good lesson on being careful what you look for in
 your regexes  :-)

 I've noticed that spammers sometimes try to get around people's spam
 filters by using commas or understrokes or somesuch between each letter of
 a word that might otherwise raise a warning flag, eg. s,e,x or m|o|n|e|y!
 So, I set the following line in my spam filter (Hamster) to get the more
 common ones I see:

 =kill() Subject: {f.r.e.e.} {v.i.a.g.r.a.}

 I haven't gotten many hits on this filter, but finally did this morning:


I find that using [^a-z]+ as a letter seperator is more effective,
especially when spammers use such text as V~ I~ A~ G~ R~ A

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: newbie hlelp!

2003-09-16 Thread Carl Jolley
On Mon, 15 Sep 2003, $Bill Luebkert wrote:

 alex p wrote:

  Hello all,
 
  I am trying to figure out a way to get the last modified date of a file.
  I have looked at the following modules but they dont seem to address what i
  need:  stat, utime, opendir
 
  does anyone know how to go about getting this date?

 stat should be fine :  my $mtime = (stat $path)[9];


And then to convert the $mtime to something useful, give it to
localtime(), e.g.

@date_fields=localtime($mtime);
   OR
$The_last_mod_time=scalar localtime($mtime);

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: newbie hlelp!

2003-09-16 Thread Carl Jolley
On Tue, 16 Sep 2003, alex p wrote:

 Thank you all for replying, I am using the code below and I am still unable
 to get the correct date
 code
 opendir (DIR, $server\\c\$\\sys\\data\\LOG\\updates);
   @allfiles = readdir(DIR);
   #print(, readdir(DIR));
   #closedir(DIR);
   foreach $f (@allfiles)
   {
 unless ( ($f eq .) || ($f eq ..) )
   {
 print $f\n;
 (undef,undef,undef,$dom,$mon,$year)=localtime((stat($f))[9]);
 $mon++;
 $year += 1900;
 $dateval = printf(%04d%02d%02d\n,$year,$mon,$dom);
}

That's probably because the files in @allfiles are not in your current
directory. Either prepend the directory to the front of each file
you stat or chdir to the directory.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


RE: Mail::Sendmail module problem?

2003-09-15 Thread Carl Jolley
On Mon, 15 Sep 2003, Xu, Qiang (XSSC SGP) wrote:

 Hi, Lakoduk:

 Thanks for pointing out the help webpage. Now I can use Mail::Sender to send
 mails. But I have difficulties with attachments. I don't know why it always
 complains that the file can't be found. My script is:

 ---
 use strict;
 use Mail::Sender;
 use CGI qw(:standard);

 my $sender = new Mail::Sender {
   smtp = 'my.smtp.server',
   from = '[EMAIL PROTECTED]',
   on_errors = undef
   } or die Can't create the Mail::Sender object:
 $Mail::Sender::Error\n;
 $sender-OpenMultipart({
   to = '[EMAIL PROTECTED]',
   subject = 'Hello, I\'ll come.'
   }) or die Can't open the message: $sender-{'error_msg'}\n;
 $sender-Body;
 $sender-SendEnc('*ABC*');
 Here is a new module Mail::Sender.
 It provides an object based interface to sending SMTP mails.
 It uses a direct socket connection, so it doesn't need any additional
 program.

 Enjoy, Jedi
 *ABC*
 $sender-Attach({
   description = 'Perl module Mail::Sender.pm',
   ctype = 'application/x-zip-encoded',
   encoding = 'Base64',
   disposition = 'attachment; filename=Mail-Sender.zip; type=ZIP
 archive',
   file = ./Mail-Sender.zip
   });
 $sender-Close or die Failed to send the message:
 $sender-{'error_msg'}\n;

 print header(), start_html(Sendmail);
 print p(Mail sent successfully!\n);
 print end_html();

 exit (0);
 ---

 I put the file Mail-Sender.zip in the same folder as this script. The error
 is:

 [Mon Sep 15 16:15:52 2003] [error] Failed to send the message: File
 ./Mail-Sender.zip not found

 Any idea on this issue?


Does the file Mail-Sender.zip exist in the current directory when your
program runs? What are its security attributes? You could easily put a
check in to see. On failure then you could print out the $! to show _why_
the file can't be found. An example of this code might be:

die Mail-Sender.zip not found: $! unless -f Mail-Sender.zip  -s _.

The fact that it is in the same folder as the script is not the issue, the
requirement is that it be in the current directory. If you cd'ed to the
script's folder then you should be OK but if you did something like:

perl scriptfolder\\script.pl

then it won't be.


 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Use of uninitialized value in concatenation (.) or string at...

2003-09-07 Thread Carl Jolley
On Sat, 6 Sep 2003, Devon Young wrote:

 What does this mean?? I'm thoroughly puzzled and I've been scouring the net
 for an answer. I've been assuming it means I'm not putting strings together
 correctly, but I can't figure out how to fix it. Here's the errors I'm
 getting, followed by the peice of code that the error is apparently in. I
 can't see what's wrong though. The code looks fine to me...

 Use of uninitialized value in substitution (s///) at
 C:\perl_stuff\artists.pl line 120.
 Use of uninitialized value in concatenation (.) or string at
 C:\perl_stuff\artists.pl line 122.

[many additional error messages deleted]


 And the code...


 my $counter = $_[0];
 my $x = 1;
 while ($counter  ($_[0]+11)) {
   # must escape double quotes, so there won't be JS errors.
   $artist[$counter][5] =~ s//\\/g;  # line 120

   print BLAH band[$x][1] = \$artist[$counter][0]\\;\n;
   print BLAH band[$x][2] = \$artist[$counter][1]\\;\n;
   print BLAH band[$x][3] = \$artist[$counter][2]\\;\n;
   print BLAH band[$x][4] = \$artist[$counter][3]\\;\n;
   print BLAH band[$x][5] =
 \magnet:?xt=urn:sha1:$artist[$counter][4]amp;dn=$artist[$counter][10]amp;xs=http://web1.freepeers.net/uri-res/N2R?urn:sha1:$artist[$counter][4]amp;dn=$artist[$counter][10]amp;xs=http://web2.freepeers.net/uri-res/N2R?urn:sha1:$artist[$counter][4]amp;dn=$artist[$counter][10]\\;\n;;
   print BLAH band[$x][6] = \$artist[$counter][5]\\;\n;
   print BLAH band[$x][7] = \$artist[$counter][6]\\;\n;
   print BLAH band[$x][8] = \$artist[$counter][7]\\;\n;
   print BLAH band[$x][9] = \$artist[$counter][8]\\;\n\n;
   $counter++;
   $x++;
 }

When you say:

=\$artist[$counter][0]\\;\n;

It appears that the specific error you are getting is:
use of an unititialized value in string, your examples
did not seem to be using the concatenation (.) operator.
Are you sure that $artist[$counter][0] is defined and
is not null ('')? You should probably be doing conditional
assignments, e.g.

 if (defined $artist[$counter][0]  $artist[$counter][0]) {
 .= '' . $artist[$counter][0] . '' . ;\n;

It might be a little more efficient to do:

$stuff=$artist[$counter][0];
if (defined $stuff  $stuff) {
   = qq{$stuff} . ;\n; }

Also note you are generating a reference to a string. Don't try to escape
enclosing quotes with a \. This is what the qq function was invented for.
Otherwise if you don't want to use the quoting functions then at least do:
 = '' . $artist[$counter][0] . '' . ;\n;
However, that too will produce a run-time error unless
$artist[$counter][0] is defined and not null.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 


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


Re: How can I write in perl: #ifdef __GNUC?

2003-09-04 Thread Carl Jolley
On Thu, 4 Sep 2003, Ecker Sandor wrote:

 Hi!

   I write a program for a win98 machine, and I use (thenks for this list) the
 Win32::Serialport module. But I would like to test this program under Linux, so
 I would like to write something like this:

 package Utils;
 #ifdef __WIN32#I know the variable$^O gives the OSname
   use Win32::Serialport;
   sub send_serial(){
   ...
   }
 #end

 ...

 How can I write it under Perl?


You have to use a BEGIN block and emulate the 'use' statement.
Look at perlfunc for the definition of the 'use' function.
The problem is that all 'use' statement get performed at
compile time therefore whether or not one executes a use
statement can't be conditional. But a require and a call
of a package's EXPORT method can be conditional.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 
k

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


Re: Illegal octal digit '9' problem??

2003-09-02 Thread Carl Jolley
On Tue, 2 Sep 2003, steve silvers wrote:

 With the below snippet, the numbers 8 and 9 work great, but 08 and
 09 give the error Illegal octal digit '9' or '8'. I read that these are
 two numbers that will have this problem! How do I get around this problem?


Ohh, don't use leading zeros on decimal numbers. Or read them (or force
then) to be strings. You can easily strip leading 0's from a string.
Lots of numbers may have this 'problem'. A leading 0 on a number indicates
that it is an octal number. All valid digits of an octal number range from
0..7. Just be glad you didn't try to use 010 as a decimal number. You
would have probably gotten really frustrated when you suddenly found the
value 8 amoung your data.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 


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


Re: Regex Help Needed

2003-09-02 Thread Carl Jolley
On Tue, 2 Sep 2003, Dax T. Games wrote:

 I have a list of characters.  I need to get a list of all possble sequences of these 
 characters for example.

 I have a string that consists of '-mevqgn' I need to pattern match any combination 
 of 'mevqgn' with a preceding - or --.

 Right now this is what I am doing but it is very ugly and difficult to come up with 
 the combinations and it makes my brain hurt!:

  if ($LS_Val =~ /-{1,2}(mevqgn|
emvqgn|evmqgn|evqmgn|evqgmn|evqgnm|
veqgnm|vqegnm|vqgenm|vqgnem|vagnme|
qvgnme|qgvnme|qgnvme|qgnmve|qgnmev|
gqmnev|gmqnev|gmnqev|gmneqv|gmnevq|
mgnevq|mngevq|mnegvq|mnevgq|mnevqg|
nmevqg|nemvqg|nevmqg|nevqmg|nevqgm|
envqgm|evnqgm|evqngm|evqgnm|evqgmn|
)/i)
 {
 #Do Something;
 }


 A subroutine that takes the string of characters as an argument and then returns 1 
 on success and undef on fail would be ideal for my purpose.

How about /^-{1,2}[mevgn]{6}/ i.e. turn all the characters you wish to
match into a character class. This assumes that the alphabetic string
you want to match will be 6 characters long. If it could be of any
arbitratry length but only consisting of the characters mevgn then
the patters might be: /^-{1,2}[mevgn]*/. This also assumes that
you are matching the beginning of a string.

The regex used in a match would of course produce a result of 0 or
1 so it you really wanted it to be in a subroutine then you could
do something like:

sub matched{
  return $mystring=~/^-{1,2}[mevgn]*/;
}

I, personally would think that just using the match directly in an if
statement would be cleaner, e.g.

if($mystring=~/^-{1,2}[mevgn]*/) { .

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Illegal octal digit '9' problem??

2003-09-02 Thread Carl Jolley
On Tue, 2 Sep 2003, Keith C. Ivey wrote:

 steve silvers [EMAIL PROTECTED] wrote:

  use strict;
  my @numbers = (4,09,15);  # 09 will error, 9 won't error
  my @numbers2 = (2,4,11);
  my (%hash_lookup,%hash_lookup2);
  @[EMAIL PROTECTED] = ('Y') x @numbers;

 If you had 07 it wouldn't give an error, but it still wouldn't
 work unless '7' (not '07') is one of your hash keys, because
 07 would be converted to 7.  Hash keys are strings, and if you
 convert a number to a string it has no leading 0s.

 Numbers that start with 0 in Perl are interpreted as octal.
 Try this:

print 010;

 It prints '8'.  That's why 09 is an illegal number, since 9 is
 not an octal digit.

 If you want to use something as a string (as a hash key), then
 it's better to set it to be a string rather than a number in
 the first place, so no unexpected conversions happen.  You can
 do this:

 my @numbers = ('4', '09', '15');

 or, equivalently,

 my @numbers = qw( 4 09 15 );



Of course then '19' lt '9' so the numeric sort wouldn't work very well.
The best bet it to not use leading zeros or quoted strings but use sprintf
on the decimal values to generate the string value (with leading zeros)
for use as the hash keys and, of course on any value used to index a
hash key/value.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Perl newb

2003-08-29 Thread Carl Jolley
On Thu, 28 Aug 2003, C. Church wrote:

  if ($comment =~ /\a?(.*?)/) {
 
  }

 It says that if the contents of $comment match the regular expression on the
 right, execute the block following.

 As for the RE:

 /\a?(.*?)/

 the \a? means 1 or 0 alarms -- this is only superfluous because it is not
 bound, via '^', to the beginning of the string (which could mean that a line
 beginning with two BELs would not match the RE.  This could easily be
 replaced with \a* -- which is what they said if not what they meant).

 (.*?)

 is the preferred way to capture only the contents of a 'tag' without
 capturing up to the end of the final 'tag' in the $comment string.  That is,
 it is non-greedy.

 RE's are, by default, greedy -- meaning that they will continue to match for
 as long as they can, and still allow the remaining RE to match true... Take,
 for example, the following RE:

 /(.*)/ :

 If $comment = 'foosomething/foo', with the above RE, the value of $1
 would be 'foosomething/foo' -- because it kept matching until it didn't
 find any more ''s.

 Now, by adding a question mark:

 /(.*?)/

 This tells the RE engine to stop as soon as it finds a match that allows the
 rest of the RE to be true... In this case, $1 would resolve to 'foo'.

 It could also be written as, although less eloquently:

 /([^]*)/

 Which, by including a character class that said zero or more characters that
 are NOT a close-angle-brace, has the same effect on the above string.


I kind of doubt the the original coder wanted to match the
0 length string after the first character and before the last character
in the string ''. A better pattern all around would be ([^]+).

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: stopping a running process

2003-08-29 Thread Carl Jolley
On Thu, 28 Aug 2003, just me wrote:

 hi

 i have a program that executes and generates a log
 file and it will stay there collecting logs till user
 intervention like Ctrl C. If i wanted to write a perl
 script and schedule it to stop the program after a
 certain time , how do i do it?? any ways?


You could either calculate the time based on the elapsed time since the
program started up, i.e. by getting the value of time() when the script
started and then in your program loop comparing the current value of time
to the startup time plus the number of seconds that your program's
argument provided (or the 60 times it if the elapsed time parameter is
given in minutes). When the current time(0 is = the calculated time to
stop, then you stop. You could also program it to stop at (or after) a
specified time of day. You could provide the stop time as a program
command line argument specifing the date/time to stop as a string. The
most simple way is to calculate the tick count corresponding to the stop
date/time and then in the main loop of your program, check for and
gracefully exit when you see that the time() function value is greater
than or equal to the tick value of the stopping time. To be safe, you'd
need to check that the spefified time to stop was some point in the future
rather than some point in the past. To convert a time/date to a tick count
you can use either the Time::Local module or the POSIX::mktime function.
The list recently had a similar discussion related to getting the tick
count for a specified day of the current year so that the corresponding
date could be generated. If you remember that discussion you multiply
the ($day_of_year-1) by 86400 (the number of seconds in a day) and add
that value to the tick count correspong to the beginning of the current
year.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


RE: WMI wierdness.

2003-08-29 Thread Carl Jolley
On Fri, 29 Aug 2003, Jim Lancaster wrote:

 Here is the offending sub:

 sub os_info {

 # From the WMI documentation. These are the possible values for
 #  OSProductSuite:
 my %os_product_suite = (
 1 = Small Business,
 2 = Enterprise,
 4 = BackOffice,
 8 = Communication Server,
 16 = Terminal Server,
 32 = Small Business (Restricted),
 64 = Embedded NT,
 128 = Data Center
);

 my %os_info;
 foreach my $os (in($WMI-InstancesOf(Win32_OperatingSystem))) {
 $os_info{'Caption'}= $os-{'Caption'};
 $os_info{'FreePhysicalMemory'} =
 $os-{'FreePhysicalMemory'};

# I'm not sure how/where this is calculated, but it doesn't
 appear to jibe with
 #  the data in Win32_PageFileUsage.
 $os_info{'FreeSpaceInPagingFiles'} =
 $os-{'FreeSpaceInPagingFiles'};

 $os_info{'InstallDate'} = substr($os-{'InstallDate'},4,2)./.

 substr($os-{'InstallDate'},6,2)./.
 substr($os-{'InstallDate'},0,4);
 if ($os-{'NumberOfLicensedUsers'}) {
 $os_info{'NumberOfLicensedUsers'} =
 $os-{'NumberOfLicensedUsers'};
 } else {
 $os_info{'NumberOfLicensedUsers'} = unknown;
 }
 $os_info{'NumberOfUsers'}  = $os-{'NumberOfUsers'};
 if ($os-{'Organization'}) {
 $os_info{'Organization'}   = $os-{'Organization'};
 } else {
 $os_info{'RegisteredUser'} = unknown;
 }
 if ($os-{'RegisteredUser'}) {
 $os_info{'RegisteredUser'} = $os-{'RegisteredUser'};
 } else {
 $os_info{'Organization'}   = unknown;
 }
 $os_info{'SerialNumber'}   = $os-{'SerialNumber'};

 # 'ServicePackMajorVersion' is a feature that was introduced
 #   with W2K.  Use it if applicable; for earler versions use
 'CSDVersion'.
 if ($os-{'Version'} le 5.0) {
 $os_info{'ServicePack'} = $os-{'CSDVersion'};
 } else {
 $os_info{'ServicePack'} = Service Pack .

 $os-{'ServicePackMajorVersion'}...

 $os-{'ServicePackMinorVersion'};
 }

 $os_info{'Version'}= $os-{'Version'};

 # Calculate system uptime
 my $byear= substr($os-{'LastBootUpTime'},0,4);
 my $bmonth   = substr($os-{'LastBootUpTime'},4,2);
 my $bday = substr($os-{'LastBootUpTime'},6,2);
 my $bhour= substr($os-{'LastBootUpTime'},8,2);
 my $bmin = substr($os-{'LastBootUpTime'},10,2);
 my $bsec = substr($os-{'LastBootUpTime'},12,2);
 my $cyear= substr($os-{'LocalDateTime'},0,4);
 my $cmonth   = substr($os-{'LocalDateTime'},4,2);
 my $cday = substr($os-{'LocalDateTime'},6,2);
 my $chour= substr($os-{'LocalDateTime'},8,2);
 my $cmin = substr($os-{'LocalDateTime'},10,2);
 my $csec = substr($os-{'LocalDateTime'},12,2);
 my ($dday,$dhour,$dmin,$dsec) =
 Delta_DHMS($byear,$bmonth,$bday,$bhour,$bmin,$bsec,

 $cyear,$cmonth,$cday,$chour,$cmin,$csec);
 $os_info{'SystemUptime'} = $dday days, $dhour hrs, $dmin mins,
 $dsec secs;

 # For testing purposes only.
 #dref(0,\%os_info);
 #exit;
 }

 return (%os_info);

 }


 -Original Message-
 From: Carl Jolley [mailto:[EMAIL PROTECTED]
 Sent: Thursday, August 28, 2003 4:15 PM
 To: Jim Lancaster
 Cc: [EMAIL PROTECTED]
 Subject: Re: WMI wierdness.


 On Thu, 28 Aug 2003, Jim Lancaster wrote:

  Background:
  I'm running perl v5.6.1 build 635 and Win32-OLE 0.1403 on a WinXP Pro
  workstation. I've written a number of scripts to query WMI for
  configuration (system, cpu, memory, disk, nic, etc.) information.
  They
  *had* been working fine until I went through them and cleaned up my
 old
  code. (I know, if it ain't broke...g).  All I did was replace the
 use
  of Win32-PerfLib with a new sub to calculate system uptime using WMI,
  and replace my clunky html subs with CGI.  The bulk of the WMI code I
  left alone.
 
  Symptoms:
  I can run my script from a command prompt against a single server and
  it works fine. If I queue up several servers in an external cfg file,
  some of the servers generate error messages indicating my script is
  trying to process an uninitialized hash value. The errors usually
  refer to the same couple of lines of code where I'm concatenating
  something, or dividing one number by another to get a percentage
  value.
 
  Wierdness:
  If I change the order of servers in the cfg file, the errors happen on

  different servers.  It never happens on all of the servers.  The
  position in the list doesn't appear to have any effect.  And if there
  is only one server in the list, no matter which, one, I almost never
  see the error.
 
  Even more wierdness:
  I inserted

Re: unlink doesn't

2003-08-29 Thread Carl Jolley
On Fri, 29 Aug 2003, Robert Shields wrote:

 my $logdir = $Server-Mappath (logs);

 if (!opendir (LOGDIR, $logdir)) {

   $Response-write (Could not open directory $logdir: $!br/);

 } else {

   my @files = grep (/.*\.xml/, readdir(LOGDIR));

   @files = sort @files;
   @files = sort {$b cmp $a} @files;

   my $nCount = 0;
   foreach my $file (@files) {

   if ($nCount  20)
   {
   #do some stuff...

   } elsif ($nCount = 90) {

   #delete if more than 90 logs

   $Response-write(unlinking file $filebr/);

   unlink $file;
   }
   ++$nCount;
 } }



 The output is:

 unlinking file 2000_2_1.xml
 unlinking file 2000_1_9.xml
 unlinking file 2000_1_8.xml
 unlinking file 2000_1_7.xml
 unlinking file 2000_1_6.xml
 unlinking file 2000_1_5.xml
 unlinking file 2000_1_4.xml
 unlinking file 2000_1_30.xml
 unlinking file 2000_1_3.xml
 unlinking file 2000_1_29.xml
 unlinking file 2000_1_28.xml
 unlinking file 2000_1_27.xml
 unlinking file 2000_1_26.xml
 unlinking file 2000_1_25.xml
 unlinking file 2000_1_24.xml

 etc.

 But the files are still there!

 What am I doing wrong?

You're not trying hard enough. (:-D)

You got the file names from $logdir but you are trying to unlink a
file with the same name from your current directory. Without a more
complete examination of your code I can't be sure but I believe
that changing your unlink code may do the trick, e.g.

unline $logdir/$file;

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Command line options question

2003-08-27 Thread Carl Jolley
On Tue, 26 Aug 2003, Medlen, Jiri wrote:

 Hi,

 I'm trying to simply capture VBAV29933 using Command line option

 result_sale.tmp contains
 XMLPayResponseResponseDataVendorjmedlenpro/VendorPartnerverisign
 /PartnerTransactionResultsTransactionResultResult0/ResultAVSResult
 StreetMatchMatch/StreetMatchZipMatchNo
 Match/ZipMatch/AVSResultCVResultService Not
 Requested/CVResultMessageApproved/MessagePNRefVBAV29933/PNRefAuth
 Code894PNI/AuthCodeHostCode00/HostCodeOrigResult0/OrigResultExtD
 ata  Name=IAVS
 Value=N/ExtData/TransactionResult/TransactionResults/ResponseData
 /XMLPayResponse


 perl -p -i.bak -e s/PNRef(.*)\/PNRef/$1/g result_sale.tmp  jiri.txt
 Does not work

 Any ideas?


Instead try:

perl -n -e print $1 if /PNRef(.*)\/PNRefs result_sale.tmp  jiri.txt

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Invoke perl script from CGI and redirect STDOUT, STDERR to afile

2003-08-27 Thread Carl Jolley
On Wed, 27 Aug 2003, Savinder Puri wrote:

 Hi All,

 Here's what I want to do:

 1. A web-page invokes a CGI perl script (say cgi.pl), and passes certain user inputs 
 in the QUERYSTRING.

 2. The CGI script does some pre-processing and invokes another perl script (say 
 a.pl), passing it the QUERYSTRING parameters.

 3. Script a.pl creates redirects STDOUT and STDERR to a log-file. (create an 
 action-log, to aid debugging).



 The problem:

 Step 2

 What is the best to invoke a perl script from CGI ? The perl script does a lot of 
 cpu and network intensive activity. The CGI should wait for the perl script to 
 finish, and then submit a webpage back.

 Step3

 The print statements in a.pl are being printed onto the browser (even when STDOUT 
 ands STDERR are redirected to a file).

 How do i solve this ?

  Hope i made myself clear.


Don't use the STDERR and STDOUT filehandles in a.pl, instead open a
different filehandle and send its output to a file. You may want to open
it with append othersize the output of a subsequent use of the cgi
script will overwrite that of the current. Note the STDOUT (and STDERR)
of all the nested scripts are inhereted from the top level cgi script
called by the web server. You should not mess with the STDOUT filehandle
usless you use it to send output back to the browser. I suggest you
use system() to call the embedded scripts. Use of backquotes messes
with STDOUT.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 


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


RE: How to execute a command under win98 via perl script?

2003-08-27 Thread Carl Jolley
On Wed, 27 Aug 2003, Wenjie Wang wrote:

 system copy c:\a.txt d:\a.txt;


This won't work due to unescaped backslashes in a double quoted string.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Obtaining a perl hash id in a call back function.

2003-08-27 Thread Carl Jolley
On Wed, 27 Aug 2003, Saber ZRELLI wrote:


 Hi all ,


 The problem is as follows :


 i have several communication sockets , to each socket i attach a costumised
 output window ( which is a perl object i've created ) .
 and i store all the output windows in a hash called WIN_LIST , this is the
 code snippet :

 
 $WIN_LIST{$sock}=new perl_modules::out_put_window();
 

 then i attach a function to the event destroy of each output window (
 when i close the putput window i want perl to call a certain function )
 this is the snippet :

 
 $WIN_LIST{$sock}-display-bind ('Destroy' = \remove_window);
 

 and this is the code of remove_window function :


 
 sub remove_window {

 print  trying to remove $Tk::widget \n;
 foreach $k (keys %WIN_LIST)
 {
 if ( $WIN_LIST{$k} == $Tk::widget )
 {
 delete $WIN_LIST{$k};
 $s-remove($SOCK_LIST{$k});
 delete $SOCK_LIST{$k};
 print  $Tk::widget Found in Hash and deleted \n;


 }
 }


 }

 

 what i have noticed  is :

 the   $Tk::widget have this format :
 while $WIN_LIST{$k} have this one  :

 what i want to know , is how can i obtain the $WIN_LIST{$k} like format in
 the remove_window function.
 i tried to send the $WIN_LIST{$k} as a parameter in the callback
 specification , but that caused instant call to the call back ( not caused
 by the destroy event ).


If you want to handle each socket as it is closed then you need to
create a custom DESTROY method for the object. If you simply
want to release all win_list objects at the time you exit your
script then code in an END block could perform this function.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: How to execute a command under win98 via perl script?

2003-08-27 Thread Carl Jolley
On Wed, 27 Aug 2003, Tony Cheung wrote:

 Hi, everybody
 How to execute a command under win98 via perl script? Example: copy c:\a.txt d:\
 Thanks

Look at the docs in perlfunc for the system() function and
either use single quotes or escape the backslashes  if the
parameter string uses double quotes.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 



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


RE: Win32: does anyone know how to fork a process ?

2003-08-25 Thread Carl Jolley
On Mon, 25 Aug 2003, Primanti, Joseph T wrote:

 Try this:

 use Win32::Process;


 my $ProcExe = c:\winnt\notepad.exe;
 my $ProcCmd = notepad.exe;
 createproc($Exe[0], $Exe);


 sub createproc() {
  my ($ProcExe) = $_[0];
  my ($ProcCmd) = $_[1];
   Win32::Process::Create($ProcessObj,
   $ProcExe,
   $ProcCmd,
   0,
   NORMAL_PRIORITY_CLASS,
   .)|| die ErrorReport();
 }



 -Original Message-
 From: Vincent Ribeaud [mailto:[EMAIL PROTECTED]
 Sent: Monday, August 25, 2003 09:06 AM
 To: [EMAIL PROTECTED]
 Subject: Win32: does anyone know how to fork a process ?



 Hi All,


 Does anyone know how to start a process, on a Win32 platform without
 hanging the perl process (like system) or never returning (like exec) ?


I thing you should use single quotes for $ProcExe or if you
want or need to use double quotes, escape the backslases with
backslashes.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


RE: about use...

2003-08-24 Thread Carl Jolley
On Sun, 24 Aug 2003, [iso-8859-9] [e]agLØrT wrote:

 hi..

 just got, i can change the options with CHMOD. so, the script will be not
 executed and not read, can't i?


Sure, but what use is a write-only script?
Perl has to read it to interpret it.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 


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


Re: Help with snippet

2003-08-21 Thread Carl Jolley
On Wed, 20 Aug 2003, steve silvers wrote:

 This should be easier than this. The script below works, except where it
 matches with a number it has a duplicate?

 #!Perl

 $count = 0;
 $nums  = 0;
 $numbers =
 04|09|15|16|21|23|25|29|38|40|41|42|54|55|56|62|64|65|67|68|73|80;

   @all = split(/\|/,$numbers);

   foreach my $key (1..80){
   $count++;$nums++;
   if($key = 9) { # put a 0 in front of single nums 1 - 9
   $key = 0.$key;
   }
   foreach $get (@all) {
   if($key eq $get) {
   print $key - $get \n;
   }
   else {
   if($count eq '1') {
   print $key\n;
   $count = ();

   }
   }
   }

   if($nums =~ m/^(?:10|20|30|40|50|60|70)$/) {
   print \n;
   }

   }

   exit;




 part of the output is.

 61
 62  #Duplicate?
 62 - 62
 63
 64  #Duplicate?
 64 - 64
 65  #Duplicate?
 65 - 65
 66
 67  #Duplicate?
 67 - 67

 Why is this happening?

I'm not sure what your problem may be but, you sure have some querky code:

$count = (); #what a strange way to do: $count = 0;

Of course the next time thru the outer loop, $count will again eq '1' and
you will repeat your one time logic. And of course by setting $count to
zero you defeat the purpose of printing out \n every 10 cycles through
your numbers. Note that if you have 22 entries in @all you will set
$count to 0 at least 21 times for every $key, 22 times if the $key
is not in the @all array.

Perhaps it might be usefull for you to describe what you are trying to
do so we could possiblly find the problem in your code and/or suggest
alternative ways to accoumplish your task. It appears to me that you
are trying to use $count for more than one purpose.

--

if($nums =~ m/^(?:10|20|30|40|50|60|70)$/) {
print \n;

I suspect that most people would code the two line above as:

 print \n if ($count % 10) == 0;

--

The code in the foreach $get (@all) { loop is very inefficient.
You continue the loop even if have already determined that $key eq $get.
It appears to me that a better solution would be to create a hash with
all the elements of @all as keys, e.g.

@[EMAIL PROTECTED] = (1) x @all;

then you can check for the presence of your key by:

if($allhash{$key}) {

instead of using a loop to search all of the @all array.

Better yet you could then code the entire logic of your two nested loops
as:

foreach $key (sort keys %allhash) {
   ...
   ...
   ...
}

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Need advice on obtaining MAC addresses...

2003-08-21 Thread Carl Jolley
On Wed, 20 Aug 2003, Todd Morrison wrote:

 Hello,

 Is there a way to capture a user's MAC address when a user visits a web
 page? Can this info be captured through the use of $ENV{'HTTP_USER_AGENT'}
 or perhaps a Net module?

 Any help/suggestions would be greatly appreciated. I am still a bit of a
 Perl greenhorn, so go easy on me! ;)


Off hand I don't know of any way using the environment of a web
server to capture the user's MAC address. The HTTP_USER_AGENT
just identifies the browser that the user was using. If you
are trying to verify the identity of a particular user then
the appropriate way with a web server is to require the user
to enter a password and do basic authenication. Note they will
only have to enter the password the first time they access the
page in their current browser session.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: NEED DEVICE : ftp disconnect

2003-08-21 Thread Carl Jolley
On Wed, 20 Aug 2003, agharmine  youssef wrote:



 -Message d'origine-
 De : agharmine youssef
 Envoyé : mercredi 20 août 2003 09:45
 À : '[EMAIL PROTECTED]'
 Objet : TR: ftp disconnect ?




 -Message d'origine-
 De : agharmine youssef
 Envoyé : mercredi 20 août 2003 09:04
 À : 'Stephen Patterson'; [EMAIL PROTECTED]
 Objet : RE: ftp disconnect ?




Why are you doing $lwrite=$datac-write($buf,$lread,10)
when you did: $lread = read(IN, $buf=,16*1_024)
and then you are requiring that $lwrite==$lread ?
It will only ever be true if the data that you are trying to
transfer is less than or equal to 10 bytes. If that is the
aways the case, then you don't need a loop to read/write more than
one time.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 


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


Re: reg exp seems to fail on stripping http headers under perl 806

2003-08-21 Thread Carl Jolley
On Wed, 20 Aug 2003, john z wrote:

 hi:
 when i bring in a gif or jp file from http with a get, the headers come
 along with the file. ive been trying to strip them and noticed that the reg
 exp seems to fail under perl 806.

 the following should (imho) work but dont.
 $got_gif=~s[^http(.*?)\n\n][]i;
 or
 $got_gif=~s[^http.*?\n\n][]i;

 the strange part is if i replace all the \n with something else, like \|,
 then it works. or course, i cant do the sub for a real image since its
 highly likely that \| is one of the bytes in the image file.

Then perhaps you don't understand the format of an URL (the http: stuff
or the HTTP headers. Perhaps _I_ don't understand the format of the
data you are working on.

I would think that am appropriate regex to capture the image file
name would be:

($got_gif)=$got_gif=~m!http://.+/([-\w]+\.(?=gif|jpg|jpeg))\b!i;
Of course this regex might need to be adjusted if you need the full
path to the file rather than just the base name. Your substitution
replaced every thing starting with http: (but only at the beginning
of a line) through the end of the header(s) with  a null string. If
you really have the http headers it is likely that they start with:
Content-Type: text/html. If on the other hand you are trying to
strip off all the header information up through the end-of-headers
then an appropriate substiturion operator would be:

$got_gif=~s/^.*\n\n/s;

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


RE: Slow file reading...

2003-08-20 Thread Carl Jolley
On Wed, 20 Aug 2003 [EMAIL PROTECTED] wrote:

  freed and available segment of memory that was used. My WAG is that if
  you changed the order of the different ways of reading the whole file,
  the first read will take longer than the others.

 Exactly.
 Anyway the time is the order of a few seconds, not minutes.


In fact a way to account for this effect is to pre-allocate the
chunk of memory before doing the first read, e.g.

$file_size=-s Test2.txt;
undef $whole_file;
$whole_file.=chr(0) x 100 until ($file_size-=100) = 0;
undef $whole_file;

It might even be interesting to calculate the elapsed time to complete
the memory allocation.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 


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


Re: Slow file reading...

2003-08-20 Thread Carl Jolley
On Wed, 20 Aug 2003, Ulf Lowig wrote:

 Hi, thanks fore the answers from all of you.

 One question that frequent comes back to me is why I am reading it to a
 memory. The answer is, I am not going to read it into memory, I plan to
 open a file handle and insert the hole file into as MS SQL server 2000.
 When I run insert to SQL server the insert process takes 6 to 30 sec, it
 depends on network and SQL server load. See code snip below.

 I run the same code on may SQL server machine that have AS perl 5.6.1 and
 the read did take 5 sec It's a PIII 700 Mhz 500Mb RAM running Win2K server
 SP2, this machine has heavy load.

 And now to the strange in this problem. I have PDK 5.2 If I make a test.exe
 on my machine and then run it on my SQL server machine it takes over 4
 minutes to load. Same code that did take 5 sec to run using AS perl 5.6.1.

 Is there something whit 5.8.0. I tried to upgrade from build 804 to 806 and
 no change.


 my $db  = DBI-connect(dbi:ODBC:$DS, , , { RaiseError = 1,
 PrintError =0}) or die Error_Log($DBI::errstr);
 my $st = $db- prepare(INSERT INTO tbFileArchive (EventId,FileData)
 VALUES(?,?)) || die Error_Log($DBI::errstr);
 open(ARKIV, Test2.tics) or die $!;
 {
  local $/ = undef;
  $whole_file = ARKIV;
  $st-bind_param(1, $fileidentity);
  $st-bind_param(2, ARKIV);
  $st- execute() || die Error_Log($DBI::errstr);
 }
 close ARKIV or die $!;


But why are you reading the file into $whole_file? That variable seems
to be reference only once, when you read the whole file into it.

And as an aside, what does the code: $st-bind_param(2, ARKIV);
accomplish when the state of the ARKIV filehandle at that point is open
and at eof()?

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: CPAN Module UNIX Windows newline character

2003-08-18 Thread Carl Jolley
On Mon, 18 Aug 2003, $Bill Luebkert wrote:

 Peter Eisengrein wrote:

  Here's a simple unix2dos script to save you from having to do the MS
  Word conversion in the future.
 

 This script will only work on a Windoze system of course:

  ### unix2dos.pl
 
  use strict;
  use File::Copy;
 
  my $file = $ARGV[0] || die Usage: $0 filename\n;
  my $temp = $ENV{TEMP}/$file\.$$;
 
  open(FILE,$file) || die Can't open $file for reading : $!\n;
  open(TMP, $temp) || die Can't open $temp for writing : $!\n;
 
  foreach my $line(FILE)
  {
  chomp($line);
  print TMP $line\n;

 The above two lines could just as easily be:
   print TMP $line;
 since the newline is just being removed and added right back.

  }
 
  close(FILE);
  close(TMP);
 
  move($file,$ENV{temp});
  move($temp,$file);
 
  ### end

 Or you could just use (on either UNIX or Windoze):

 #!perl -pi.bak
 BEGIN { binmode STDIN; binmode STDOUT; }
 s/[\r*\n*]+$/\r\n/;
 __END__

 or simply from the commandline (Windoze only version):

   perl -pi.bak -e  test.txt

 Perl can handle either UNIX or Windoze line endings on a Windoze system.
 UNIX can handle windoze line endings (except on the shebang line when
 started as 'scriptname' instead of 'perl scriptname', since the shell
 will barf on the \r).


And of course in the four lines:

foreach my $line(FILE)
{
chomp($line);
 print TMP $line\n;

could have been replaced with:

print TMP foreach (FILE);

or if the file was of reasonable size:

print TMP FILE;

On the other hand with the script:

#!perl -pi.bak
BEGIN { binmode STDIN; binmode STDOUT; }
s/[\r*\n*]+$/\r\n/;
__END__


I can't figure out why you would want to replace the first string of one
or more consecutive '*' characters on each line with \r\n while ignoring
the ending of that line. Or, for that matter why you would want to replace
the \r with \r\n unless you were trying to create a double spaced
version of the file. I suspect you were intending to instead do:
s/\r?\n/\r\n/;

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 



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


Re: Thoritical limits on perl processes

2003-08-18 Thread Carl Jolley
On Mon, 18 Aug 2003, Subrahmanyam Vadlamani wrote:

 Hi:

 Suppose I want to read in large text files and want to
 do something with them.  Are there any theoritical
 limits on the process size of a perl script?

 My scripts are going to be running on an AIX 5.1
 machine with quite a bit of RAM (about 8 GB RAM).  I
 will be using perl 5.6.0.


In most cases, it is not necessary to read in the entire contents of a
file but rather to work on one line at a time. In other cases when it is
really necessary to have the content of a fixed number of lines, you can
just read the fixed number of lines instead of reading all of them at
once.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: What is wrong with this?

2003-08-14 Thread Carl Jolley
On Tue, 12 Aug 2003, steve silvers wrote:

 I don't understand why the output of the below snippet kind of blows up..

 --TEXT FILE test.txt--

 03|04|09|14|15|18|24|27
 09|23|24|26|27|28|33|35
 10|11|13|15|17|18|19|22
 07|08|13|17|22|23|24|25
 03|06|07|08|11|12|16|17
 02|05|06|09|12|18|19|22

 --SCRIPT

 #!Perl -w

 use strict;
 use vars qw(%counts $numbers @numbers);

 open(FILE,test.txt) || die Can't open file $^E;
 while(FILE) {
   push(@numbers, split(/\|/,$_));
 }
 close(FILE);

 # -
 # Get Count..

 $counts{$_}++ foreach @numbers;

 foreach (sort { $counts{$b} = $counts{$a} } keys %counts) {
   print qq( $_ - $counts{$_} \n);
 }


 -- RESULTS --

 18 - 3
 24 - 3
 09 - 3
 07 - 2
 23 - 2
 15 - 2
 08 - 2
 17 - 2
 19 - 2
 03 - 2
 11 - 2
 12 - 2
 13 - 2
 06 - 2
 22 - 2
 22
 - 1
 25
 - 1
 17
 - 1
 35
 - 1
 27
 - 1
 02 - 1
 05 - 1
 16 - 1
 33 - 1
 04 - 1
 26 - 1
 10 - 1
 14 - 1
 27 - 1
 28 - 1


 Why do the last numbers as it seems is blowing out and not keep a nice form
 like the rest of the results?
 It seems likes it's just the last numbers?

 22
 - 1
 25
 - 1
 17
 - 1
 35
 - 1
 27
 - 1


It's because you aren't chomp'ing the lines when you read them. Note that
each number with a problem is the the last one on its line, i.e. you are
not using 27 you are using the value of 27\n. Note for example in your
output 27 occurs twice. This is not possible for a hash key. But you have
two separate hash keys, 27 and 27\n.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: CGI Error

2003-07-26 Thread Carl Jolley
On Sat, 26 Jul 2003, [gb2312] л ¸ù±¾ wrote:

 i got a CGI Error message
 The specified CGI application misbehaved by not returning a complete set of
 HTTP headers. The headers it did return are:

 there are the relative codes in the script
 print header,
 start_html('mail'),
 i don't know why i always get this kind of message. following is the whole
 coldes

   use CGI qw/:standard/;
   use Mail::Sender;
   print header,
 start_html('mail'),
 h1('Mail'),
  $sender = new Mail::Sender
   {smtp = 'smtp.china-netcom.com', from = 'gzip-noc'};
  $sender-MailFile({to = '[EMAIL PROTECTED]',
   subject = 'Here is the file',
   msg = I'm sending you the list you wanted.});


My WAG is that you should have h1('Mail'); instead of
   h1('Mail'),' with the way
that it is coded, the print statement is trying to print
the result of $sender=new Mail::Sender.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 


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


Re: Rename does not work with Windows

2003-07-25 Thread Carl Jolley
On Fri, 25 Jul 2003, Perl Thingy wrote:

 Hi,

 I use the statement in OS Win2K:
 rename(oldfile, newfile);
 even though it could see the file, but it doesnot seem to do rename.
 It may have somthing to do with permission, but I'm the one who wrote the
 script!
 Any idea as why it's not working


In the absence of any code my guess would be something to do with
premissions.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Archive::Zip

2003-07-25 Thread Carl Jolley
On Thu, 24 Jul 2003, Alexander Bel... wrote:

 Hi guys!
 I am currently trying write script for archiving of the data under Linux OS.

 In the Windows OS  I don't have a problem. I put putch f:/usr/web. It working fine. 
 But in the Linux I put path /var/www and I receive error:
 Can't locate object method addTree via package Archive::Zip::Archive at 
 /var/www/cgi-bin/arhivator.pl line 117.

 It is my code:
 109 sub CreateArhiv {
 110   my $inp = shift @_;
 111   my $name = '20030700';
 112   my $root = '/var/www';
 113   my $mess = New;
 114   my $out  = '${root}/arhive/${name}.zip';
 115   my $temp = '${root}/${inp}';
 116   my $zip = Archive::Zip-new();
 117   $zip-addTree($temp, $inp);
 118   my $member = $zip-addString($mess,'info');
 119   my $oldAttribs = $member-unixFileAttributes(0750);
 120   $zip-writeToFileNamed($out);
 121 return $out;
 122 }

 Where my mistake, please help me!


The path does control where perl looks for libraries except that the
current directory is always searched for libraries. It sounds like
you need to look at the 'use lib' pragma.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Page generation tweeking

2003-07-23 Thread Carl Jolley
On Wed, 23 Jul 2003, Farrington, Ryan wrote:

 Ok I have a page that reads 2 files into arrays. Pretty simple stuff like
 this:
   open(FILE, file1.txt);
   @file1 = FILE;
   close(FILE);

   open(FILE, file2.txt);
   @file2 = FILE;
   close(FILE);

 Now file1 contains a complete list of users. And file2 contains a list of
 specific users. What I really want in the long run is to output the complete
 user list into a select/select form on a webpage... Below is what I
 currently have:

 --- CODE ---
   $count = 0;
   MEMBER:foreach my $curmem (@memberlist) {
   $curmem =~ s/[\n\r]//g;
   my $there = 0;
   NOTE:foreach my $note (@notify){
   $note =~ s/[\n\r]//g;
   if($note eq $curmem){
   $there = 1;
   last NOTE;
   }
   }
   if($there){
   $memberlist_htmlvar .= qq~option selected
 value=$curmem$curmem/option~;
   } else {
   $memberlist_htmlvar .= qq~option
 value=$curmem$curmem/option~;
   }
   }
 --- END CODE ---

 Now my problem is this: the above code works fine when I have to write it
 3-4 times. But when I have it being written more then that the page slows
 down drastically. Ideally what I would like is a single variable that
 generates the option list once then have some dynamic way of checking it
 against the @notify array and marking it selected if it exists. BTW each
 time I get to the notify section I have to read a different file depending
 on where I am at in the loop. So the memberlist stays constant and the
 notify is dynamic. Ex:

 --- bad code no flames =)---
 ##before initial loop starts generate the member list with a variable I want
 filled in when I make reference to the variable
 foreach my $curmem (@memberlist) {
   $curmem =~ s/[\n\r]//g;
   $memberlist_htmlvar .= qq~option $hash{$curmem}
 value=$curmem$curmem/option~;
 }
 ##during loop
   %hash = ();
   NOTE:foreach my $note (@notify){
   $note =~ s/[\n\r]//g;
   $hash{$note} =  selected ;
   }
   Print $memberlist_htmlvar; # I would like this to output the
 memberlist_htmlvar but have the $hash{$curmem}
  #filled in with the new variables


 Anyone have thoughts?


Yuck. I suggest that you create a %notify hash and then simply do a
check on the %notify hash indexed by the $curmem, i.e.

if ($notify{$curmem}) { #its there

I don't believe that the html code generation is the appropriate
target for optimization.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 


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


Re: Reading EXCEL Sheet question

2003-07-21 Thread Carl Jolley
On Mon, 21 Jul 2003, Gianvittorio Negri wrote:

 I perl-ers.

 I have a question regarding the Excel I/F using perl

 I'm using a script reading excel sheet as a configuration file and the script is an 
 infinite loop and it is closed only by CTRL-C or KILL command. In this condition the 
 excel executable is invoked and never closed becuse the close of the excel is 
 performed only at normal termination of perl proces. This cause me some little 
 problems, and now I'm looking for a solution or workaround for close the excel 
 process.

 I'v tried to kill the excel.exe, but is not an easy task and it cause me some other 
 problems.

 There is a way to close process usinmg the normal structure of the OLE I/F ?.
 The script run normally as a W2K service (using the srvany.exe, I'm lernning for 
 porting the service in a real W2K serviuce using Win32::Service, but at the 
 moment I'v no time to do this, and I'm not sure that solve also this problem)

 Following I paste some code (an example and a part of whole script) if you run this 
 code and break the execution after printout and before sleep completion the problem 
 happen.

 Have you some idea/experience to share ?


Try defining an END block with your close of excel code there.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Problem reading directory in perl via IIS

2003-07-21 Thread Carl Jolley
On Mon, 21 Jul 2003, Stewart, Tom wrote:

 I seem to have a problem reading a directory using opendir() within a perl
 script launched from a IIS server. I have added the code to use NetResource
 and it works fine at cmd line but not within IIS. Has anyone else run into
 this problem?


When you are running under IIS, what is your cd set to? Try explicitly
setting the cd to an absolute path via the chdir function.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


RE: regular expression on military time

2003-07-21 Thread Carl Jolley
On Fri, 18 Jul 2003, Ted S. wrote:

 On 18 Jul 2003, Carl Jolley wrote in perl:

  On Thu, 17 Jul 2003, Ted S. wrote:
 
  On 17 Jul 2003, Tobias Hoellrich wrote in perl:
 
   my @t=(08:00, 23:59, 00:00, aa:00, 24:00,  00:01,
   8:00, 08.00, 36:12, 08:61 ); foreach(@t) {
 unless(/^(\d{2}):(\d{2})$/  $124  $260) {
 
  Forgive my ignorance, since I only use perl for basic things and
  haven't yet gotten to text-munging:
 
  I don't see what in your regex is capturing a $1 and a $2.  (Yes, I
  know what $1 and $2 are for.  You can all stop laughing now.  ;-)
 
 
  The first set of parens maps to $1, the second to $2, etc.

 Thanks, Carl and Bill.  Wouldn't you know that this information about
 parentheses mapping to $1 etc. actually *is* in the mess of documents that
 is the Perl manpages.  :-)  (Specifically, perlre, but who can remember
 what all the different page names actually stand for?)


You don't have to remember each of the perl pod file names. Just
remenber one command: perldoc perltoc.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Get time and date for 2 weeks at a time

2003-07-16 Thread Carl Jolley
On Tue, 15 Jul 2003, steve silvers wrote:

 Quick question. I need my script to generate two weeks worth of dates and
 days starting with the Saturdays.

 So on Friday 07/04/2003 my script would generate the below for the next two
 weeks, and so on..

 07/05/2003Saturday
 07/06/2003Sunday
 07/07/2003Monday
 07/08/2003Tuesday
 07/09/2003Wednesday
 07/10/2003Thursday
 07/11/2003Friday

 07/12/2003Saturday
 07/13/2003Sunday
 07/14/2003Monday
 07/15/2003Tuesday
 07/16/2003Wednesday
 07/17/2003Thursday
 07/18/2003Friday


 Any suggestions on how to implement this?

Localtime or gmtime would work. Once you have the timestamp of the
first Saturday, you can just increment the timestamp by an ammount,
in seconds for a daya, i.e. $saturday+=24*3600; Just feed the
adjusted timestamp as a parameter to localtime and get the values
of month, day and year. Do this loop 14 times and you have your 2 weeks
of dates. If you always run this program on Friday then you can get the
starting timestamp value by adding 24 hours worth of seconds to the
current time, e.g. $saturday=time()+24*3600; Alternatively you
can set $Saturday to time() and then in your loop, increment it
by 24*3600 before using it as a parameter to localtime.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: More confused Re: Resetting $1 when no-match

2003-07-15 Thread Carl Jolley
On Sun, 13 Jul 2003, Lawrence F. Durfee wrote:

 I wanted to examine my old code to see that this isn't a problem elsewhere. I 
 thought I understood the issue, but I guess not. I looked at several PerlMonk 
 threads, as suggested, including:
http://www.perlmonks.org/index.pl?node_id=30185
 and I am now more confused than ever. Not only is there an issue about scope 
 (especially with a block in an if statement) but also an issue as to when the 
 values are reset. The following code shows me that sometimes they ARE reset:

 @TestVectors=
 (800 555 1212,
  888 456 1234,
  999 --- 4321,
  --- --- ,
  ,
  656  ---);

 print \n--- --- - - -\n;
 foreach $Line (@TestVectors) {
   $Subst = $Line;
   $Subst =~ s/\s*([0-9]*)\s*([0-9]*)\s*([0-9]*)//;
   printf(%.2d) %15s %5s %5s %5s\n, $i, $Line, $1, $2, $3);
   $i++;
   }

 exit;

 Results in:
 --- --- - - -
 00)800 555 1212   800   555  1212
 01)888 456 1234   888   456  1234
 02)999 --- 4321   999
 03)--- --- 
 04)
 05)656  ---   656  

 This shows that they ARE reset, sometimes, if there is no match...


 At 03:46 PM 7/10/2003 -0500, you wrote:

 My thanks to Johan Lindstrom for setting me straight on this issue. I must admit, I 
 don't like it but it seems it is documented to work that way. I have been using PERL 
 for several years now and I really like it (for many, many reasons). However, this 
 is the first time that it behaved unexpectedly (outside the problems that I have 
 because I run it under an inferior O/S).

 Thanks again,
  LarryD


Note that (\s*[0-9]*) matches the null string.
Try again with (\s*[0-9]+).

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 


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


Re: Error trapping

2003-07-15 Thread Carl Jolley
On Mon, 14 Jul 2003, FARRINGTON, RYAN wrote:

 Ok I have a perl script that has been compiled as an executable and is
 running on a 2K server as a service. Now the problem is that it is die'ing
 without generating an error. Is there anyway to trap the die and then have
 it output it to a function before actually die'ing?

Have you tried to define a $SIG{DIE} subroutine?

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 


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


Re: Foreach question.

2003-07-11 Thread Carl Jolley
On Fri, 11 Jul 2003, Beckett Richard-qswi266 wrote:

 Guys,

 This is one I don't know how to approach at all.

 I've read a text file into @lines.
 I then process it like this...

 foreach (@lines) {
   last if /Next section$/;
   next unless (/match$/);
   chomp;
   process $_;
 }

 My data is random, but in this form:

 A line I want data from ending in match
 http://some.link/

 A line I don't want data from ending in something else
 http://some.other.link/

 ...

 A line I do want data from, light a match
 http://whatever
 ...

  Next section
  



 Everything was working fine, I was pulling out the required data, and doing
 what I wanted with it.

 Unfortunately, now they've decided that they want me to process the url on
 the next line as well as the first line, but only provided the line before
 matches.

 I have no idea where to start with this. Is it possible to pull 2 lines at a
 time from @lines, or something?


Sure, just to a : $second_line=shift(@lines) ; when the first line
matches. But in gereral, it's not good technique to read all the lines
into an array so that you can work on each line. Instead just loop
reading a single line, e.g.

while(FH) {

and then when you find a match you can do: $second_line=FH;

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Excel and empty rows.

2003-07-11 Thread Carl Jolley
On Fri, 11 Jul 2003, Beckett Richard-qswi266 wrote:

 Guys,

 I have sorted out what the problems are, I just don't know how to address
 them.

 I am trying to find the first empty row in a spreadsheet.

 If I use this suggestion:

 my $EmptyRow = $sheet-UsedRange-rows-count;
 $EmptyRow++;

 This points $LastRow to the first empty row of the spreadsheet, UNLESS the
 spreadsheet is totally empty. Then, the first line returns a 1, and so I
 write into row 2 by mistake.


 This suggestion:

 my $EmptyRow = $sheet-UsedRange-Find({What=*,
 SearchDirection=xlPrevious,
 SearchOrder=xlByRows})-{Row};
 $EmptyRow++;

 Will again point $LastRow at the first empty row, UNLESS the spreadsheet is
 totally empty, when it causes the script to die with...

 Can't use an undefined value as a HASH reference at D:\PR.pl line 43, FILE
 line 167.
 Win32::OLE(0.1502) error 0x80010108: The object invoked has disconnected
 from its clients in METHOD/PROPERTYGET  at D:\PR.pl line 119


 So, either I need to be able to test for an empty spreadsheet, or I need to
 catch the error generated, and set the value of $LastRow to 0.

 Unfortunately, both options are beyond me.


For an empty spreed sheet, it _may_ be that the UsedRange property is
undefined. That seems both logical a reasonable to me. It that is
correct then you could check for this condition by:

if (ref($sheet-UsedRange) eq Win32::OLE) { # sheet not empty
..
..
}
else {
   $EmptyRow=1;
}

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Excel, hyperlinks and empty rows.

2003-07-10 Thread Carl Jolley
On Thu, 10 Jul 2003, Beckett Richard-qswi266 wrote:

 Guys,

 Struggling to find the following information...

 I'm using Win32:OLE to insert text into a spreadsheet.

 Currently I have to start a new spreadsheet every time. How can I detect the
 first empty row, so that I can append new data to the bottom of an existing
 sheet?

 If I insert some text into a box, how can I set what the hyperlink for that
 text should be?


Here's one possible way. If you've set a PrintArea to print the entire
spreadsheet then, via OLE you can extact the range of the print area
($myrange=$Sheet-PageSetup-{PrintArea};) then by use of a regex
you can tretieve the value of the last row. You can't then bump the
row value by one so the print area contains the new row. Then you
can add your info to the new row.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 
k

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


Re: This is what confuses me about my...

2003-07-10 Thread Carl Jolley
On Thu, 10 Jul 2003, Beckett Richard-qswi266 wrote:

 Hello World!

 This is why I get into a state with my.

 Because the first time I encounter $spreadsheet in my script is within
 brackets, I have to add the line my $spreadsheet at teh beginning of my
 script.

 Is there a way of effectively doing this... but that works?


Have you considered the use vars pragma?

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: case insensitive index() ?

2003-07-08 Thread Carl Jolley
On Tue, 8 Jul 2003, =James Birkholz= wrote:

 Is there a way to do an index function that is case-insensitive?

 For example:

 sub stripTag {
   my $startTag = $_[0];
   my $endTag = $_[1];
   while (index($content, $startTag)0) {
   my $first = substr($content, 0, index($content, $startTag) );
   my $last = substr($content, (index($content, $endTag)+length($endTag) 
 ) );
   $content = $first.$last;
   }
   }

 stripTag(font,);
 stripTag(FONT,);

 this code has to be called with each case variant, or I'd have to put a lot
 of IFs inside the SUB

 James

 ps, tips on improving the above coding welcome, I'm just starting to come
 to grips with Perl. I know there are modules that include similar
 functions, but I'm doing this as a learning exercise.


In the StripTag sub, my suggestion would be to lowercase the tags and also
lower case a copy of the content and do your index on the copy.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


RE: Easy Reg-Ex

2003-07-07 Thread Carl Jolley
On Fri, 4 Jul 2003, Beckett Richard-qswi266 wrote:

 Isn't it because the ! hasn't been escaped with a \ that it doesn't work?

 That's what I thought, hence:

 /^Test.+PASS\!$/

 This seems to work nicely.


-
The ! is not a regex metacharacter so it does not _require_ escaping.
Of course any character CAN be escaped. So the ! will work in
either case.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Easy Reg-Ex

2003-07-07 Thread Carl Jolley
On Fri, 4 Jul 2003, M Ajmal wrote:

 Hi,

 I'm parsing a file and want to eliminate all lines
 that start with Test and end with PASS!. I'm
 trying to do the following:

 /^Test.+PASS!$/

 but it says no patterns match!

 Some help please.

Show more code, please.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Help needed: String 'C++' was treated as Nested quantifiers

2003-07-07 Thread Carl Jolley
On Mon, 7 Jul 2003, Wenjie Wang wrote:

 Greetings,

 I'm using regular expressions to parse strings read in from a data file.
 The data file happened to have text which contains ++ and it was treated
 as Nested quantifiers before  HERE in regex m/%s/ at run time.  Is there
 any way to avoid it?  It can be simply repro in following code snip:
 --8---
 my $myLine = 'Micrisoft Visual C++';
 print Got you.\n if 'ABC' =~ /$myLine/i;
 --8---

Use the \Q escape to escape regex meta characters in your data:

print Got you.\n if 'ABC' =~ /\Q$myLine\E/i;

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: how to speed up my program?

2003-07-03 Thread Carl Jolley
On Wed, 2 Jul 2003, Shuo Wang wrote:

 Hi, guys,
 I am writing a perl program with losts calculations and loading lots of data. It is 
 quite slow. Is there anyway to speed it up? Thanks.


Yes, run your code on a faster computer OR show us some code
and _maybe_ someone on this list can suugest ways to make your
code run faster on your current computer.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Perl Formats

2003-06-27 Thread Carl Jolley
On Fri, 27 Jun 2003, Christopher Moss wrote:

 Can anyone help me with this problem? I am trying to produce a report
 using the format function that is in the following format (trivial
 example):

 Family Name   Role Name
 
 flintstones   lead fred
   pal  barney
 jetsons   his boy  elroy
   lead george
   wife jane
 simpsons  kid  bart
   lead homer
   wife marge

 In other words there are repeating groups!

 The code I am using, in this case partly taken from the Perldsc as my
 actual data also makes use of a hash of hashes. So far I have been able
 to produce the following:

 Family Name   Role Name
 
 flintstones   lead fred
 flintstones   pal  barney
 jetsons   his boy  elroy
 jetsons   lead george
 jetsons   wife jane
 simpsons  kid  bart
 simpsons  lead homer
 simpsons  wife marge

 which is not quite right! I have read the docs but I can't see a way to
 define two formats side by side and switch between them. I know the
 other option is to use print/printf but I find the format function very
 useful. Any suggestions would be appreciated.

 My code follows:

 ...code...

 #!perl -w

 my %HoH = (
 flintstones = {
 lead  = fred,
 pal   = barney,
 },
 jetsons = {
 lead  = george,
 wife  = jane,
 his boy = elroy,
 },
 simpsons= {
 lead  = homer,
 wife  = marge,
 kid   = bart,
 },
  );

 open (FORM, report2.txt);

 my ($rfamily, $rrole, $rname);

 foreach $family ( sort keys %HoH ) {

   for $role ( sort keys %{ $HoH{$family} } ) {
   $rfamily = $family;
   $rrole = $role;
   $rname =$HoH{$family}{$role};
   write FORM;
   }
  }

 format FORM_TOP =
 Family Name   Role   Name
 
 .

 format FORM =
 @   ^^
 $rfamily, $rrole, $rname
 .

 end code


I suggest that, in your loop right after you assign $rfamily that you
put the following line:

 $rfamily=' ' if $seen{$rfamily}++;

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: out of memory problem!

2003-06-25 Thread Carl Jolley
On Wed, 25 Jun 2003, Suwimon Kooptiwoot wrote:

 Hi all,
  My perl program cannot work with input data, text file, size 48 MB!. I
 am running ActivePerl 5.6 under  Windows XP,  1 GB RAM . It takes
 running time overnight more than 15 hours then show me that it's out of
 memory. How can I do ? Anyone know how to solve this problem, please
 help me.


My WAG is that your problem is with your code but since you didn't
show any code, its difficult to say for sure.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Trouble counting chars

2003-06-18 Thread Carl Jolley
On Tue, 17 Jun 2003 [EMAIL PROTECTED] wrote:

 Hi!

 i've been writing a sub in order to validate a list of permissions.
 Each permission must appear once at most. Code and result are below.

 i run a simple test against the group of permission but i can't
 figure out why it stops working when the string has more than 5
 chars.

 It must be something stupid, but i can not find it. Any help would be
 appreciated.

 Regards,

 Rodrigo

 code

 use strict;

 #Function for validating a list of permisssions. Returns false if not
 valid.

 sub ValidP(@)

 { while ( @_ )

{ my $perms= shift;

  my @letters= split //, $perms;

  foreach ( @letters )

   { my $presents= m/[lrswipcda]/;

 print Fails because '$_' is not in 'lrswipcda'.  unless $presents;

 return 0 unless $presents; # Must be present!!

   }

  for my $perm ( 'l', 'r', 's', 'w', 'i', 'p', 'c', 'd', 'a' )

   { my $times= $perms =~ tr/$perm//;

 print Fails because '$perm' appears $times times in '$perms'.  if
 $times  1;

 return 0 if $times  1; # Just once or absent!!

   }

}
   return 1; #If we got here then it is valid

 }


 my @tests= qw( l lr lrs lrsw lrswi lrswip lrswipc lrswipcd Zlrswipcda
 );

 print Strings to test against 'lrswipcda':\n, join(\t\n, @tests),
 \n\n;

 my $result= ValidP(@tests);

 print General result: , $result?Ok:At least one failed, \n;

 exit(0) if $result;

 print \nDetails:\n\n;

 for my $test ( @tests )

  { print $test\t--\t;

print ValidP($test)?Ok:Bad, \n;

  }

 /code

 This is what i got.

 result

 Strings to test against 'lrswipcda':

 l

 lr

 lrs

 lrsw

 lrswi

 lrswip

 lrswipc

 lrswipcd

 Zlrswipcda

 Fails because 'l' appears 2 times in 'lrswip'. General result: At
 least one failed

 Details:

 l -- Ok

 lr-- Ok

 lrs   -- Ok

 lrsw  -- Ok

 lrswi -- Ok

 lrswip-- Fails because 'l' appears 2 times in 'lrswip'. Bad

 lrswipc   -- Fails because 'l' appears 2 times in 'lrswipc'. Bad

 lrswipcd  -- Fails because 'l' appears 2 times in 'lrswipcd'. Bad

 Zlrswipcda-- Fails because 'Z' is not in 'lrswipcda'. Bad

 /result

 Results were obtained using v5.6.1 built for MSWin32-x86-multi-thread
 Binary
 build 633 provided by ActiveState Corp. running on W2K Advanced
 Server SP 3.


Your problem is the line:

my $times= $perms =~ tr/$perm//

You are counting all instances of the characters $, p, e, r, m.

As it turns out the string: lrswip contains two of them, i.e. r and p.
In other words, the replacestring can't be a variable. Your problem
has nothiong to do with the fact that the length of the string is  5.
It has everything to do with the fact the the sixth character is a 'p'.
To see this for your self, try your code on the two character string rp.

You should either use an alternative approach to counting the characters
(perhaps a regex which can use a variable or a hash) or replace your code
with: eval my \$times= \$perms =~ tr/$perm//;

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


RE: Reverse of Chomp..(regarding not chomping)

2003-06-14 Thread Carl Jolley
On Fri, 13 Jun 2003, George Gallen wrote:

 Possibly in some cases, yes. In my case no. While
 yes by creating a second working array which is
 chomped would be fine, except for the additional
 memory needed to hold the second array. That also
 assumes that the array contents won't change from
 when it was chomped to when I need to join it back,
 which in my case, will happen, so by not chomping
 in the first place (if you mean by keeping a working
 array and chomping that one). Otherwise it would take
 more coding (for my application) to constantly ignore
 the tailing \n on each element.


The terminal $ in a regex will match either the end of the string OR
the \n at the end of a string.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


RE: Help needed -- Net::telnet gives errors

2003-06-14 Thread Carl Jolley
On Sat, 14 Jun 2003, ashish srivastava wrote:

 Hi Ibrahim
 Thanks for ur help !
 I am able to connect to the UNIX server using Prompt='/[\w]$-/' (the login
 being the user id with which the person has logged in eg. tom- ). But 1
 more prob.
 i have an application in which this perl script is being called by an HTML
 form (the usual Login screen ) and the login pwd is passed to the perl
 script

 This is my code for the HTML form
 ==
 html
 head
   titleLogin Screen/title
 /head
 body
 H1centerU User Log in Screen /U/H1/center
 brbrhr
 form name=usrlogin
 action=/cgi-bin/telp.pl method=GET 
 center
 User id  : nbspnbspnbsp
 input type=text name=fname 
 br
 Password :
 input type=password name=fpwd  brbr
 input type=reset Value=Reset  nbspnbsp  input type=submit
 Value=Submit hr
 / center
 /form

 /body
 /html

 And this is the Perl code
 

 use CGI;
 use CGI::Carp qw(fatalsToBrowser);
 use Net::Telnet();
 print Content-type:text/html\n\n;
 read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
 @pairs = split(//,$buffer);
 print  @pairs \n;
 $j=0;
 foreach $pair (@pairs) {
 ($name, $value) = split(/=/, $pair);
 $value =~ tr/+/ /;
   #($dummy,$name)= split(/?/,$name);
 $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(C, hex($1))/eg;
 $FORM{$name} = $value;
   $info[$j]= $value;
   $j++;
 }


 $t = new Net::Telnet (Timeout = 10, Prompt
 ='/-/i',input_log='D:\server\logs\inputlog.txt');
  $t-open(xxx..xxx.xxx) or die Server not found \n;
 $t-login($usr, $pwd);
   @lines = $t-cmd(ls -l);
   foreach $temp(@lines)
   {
 print a href = \cgi-bin/change_dir.pl\$temp/abr;
   }

 == The problem is that when i clik submit in the login screen, it dosent
 paas the usrname nad pswd to the perl prog. I dont understand why this is
 happening.
 Please help.


It's because you said the method was GET but you tried to retreive the
value from the form as though the method was POST. When the method is GET
the form values are passed via the $ENV{QUERY_STRING}. I strongly suggest
that the GET method NOT be used when you are passing a password unless you
only want to keep the password secret from those who don't know how to
view/source on an HTML page. Also why are you hand-parsing the form
input anyway when the CGI module has already done it for you?

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: easy newbie REGEX

2003-06-12 Thread Carl Jolley
On Tue, 10 Jun 2003, alex p wrote:

 All,
 I am really bad at REGEX's and am in need of help!
 I have a script that asks for users input but I need to check that the input
 begin with MDS(and a number 0-9) before proceeding

 below is something like what I am doing:

 print ask for input;
 chomp ($answer=STDIN);
 #(not sure which one to use below)
 while/unless/if
$answer does not begin with MDS[0-9] (and a number 0-9)
   { keep asking for answer };


I'd do it like this:

while($answer !~ /^MSD\d$/) {
  print ask for answer\n;
  chomp($answer=STDIN);
}

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

I'd do it like this:

while($answer !~ /^MSD\d$/) {
  print ask for answer\n;
  chomp($answer=STDIN);
}

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

I'd do it like this:

while($answer !~ /^MSD\d$/) {
  print ask for answer\n;
  chomp($answer=STDIN);
}

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: -d file test under WinXP Pro?

2003-06-12 Thread Carl Jolley
On Wed, 11 Jun 2003, Paul Decker wrote:

 I don't seem to be able to test for the existence/non-existence of a
 directory path using the -d file test using AS Perl 5.6.1 on WinXP
 Pro.  Regardless of the existence of the directory, the test returns
 true.  Anyone else see this?


See what? Show some code.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


RE: Win32::OLE and Excel Sorting

2003-06-12 Thread Carl Jolley
On Thu, 12 Jun 2003, Charbeneau, Chuck wrote:


  From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
  Subject: Win32::OLE and Excel Sorting

  heres one for u folks to get ur heads around - cos its doin mine in
 
  keeps throwing range method error in OLE


 The problem lies in the definition of the method, and how you are using it.
 The Excel Ole Server expects that sort be used:

 EXPRESSION-Sort (blah);

 where EXPRESSION is a range object, _not_ a sheet object.

 The following worked for me using random data in the first 9 cells of the
 first three columns.  In the example, I only selected a few cells to sort in
 my selection.  You could select the entire sheet, just a column, whatever,
 it just needs to be a range object that you are sorting.

 code
 use strict;

 use Win32::OLE qw(in with);
 use Win32::OLE::Const 'Microsoft Excel';
 use Win32::OLE::Variant;
 use Win32::OLE::NLS qw(:LOCALE :DATE);

 $Win32::OLE::Warn = 3; # Die on Errors.

 my $Excel = Win32::OLE-GetActiveObject('Excel.Application')
   || Win32::OLE-new('Excel.Application', 'Quit');
$Excel-{DisplayAlerts}=0;

 my $sheet = $Excel-{ActiveSheet};
 my $vtfalse =  Variant(VT_BOOL, 0);

 my $SortOrd1 = $sheet-Range(A1:A9);
 my $SortOrd2 = $sheet-Range(C1:C9);
 my $SortOrd3 = $sheet-Range(b1:b9);

 #IMPORTANT LINE
 my $Selection = $sheet-Range(A1:c9);

 $Selection-Sort({Key1 = $SortOrd1,
Order1 = xlDescending,
Key2 = $SortOrd2,
Order2 = xlDescending,
Key3 = $SortOrd3,
Order3 = xlAscending,
});
 /code


Yhe OP's code was missing:

use Win32::OLE::Const 'Microsoft Excel';

And yet he used the xl... constants. for descedning, etc.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Use of split function...

2003-06-10 Thread Carl Jolley
On Mon, 9 Jun 2003, Zbynek Houska wrote:

 dear all,

 I wonder how to initialize and use split function in this case:

 here are some datas (stored in file):

 28.10.2002  06:47   DIR  Almighty - Just add life
 28.10.2002  06:47   DIR  Anastacia - Freak of nature
 28.10.2002  06:47   DIR  Anastacia - Not that kind
 28.10.2002  06:47   DIR  Anathema - (1998) Alternative 4
 28.10.2002  06:47   DIR  Ancient - The Halls Of Eternity
 28.10.2002  06:47   DIR  Annie Lenox - Diva
 15.11.2002  09:46   DIR  Aerosmith
 22.11.2002  08:37   DIR  Blind Guardian - A Night At The Opera
 28.11.2002  11:04   DIR  Craig David - Slicker Than Your
 Average

 and I would like to wipe out all dates a DIR prefixes. Only third column
 should be sorted and printed...
 I have this simple script:

 #!/usr/bin/perl -w
 $file=;
 @list=();
 @result=();
 print 'Which file do you want to open: ';
 chomp ($file=STDIN);
 open (FILE, $file);
 @list=FILE;
 @result = sort {$a cmp $b } @list;
 print @result;

 It works great, but I really don't know how to properly use/initialize split
 (or maybe %hash).I know I should use something like this:
 @list= split (' ', $file), but it doesn't work, it returns file name only...
 So, could someone help me?


After: @list=FILE do:

foreach (@list) {
  chomp;
  $_=(split(/ /,$_))[3];
}

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


RE: Can't locate Cisco.pm in @INC...again

2003-06-10 Thread Carl Jolley
On Tue, 10 Jun 2003, [iso-8859-1] Wermström Emma wrote:

 Hi Randy,

 Do you have similar problems with any other modules? For example,
 if you do
C:\ perl -MNet::Telnet -e print 1
 is an error produced?

 If you make up a file Silly.pm:
 ===
 # file Silly.pm
 package Net::Telnet::Silly;
 1;
 ===
 and place it in the C:\Perl\site\lib\Net\Telnet\ directory,
 does
C:\ perl -MNet::Telnet::Silly -e print 1
 produce any error?

 None of the above produces an error. They both just print the number 1. Like I said, 
 I have no problem running the html-code with embedded perl on the web server. It's 
 when I try to access the web-pages from a client pc that the error message is 
 produced. It may have something to do with permissions in the IIS web server. I just 
 don't know what. Thanks again for helping me.


Could it possibly be that perlscript doesn't run on the server?
If perlscript isn't installed on the client, it won't work.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 


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


Re: Single quotes on the command line

2003-05-31 Thread Carl Jolley
On Thu, 29 May 2003 [EMAIL PROTECTED] wrote:

 I'm not a Windows user, so be patient with me.

 Is there something wrong with my installation or is this normal behavior?

 C:\perl -e 'print hello\n'
 Can't find string terminator ' anywhere before EOF at -e line 1.

 C:\perl -e print qq(hello\n)
 hello


 I suppose that since there's a workaround it's not a big deal, but it just
 seems awkward.


Take it up with Bill. The shell simply doesn't recognize ' as a quote
character. Perl can use either (unless you need interpolation). In
fact using the q and qq functions, just about any special character
can be used to delimit text.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Daemonizing a perl application

2003-05-31 Thread Carl Jolley
On Fri, 30 May 2003, Mark Calleja wrote:

 G'day All,

 I'm trying to daemonize a perl app under Windows but without much joy. Under
 a *nix OS I have no such problems, as the following bit of code does the
 trick:

 
 use POSIX;

 $pid = fork;
 exit if ($pid);
 die Couldn't fork: $! unless defined ($pid);
 POSIX::setsid() or die Can't start new session: $!;
 

 One then simply starts the job from the command line which forks off the
 child into the background leaving the parent to exit gracefully.
 Unfortunately ActivePerl does not implement setsid, leaving me in a pickle.
 I suppose my ignorance of Perl+Windows is showing here, but can anyone
 suggest a solution/workaround?


It's not that perl doesn't implement setsid. It can't. Windows doesn't
implement setsid. Generally perl can only provide system-level
functionality if the underlying OS provides it and also provides a hook
into it.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 


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


Re: Global substitution

2003-05-31 Thread Carl Jolley
On Fri, 30 May 2003, Ricci, Mark wrote:

 Hello All,

   I have a file that has br characters instead of carriage returns.
 I'm having a hard time coming up with an automated search and replace
 script.

   Any ideas would be appreciated...


How about $data=~s/br/\n/gi;

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Global substitution

2003-05-31 Thread Carl Jolley
On Fri, 30 May 2003, Charlie Schloemer wrote:

 - Original Message -
 From: Ricci, Mark [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Friday, May 30, 2003 11:04 AM
 Subject: Global substitution


  Hello All,
 
  I have a file that has br characters instead of carriage returns.
  I'm having a hard time coming up with an automated search and
 replace
  script.
 
  Any ideas would be appreciated...
 
  Mark
 
  #!c:\perl\bin -w
  use strict;
 
 
  my $infile = text.txt;
  My $outfile = results.txt;
  open(DATA, $infile);
  open(OUTDATA, $outfile);
  my %counts;
  while (DATA) {
   pull in data and replace  br with a carriage return
  $data =~ (/(\S+)/g);
   assign the new DATA to a variable
  my $newdata = $data;
  print OUTDATA $newdata\n;
  }
  Close DATA;
  Close OUTDATA;
 


 Mark, here's some workable code:

 #!c:\perl\bin -w
 use strict;

 my $in  = in;
 my $out = out;

 open(IN,  $in);
 open(OUT, $out);

 while (IN) {
  s/[Bb][Rr]/\n/g;
  print OUT $_;
 }

 close IN;
 close OUT;
 # The End

 Problems with your script are many.  Perl's built-in functions are
 typically lower-case (Close != close, My != my, etc.)  In your while
 loop, there is no assignment made to $data, so the subsequent
 transformation (not to remove br tags) are operating on an
 uninitialized variable.  DATA's incoming lines are not automatically
 assigned to $data, but to $_.  There was only one mention of %counts,
 too.  While not fatal, it serves no purpose and should be removed.


Another way of dealing with a file that has br instead of linefeeds
is to do: $\=br before the file is opened, however that won't work
if any BR tags are used.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 


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


Re: Global substitution

2003-05-31 Thread Carl Jolley
On Fri, 30 May 2003, Nut Cracker wrote:

 open(MF, MyFile.txt);
 while(defined($line=MF)){
 if($line =~ /\br\/ig){
 $line =~ s/\br\/\r/;
 }
 }


 it might be ugly, but it should work.

 NuTs


It's unnecessarily ugly. There's no need to escape the  or  characters.
And BTW, \r is the carrage return character not the linefeed character.
Also its not necessary to do a match before doing the substitute. The
substiture function will only happen if the match is made. The more
straight-fowared way to do change the br tags to linefeeds is:

$line=~s/br/\n/gi;

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Chopping out 5 Digits At the end of a string

2003-03-28 Thread Carl Jolley
On Wed, 26 Mar 2003, viktoras wrote:

 Hi !
 This is the fastest :-)

 substr($i, -5, 5)=;

 where $i is your number or any other string. It removes last 5
 characters from any string.

 Regards
 Viktoras

 Barlow, Neil wrote:

  Hi all,
 
 
 
  This is a simple question for those in the know.
 
  I am looking to chop out the last 5 digits of a string of numbers?
 
  What would be the fastest way to do it?
 
  Can anyone point me in the right direction seeing how to do it?
 

But, it would not work corrrectly if the string ended with a linefeed,
whereas the regex methods, anchored at the end with a $ regex
metacharacter, would.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Another regular expression question

2003-03-20 Thread Carl Jolley
On Thu, 20 Mar 2003 [EMAIL PROTECTED] wrote:

 Filename = Base-02.04.1.20.5.002-xlite_katana_free.ndu;

 I want to get extension of the file name which is ndu, but I always get
 04.1.20.5.002-xlite_katana_free.ndu instead of ndu.

 The sub is like:

 sub extension
 {
   my $path = shift;
   my $ext = fileparse($path, '\..*?'))[2];
   $ext =~ s/^\.//;
   return $ext;
 }

 what is wrong with it?

 Thanks

 Lixin


 -Original Message-
 From: Randy W. Sims [mailto:[EMAIL PROTECTED]
 Sent: Wednesday, March 19, 2003 6:24 PM
 To: [EMAIL PROTECTED]
 Cc: [EMAIL PROTECTED]
 Subject: Re: an regular expression question


 On 3/19/2003 6:16 PM, [EMAIL PROTECTED] wrote:
  All,
 
  A question:
  A file like C:\temp\test.txt, how can I get test.txt from this path by
  regular expression? I can do it by split function, but I hope I can learn
  how to do it by regular expression.
 
  Thanks a lot in advance!
 
  Lixin
 

 use File::Basename;
 my $fullpath = 'C:\temp\test.txt';
 my $basename = basename( $fullpath );

 Randy.


Your best bet is to use a regex match on the extension anchored at the end
of the string. If your extension is always 3 characters, this would work:

($extension)=$path=~/\.(\w{3})$/;

If the extention can be of arbirtrary length then you could use

($extension)=$path=~/\.(\w+)$/;

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 


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


Re: Problem with Net::FTP

2003-03-19 Thread Carl Jolley
On Wed, 19 Mar 2003, Koteshwar Rao A wrote:


 Hai ,

 My name is eswar , I am in a process of automating the ftp process from
 a windows worstation to Unix server,

 When I am using this Net::Ftp for this , I am getting the  following
 error,

 Can't locate object method Use via package Net::ftp(perhaps you
 forgot to load Net::ftp?)

  Is there any problem with the Perl package that is installed???

 Second question : How do I get the information about the modules that
 are loaded in existing Perl ..

 Can anyone help me in getting out of this problem , Thanx in advance


Check your capitalization carefully. It's 'use' and Net::FTP.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Results per page

2003-03-14 Thread Carl Jolley
On Wed, 5 Mar 2003, Erich C. Beyrent wrote:

 Hey folks,

 Looking for some ideas.  I have a flat file database, which contains a
 buttload of records.  When I go get a bunch of records, I am running into a
 problem where a huge number of records is taking a while to print to the
 browser.  My solution was to break it up and only display 50 results per
 page.  The problem is, I am not sure how to go about doing this and am
 looking for ideas.  The code that gathers the results is listed below.

 Thanks in advance!

 -Erich-
 ===

 open (FILE, $file) or die Cannot open $file: $!\n;
  while ( FILE )
  {
   last if /^\[$start_rec\]$/;
  }
 while ( FILE )
  {
   last if /^\[.+\]$/;
   chomp $_;
   ($cat_num, $link, $name, $title, $composer,
   $arranger, $publisher, $price, $description) = split(/\:/, $_);

   %temp=( catalog = $cat_num,
link   = $link,
name  = $name,
title  = $title,
composer = $composer,
arranger = $arranger,
publisher  = $publisher,
price  = $price,
description  = $description,
 );
   push(@records,{%temp});
  }

 foreach $saleitem(sort {lc($a-{arranger}) cmp lc($b-{arranger}) }
 @records)
   {
$count++;
# Colored row stuff
if ($count %2 == 0)
{
 $color = white;
}
else
{
 $color = #DD;
}

 foreach $hash_key (sort keys %{$saleitem})
 {
  $cat_num=$saleitem-{catalog};
  $link = $saleitem-{link};
  $name = $saleitem-{name};
  $title = $saleitem-{title};
  $composer = $saleitem-{composer};
  $arranger = $saleitem-{arranger};
  $publisher=$saleitem-{publisher};
  $price=$saleitem-{price};
  $description=$saleitem-{description};

 print LIST;
 tr height=15
  td align=left width=20 bgcolor=$colorfont size=2$cat_num/td
  td align=left bgcolor=$colora href=../$link target=_blankfont
 size=2$title /a/td
  td align=left bgcolor=$colorfont size=2$composer/td
  td align=left bgcolor=$colorfont size=2$arranger/td
  td align=left bgcolor=$colorfont size=2$publisher/td
  td align=left bgcolor=$colorfont size=2$price/td
  /tr
 LIST



I would read the first 50 records and send the response with a hidden form
field with the value of tell(F).I'd also have a second submit button and a
message saying Hit next for next page of records. On subsequent pages I
would use the same program but if the hidden form filed was present, I
would retrieve its value and first do a seek(F,$value,0) before reading
the next 50 entries. When end of file was reached I'd send the hidden form
field with a 0 value and perhaps a message saying Done, hit next to
restart at beginning of file. If you wanted to, you could also send
a hidden form field with a page-number value.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Parsing test file question

2003-03-14 Thread Carl Jolley
On Thu, 6 Mar 2003, James wrote:

 Hi all,

 I have a test file which conatin words separated by
 comma and I would like to process and print the result
 to an ouput file. The output file should only have at
 most 32 characters per line.If the line read is more
 than 32 char, then the rest should be printed in the
 next line. Can anybody help me with this?

 This is the input file:

 ###   INPUT  FILE 
 AA1234,AA3134,AA1345,AA091,A2,AA1206,AAA0912,AA8731
 BB1344
 C1,CC1299,CC2425,0965,C4,CC1400,CCC1345,CC0012,CC231
 DD6623,DD1200,DDD2456,DDD1123,D2,DD1206,D1,DD0011,D3
 EE5609,EE1200
   END  ##

 And I want to create an ouput file like this(print the
 word read but cannot have more than 32, if more print
 it in the next line):

  OUTPUT FILE #
 AA1234,AA3134,AA1345,AA091,A2,
 AA1206,AAA0912,AA8731
 BB1344
 C1,CC1299,CC2425,0965,C4,
 CC1400,CCC1345,CC0012,CC231
 DD6623,DD1200,DDD2456,DDD1123,
 D2,DD1206,D1,DD0011,D3
 EE5609,EE1200
   END  


Use the rindex function to find the left-most comma that
is 32 characters from the start. Note this can be done
in a loop in case the input line is longer than 64 characters.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: How do I edit the tab of an Excel worksheet?

2003-03-14 Thread Carl Jolley
On Fri, 7 Mar 2003, Joel Brockman wrote:

 After I insert data in a worksheet.

 use Win32::OLE;
 $Excel = Win32::OLE-new(Excel.Application);
 $Excel-{Visible} = 1;
 $Book = $Excel-Workbooks-Add;
 $Sheet = $Book-Worksheets(1);
 $Range = $Sheet-Range(A1);
 $Range-{Value} = ['Test'];

 I would like to change the tab on the worksheet from Sheet1 to some label of my 
 choice.

 $label = MyLabel;

 I tried recording a macro while doing it manually to see what the VB code looks 
 like, but the code stops after I select the tab!

 Sheets(Sheet1).Select


No need to select the sheet to change its name.

$Sheet-{Name}=$label;

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Regular Expression matching problem

2003-03-14 Thread Carl Jolley
On Sun, 9 Mar 2003, Electron One wrote:

 Hello Everyone,

   If I have a file that contains this,

 test3.txt##
 wilma

 wimagren was here

 twilma was type wilma

 wilma

 wilma

 wilma

 twowilmase
 ##

 and i have a perl script that contains this,

 ###perlname.pl
 #!/usr/bin/perl


 while(){
 chomp;
 if(/wilma\s+/){
print wilma was mentioned\n;
}
 }

 #

 and I type, perl -w perlname.pl test3.txt
 shouldnt the output be, wilma was mentioned \n, 7 times? My output file
 only mentions it once. What am I doing wrong?


Two things:

One since your are chomping the input line, your regex which requires
trailing white space after 'wilma' wont't match those lines which end with
the characters wilma. I suggest you change your regex to: /wilma\b/.
Alternatively you could just take out the chomp.

Two you are only checking for one instance of your regex per input line.
I suggest you change your code from an 'if' to:

while(/wilma\b/g) {

You should get 6 matches on your input file not seven.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Not matching a dot

2003-03-14 Thread Carl Jolley
On Mon, 10 Mar 2003, Andrew Mansfield wrote:

 I want to match files that have no period in their filename.

 So far I have:

 use strict;
 use warnings;

 my $start_dir = $ARGV[0] || .;
 use File::Find;
 print Temp file list:\n;
 find sub {
   return unless -f;
   my $file=$File::Find::name;
   if( $_ =~ /[^.]/) {
 print $file\n;
   }
 }, $start_dir;

 I'm getting mixed up with the character class: if I have [.] it matches
 only the files with a dot; [^.] matches everything.

 What am I doing wrong?


What you are matching is any character that isn't a dot. You could try:

if($file !~ /\./) or better yet try:

print file $file has no dot\n unless $file=~tr/././;

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: environment variable issues

2003-03-14 Thread Carl Jolley
On Tue, 11 Mar 2003, jphipps wrote:

 I am having problems retreiving some of the environment variables using cgi.pm
 here is the code that I am trying to use, what the heck is wrong

 Code
 declartions:
 use CGI qw/:ALL/;
 $cgi = new CGI;

 routine:
 {
 if (($cgi-http('request_method)) ne 'POST'){
 die  invalid script call method $cgi-http('request_method'),\n 
 $cgi-http('script_name') MUST be called using POST
 }

 error:
 invalid script call method CGI=HASH(0x11b21c8)-http('request_method'),
  CGI=HASH(0x11b21c8)-http:('script_name') MUST be called using POST at 
 D:\pumaspalace\cgi-bin\feedback.cgi line 87.


 I have no idea how to fix it, the code seems to be set up the way the CGI.PM docs 
 want it... but the output from the die command is not giving proper information.

 Another thing, do you folks have any idea how to check and make sure that and email 
 address is valid, by this i mean that it actually exists on a server??


Just use:

$ENV{REQUEST_METHOD}

The CGI module isn't used to retrieve enviromental variables. The
environmental variables are in the %ENV hash.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Simple syntax question

2003-03-14 Thread Carl Jolley
On Thu, 13 Mar 2003, Mark A. Chalkley wrote:

 Ok, a dumb question here (I must be having a brain halt...):

 Given the following snippet of code to load data from a file into a
 hash,

 while( DATA ) { /(.*)\,(.*)/  ($hash{$1} = $2) };


 what does the '' do?


It's a logical AND operator so that the hash assignment is done
only when the regex matches. However the regex is pretty sloppy.
Note tbe following lines all will match:

?,*
,
 ,
#,#
screwed,eval {`format drive C: \\V:x \\U`}

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Adding a WorkSheet to Excel using Win32::OLE

2003-03-14 Thread Carl Jolley
On Thu, 13 Mar 2003 [EMAIL PROTECTED] wrote:



 I am trying to add a Worksheet to an Excel Workbook file.  I can use the Add
 method to put the sheet with its tab on the left hand side but I want to add its
 tab on the RIGHT hand side.  I have tried:

 $book-Worksheets-Add( After=$book-Worksheets-{Count} );
 $sheet = $book-{ActiveSheet};
 $sheet-{Name} = $sname;

 but this does not work and fails with the following error:

  Win32::OLE(0.1601) error 0x80020009: Exception occurred
  in METHOD/PROPERTYGET Add at /PerlApp/Sheet.pm line 299

 Can anyone help me out please?


Try this:

$Sheet=$book-WorkSheets-Add;
$_=$book-WorkSheets-{Count};
$Sheet-Move(After=$book-WorkSheets{$_});

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: CALLED

2003-02-27 Thread Carl Jolley
On Thu, 27 Feb 2003, [iso-2022-jp] $B#t#a#g#u#t#i(B wrote:

 Hi,

 Is there Perl built-in function, the reverse of caller?
 Now I'm coding many many subroutines.
 I like to get current name of subroutine just I'm in.

 ...
 sub sub_1 {
   my (@parm) = @_;
   my ($pkg, $filename, $line, $subname) = called;
   log_debug($subname start, number of parm = , scalar(@parm), \n;
   ...
 }

 If not possible I must code like;
 ...
 sub sub_1 {
   my (@parm) = @_;
   my $subID = sub_1;
   log_debug($subID start, number of parm = , scalar(@parm), \n;
   ...
 }
 sub sub_2 {
   my (@parm) = @_;
   my $subID = sub_2;
   log_debug($subID start, number of parm = , scalar(@parm), \n;
   ...
 }
 sub sub_3 {
   my (@parm) = @_;
   my $subID = sub_3;
   log_debug($subID start, number of parm = , scalar(@parm), \n;
   ...
 }


Just write another sub and call it. It's caller will be whatever
sub its called from. For example the new sub could be named
called. If you're only interested in allowing a sub to fetch
its own name then called might be written like this:

sub called{
  return (caller)[3];
}

and you might call it like this:

sub sub_1 {
my (@parm) = @_;
my ($subname) = called;
log_debug($subname start, number of parm = , scalar(@parm), \n;
   ...
}

Alternativly you might just put the caller code in the log_debug routine
instead of passing the subname as a parameter since, I assume the subname
that the log_debug sub prints will always be the name of the sub that called
it.

In that case, you could call log_debug like:

log_debug(start, number of param = , scalar(@param)); and
the code in log_debug might look like:

sub log_debug{
  my($info)=(caller)[3] .  . $_[0] . $[1] . \n;
  ..
  ..
}

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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


Re: Newbie Question

2003-02-10 Thread Carl Jolley
On Mon, 10 Feb 2003, Heberson Almeida wrote:

 HI all!!!

 I want to change some strings inside a HTML files, but I am trying to do this using 
a command listed for Perl for Unix.

 How can I change the string inside many html files using Perl for Win32 (5.6.X.X)???


You haven't provided enough information to allow a definative answer
to your question. If all the .html? files are in a specified directory
then the script could either do an opendir with readdir function calls
in a loop to get all the file names or use a glob to do the same
thing. If the files are simply an arbitrary list then their names could
be provided as multiple arguments via the @ARGV array. Once the set of
file names are provided the loop could open, read each one and create a
corresponing output file for each file that it changes.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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



Re: Regex question

2003-02-06 Thread Carl Jolley
On Thu, 6 Feb 2003, Ben Gonzalez wrote:

 All,

 I have a string that can contain any number from 0 to 1048575.

 I can verify that the numbers are digits like this: ^\d{1,7}$

 The above regex matches any 1 to 7 digits. It will ensure that the string
 contains digits 0 to 999.

 I need to make sure that the number is less or = to 1048575. I can easily do
 this without regex. But I'm just curious if I can do this with a regular
 expression?


---
Yes, but it probably isn't worth the effort.

Note that all numbers of 6 digits or less would be acceptable.
Additionally all 7 digits numbers that begin with a 0 character are also
acceptable. Further note that a 7 digit stiring beginning with 10 would
be aceceptable if the next digit was from the class [0123]. That the 7
digit number would be acceptable if the first three digits were 104 and
the next digit came from the class [0-7], etc. etc.. Like I said possible
but not worth the effort and likely to confuse either you or who ever
might inherit the task of maintain the script in the future absent copious
documentation.

The leading part of such a regex might look like:

$number=/^(?:\d{1,6}|0\d{6}|10[0-3]\d{4}|104[0-7]\d{3}|

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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



Re: Regex question

2003-02-06 Thread Carl Jolley
On Thu, 6 Feb 2003, Richard Morse wrote:

 On 02/06/2003 2:09 PM, Ben Gonzalez [EMAIL PROTECTED] wrote:

  All,
 
  I have a string that can contain any number from 0 to 1048575.
 
  I can verify that the numbers are digits like this: ^\d{1,7}$
 
  The above regex matches any 1 to 7 digits. It will ensure that the string
  contains digits 0 to 999.
 
  I need to make sure that the number is less or = to 1048575. I can easily do
  this without regex. But I'm just curious if I can do this with a regular
  expression?

 Just because something _can_ be done with at regular expression, doesn't
 necessarily mean that it should be

 It may be possible.  I don't know how off the top of my head.  Is it that
 much harder to write:

 If (($var =~ m/^\d{1,7}$/) and (($var = 0) and ($var = 1048575))) ...


The check for ($var = 0) is redundant. All strings of 7 digits or less
will have a value of = 0.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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



Re: Search a free Perl debugger

2003-02-04 Thread Carl Jolley
On Mon, 3 Feb 2003 [EMAIL PROTECTED] wrote:

 Hi,

 I have to debug my scripts. But i don't know a free Perl debugger.
 Can you recommand me one.

Have you tried the one that is built into perl? It's activated
with the -d flag and the standard documentation contains
information about it.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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



Re: determining if a scalar is an integer or not

2003-02-04 Thread Carl Jolley
On Fri, 31 Jan 2003, Andreas.Kamentz wrote:


 I'd like to supplement the suggestions that came from all sides with a little
 subroutine which always worked for me determining whether the scalar is a number
 (not only integer) and returning the number if it is one. Once having the $res
 number from $val variable , you can always test it for being integer, e.g. by
 evaluating the expression
  (int abs $res == abs $res)
 or, alltogether, checking the $val variable for being integer by the
(isnumber $val  int abs isnumber $val == abs isnumber $val)
 expression.

 Cheers,

  --  Andreas

 
 # (isn) isnumber
 # Returns decimal value of the contents if argument
 # is a number (integer if octal or hexadecimal),
 # otherwise returns empty string ('')
 
 sub isnumber($) {
 local $_ = shift;
 return '' unless /^[+-]?(?:\d+\.?\d*|\.\d+)$|^[+-]?0x[0-9a-fA-F]*$/;
 s/\+//; my $sign = s/^-// ? '-' : '';
 /^0[0-7]*$|^0x[0-9a-fA-F]*$/ ? $sign.oct : $sign.$_*1;
 }



Correct me if I'm wrong but I believe your isnumber sub would indicate
that 3e4 is not a number.

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



Re: What's wrong with this?

2003-02-04 Thread Carl Jolley
On Mon, 3 Feb 2003, Dax T. Games wrote:

 print What is the number?\n\n;

 %Number = (1=800 ,2=810,3=1600,4=1610);

 foreach $Key(%Number) {
  print   $Key\n;
 }

 print New Number: ;

 I get:

 What is the number?

   1
   800
   2
   810
   3
   1600
   4
   1610
 New Model:

 When I should get:

 What is the number?

   1
   2
   3
   4
 New Model:

 I'm feeling very stupid right now, I need a sanity check!


Without knowing for sure you probably intended to say:

foreach $KEY (keys %Number) {

Otherwise you are simply assigning each item that is part of
the %Number hash to the variable $Key. Recall that the items in
a hash are simply the key/value pairs. When you are printing out
the items in the hash you are simply printing the first key, first
value, second key, second value, etc.. The fact that you named
the iteration variable $Key means nothing.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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



Re: is it a binary file?

2003-01-30 Thread Carl Jolley
On Wed, 29 Jan 2003 [EMAIL PROTECTED] wrote:

 Hi all,

 is there a built in way to distinguish a binary file from a text file, such that
 I can call different routines to read and process it?

 Or is the only way to make a statistics about all the character codes
 in the file, and treat it as a binary file if there are lots of 0x00...0x1f and
  0x80 characters?


Perl will test the first several hundred bytes of a file and tell you
based on the value of those characters whether a file is a text or bindary
file. It uses the -T test to say that the file has text content and the -B
test to say if the file has binary characters vs. just printable ASCII
characters. Note if the file is several thousand bytes long and the first
binary character doesn't occur until near the end of the file, perl will
still tell you its a text file. Note, this may sometimes result in perl
telling you that a .pdf file is text because it in fact it really is in
that it considst of only ASCII text characters. It's just that those ASCII
characters describe (in the PDF language) how to create the
corresponding PDF document. Just because a file consists only of ASCII
characters does not necessarally mean that it is a unformatted text
document.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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



Re: string compare

2003-01-30 Thread Carl Jolley
On Wed, 29 Jan 2003, Krishna, Hari wrote:

 Friends,

 I have two string
 $m1=hari$;
 $t1=HaRi$;

 How do I compare irrespective of the case?

 Since they are strings, I have to use 'eq' as comparison operator.

   if ($m1 eq $t1) -- doesn't work as it looks at the case
 $m1 eq m/$t1/i  I know m// is used to match a string against a regular
 expression.
 $m1 eq ~/$t1/

 so I tried

 $m1 == /$t1/i

 $m1 =~ /$t1/

 $m1 eq /\[A-Z][a-z]$t1/

 and others too but it doesn't work. I couldn't find help on the net either.


If you want to use the comparison operators rather than the regex
match with the i flag then either use the uc or lc functions on
both items, e.g. if (lc($m1) eq lc($t1)) {

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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



Re: sort a table

2003-01-30 Thread Carl Jolley
On Wed, 29 Jan 2003, Andrew Mansfield wrote:

 Thanks for the tips about command line arguments, working great..

 however I'm faced with another problem in which walking thru my O'Reilly
 books  perldocs isn't made clear enough for me..

 I have a list of data read in from a text file in which each line has the
 following format:

 time status type first_name last_name machine_name

 where each value is separated by a space. I want to do a multi-sort by the
 various field types

 for example: last_name then first_name then type then status then time.

 Do I need to split each line into an array first and do something or can I
 sort by setting the $a and $b to match each of the fields in succession..

 Here's what I tried out as an experiment to sort by machine_name, trying to
 use \w$ to match the last word without splitting the line:

 my @userdata=sort {$a =~ /\w$/ cmp $b =~ /\w$/} @userlist; # where userlist is the 
unsorted list.

 It doesn't work: the list comes out as if it was sorted on the time field.

 Is there a better way to do this?


I suggest that you take the time to learn the differce between
comparison operators and regex match operators including the appropriate
syntax in whith each is used.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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



Re: determining if a scalar is an integer or not

2003-01-30 Thread Carl Jolley
On Thu, 30 Jan 2003, Andre van der Lingen wrote:

 I would do it like this:

 if ($var / 1) {
   print (var: $var is: integer\n);
 } else{
   print (var: $var is: string\n);
 }

 if $var is a string than the outcome = 0 so the if statement will
 print that $var is a string.


Try your code when ($var = 0). I think you may be suprised to discover
that the number 0 is a string rather than an integer.

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 
k

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



Re: determining if a scalar is an integer or not

2003-01-30 Thread Carl Jolley
On Thu, 30 Jan 2003, Sisyphus wrote:


 - Original Message -
 From: Andre van der Lingen [EMAIL PROTECTED]
 To: Mundell R. (Ronald) [EMAIL PROTECTED];
 [EMAIL PROTECTED]
 Sent: Thursday, January 30, 2003 7:14 PM
 Subject: Re: determining if a scalar is an integer or not


  I would do it like this:
 
  if ($var / 1) {
  print (var: $var is: integer\n);
  } else {
  print (var: $var is: string\n);
  }
 
  if $var is a string than the outcome = 0 so the if statement will
  print that $var is a string.
 
  gr,
  Andre
 

 Actually, when I run that code I find that '123x' is  reported as being an
 integer :-)


But 0 will be reported to be a string!

 [EMAIL PROTECTED] Carl Jolley
 All opinions are my own and not necessarily those of my employer 

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



  1   2   3   4   >