[18943] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1138 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 15 00:05:36 2001

Date: Thu, 14 Jun 2001 21:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <992577910-v10-i1138@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 14 Jun 2001     Volume: 10 Number: 1138

Today's topics:
    Re: A simple pattern match problem? <leapius@hotmail.com>
    Re: A simple pattern match problem? (E.Chang)
    Re: A simple pattern match problem? <krahnj@acm.org>
    Re: A simple pattern match problem? (Craig Berry)
    Re: A simple pattern match problem? (E.Chang)
    Re: Another possible need for a pattern match <leapius@hotmail.com>
    Re: Another possible need for a pattern match (Logan Shaw)
    Re: Another possible need for a pattern match <krahnj@acm.org>
    Re: Another possible need for a pattern match (E.Chang)
    Re: Another possible need for a pattern match <krahnj@acm.org>
    Re: autoload troubles <skilchen@swissonline.ch>
        Can't locate Slash.pm in @INC <msperrin@u.washington.edu>
        cgi / web client stream interactivity <jhall@ifxonline.com>
    Re: cgi / web client stream interactivity (Logan Shaw)
    Re: Design pattern for a generic functions dispatcher <goldbb2@earthlink.net>
        dtd2xsl anyone? (Emmett McLean)
    Re: initialising multi-dimensional array <mjcarman@home.com>
        Looking for a domain tracking script newsone-removeallbetweendashes-reply@triqi.com
    Re: Looking for good tutorial/book on Perl programming. <ufnitehawk@yahoo.com>
    Re: Looking for good tutorial/book on Perl programming. <lignite@oceanfree.net>
    Re: Looking for good tutorial/book on Perl programming. <ron@savage.net.au>
    Re: newbie-- re:win32 system() calls -- rmdir /s/q (Jay Tilton)
    Re: package, module or ??? (Damian James)
        transfer file <north@nmpm.com.my>
    Re: Validating postcodes (Craig Berry)
    Re: Validating postcodes (Sweth Chandramouli)
        Validation and escape \ requirement? <davsoming@lineone.net>
    Re: Validation and escape \ requirement? <krahnj@acm.org>
    Re: Validation and escape \ requirement? <davsoming@lineone.net>
    Re: Validation and escape \ requirement? <davsoming@lineone.net>
    Re: Validation and escape \ requirement? <krahnj@acm.org>
    Re: Which C compiler to use for modules? <bowman@montana.com>
    Re: Why does my a: grind when I copy a file in perl? <ron@savage.net.au>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 15 Jun 2001 01:49:52 +0100
From: "Leo Hemmings" <leapius@hotmail.com>
Subject: Re: A simple pattern match problem?
Message-Id: <9gbm26$ccr$1@plutonium.btinternet.com>

Hi all,

I have a problem, which I think a pattern match might sort out but don't
know how to do it. Basically I have a string with a number of lines of text.
I want to remove any empty lines in this string (i.e. when there are two or
more '\n' in a row). So the following text:

line1
line2


line3

line4

would produce:

line1
line2
line3
line4

Any help greatly appreciated,
Leo




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

Date: Fri, 15 Jun 2001 01:10:23 GMT
From: echang@netstorm.net (E.Chang)
Subject: Re: A simple pattern match problem?
Message-Id: <Xns90C0D7E95F50Fechangnetstormnet@207.106.92.86>

"Leo Hemmings" <leapius@hotmail.com> wrote in
<9gbm26$ccr$1@plutonium.btinternet.com>: 

> Hi all,
> 
> I have a problem, which I think a pattern match might sort out but
> don't know how to do it. Basically I have a string with a number of
> lines of text. I want to remove any empty lines in this string
> (i.e. when there are two or more '\n' in a row).

[snip]

Use 

   s/\n+/\n/g;  

The + quantifier means 1 or more occurrences.  For example

   $string = "line1\nline2\n\n\nline3\n\nline4";
   $string =~ s/\n+/\n/g;
   print $string;

yields the output:

line1
line2
line3
line4

-- 
EBC


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

Date: Fri, 15 Jun 2001 01:27:31 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: A simple pattern match problem?
Message-Id: <3B2964B0.6BA2AEE6@acm.org>

Leo Hemmings wrote:
> 
> Hi all,
> 
> I have a problem, which I think a pattern match might sort out but don't
> know how to do it. Basically I have a string with a number of lines of text.
> I want to remove any empty lines in this string (i.e. when there are two or
> more '\n' in a row). So the following text:
> 
> line1
> line2
> 
> line3
> 
> line4
> 
> would produce:
> 
> line1
> line2
> line3
> line4

s/\n(?=\n)//g;



John
-- 
use Perl;
program
fulfillment


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

Date: Fri, 15 Jun 2001 01:42:06 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: A simple pattern match problem?
Message-Id: <tiipve7too51a2@corp.supernews.com>

Leo Hemmings (leapius@hotmail.com) wrote:
: I have a problem, which I think a pattern match might sort out but don't
: know how to do it. Basically I have a string with a number of lines of text.
: I want to remove any empty lines in this string (i.e. when there are two or
: more '\n' in a row). So the following text:

  $string =~ tr/\n//s;

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Magick is the art and science of causing change in conformity
   |   with Will."  - Aleister Crowley


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

Date: Fri, 15 Jun 2001 02:02:51 GMT
From: echang@netstorm.net (E.Chang)
Subject: Re: A simple pattern match problem?
Message-Id: <Xns90C0E0CE92D1echangnetstormnet@207.106.92.86>

cberry@cinenet.net (Craig Berry) wrote in
<tiipve7too51a2@corp.supernews.com>: 

> Leo Hemmings (leapius@hotmail.com) wrote:
> : I have a problem, which I think a pattern match might sort out
> but don't : know how to do it. Basically I have a string with a
> number of lines of text. : I want to remove any empty lines in this
> string (i.e. when there are two or : more '\n' in a row). So the
> following text: 
> 
>   $string =~ tr/\n//s;

This is certainly the version to use, since it's much faster.  

Is this effect of /s  with a null replacement character documented 
anywhere?  I interpreted "If the /s modifier is specified, sequences of 
characters that were transliterated to the same character are squashed 
down to a single instance of the character." to mean squashed to a 
single instance of the replacement character, not the original, and 
that is certainly what happens with a non-null. Just hoping to learn 
something.

-- 
EBC


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

Date: Fri, 15 Jun 2001 02:22:05 +0100
From: "Leo Hemmings" <leapius@hotmail.com>
Subject: Re: Another possible need for a pattern match
Message-Id: <9gbnuj$e3e$1@plutonium.btinternet.com>

Hi all,

I need to substitute a string with the equivalent number of stars "*".

E.g:

hello = *****
love perl = *********

etc.

Any ideas? Thankyou in advance,

Leo




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

Date: 14 Jun 2001 20:39:54 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Another possible need for a pattern match
Message-Id: <9gbp1a$op4$1@charity.cs.utexas.edu>

In article <9gbnuj$e3e$1@plutonium.btinternet.com>,
Leo Hemmings <leapius@hotmail.com> wrote:
>I need to substitute a string with the equivalent number of stars "*".
>
>E.g:
>
>hello = *****
>love perl = *********

$string =~ s/./\*/g;

By the way, I suggest reading/learning about regular expressions.

  - Lgoan
-- 
my  your   his  her   our   their   _its_
I'm you're he's she's we're they're _it's_


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

Date: Fri, 15 Jun 2001 01:41:01 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Another possible need for a pattern match
Message-Id: <3B2967DE.D235B58C@acm.org>

Leo Hemmings wrote:
> 
> Hi all,
> 
> I need to substitute a string with the equivalent number of stars "*".
> 
> E.g:
> 
> hello = *****
> love perl = *********

$string =~ tr/\0-\0377/*/;
# or
$string =~ s/./*/s;
# or
$string = '*' x length( $string );



John
-- 
use Perl;
program
fulfillment


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

Date: Fri, 15 Jun 2001 01:44:06 GMT
From: echang@netstorm.net (E.Chang)
Subject: Re: Another possible need for a pattern match
Message-Id: <Xns90C0DDA12FB49echangnetstormnet@207.106.92.86>

"Leo Hemmings" <leapius@hotmail.com> wrote in
<9gbnuj$e3e$1@plutonium.btinternet.com>: 

> Hi all,
> 
> I need to substitute a string with the equivalent number of stars
> "*". 

Use    s/./*/g;

The . matches any single character except a newline.  If you want to 
match newlines too, add the s modifier:  s/./*/sg;


For example, 

@str = ("Hello", "12345 789", "Just a beginning Perl user");
foreach (@str) {
   s/./*/g;
   print "$_\n";
}

produces the output.

*****
*********
**************************

See the Perl regular expressions documentation (perlre) at 
http://www.perldoc.com/ for anexplanation of the modifiers.

-- 
EBC


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

Date: Fri, 15 Jun 2001 02:39:36 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Another possible need for a pattern match
Message-Id: <3B297599.6E90FD53@acm.org>

"John W. Krahn" wrote:
> 
> Leo Hemmings wrote:
> >
> > Hi all,
> >
> > I need to substitute a string with the equivalent number of stars "*".
> >
> > E.g:
> >
> > hello = *****
> > love perl = *********
> 
> $string =~ tr/\0-\0377/*/;
> # or
> $string =~ s/./*/s;

Oops, forgot the /g

$string =~ s/./*/sg;

> # or
> $string = '*' x length( $string );


John
-- 
use Perl;
program
fulfillment


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

Date: Fri, 15 Jun 2001 01:56:55 +0200
From: "Samuel Kilchenmann" <skilchen@swissonline.ch>
Subject: Re: autoload troubles
Message-Id: <9gbitt$89jun$1@ID-13368.news.dfncis.de>

"Stefan Weiss" <der.prinz@gmx.net> schrieb im Newsbeitrag
news:3b287d53@e-post.inode.at...
> Samuel Kilchenmann <skilchen@swissonline.ch> wrote:
>
>
> That part was written about a week ago, and I only got a problem
> yesterday when I needed two successive method calls. After reading
> your answer I tried again to use a seperate namespace, and have
> found a way that works, although maybe it's not very elegant:
>
>   require $self->{pkg} . ".pl";
>   my $coderef = eval '$XLib::'. $self->{pkg} . "::methods{$method}";
>   my $result = $coderef->($params);
>
> Is this an acceptable solution (assuming a package like "XLib::Foo")?
>
What about exporting only the method dispatch table into callers
namespace?
Then your library.pl would look like:

package Xlib::Foo;

use strict;
use warnings;
use Exporter;

our @ISA = qw(Exporter);
our @EXPORT = qw(%methods);

sub wrong {
 warn "called from ".(caller)[0].", received a ".ref(shift)." ref\n";
}

sub Xright {
 warn "called from ".(caller)[0].", received a ".ref(shift)." ref\n";
}

our %methods = (
 wrong => \&wrong,
 right => \&Xright,
);

1;


and your XWrapper would look like:

package XWrapper;
use strict;
use warnings;

sub new {
  my $self = {
    'pkg'  => 'Xlib::Foo',
    'file' => 'library.pl',
  };

  bless $self;
}

sub AUTOLOAD {
 my $self = shift;
 my $params = shift;
 my $method = (split '::', our $AUTOLOAD)[-1];
 return if $method eq 'DESTROY';
 $self->callfunc($method, $params);
}

sub callfunc {
 my $self = shift;
 my $method = shift;
 my $params = shift;

 require $self->{file};
 $self->{pkg}->import();

 $XWrapper::methods{$method}->($params);
}
1;

Then your runme.pl should produce the following output (as expected?):
called from XWrapper, received a HASH ref
called from XWrapper, received a HASH ref
called from XWrapper, received a HASH ref
called from XWrapper, received a HASH ref


and if you change the @EXPORT array in library.pl to
our @EXPORT = qw(%methods wrong);
then runme.pl should produce:
called from XWrapper, received a HASH ref
called from XWrapper, received a HASH ref
called from main, received a XWrapper ref
called from main, received a XWrapper ref





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

Date: Thu, 14 Jun 2001 20:32:12 -0700
From: "M. Scholz" <msperrin@u.washington.edu>
Subject: Can't locate Slash.pm in @INC
Message-Id: <Pine.A41.4.33.0106142027490.29492-100000@dante58.u.washington.edu>

I know why I'm getting the message above (I think) but I don't know how to
fix it.

I have two separate trees for perl5 installed on my machine:
/usr/lib/perl5/5.6.0
& /usr/local/perl5/5.6.1

CPAN has been installing new modules in the second tree.  However,
according to Config.pm (in the 5.6.0 tree, which perl seems to be
checking) the /usr/local/perl5/ directory doesn't exist.  Any great ideas
on how to update Config.pm to include the second tree so I don't have to
manually copy all of the files over?

Thanks.

This is on RH7.1, if the version is important.

-Matthew Scholz
			Where does Thinking end,
			    and Feeling ...



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

Date: Thu, 14 Jun 2001 22:53:06 GMT
From: "John Hall" <jhall@ifxonline.com>
Subject: cgi / web client stream interactivity
Message-Id: <mfbW6.48000$%a.2431744@news1.rdc1.sdca.home.com>


If a web client were to hit the 'stop' button on their browser as a CGI app
was executing [perl cgi of course] Does it have any affect on the CGI app
itself as far as redirection of STDOUT or the like?

I am just curious if in a case where the script wasn't waiting for input or
anything, but the client hit stop, and the webserver stops sending stuff,
does it also kill the cgi? Or does the cgi just keep puffing along into some
kind of bit-void?






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

Date: 14 Jun 2001 20:10:12 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: cgi / web client stream interactivity
Message-Id: <9gbn9k$ogb$1@charity.cs.utexas.edu>

In article <mfbW6.48000$%a.2431744@news1.rdc1.sdca.home.com>,
John Hall <jhall@ifxonline.com> wrote:
>
>If a web client were to hit the 'stop' button on their browser as a CGI app
>was executing [perl cgi of course] Does it have any affect on the CGI app
>itself as far as redirection of STDOUT or the like?
>
>I am just curious if in a case where the script wasn't waiting for input or
>anything, but the client hit stop, and the webserver stops sending stuff,
>does it also kill the cgi? Or does the cgi just keep puffing along into some
>kind of bit-void?

Speaking of void, your post appears to be devoid of Perl
content.  This is a question about the specification of CGI.

  - Logan
-- 
my  your   his  her   our   their   _its_
I'm you're he's she's we're they're _it's_


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

Date: Thu, 14 Jun 2001 23:15:27 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Design pattern for a generic functions dispatcher
Message-Id: <3B297DCF.E7F5D3CE@earthlink.net>

Abe Timmerman wrote:
> 
> Benjamin Goldberg wrote:
> > Phouric Ung wrote:
> > >
> > > i would like to have some advice on perl
> > > programming design for a dynamic function
> > > dispatcher.

[snip]
> >                       ${$subname}(); # symref call

This should be:		  &{$subname}(); # symref call

> >                       $ACTION_MAPS{$Action} = \&{$subname};

[snip]
> There is no need to give up strict in this case, it can be done
> without symrefs.
> 
> You can build a real dispatch table from the %action_map hash (if it
> were initialized properly, as you stated):

[snip]
>       if ( defined &$subname and $dispatch{ $action } = \&$subname ) {
>               return $dispatch{ $action }->( @_ );

Are you sure that \&$subname is allowed under strict refs?

Also, if the sub is an autloaded one, yours is unlikely to work.

-- 
The longer a man is wrong, the surer he is that he's right.


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

Date: 14 Jun 2001 15:09:16 -0700
From: emclean@slip.net (Emmett McLean)
Subject: dtd2xsl anyone?
Message-Id: <9gbcmc$4g1@slip.net>

Hi,

Is there a perl module with a dtd2xsl script?

Or might someone have a script to share ;-)

Thanks,

Emmett



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

Date: Fri, 15 Jun 2001 02:23:29 GMT
From: Michael Carman <mjcarman@home.com>
Subject: Re: initialising multi-dimensional array
Message-Id: <3B29715A.FE4184F2@home.com>

Mark Grimshaw wrote:
> 
> I really wanted to know how to specify (if possible)
> that prior to any population of the multi-dimensional array, any
> non-populated elements [...] would be 0 instead of undef.
> The answer, it seems is no.

Well, almost anything is possible in Perl. Maybe this is too, using 
tie(). For regular arrays, it's pretty easy:

#!/usr/bin/perl -w
use strict;

package Tie::Array::Undef_Is_Zero;
use Tie::Array;
@Tie::Array::Undef_Is_Zero::ISA = ('Tie::Array');

sub TIEARRAY {
    return bless [], shift;
}

sub STORE {
    my ($s, $i, $v) = @_;
    return $s->[$i] = $v;
}

sub FETCH {
    my ($s, $i) = @_;
    return defined $s->[$i] ? $s->[$i] : 0;
}

sub FETCHSIZE {
    my $s = shift;
    return @$s;
}

sub STORESIZE {
    my ($s, $c) = @_;
    $#{$s} = $c - 1;
}

package main;
my @x;
tie @x, 'Tie::Array::Undef_Is_Zero';

$x[5] = 1;
print "@x\n";

__END__

0 0 0 0 0 1

The problem, of course, is that you need to explicitly tie() each array,
and that doesn't scale well to multidimensional data structures. (If
nothing else it's tedious.) So I thought that I could change the STORE
method to make it automatically tie() the lower levels as needed:

sub STORE {
    my ($s, $i, $v) = @_;
    if (ref($v) eq 'ARRAY' && ! defined $s->[$i]) {
        tie @{$s->[$i]}, __PACKAGE__;
    }
    return $s->[$i] = $v;
}

But this doesn't work, because when you say

$x[5][1] = 4;

perl first looks up $x[5] (using the FETCH method). Our new class
obediently returns 0 instead of undef, and therefore perl won't 
autovivify a reference to a new anonymous array. Damn.

What we really need here is a wantref() function so that FETCH can know
how it's being used, but there's no such builtin. Does anyone have any
ideas on how to emulate one?

-mjc


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

Date: 15 Jun 2001 03:30:07 GMT
From: newsone-removeallbetweendashes-reply@triqi.com
Subject: Looking for a domain tracking script
Message-Id: <9gbvfv$cil$1@news.netmar.com>

I'm looking for a domain tracking script - not a whois? script, something
where you can enter a list of domain names and then the script will
automatically check them for availability every x hours or so. Maybe the
script then emails the user when one of the names becomes available?

There are a number of expired domain names that haven't fallen off the
register just yet that I could do with getting hold of, but I don't want to
have to check every day. Surely there's a script out there that can do it
automatic?

Cheers,
G

 -----  Posted via NewsOne.Net: Free (anonymous) Usenet News via the Web  -----
  http://newsone.net/ -- Free reading and anonymous posting to 60,000+ groups
   NewsOne.Net prohibits users from posting spam.  If this or other posts
made through NewsOne.Net violate posting guidelines, email abuse@newsone.net


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

Date: Thu, 14 Jun 2001 19:03:31 -0400
From: "Axiom" <ufnitehawk@yahoo.com>
Subject: Re: Looking for good tutorial/book on Perl programming.
Message-Id: <9gbe0p$15hs$1@node21.cwnet.roc.gblx.net>

Thank you again,
Malcolm Taylor

Richard A. Evans <EvR@compuserve.com> wrote in message
news:9gb3ii$hf7$1@sshuraab-i-1.production.compuserve.com...
> My preferences would be...
>
>
> "Learning Perl " or "Learning Perl on Win32 Systems" (basic)  (basically
the
> same book, flavored for the OS)
> "Programming Perl" (more advanced)
> "CGI Programming with Perl"
>
> All of these are O'Reilly books.  They have others that are excellent, but
> these should get you started.
>
> Regards,
>
> Rick Evans
>
> "Axiom" <ufnitehawk@yahoo.com> wrote in message
> news:9gb0cb$jlq$1@node21.cwnet.roc.gblx.net...
> > I'm a windows user. If you have any information on a good tutorial/book
> that
> > i can use to learn please inform me. I am wanting to get into Perl
> > programming and using it on web design.
> >
> > Thanks in advance for any help,
> > Malcolm Taylor
> >
> >
>
>




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

Date: 14 Jun 2001 23:55:09 GMT
From: "Lig" <lignite@oceanfree.net>
Subject: Re: Looking for good tutorial/book on Perl programming.
Message-Id: <9gbiss$817aj$1@ID-31507.news.dfncis.de>

Excellent.But don't you ever prefer free sites . Pl suggest some
Lig

Lignite.nospamm@oceanfree.net

> My preferences would be...
>
>
> "Learning Perl " or "Learning Perl on Win32 Systems" (basic)  (basically
the
> same book, flavored for the OS)
> "Programming Perl" (more advanced)
> "CGI Programming with Perl"
>
> All of these are O'Reilly books.  They have others that are excellent, but
> these should get you started.
>
> Regards,
>
> Rick Evans
>
> "Axiom" <ufnitehawk@yahoo.com> wrote in message
> news:9gb0cb$jlq$1@node21.cwnet.roc.gblx.net...
> > I'm a windows user. If you have any information on a good tutorial/book
> that
> > i can use to learn please inform me. I am wanting to get into Perl
> > programming and using it on web design.
> >
> > Thanks in advance for any help,
> > Malcolm Taylor
> >
> >
>
>




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

Date: Fri, 15 Jun 2001 09:55:57 +1000
From: "Ron Savage" <ron@savage.net.au>
Subject: Re: Looking for good tutorial/book on Perl programming.
Message-Id: <YccW6.4860$qJ4.214011@ozemail.com.au>

See below.

--
Cheers
Ron  Savage
ron@savage.net.au
http://savage.net.au/index.html

Lig <lignite@oceanfree.net> wrote in message news:9gbiss$817aj$1@ID-31507.news.dfncis.de...
> Excellent.But don't you ever prefer free sites . Pl suggest some
> Lig

http://savage.net.au/Perl-tutorials.html

Also, check my Links pages. There are Perl tutorials all over the web.





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

Date: Thu, 14 Jun 2001 23:08:28 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: newbie-- re:win32 system() calls -- rmdir /s/q
Message-Id: <3b2940a0.48659990@news.erols.com>

On Thu, 14 Jun 2001 11:26:28 -0400, Korac <korac@dirig.com> wrote:

>Jay Tilton wrote:
>
>> On Wed, 13 Jun 2001 15:41:51 -0400, Korac <korac@dirig.com> wrote:
>>
>> >I'm having trouble using "rmdir /s/q dirname" within the sytem call,
>>
>> Win32 will bark about 'invalid switch' if you use forward slashes to
>> separate directory names.  Use backslashes.
>>
>>   $remdir_cmd = 'rmdir \s\q';
>
>Only problem is, it doesn't work.

In your example they're clearly switches, but I saw them as directory names.
I apologize to you and the rest of the group for saying foolish things
without completely reading the question.


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

Date: 15 Jun 2001 00:10:00 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: package, module or ???
Message-Id: <slrn9iikhs.qa7.damian@puma.qimr.edu.au>

Anno Siegel chose 14 Jun 2001 10:00:59 GMT to say this:
>According to Peter Søgaard <peter.sogaard@tjgroup.com>:
>> ...
>> Should I put all the parts in a module?
>> Should I put each part in it's own module?
>> 
>> Is it possible to somehow only include something in your code if it is
>> needed? ie:
>> if( module1IsActivated) use module 1;
>> ...
>
>Make the optional routines autoloading.  For more on that subject,
>look for 'autoload' in perlsub.  It will point you to further
>documents on the subject.
>

A slightly different approach that I have had some success with is to
require() modules from subs at runtime:

[warning: untested example code]

package Dispatcher;
use strict;
use warnings;

my %_dispatch = (
	command1	=>	\$function1,
	command2	=>	\&function2
);

sub dispatch { 
	my $command = shift or die 'Missing command argument';
	die 'Bad command argument'
		unless defined $command and exists $_dispatch{$command};
	return $_dispatch{$command}->(@_);
};

sub function1 {
	require Module1;
	return Module1::some_sub(@_);
};

sub function2 {
	require Module2;
	return Module2::some_sub(@_);
};

1;
__END__

I like this because there are multiple levels of indirection (into which
can be inserted less generic code), and it is easy to alter it to loop over
a list of coderefs (by making the hash values arrayrefs), allowing you to
break commands up into reusable functions.

This works for me, but perhaps someone can tell me if (and why) this is a
bone-headed thing to do? :-)

Cheers,
Damian
-- 
@:=grep!($;+=m!$/|#!),split//,<DATA>;@;=0..$#:;while(@;){for($;=@;;--$;;)
{@;[$;,$:]=@;[$:,$;]if($:=rand$;+$|)!=$;}push@|,shift@;if$;[0]==@|;select
$,,$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker # rev 3.1 -- a JAPH in progress, I guess...


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

Date: Fri, 15 Jun 2001 11:42:40 +0800
From: miss <north@nmpm.com.my>
Subject: transfer file
Message-Id: <3B298430.F98FB467@nmpm.com.my>

Dear sir/madam;

Does anyone know how to use perl program to transfer the file. eg: I got
C:/temp/a.txt ,when I run perl ,it will copy this a.txt to other folder/
pc.

how to do this??

Dose anyone what is e-ftp.bat ?
how does it function??




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

Date: Thu, 14 Jun 2001 22:36:24 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Validating postcodes
Message-Id: <tiif38r2a5kpff@corp.supernews.com>

Wayne Marrison (wayne.marrison@consignia.com) wrote:
: I need to validate postcodes given to my program to ensure that they
: correspond to the RoyalMail standard (UK).
: 
: I have the patterns required, i.e. "AN NAA","ANN NAA","AAN NAA","AANN
: NAA","ANA NAA","AANA NAA","AAA NAA" (with or without the space) and need to
: ensure that the code passed to my program conforms to one of the above
: (A=Alpha, N=Numeric).

#!/usr/bin/perl -w
# postcode - validate British post codes (demo for clpm)
# Craig Berry (20010614)

use strict;

my @patterns = ('AN NAA', 'ANN NAA', 'AAN NAA', 'AANN NAA',
                'ANA NAA', 'AANA NAA', 'AAA NAA');

foreach (@patterns) {
  s/A/[A-Z]/g;
  s/N/\\d/g;
  s/ /\\s?/g;
}

my $re = join '|', @patterns;

while (<>) {
  print /^(?:$re)$/o ? "valid\n" : "invalid\n";
}

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Magick is the art and science of causing change in conformity
   |   with Will."  - Aleister Crowley


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

Date: Fri, 15 Jun 2001 02:14:26 GMT
From: sweth+perl@gwu.edu (Sweth Chandramouli)
Subject: Re: Validating postcodes
Message-Id: <6ceW6.81503$G5.17517347@news1.rdc1.md.home.com>

In article <9gapsn$rgg$1@mamenchi.zrz.TU-Berlin.DE>,
Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>Here is a way that doesn't use a regex.  First build a hash of
>admissible patterns:
>
>    my %patterns;
>    @patterns{ "AN NAA","ANN NAA","AAN NAA","AANN NAA",
>               "ANA NAA","AANA NAA","AAA NAA"} = ();
>
>Now, if $_ contains the postal code in question, translate digits
>to the letter 'N' and alphabetics to 'A' (leave everything else
>alone):
>
>    tr/0-9A-Za-z/NNNNNNNNNNA/; # final A is effectively repeated
>
>Now see if we got one of the patterns:
>
>    if ( exists $patterns{ $_} ) {
>        # it's fine
>    }
	A slower variant that I used once for license plates,
modified for this purpose:

perl -ne 'tr/0-9C-Za-z/DDDDDDDDDDC/;/^CC?(?:DD?|C) DCC$/&&do_whatever;'

	-- Sweth.

-- 
Sweth Chandramouli ; <sweth+perl@gwu.edu>


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

Date: Fri, 15 Jun 2001 02:28:16 +0100
From: "David Soming" <davsoming@lineone.net>
Subject: Validation and escape \ requirement?
Message-Id: <tiiopfjbjdaaad@corp.supernews.co.uk>

Hi,
Could someone explain why this happens:

if ($message =~ tr/a-zA-Z0-9?',.\-\!\n\t //c) {  #The escape is needed for
characters after the period "." (full stop char)? otherwise what ever char
follows it - trips $errormessage

I suspect it might be because it's the concatenation ( . )operator! in which
case I've partly answered my own question, but why are other characters ok
such as $ % & etc. - why dont they cause the trip?
I since moved the ( . ) to the end anyway, but just curious why valid
(specified) meta-characters after the period caused the trip!

if ($message =~ tr/a-zA-Z0-9?',.-!\n\t //c) {  #Char -! = $errormessage

--
David Soming
'Just a head-banger- doing what I do best'
______________




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

Date: Fri, 15 Jun 2001 01:35:58 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Validation and escape \ requirement?
Message-Id: <3B2966AC.E0EF887D@acm.org>

David Soming wrote:
> 
> Hi,
> Could someone explain why this happens:
> 
> if ($message =~ tr/a-zA-Z0-9?',.\-\!\n\t //c) {  #The escape is needed for
> characters after the period "." (full stop char)? otherwise what ever char
> follows it - trips $errormessage
> 
> I suspect it might be because it's the concatenation ( . )operator! in which
> case I've partly answered my own question, but why are other characters ok
> such as $ % & etc. - why dont they cause the trip?
> I since moved the ( . ) to the end anyway, but just curious why valid
> (specified) meta-characters after the period caused the trip!
> 
> if ($message =~ tr/a-zA-Z0-9?',.-!\n\t //c) {  #Char -! = $errormessage

The hyphen character (-) is special in character classes hence it has to
be escaped unless it is at the beginning or end or specifies a valid
range of characters.

tr/a-f//; # characters a,b,c,d,e,f

tr/-af//; # characters -,a,f

tr/af-//; # charcters a,f,-

tr/f-a//; # ERROR



John
-- 
use Perl;
program
fulfillment


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

Date: Fri, 15 Jun 2001 03:30:58 +0100
From: "David Soming" <davsoming@lineone.net>
Subject: Re: Validation and escape \ requirement?
Message-Id: <tiisf155e2n4cb@corp.supernews.co.uk>

<big snip>
>
> The hyphen character (-) is special in character classes hence it has to
> be escaped unless it is at the beginning or end or specifies a valid
> range of characters.

Ah! so its not the ( . ) that causes it!

> tr/a-f//; # characters a,b,c,d,e,f
>
> tr/-af//; # characters -,a,f
>
> tr/af-//; # charcters a,f,-
>
> tr/f-a//; # ERROR
>
>
>
> John
> --
I  noticed the hyphen just affects one single character before the escape
and not the rest? I thought it was supposed to escape the one following \
or is this just special in character classes as you point out?
--
David Soming
'Just a head-banger- doing what I do best'
______________





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

Date: Fri, 15 Jun 2001 03:44:12 +0100
From: "David Soming" <davsoming@lineone.net>
Subject: Re: Validation and escape \ requirement?
Message-Id: <tiit7qs2bfbkd0@corp.supernews.co.uk>

<snipped>
> >
> > The hyphen character (-) is special in character classes hence it has to
> > be escaped unless it is at the beginning or end or specifies a valid
> > range of characters.
>
This is at the 'end' but ($) trips errormessage: tr/a-zA-Z0-9?',£&.!$-\n\t
//c)
Now I am confused!

--
David Soming
'Just a head-banger- doing what I do best'
______________




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

Date: Fri, 15 Jun 2001 02:56:28 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Validation and escape \ requirement?
Message-Id: <3B297986.FF711A1@acm.org>

David Soming wrote:
> 
> <snipped>
> > >
> > > The hyphen character (-) is special in character classes hence it has to
> > > be escaped unless it is at the beginning or end or specifies a valid
> > > range of characters.
> >
> This is at the 'end' but ($) trips errormessage: tr/a-zA-Z0-9?',£&.!$-\n\t
> //c)
> Now I am confused!

Here you have a hyphen between the dollar sign and the newline
characters, not at the end.
Either
tr/a-zA-Z0-9?',£&.!$\n\t -//c;
or
tr/-a-zA-Z0-9?',£&.!$\n\t //c;


John
-- 
use Perl;
program
fulfillment


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

Date: Thu, 14 Jun 2001 21:22:31 -0600
From: "bowman" <bowman@montana.com>
Subject: Re: Which C compiler to use for modules?
Message-Id: <c9fW6.10372$e21.7428@newsfeed.slurp.net>


"John Imrie" <john.imrie@pa.press.net> wrote in message
news:Gc3W6.1421$h45.8569@news.uk.colt.net...
>
> If you are going to get the free compiler talked about in this thread then
> the first thing you need to do is get the Perl source code and compile it
> with your program.

If the OP does the full meal deal install of cygwin, it includes Perl 5.6.1.
(and Python 2.1 also)





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

Date: Fri, 15 Jun 2001 09:56:27 +1000
From: "Ron Savage" <ron@savage.net.au>
Subject: Re: Why does my a: grind when I copy a file in perl?
Message-Id: <pdcW6.4862$qJ4.213872@ozemail.com.au>

See below

--
Cheers
Ron  Savage
ron@savage.net.au
http://savage.net.au/index.html
Arvin Portlock <temp133@hotmail.com> wrote in message news:9gb1di$2c4l$1@agate.berkeley.edu...
> I'm guessing this isn't a perl-specific question, or at least the
> solution won't be perl-specific.
>
> Whenever I do file copy in perl, my a: drive starts to grind for
> a couple of seconds, even though I'm not copying anything to

Probably an anti-virus program.





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

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.  

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


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