[24136] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6330 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 29 11:10:41 2004

Date: Mon, 29 Mar 2004 08:10:12 -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           Mon, 29 Mar 2004     Volume: 10 Number: 6330

Today's topics:
    Re: Question about import user defined modules. <ckacka@163.com>
    Re: Question about import user defined modules. <ckacka@163.com>
    Re: Question about import user defined modules. (Anno Siegel)
    Re: Question about import user defined modules. <ckacka@163.com>
    Re: Regex match for one and only one occurrence of a pa <tadmc@augustmail.com>
    Re: Search for Unix created/modified date in script <tadmc@augustmail.com>
    Re: Search for Unix created/modified date in script <mark.harris.nospam@ukonline.co.uk.nospam>
        split string to chars <ppi_doesnt_like_@spam_inhis_email_searchy.net>
    Re: split string to chars <noreply@gunnar.cc>
    Re: split string to chars <matrix_calling@yahoo.dot.com>
    Re: split string to chars (Anno Siegel)
    Re: Testing PHP script using Test::Simple perl script <alrdbg@southtech.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 29 Mar 2004 22:34:22 +0800
From: "ckacka" <ckacka@163.com>
Subject: Re: Question about import user defined modules.
Message-Id: <c49c5f$2fn9ot$1@ID-224383.news.uni-berlin.de>


"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> 写入邮件
news:c4986n$q7k$1@mamenchi.zrz.TU-Berlin.DE...
> ckacka <ckacka@163.com> wrote in comp.lang.perl.misc:
> > I write code as follows:
> >
> > ==================================================================
> > =====  /home/ckacka/public_html/cgi-bin/ckacka/Module.pm
> >
>
> This is awfully messy.
>
> I'm not sure how the module "ckacka::Module" is found at all, but
> what you push on @INC has nothing to do with it because it comes
> after "use ckacka::Module ...".
>
> In any case, the imports you have planned will not be executed.  For
> that, the name of the module you load ("ckacka::Module") and the
> package from which to export must be the same.  However, your
> package is just "Module", so the system looks for
"ckacka::Module->import",
> doesn't find it and shrugs.
>
> Either change the module name (which, in part, determines where the
> module file must be stored_), or change the "package" statement in the
> module.
>
> Anno

Sorry, I think I make a silly mistake ;-) . I have changed something, and
get another error:

==================================================================
=====  /home/ckacka/public_html/cgi-bin/ckacka/Module.pm

package Module;

use strict;
use Exporter;
use vars qw/$VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS/;

$VERSION     = 0.91;
@ISA         = qw/Exporter/;
@EXPORT      = ();     #################### This is Line 10
@EXPORT_OK   = qw/&wwwdoc &wwwcgi &docdir &cgidir/;
%EXPORT_TAGS = (
                ':default' => [ qw/wwwdoc wwwcgi docdir cgidir/ ],
                );

# Global varibles.
# Depends your host's setting.
sub wwwdoc { return 'http://localhost/~ckacka'; }
sub wwwcgi { return 'http://localhost/~ckacka/cgi-bin'; }
sub docdir { return '/home/ckacka/public_html'; }
sub cgidir { return '/home/ckacka/public_html/cgi-bin'; }

1;

==================================================================
=====  /home/ckacka/public_html/cgi-bin/ckacka/Module.pm

#!/usr/bin/perl -w

use Fcntl qw/:flock/;
use CGI::Pretty qw/:standard/;
use strict;
use diagnostics;

BEGIN { push @INC, '/home/ckacka/public_html/cgi-bin/ckacka' }
use Module qw/:default/;   #################### This is Line 10

my $wwwdoc = wwwdoc();
my $wwwcgi = wwwcgi();
my $docdir = docdir();
my $cgidir = cgidir();

 ...
 ..
 .

==================================================================

Run it with ouput:

$ perl home.cgi
"default" is not defined in %Blog::EXPORT_TAGS at home.cgi line 10
        main::BEGIN() called at
/home/ckacka/public_html/cgi-bin/ckacka/Blog.pm
line 10
        eval {...} called at /home/ckacka/public_html/cgi-bin/ckacka/Blog.pm
lin
e 10
Uncaught exception from user code:
        Can't continue after import errors at home.cgi line 10
BEGIN failed--compilation aborted at home.cgi line 10.

==================================================================

Thanks

ckacka







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

Date: Mon, 29 Mar 2004 22:42:25 +0800
From: "ckacka" <ckacka@163.com>
Subject: Re: Question about import user defined modules.
Message-Id: <c49cki$276ev3$1@ID-224383.news.uni-berlin.de>

Sorry,
==================================================================

Run it with ouput:

$ perl home.cgi
"default" is not defined in %Blog::EXPORT_TAGS at home.cgi line 10
        main::BEGIN() called at
/home/ckacka/public_html/cgi-bin/ckacka/Blog.pm
line 10
        eval {...} called at /home/ckacka/public_html/cgi-bin/ckacka/Blog.pm
lin
e 10
Uncaught exception from user code:
        Can't continue after import errors at home.cgi line 10
BEGIN failed--compilation aborted at home.cgi line 10.

==================================================================

the "Blog" should be "Module". "Module" is just for my test.




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

Date: 29 Mar 2004 15:32:36 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Question about import user defined modules.
Message-Id: <c49fik$2ao$1@mamenchi.zrz.TU-Berlin.DE>

ckacka <ckacka@163.com> wrote in comp.lang.perl.misc:
> 
> "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> 写入邮件
> news:c4986n$q7k$1@mamenchi.zrz.TU-Berlin.DE...
> > ckacka <ckacka@163.com> wrote in comp.lang.perl.misc:

[import problems]

> Sorry, I think I make a silly mistake ;-) . I have changed something, and
> get another error:
> 
> ==================================================================
> =====  /home/ckacka/public_html/cgi-bin/ckacka/Module.pm
> 
> package Module;
> 
> use strict;
> use Exporter;
> use vars qw/$VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS/;
> 
> $VERSION     = 0.91;
> @ISA         = qw/Exporter/;
> @EXPORT      = ();     #################### This is Line 10
> @EXPORT_OK   = qw/&wwwdoc &wwwcgi &docdir &cgidir/;
> %EXPORT_TAGS = (
>                 ':default' => [ qw/wwwdoc wwwcgi docdir cgidir/ ],
                   ^

Here is your error.  The leading ":" is only used in the calling program,
not in the exporting module.  Cf. examples in the Exporter documentation.
Change that and it's going to work.

Anno

[...]


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

Date: Mon, 29 Mar 2004 23:52:20 +0800
From: "ckacka" <ckacka@163.com>
Subject: Re: Question about import user defined modules.
Message-Id: <c49gnk$2dlf9k$1@ID-224383.news.uni-berlin.de>


"Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> 写入邮件
news:c49fik$2ao$1@mamenchi.zrz.TU-Berlin.DE...
> ckacka <ckacka@163.com> wrote in comp.lang.perl.misc:
> >
> > "Anno Siegel" <anno4000@lublin.zrz.tu-berlin.de> 写入邮件
> > news:c4986n$q7k$1@mamenchi.zrz.TU-Berlin.DE...
> > > ckacka <ckacka@163.com> wrote in comp.lang.perl.misc:
>
> [import problems]
>
> > Sorry, I think I make a silly mistake ;-) . I have changed something,
and
> > get another error:
> >
> > ==================================================================
> > =====  /home/ckacka/public_html/cgi-bin/ckacka/Module.pm
> >
> > package Module;
> >
> > use strict;
> > use Exporter;
> > use vars qw/$VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS/;
> >
> > $VERSION     = 0.91;
> > @ISA         = qw/Exporter/;
> > @EXPORT      = ();     #################### This is Line 10
> > @EXPORT_OK   = qw/&wwwdoc &wwwcgi &docdir &cgidir/;
> > %EXPORT_TAGS = (
> >                 ':default' => [ qw/wwwdoc wwwcgi docdir cgidir/ ],
>                    ^
>
> Here is your error.  The leading ":" is only used in the calling program,
> not in the exporting module.  Cf. examples in the Exporter documentation.
> Change that and it's going to work.
>
> Anno
>
> [...]

Thanks for your help. Now, I have another question:

I use

==================================================================
> > %EXPORT_TAGS = (
> >                 ':default' => [ qw/wwwdoc wwwcgi docdir cgidir/ ],
>                    ^
==================================================================
because I see the CGI.pm use:
==================================================================
}

%EXPORT_TAGS = (
  ':html2'=>['h1'..'h6',qw/p br hr ol ul li dl dt dd menu code var strong em
      tt u i b blockquote pre img a address cite samp dfn html head
      base body Link nextid title meta kbd start_html end_html
==================================================================
in CGI.pm, the ":" is used before every symbol, such as

':html2'=>
    tt
    bas
    inp
':html3'=>
    emb
        ':
 ....

I cannot understand it.


thanks

ckacka





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

Date: Mon, 29 Mar 2004 07:32:06 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Regex match for one and only one occurrence of a pattern
Message-Id: <slrnc6g9am.bbb.tadmc@magna.augustmail.com>

Brian McCauley <nobull@mail.com> wrote:
> Tad McClellan <tadmc@augustmail.com> writes:
> 
>> Steve Allgood <chiriones@yahoo.com> wrote:

>> > I'm trying to match one and only one occurrence of a pattern in a string.


>>    print "matched\n" if s/bc/bc/g == 1;
> 
> Nice, but using s/// to not modify a string makes me feel a little
> uncomfortable.
> 
>     print "matched\n" if (() = /bc/g) == 1;


I had that one too, but I felt it had too much "startle factor" to post.


> Or..
> 
>     # Assume pos() == 0 initially
>     print "matched\n" if /bc/g && ! /bc/g;
>     # Warning: maybe pos() != 0 now
> 
> 
> Or rather more directly...
> 
>     print "matched\n" if /bc/ && !/bc.*bc/;
> 
> Of course if you must do it in one regex:
> 
>     print "matched\n" if /^(?!(.*bc){2}).*bc/;


I gave The Way I did because the alternatives fell victim to:
   
   it doesn't pass the 'just read it aloud' test

(some good advice that I was given here recently)


Now the pendulum swings the other way.  :-)


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


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

Date: Mon, 29 Mar 2004 08:11:44 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Search for Unix created/modified date in script
Message-Id: <slrnc6gbl0.bbb.tadmc@magna.augustmail.com>

Mark <mark.harris.nospam@ukonline.co.uk.nospam> wrote:


> I have a Perl script which creates an array of all files in a Unix directory
> which have a .info suffix, thusly:
> 
> opendir(DIR, "$dir") or die("dir error: $!");
               ^    ^
               ^    ^

Avoid useless uses of double quotes.

The name of the failed directory would be handy if it fails.


   opendir(DIR, $dir) or die("dir error for '$dir': $!");



> @entries = grep(/\.info$/, sort(readdir(DIR)));


Why sort() the "big" list here...


> closedir(DIR);
> 
> foreach $file (@entries)


 ... when you could instead sort() this little list?


> I'm looking to restrict the search to only include .info files which have
> been created 


That is going to be a trick on Unix.

The Unix filesystem does not keep track of file creation time.


> or modified since the last time the script was run.
> 
> I think that I need to store the date & time of the last run in a file
> somewhere so that I can read it back in and use it, then set it to the
> current date & time before the script ends.


You don't even need any contents for the file, just "touch" it
and use its timestamps.


> The question is: how do I use the retrieved date to match against the
> created/modified date of the Unix file?


   # untested
   @entries = grep { /\.info$/ and (stat "$dir/$_")[9] > $stamp } readdir DIR;


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


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

Date: Mon, 29 Mar 2004 16:04:39 +0100
From: "Mark" <mark.harris.nospam@ukonline.co.uk.nospam>
Subject: Re: Search for Unix created/modified date in script
Message-Id: <40683b7c$0$29905$afc38c87@news.easynet.co.uk>

Thanks for the hints & pointers, as well as the comments on my existing
code, all of which I've noted.

Regards,

Mark




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

Date: Mon, 29 Mar 2004 16:51:03 +0200
From: Frank de Bot <ppi_doesnt_like_@spam_inhis_email_searchy.net>
Subject: split string to chars
Message-Id: <c49d41$5o1$1@news1.tilbu1.nb.home.nl>

Hi,

I got the following case

$string = "Test String";
@split = split(//,$string);

in each element of @split will be each character as string ( 'T\0' for 
example)
But I want to have only the char in each element of the array, so this 
could be done for example:

for ($i=0;$i<@split;$i++) {
	printf "This char is: %c\n", $split[$i];
}

Is there any way to do this? I do know how to do this in C, but I've no 
realy clue how to do this  in perl.

thanks in advanced,

Frank de Bot


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

Date: Mon, 29 Mar 2004 17:20:13 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: split string to chars
Message-Id: <c49esl$2h2fam$1@ID-184292.news.uni-berlin.de>

Frank de Bot wrote:
> I got the following case
> 
> $string = "Test String";
> @split = split(//,$string);
> 
> in each element of @split will be each character as string ( 'T\0'
> for example)
> But I want to have only the char in each element of the array, so
> this could be done for example:
> 
> for ($i=0;$i<@split;$i++) {
>     printf "This char is: %c\n",
> $split[$i]; }

Is this what you mean:

     @split = map ord, split //, $string;

perldoc -f map
perldoc -f ord

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Mon, 29 Mar 2004 21:10:03 +0530
From: Abhinav <matrix_calling@yahoo.dot.com>
Subject: Re: split string to chars
Message-Id: <2yX9c.14$_A3.64@news.oracle.com>



Gunnar Hjalmarsson wrote:

> Frank de Bot wrote:
> 
>> I got the following case
>>
>> $string = "Test String";
>> @split = split(//,$string);
>>
>> in each element of @split will be each character as string ( 'T\0'

If i got the question correctly, the OP wants to remove the "\0" ?

Just that in perl there is no "\0"
>> for example)
>> But I want to have only the char in each element of the array, so
>> this could be done for example:
>>
>> for ($i=0;$i<@split;$i++) {
>>     printf "This char is: %c\n"
print "This char is : $split[$i]\n"
,
>> $split[$i]; }
> 
> 
> Is this what you mean:
> 
>     @split = map ord, split //, $string;
> 
> perldoc -f map
> perldoc -f ord
> 
Is this what is required ??

--
Abhinav



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

Date: 29 Mar 2004 15:54:14 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: split string to chars
Message-Id: <c49gr6$2ao$2@mamenchi.zrz.TU-Berlin.DE>

Frank de Bot  <ppi_doesnt_like_@spam_inhis_email_searchy.net> wrote in comp.lang.perl.misc:
> Hi,
> 
> I got the following case
> 
> $string = "Test String";
> @split = split(//,$string);
> 
> in each element of @split will be each character as string ( 'T\0' for 
> example)

Perl strings have no trailing null byte.  Their length is kept elsewhere.

> But I want to have only the char in each element of the array, so this 
> could be done for example:
> 
> for ($i=0;$i<@split;$i++) {
> 	printf "This char is: %c\n", $split[$i];
> }

There's no need to use indexing to access array elements (untested):

    printf "This char is: %s\n", $_ for @split;

Note that I changed the printf format to "%s".  Perl represents single
characters as strings of length 1.  There is no character data type.
As in C, the "%c" format prints a character whose numeric value is given,
so to use the "%c" format, you'd write

    printf "This char is: %s\n", ord $_ for @split;

But nobody does that.

Anno


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

Date: Mon, 29 Mar 2004 16:36:07 +0200
From: Allan Rydberg <alrdbg@southtech.net>
Subject: Re: Testing PHP script using Test::Simple perl script
Message-Id: <c49c27$3h2$1@newshispeed.ch>



maybe php-commandline?

http://www.php.net/manual/en/features.commandline.php



John Ramsden wrote:

> I have a perl logging module that sends log messages,
> via post variables, to a simple PHP web app whose
> purpose is to write them to a database table.
> 
> The module is organized in the standard Test::Simple
> format, and as one of the unit tests I'd like to
> include a message send (followed by a read of the
> database table). But to make the tests self-contained
> I'd prefer not to assume that the logging web app is
> installed.
> 
> Can anyone suggest a way of running a PHP script,
> possibly with an auxiliary script (?) to accept
> post variables in interactive mode?
> 
> I thought of starting an Apache instance, using a
> config file in the perl test directory and listening
> on a non-standard port. But this, even if possible,
> seems like using a hammer to crack a nut.
> 
> All constructive suggestions welcome...
> 
> 
> Cheers
> 
> John R Ramsden



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

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 6330
***************************************


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