[26576] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 8711 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 27 11:05:30 2005

Date: Sun, 27 Nov 2005 08:05:05 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sun, 27 Nov 2005     Volume: 10 Number: 8711

Today's topics:
        hash on private member variable <samwun@telpacific.com.au>
    Re: hash on private member variable <1usa@llenroc.ude.invalid>
    Re: Help:  String search in Windows 2000 doesn't find t <tadmc@augustmail.com>
        Help:  String search in Windows 2000 doesn't find text  <millmanbarry@hotmail.com>
    Re: Help:  String search in Windows 2000 doesn't find t <millmanbarry@hotmail.com>
    Re: Logging Errors (Instead of Just Dying) <hal@thresholddigital.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Mon, 28 Nov 2005 00:01:03 +1100
From: sam <samwun@telpacific.com.au>
Subject: hash on private member variable
Message-Id: <4389ae12$1@news.rivernet.com.au>

Hi,

I need to use hash on a private member variable.
But I don't  know how to make it happen. Here is the code:

#!/usr/bin/perl

package dbm_lib;

use strict;
use Time::Local;
use Data::Dumper;

sub new {
     my $class = shift;
     my $self  = { _map => undef };
     bless ($self, $class);
     return $self;
}

sub gen_name()
{
         my $self = shift;
      localtime(time);
      return rand(time).".pl";
}

sub create()
{
         my $self = shift;
    my ($name) = "/usr/local/code.dbm";
    dbmopen($self->{%_map},$name,0666);
    $file_name = $self->gen_name();
    $status = "0"; # 0 - not yet execute; 1 - had been executed.
    $val = join("\t",$file_name, ,$status);
    $map{$file_name} = $val;
}

sub cclose()
{
         my $self = shift;
    dbmclose($self->{_map});
}

1;


Thanks
Sam


------------------------------

Date: Sun, 27 Nov 2005 13:33:19 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: hash on private member variable
Message-Id: <Xns971B570B57901asu1cornelledu@127.0.0.1>

sam <samwun@telpacific.com.au> wrote in news:4389ae12$1
@news.rivernet.com.au:

> I need to use hash on a private member variable.
> But I don't  know how to make it happen. Here is the code:

1. What does it mean to "use hash on a private member variable"?

2. The code you posted does not compile.

Please read the posting guidelines for this group to learn how you can 
help yourself, and help others help you.

> sub new {
>      my $class = shift;
>      my $self  = { _map => undef };
>      bless ($self, $class);
>      return $self;
> }

Are you saying you want $self->{_map} to be a reference to an anonymous 
hash? Then, make it so:

sub new {
   my $class = shift;
   my $self  = { _map => { } };
   bless ($self, $class);
   return $self;
}

> sub gen_name()

Why are you using prototypes with method calls?

> {
>       my $self = shift;
>       localtime(time);

What do you think the line above does?

>       return rand(time).".pl";
> }

If gen_name is invoked more than once in a second, this will return 
identical filenames ... I have a feeling that will not be good for your 
program. What are you trying to do?

> 
> sub create()
> {
>          my $self = shift;
>     my ($name) = "/usr/local/code.dbm";
>     dbmopen($self->{%_map},$name,0666);
>     $file_name = $self->gen_name();
>     $status = "0"; # 0 - not yet execute; 1 - had been executed.
>     $val = join("\t",$file_name, ,$status);
>     $map{$file_name} = $val;

????


Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines.html



------------------------------

Date: Sun, 27 Nov 2005 09:54:43 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Help:  String search in Windows 2000 doesn't find text in Windows XP: MS Word document
Message-Id: <slrndojlm3.n8r.tadmc@magna.augustmail.com>

Barry Millman <millmanbarry@hotmail.com> wrote:

> The format for the HYPERLINK that I am 
> searching for in the document is:
> 
> HYPERLINK "mydoc.doc"

> PROBLEM: 	The program works on the Windows 2000 machine, but does not 
> find the files on the Win Xp machine.


I don't think I can help with that part, but the code is too hokey
to just let it pass...


> -----------  start actual code segment --------------------
> 	while (/HYPERLINK(\s+.{1,80}?\.doc)/gim)  #  the "g" causes multiple 
> matches


The //m does not do anything, so why is it there?

It changes the meaning of ^ and $, but you don't use those
anchors in your pattern, so you don't need //m.

   .{1,80}?

is the same as

   .{0,80}

Do you really want to match ' .doc' ?


We can't help you analyse why the match is failing because we
need two things to do that: the pattern and the string that
the pattern is to be matched against.

We have only one of those two things...


> 
> 	{
> 		  $fndxx = $1;
> 
> 		  $fndxx =~ s/\"//;   # remove leading quote
> 		  $fndxx =~ s/\s+//;   # remove leading spaces


Why capture them only to strip them out of the captured string?

Why not just leave them out of the capture in the first place?


   while (/HYPERLINK\s+"(.{1,78}\.doc")/gi)

or, probably better:

   while (/HYPERLINK\s+"([^"]{1,78}\.doc")/gi)


> 		  $dir="C:\\IGINproducts\\UserDocuments\\"; 	
> 		


Use single quotes unless you want to make use of one of the two
extra things that double quotes give you (interpolation
and backslash escapes).

Use forward slashes instead of silly slashes unless the path
is going to be fed to the "command interpreter".


   $dir='C:/IGINproducts/UserDocuments/';


> 		  print(OUTFILE  $fndxx,",",$date_string,", in: ",basename($file), 
> "\n")  ;


Gak!

Use double quoted strings to concatenate your output string:

    print(OUTFILE  "$fndxx,$date_string, in: ", basename($file), "\n")  ;


> If I try this with a test program (the string to test is in the program 
> itself ) it works fine on the XP machine.


If you had shown us your complete test program, then we could
have helped you debug it.

But you didn't, so we can't.  (hint)


> I would really appreciate any comments or suggestions about what I am 
> doing wrong.


Not posting a short and complete program that we can run that
illustrates your problem.

Have you seen the Posting Guidelines that are posted here frequently?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Sun, 27 Nov 2005 09:13:16 -0500
From: Barry Millman <millmanbarry@hotmail.com>
Subject: Help:  String search in Windows 2000 doesn't find text in Windows XP: MS Word document
Message-Id: <IZydnRIVSpphIxTenZ2dnUVZ_sWdnZ2d@rogers.com>

Hi:

	I am using Perl 5 (I believe both machines are using ActivePERL 5) on 
two machines with the same data files.  One machine is Win 2000 the 
other is Win XP.  The files are MS Word 2000 documents e-mailed 
(manually) from the Win 2000 machine to the XP machine.

	The program searches the MS Word Files (both created with MS Word 2000) 
for the word HYPERLINK.  The format for the HYPERLINK that I am 
searching for in the document is:

HYPERLINK "mydoc.doc"

(I checked this on the XP machine in Notepad and it is OK.)

PROBLEM: 	The program works on the Windows 2000 machine, but does not 
find the files on the Win Xp machine.

	The code that is not finding the text on the Win XP machine (same as 
the Win 2000 machine which does find the test)is:

-----------  start actual code segment --------------------
	while (/HYPERLINK(\s+.{1,80}?\.doc)/gim)  #  the "g" causes multiple 
matches

	{
		  $fndxx = $1;

		  $fndxx =~ s/\"//;   # remove leading quote
		  $fndxx =~ s/\s+//;   # remove leading spaces
		  $dir="C:\\IGINproducts\\UserDocuments\\"; 	
		
		  $fullname = ($dir . $fndxx);
		  $date_string = "Cannot Find";
		  if (-e $fullname) { $date_string = ctime(stat($dir . 
$fndxx)->mtime); }     #last update date of that file
		  print(OUTFILE  $fndxx,",",$date_string,", in: ",basename($file), 
"\n")  ;
		  $matches += 1;  # count matches
		
	}	#end while HYPERLINK
-----------  end actual code segment --------------------

The output for a found HYPERLINK should look like this (it does on the 
Win 2000 machine):

mydoc.doc,(date of last update), in: otherdoc.doc

On Win XP, the program cannot even find the word HYPERLINK (if I modify 
the code to just search for that).  The directories are valid, I can 
have the program print a list of all files as it processes them.

If I try this with a test program (the string to test is in the program 
itself ) it works fine on the XP machine.

There are no encryption issues, nor any file or directory problems.

I would really appreciate any comments or suggestions about what I am 
doing wrong.

Thanks,

Barry Millman

	


------------------------------

Date: Sun, 27 Nov 2005 10:27:28 -0500
From: Barry Millman <millmanbarry@hotmail.com>
Subject: Re: Help:  String search in Windows 2000 doesn't find text in Windows XP: MS Word document
Message-Id: <4MKdnbbozq_DTRTeRVn-qQ@rogers.com>

Just some added info:

The search works fine if I save the MS Word files as RTF.

Also I wanted to mention that I have this around the hyperlink search code:
	#open the file		
         open(INFILE,"< $file") or die "Couldn't open file ",$file;
	

	while(<INFILE>)
	{
		# the hyperlink code I posted earlier
	}       # end while infile

Barry



Barry Millman wrote:

> Hi:
> 
>     I am using Perl 5 (I believe both machines are using ActivePERL 5) 
> on two machines with the same data files.  One machine is Win 2000 the 
> other is Win XP.  The files are MS Word 2000 documents e-mailed 
> (manually) from the Win 2000 machine to the XP machine.
> 
>     The program searches the MS Word Files (both created with MS Word 
> 2000) for the word HYPERLINK.  The format for the HYPERLINK that I am 
> searching for in the document is:
> 
> HYPERLINK "mydoc.doc"
> 
> (I checked this on the XP machine in Notepad and it is OK.)
> 
> PROBLEM:     The program works on the Windows 2000 machine, but does not 
> find the files on the Win Xp machine.
> 
>     The code that is not finding the text on the Win XP machine (same as 
> the Win 2000 machine which does find the test)is:
> 
> -----------  start actual code segment --------------------
>     while (/HYPERLINK(\s+.{1,80}?\.doc)/gim)  #  the "g" causes multiple 
> matches
> 
>     {
>           $fndxx = $1;
> 
>           $fndxx =~ s/\"//;   # remove leading quote
>           $fndxx =~ s/\s+//;   # remove leading spaces
>           $dir="C:\\IGINproducts\\UserDocuments\\";    
>        
>           $fullname = ($dir . $fndxx);
>           $date_string = "Cannot Find";
>           if (-e $fullname) { $date_string = ctime(stat($dir . 
> $fndxx)->mtime); }     #last update date of that file
>           print(OUTFILE  $fndxx,",",$date_string,", in: 
> ",basename($file), "\n")  ;
>           $matches += 1;  # count matches
>        
>     }    #end while HYPERLINK
> -----------  end actual code segment --------------------
> 
> The output for a found HYPERLINK should look like this (it does on the 
> Win 2000 machine):
> 
> mydoc.doc,(date of last update), in: otherdoc.doc
> 
> On Win XP, the program cannot even find the word HYPERLINK (if I modify 
> the code to just search for that).  The directories are valid, I can 
> have the program print a list of all files as it processes them.
> 
> If I try this with a test program (the string to test is in the program 
> itself ) it works fine on the XP machine.
> 
> There are no encryption issues, nor any file or directory problems.
> 
> I would really appreciate any comments or suggestions about what I am 
> doing wrong.
> 
> Thanks,
> 
> Barry Millman
> 
>     


------------------------------

Date: Sun, 27 Nov 2005 01:00:46 -0500
From: Hal Vaughan <hal@thresholddigital.com>
Subject: Re: Logging Errors (Instead of Just Dying)
Message-Id: <08mdnYCqzekT1hTeRVn-rQ@comcast.com>

Just a quick 'thanks!' to those who replied.  When I was reading the FAQ, it
looked more complex, and the examples here showed me just how easy this is! 
I wish I had known about this a long time ago.  I've already set it up,
roughly like this:

eval {
        mainloop();
}
if ($@) {
        serverlog("error Perl has reported an error: $@");
        serverlog("exiting so program will restart");
        exit();
}

There was just enough in the faq (and enough left out) to make it seem like
it was more complex than it is.

Your help is appreciated!

Hal

Hal Vaughan wrote:

> I have several Perl daemons running on a particular system.  For the most
> part, they are behaving well, but I notice that two need to be restarted a
> few times a week.  I have a lot of logging statements saying what the
> program is doing at different points.  What I'd like to do is log the
> actual errors before the program dies (and is then restarted by it's
> monitor).  In the routine, I want to be able to print the line number and
> type of error (as given in the normal error messages) to my log file.
> 
> Is there any way, inside a Perl module, to do something like "If there are
> any errors, don't die, call this function, THEN die"?  (Or just "call this
> function" and I can always make the function itself terminate the
> program.)
> 
> I know the FAQ mentions using eval, but they reference Larry Wall's
> "&realcode", which, when I Google it, comes up with references to the same
> FAQ, where it is not explained.  I'm trying to understand using eval, but
> I don't see how I could put an entire module in an eval block -- I would
> expect that to only evaluate it when the module is loaded.  The few
> examples of this (that I can find) are, at least to me, hard to follow, so
> clearer examples would help a LOT.  (I'm wondering if, since it's in the
> FAQ, nobody's bothered to cover this in depth or with more examples.)
> 
> For example, if most of what the program does is in the module, how would
> I
> use eval around the subroutine calls from the main program?  Can I get
> away with having one call to the mainloop (which is in a subroutine by
> itself) in it and then using eval only around that one call to the main
> loop?
> 
> Any help in clarifying this is appreciated!
> 
> Hal



------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 8711
***************************************


home help back first fref pref prev next nref lref last post