[13434] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 844 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Sep 18 20:07:20 1999

Date: Sat, 18 Sep 1999 17:05:09 -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: <937699507-v9-i844@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 18 Sep 1999     Volume: 9 Number: 844

Today's topics:
    Re: Can I call a compiled C program from Perl? (Abigail)
    Re: Can I call a compiled C program from Perl? <flavell@mail.cern.ch>
    Re: CONTEST: Range Searching <Richard@waveney.demon.co.uk>
    Re: CONTEST: Range Searching <jamie@mccarthy.org>
        CRAP Software <Kenny@gapdev.com>
        DB_File problem <dheera@usa.net>
    Re: DB_File problem <rick.delaney@home.com>
        Locking a tied database with DB_File <admin@gatewaysolutions.net>
    Re: Making and using a DB. (Help!!!) <dheera@usa.net>
        Problem developing module - eval guru wanted (take #2) <dfavor@austin.ibm.com>
        Problem developing module - eval guru wanted <dfavor@austin.ibm.com>
        Programming Modules for Perl <bernard@muenster.de>
    Re: regexp odity with (?s-x:) <rick.delaney@home.com>
    Re: Search Engine <sjohns17@uic.edu>
    Re: Search Engine <meridamx@enol.com>
        slip dialer in perl? fheitka@ibm.net 
    Re: Sorting on a string, by value. <uri@sysarch.com>
    Re: transform / in \/ <jkline@one.net>
    Re: transform / in \/ (Larry Rosler)
    Re: Using a period as a delimiter in the split() functi (Larry Rosler)
    Re: Using a period as a delimiter in the split() functi <tchrist@mox.perl.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 18 Sep 1999 16:36:58 -0500
From: abigail@delanet.com (Abigail)
Subject: Re: Can I call a compiled C program from Perl?
Message-Id: <slrn7u81kn.2ml.abigail@alexandra.delanet.com>

Rocky (MrETS@inconnect.com) wrote on MMCCIX September MCMXCIII in
<URL:news:7s0lsd$dts$1@news.inconnect.com>:
|| Does anyone know how to call a compiled C executable
|| from within a Perl program on a UNIX server.

system, exec, open, qx.

|| My executable C is in the same directory as my Perl Script.

Irrelevant.

|| I have tried extensions . .out .exe and (no extension)

Irrelevant.

|| I have "chmod" executable files to 755
|| 
|| The executables run just fine if I telnet to the directory
|| and just type their names from the command line...
|| 
|| What Gives? - Val Patterson, SLC UT

I dunno. You didn't tell us how you tried calling it.



Abigail
-- 
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: Sun, 19 Sep 1999 00:08:34 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Can I call a compiled C program from Perl?
Message-Id: <Pine.HPP.3.95a.990919000219.27423A-100000@hpplus03.cern.ch>

On Sat, 18 Sep 1999, Rocky wrote:

> Does anyone know how to call a compiled C executable
> from within a Perl program on a UNIX server.

Yes, they do.

> The executables run just fine if I telnet to the directory
> and just type their names from the command line...
> 
> What Gives? 

Probably the usual.  You assumed you had a path to the executable, and
you didn't.  Anyhow, your taint check should go bang (you _do_ use taint
checking on server scripts, right?) for failing to specify the path
explicitly. 

When you have questions about servers, it's helpful to say more
explicitly what your situation is.  If, in fact, you're talking about
the CGI environment, then your question would be more at home on the CGI
authoring group than here.

-- 

    Note : there are only about CCL years (written in MCMXCVII) until 
    the Annus MMM AUC, which is itself no great problem; but in the 
    year MMDCCCLXXXVIII the date field will be longer than ever before.
          - John Stockton, http://www.merlyn.demon.co.uk/miscdate.htm



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

Date: Sat, 18 Sep 1999 21:22:29 +0100
From: Richard Proctor <Richard@waveney.demon.co.uk>
Subject: Re: CONTEST: Range Searching
Message-Id: <ant1820290b0Rr9i@waveney.demon.co.uk>

Ok, here is my offering...

Simple, does all 3 jobs before/after/span handles overlapping ranges
has a few frills (Highlighting the matched line, and line numbering - delete
if not wanted)

#!perl
# patfind
# written by Richard Proctor

use Getopt::Std;

sub usage {print <<END; exit}
$0 [-m] [-N] [-B lines] [-A lines] [-C lines] /pattern/ [files...]

  -m    Print indication of matched line
  -N	Print Line Numbers
  -B n  Print n lines before the match
  -A n  Print n lines after the match
  -C n  Print n lines before and after the match

  Slashes on the pattern are optional.
END

getopts('mNB:A:C:') and $pat = shift and @ARGV or usage;
$opt_A = $opt_B = $opt_C if $opt_C;
$pat =~ s!^/(.*)/$!$1!;

while (<>) {
    $_ = "$.\t$_" if $opt_N;
    if (/$pat/) {
        print "\n";
        print @Past; 
        @Past=();
        print ">>>>\t" if $opt_m;
        print;
        $ToDo = $opt_A;
    }
    elsif ($ToDo) {
        $ToDo--;
        print;
    }
    elsif ($opt_B) {
        push @Past,$_;
        shift @Past if ($#Past == $opt_B);
    }
}

-- 
Richard@waveney.demon.co.uk


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

Date: Sat, 18 Sep 1999 18:20:05 -0400
From: Jamie McCarthy <jamie@mccarthy.org>
Subject: Re: CONTEST: Range Searching
Message-Id: <37E41015.3535E71E@mccarthy.org>

Chris Nandor wrote:

> # I am concerned that it still seems to
> # emphasize the mentality of cleverness (which seems to cause obscurity).
> 
> Why is that bad?  It is an exercise.  Consider it research.

OK, here's another answer then:

@l=<>;for$i(0..$#l){map{$m{$_}++}($i-$b..$i+$a)if$l[$i]=~/$r/o}print@l[grep{$m{$_}}(0..$#l)]

It's horrible for space (processes the whole input before beginning
to print) and not terrible for time.  Here's the full script,
including initialization (214 bytes long, 211 if you lose the "-w"):

#!/usr/bin/perl -w
while(@ARGV&&$ARGV[0]=~/^-([ABC])$/){$1ne'B'and$a=$ARGV[1];$1ne'A'and$b=$ARGV[1];shift;shift}$r=shift;@l=<>;for$i(0..$#l){map{$m{$_}++}($i-$b..$i+$a)if$l[$i]=~/$r/o}print@l[grep{$m{$_}}(0..$#l)]

Sample runs:

$ ./patba4.pl -B 1 -A 3 perl /usr/dict/words
improper
improperly
impropriety
improve
improved
proper
properly
properness
propertied
properties
superiors
superlative
superlatively
superlatives
supermarket
supermarkets
supermini

$ ./patba4.pl -C 2 '^Aa|perl' /usr/dict/words
Aarhus
Aaron
Ababa
aback
impromptu
improper
improperly
impropriety
improve
propensity
proper
properly
properness
propertied
superiority
superiors
superlative
superlatively
superlatives
supermarket
supermarkets

--
 Jamie McCarthy


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

Date: Sat, 18 Sep 1999 23:32:27 GMT
From: "Kenny Gardner" <Kenny@gapdev.com>
Subject: CRAP Software
Message-Id: <fiVE3.5736$tJ1.59086@news.rdc2.occa.home.com>

I couldn't let this one go since the Perl Gurus are totally against
anything that Matt or Solena writes and considers their software to be
CRAP.

On the www.perl.com site, if you search for the term "cookies", the
first listing will be, of course, the CGI::Cookie module.

However,

Notice what appears in the next section:

Matt's Script Archive.

Now, why is CRAP software allowed to show up on the Perl Site if CRAP
software is not to be used?

I find it ironic that the same people or organizations who label
software as CRAP provide links to said barnyard dung.

And Yes, I'll be using the Perl Module for this purpose but the double
standard that was discovered is unbearable.

Kenny





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

Date: Sat, 18 Sep 1999 19:55:08 GMT
From: Dheera <dheera@usa.net>
Subject: DB_File problem
Message-Id: <7s0qmp$ft9$1@nnrp1.deja.com>

Hi,
I've got this:
____________________
use DB_File;
use Fcntl;
$DB_RECNO->{'cachesize'}=4000000; # thousands of records to come
$DB_RECNO->{'reclen'}=500;
$DB_RECNO->{'flags'}=R_FIXEDLEN;
$DB_RECNO->{'bval'}="*";
tie @a, 'DB_File', "./list.db",O_RDWR|O_CREAT,0640,$DB_RECNO;
  $a[0]="this is a test";
untie @a;
____________________

After executing, list.db is simply blank. File size of 0 bytes.
The DB_HASH and DB_BTREE database types work perfectly fine, but
DB_RECNO seems to have some problems... can anyone help?

Thanks,
Dheera
dheera@usa.net


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Sat, 18 Sep 1999 20:29:23 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: DB_File problem
Message-Id: <37E3F61F.D495B34E@home.com>

[posted & mailed]

Dheera wrote:
> 
> tie @a, 'DB_File', "./list.db",O_RDWR|O_CREAT,0640,$DB_RECNO;
>   $a[0]="this is a test";
> untie @a;
> ____________________
> 
> After executing, list.db is simply blank.

Did you check that the tie succeeded?

tie @a, 'DB_File', "./list.db",O_RDWR|O_CREAT,0640,$DB_RECNO
    or die "tie to ./list.db failed: $!";

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Sat, 18 Sep 1999 16:35:45 -0500
From: "Scott Beck" <admin@gatewaysolutions.net>
Subject: Locking a tied database with DB_File
Message-Id: <ru818ll9lg721@corp.supernews.com>

I am just starting to learn about the DB_File module.
From the documentation I came up with this locking 
method and I wanted to see if anyone could see something
wrong with it.
As far as I can tell it is working but ya never know 
maybe there is a better way. TMTOWTDI

use DB_File;
use Fcntl qw(:flock);

 $db = tie @db, "DB_File", $file_location, O_RDWR|O_CREAT, 0666, $DB_RECNO 
            or die "Cannot open file '$file_location': $!\n";
 &lock_db("$db");

#do some stuff to the array @db

&unlock_db("$db");
undef $db;
untie @db;

sub lock_db{
 my($db)=shift;
my $fd = $db->fd;
 open(DB_FH, "+<&=$fd") || die "dup $!";
 unless (flock (DB_FH, LOCK_EX | LOCK_NB)) {
  sleep 5;
  unless (flock (DB_FH, LOCK_EX)) { die "flock: $!" }
 }
}
sub unlock_db{
my($db)=shift;
 $db->sync;
 sleep 10;
 flock(DB_FH, LOCK_UN);
 close(DB_FH);
}

Thanks,
-- 
Scott Beck



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

Date: Sat, 18 Sep 1999 22:40:19 GMT
From: Dheera <dheera@usa.net>
Subject: Re: Making and using a DB. (Help!!!)
Message-Id: <7s14ci$lrq$1@nnrp1.deja.com>

Actually all you need to do is get the zip file you want from the URL I
gave, then extract it under the bin directory. It'll put a .ppd file
there and a x86 directory or soemthing like that. Then run ppm and
simply type "install <filename.ppd>" and you're ready.

I've tried a whole bunch of things from that address and they all
instally properly!!! (...i'm behind a proxy so obviously the ppm
program wouldn't fetch them easily anyway...)

In article <37E2DF3E.F79CE30E@mail.cor.epa.gov>
  David Cassell <cassell@mail.cor.epa.gov> wrote:
> Dheera wrote:
> >
> > Here is the exact address (DB_File and a bunch of others are
available
> > here):
> >
> > http://www.activestate.com/packages/zips/
>
> But it will be better to use the ppm program to fetch them
> and get them installed *properly*.
>
> Read the win32perl FAQ on your hard drive to see how to
> use ppm.
>
> Type 'ppm help' at a command prompt to find out what the
> options are.
>
> Type 'ppm search DB' to get a list of available packages
> with "DB" in their names.
>
> Then type the appropriate thing using the ppm install
> option.  And voila!
>
> HTH,
> David
> --
> David Cassell, OAO                     cassell@mail.cor.epa.gov
> Senior computing specialist
> mathematical statistician
>


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.


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

Date: Sat, 18 Sep 1999 15:16:58 -0500
From: "David R. Favor" <dfavor@austin.ibm.com>
Subject: Problem developing module - eval guru wanted (take #2)
Message-Id: <37E3F33A.1D0D9666@austin.ibm.com>

This is a multi-part message in MIME format.
--------------6A66805FE05D95527BEB3FEC
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Attached are the files in question:

   t             - test script
   DynaVector.pm - module file


_______



I'm trying to develop a module that works somewhat like Thread::Queue:

   #!/usr/local/bin/perl -w

   use strict;

   use Net::NNTP;
   use DynaVector;
   use Data::Dumper;

   my $host   = $ENV{NNTPSERVER};
   my $iopool = new DynaVector(create=>"Net::NNTP->new",max=>10);
   my $nntp   = $iopool->alloc($host,Debug=>1);

   print Dumper $nntp;

I've tried numerous approaches. Several work, but I can never seem to
hit on the correct eval to get the arguments ($host,Debug=>1) passed.

I'm sure there is something very simple I'm missing, so someone point
me in the correct direction.

Thanks.
--------------6A66805FE05D95527BEB3FEC
Content-Type: text/plain; charset=us-ascii;
 name="t"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="t"

#!/usr/local/bin/perl -w

use strict;

use Net::NNTP;
use DynaVector;
use Data::Dumper;

my $host   = $ENV{NNTPSERVER};
my $iopool = new DynaVector(create=>"Net::NNTP->new",max=>10);
my $nntp   = $iopool->alloc($host,Debug=>1);

print Dumper $nntp;

--------------6A66805FE05D95527BEB3FEC
Content-Type: text/plain; charset=us-ascii;
 name="DynaVector.pm"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="DynaVector.pm"

package DynaVector;

use strict;
use fields qw(max create pool allocated);

use Thread qw(cond_wait);

sub new {

   # class init
   my $proto = shift;
   my $class = ref($proto) || $proto;

   my $self  = {

      #
      # default arguments
      #

      create    => undef,   # create method or function
      max       => 0,       # <1 means unlimited

      #
      # override via constructor values
      #

      @_,

      #
      # these may not be overridden, so anything passed
      # in constructor is clobbered here
      #

      allocated => 0,       # number of entries allocated
      pool      => [],      # $#pool is number of entries available

   };

   bless $self, $class;

}

sub alloc {

   my $self = shift;

   my $pool = $self->{pool};

   my $thingy;

   lock $pool;

   #
   # at least one thingy is available
   #

   if ($#$pool > -1) {
      $thingy = shift @$pool;
   }

   #
   # no thingy's available and it's okay to create another one
   #

   elsif ($self->{allocated} < $self->{max}) {
      my $cmd = $self->{create} . '(@_)';
      $thingy = eval $cmd;
   }

   #
   # no thingy's avaiable and need to wait until one is freed
   #

   else {
      cond_wait $thingy while ($#$pool < 0);
      $thingy = shift @$pool;
   }

   return $thingy;

}

sub free {

   my $self   = shift;
   my $thingy = shift;
   my $pool   = $self->{pool};

   lock $pool;

   push @$pool, $thingy;

   cond_signal $pool;

}

1;

--------------6A66805FE05D95527BEB3FEC--



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

Date: Sat, 18 Sep 1999 15:14:14 -0500
From: "David R. Favor" <dfavor@austin.ibm.com>
Subject: Problem developing module - eval guru wanted
Message-Id: <37E3F296.19A04A88@austin.ibm.com>

I'm trying to develop a module that works somewhat like Thread::Queue:

   #!/usr/local/bin/perl -w

   use strict;

   use Net::NNTP;
   use DynaVector;
   use Data::Dumper;

   my $host   = $ENV{NNTPSERVER};
   my $iopool = new DynaVector(create=>"Net::NNTP->new",max=>10);
   my $nntp   = $iopool->alloc($host,Debug=>1);

   print Dumper $nntp;

I've tried numerous approaches. Several work, but I can never seem to
hit on the correct eval to get the arguments ($host,Debug=>1) passed.

I'm sure there is something very simple I'm missing, so someone point
me in the correct direction.

Thanks.


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

Date: Sun, 19 Sep 1999 01:08:14 +0200
From: Frederik bernard <bernard@muenster.de>
Subject: Programming Modules for Perl
Message-Id: <37E41B5E.BBB16B0F@muenster.de>

Hi everybody,

does anybody know a good book or
a good script in the net which gives
me some good information
about programming modules for
perl?

Thanks for any help,

fred :-)





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

Date: Sat, 18 Sep 1999 20:22:32 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: regexp odity with (?s-x:)
Message-Id: <37E3F483.F2E1DFF1@home.com>

[posted & mailed]

Bob Walton wrote:
> 
> Thanks for the clarification.  I guess I just assumed the paren set
> in which the "-x" was defined didn't count as an "enclosing" paren set.

Well, it does.

> It isn't clear to me from perlre that this isn't actually the case,
> given the examples with (?i), in which the effect of the (?i)
> clearly proceeds until the end of the paren group surrounding the (?i).

Yes, but if you look at both (?imsx-imsx) and (?:imsx-imsx:pattern)
together you can see that the modifiers in (?:imsx-imsx:pattern) must be
local to the (?:) group.  Lee has already quoted the relevant sections:

lt lindley wrote:
> 
> These lines about (?imsx-imsx):
>                These modifiers are localized inside an enclosing
>                group (if any).  Say,
> and these about (?:imsx-imsx:pattern):
>                The letters between ? and : act as flags
>                modifiers, see the (?imsx-imsx) manpage.  In
>                particular,
> 
>                    /(?s-i:more.*than).*million/i
> 
>                is equivalent to more verbose
> 
>                    /(?:(?s-i)more.*than).*million/i
                      ^^^^^^^^^^^^^^^^^^^^
                      This is an enclosing group around (?s-i).

So this will match

    more than a million

    more than a MILLION

but not

    MORE THAN A MILLION

-- 
Rick Delaney
rick.delaney@home.com


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

Date: Sat, 18 Sep 1999 16:41:55 -0500
From: Seth David Johnson <sjohns17@uic.edu>
Subject: Re: Search Engine
Message-Id: <Pine.A41.4.10.9909181640130.827610-100000@tigger.cc.uic.edu>

On Sun, 19 Sep 1999, Pawan Bhati wrote:

> 
> Can anyone please help me build a small search engine for my site in perl.
> My website is on Webjump & I have tried many free search scripts but all
> fail to work.
> Somebady pleaze help me !!

You can probably do what you want using File::Find and HTML::Parser. Oh,
you may want to learn Perl, too :)

-Seth



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

Date: Sat, 18 Sep 1999 17:07:34 -0600
From: "Chuck Burgess" <meridamx@enol.com>
Subject: Re: Search Engine
Message-Id: <7s16d4$ns8$1@news.inquo.net>

Hi,
It's strangly obvious you have not searched for any information on your own
before posting your plea.  Of course, telling you about it will probably
accomplish less. SO... go get ICE at:
http://www.objectweaver.de/ice/

It's so easy to setup, my 4 year old can do it in 5 minutes. It exists of
two scripts. One called *ice2-idx.pl * and one called *ice2-for.pl*

You will have to configure the path to indicate where you want ICE to start
indexing your site. Then from a command line you will:

cd /home/you/html/cgi-bin
perl ice2-idx.pl

The script will index your site. Then you use the ice2-for.pl to access the
search/index via the browser.

Good-luck!

BTW. Try using something like http://cgi.resourceindex.com to find some free
scripts and get more information about things you might be looking for as
apposed to posting it in a newsgroup.


Pawan Bhati wrote in message <7s1v8e$1ks$1@news.vsnl.net.in>...
>
>Can anyone please help me build a small search engine for my site in perl.
>My website is on Webjump & I have tried many free search scripts but all
>fail to work.
>Somebady pleaze help me !!
>
> Pawan
> pawanbhati@hotmail.com
>
>
>




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

Date: 18 Sep 1999 21:12:50 GMT
From: fheitka@ibm.net 
Subject: slip dialer in perl?
Message-Id: <37e40052@news1.prserv.net>
Keywords: SLIP, perl, slattach 

I was wondering if anyone has written a dialer
script to connect to an ISP (dynamic) using
say perl and slattach?

-- 
Fred


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

Date: 18 Sep 1999 19:43:39 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Sorting on a string, by value.
Message-Id: <x7btazaiqc.fsf@home.sysarch.com>

>>>>> "LR" == Larry Rosler <lr@hpl.hp.com> writes:

  LR> Only in your dreams!  At least this way the world will have seen yet 
  LR> another well-written example of this magnificent technique.  :-)

regarding you, it is in my nightmares. :-)

  LR> Note that use of the Schwartz on these six sortfields would have been 
  LR> pretty ugly, to say nothing of slow and error-prone.  (You got a bug in 
  LR> with only three sortfields. :-)

i beg to differ, python breath. the original post did a pure numeric
compare on the prefix digits as a single number. i quote:

And I want them to be sorted first by the prefix to the period, as if
they are numeric (2345, 2346, 23411, etc.) and if they are the same
numerical value, 

        my ($parta1, $parta2) = split /\./, $a;
        
        $parta1 =~ s/_//g;

that makes it a single numeric string

        return ( ( $parta1 == $partb1) ? (( $parta2 > $partb2 ) ? 1 : -1) :
                           ^^
		(($parta1 > $partb1) ? 1 : -1 ));
                          ^
both are numeric compares of the prefix digits as a single number.

so my ST was correct in making that one field. i admit the minor bugs
you found but you are dead wrong here! what you have to do is make the
numeric prefix a single N pack field.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com
"F**king Windows 98", said the general in South Park before shooting Bill.


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

Date: Sat, 18 Sep 1999 16:28:54 -0400
From: Joe Kline <jkline@one.net>
Subject: Re: transform / in \/
Message-Id: <37E3F606.C967CF3B@one.net>

Andreas Hagelberg wrote:
> 
> Joe Kline wrote:
> >
> > tr/\//\\\/;
> >
> 
> Hmmm... I actually think you missed a / at the end... It's definitely a
> good idea to use some other quote-character in this case...

Damn...I did. Yet another reason to use alternate delimiters when
messing with slashes in regexes.

joe


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: Sat, 18 Sep 1999 15:16:46 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: transform / in \/
Message-Id: <MPG.124daf22c5563728989fa2@nntp.hpl.hp.com>

In article <37E3F606.C967CF3B@one.net> on Sat, 18 Sep 1999 16:28:54 -
0400, Joe Kline <jkline@one.net> says...
> Andreas Hagelberg wrote:
> > 
> > Joe Kline wrote:
> > >
> > > tr/\//\\\/;
> > 
> > Hmmm... I actually think you missed a / at the end... It's definitely a
> > good idea to use some other quote-character in this case...
> 
> Damn...I did. Yet another reason to use alternate delimiters when
> messing with slashes in regexes.

There are no regexes there.

And, as I posted earlier, adding the terminating slash just produces a 
fast way to translate a slash to a backslash.

A question for p5p folks:  Might tr/// warn if the REPLACEMENTLIST is 
longer than the SEARCHLIST, as there are no semantics for the trailing 
unmatched characters?

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Sat, 18 Sep 1999 15:31:12 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Using a period as a delimiter in the split() function
Message-Id: <MPG.124db28c8c92886e989fa3@nntp.hpl.hp.com>

In article <37E3EE80.5FE7F445@home.com> on Sat, 18 Sep 1999 19:56:53 
GMT, Rick Delaney <rick.delaney@home.com> says...
 ... 
> Of course, when presented with the code
> 
>     split ':', $passwd;
> 
> it's no wonder people think split works on strings.  Please go smack the
> person that showed you code like that when 
> 
>     split /:/, $passwd;
> 
> would be clearer.
> 
> It's getting to the point where I'd like to see 
> 
>     split ''
> 
> deprecated in favour of
> 
>     split m''

You are pointing out a flaw in the evolution of this function:  the 
interpretation of what is syntactically a string to have the semantics 
of a regex.  The frequency of programmer error (often for '|') would 
indicate the appropriateness of some corrective action.

Here is a comparable situation.  Suppose someone proposed extending the 
semantics of $/ to include regexes.  (I know this has been discussed to 
death, but perhaps might be reconsidered.)

With our current knowledge, it would not be done by changing the 
semantics of a string assigned to $/ to those of a regex.  A line 
separator of '0.0' would not suddenly become equivalent to /0.0/ !  
Instead an assignment such as

    $/ = qr/0.0/;

would be required to get the regex semantics.  A flag could be set for 
the input routine in this case, and unset if a string were later 
assigned to $/, making it possible to preserve the efficiency of the 
string input terminator.

I conjecture that split() originally took a string as the separator, and 
then when split() was later enhanced to take a regex as the separator 
the string arguments were grandfathered for backwards compatibility in 
existing code.  Changing their semantics to regex semantics feels like a 
mistake to me.

Except for the magic of split ' ', I don't see what purpose is served 
now by having two ways of saying the same thing, one of which is fraught 
with surprises.  I agree that no educator should ever show split with a 
string argument (except for the magic case), unless and until the string 
semantics were obeyed when a string is specified.  (Someone who would 
write a string argument in the expectation of regex semantics is 
malicious, at best.) Until then, a warning seems like a good thing.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 18 Sep 1999 17:15:51 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Using a period as a delimiter in the split() function
Message-Id: <37e41d27@cs.colorado.edu>

     [courtesy cc of this posting mailed to cited author]

In comp.lang.perl.misc, 
    lr@hpl.hp.com (Larry Rosler) writes:
:I conjecture that split() originally took a string as the separator, and 
:then when split() was later enhanced to take a regex as the separator 
:the string arguments were grandfathered for backwards compatibility in 
:existing code.  

I find that unlikely, since awk's split() has always supported a 
regex at that point.  Certainly perl1 already had it.

% man perl1
[...]
 1 split(/PATTERN/,EXPR)
 2 split(/PATTERN/)
 3 split   
 4      Splits a string into an array of strings, and returns it.
 5      If EXPR is omitted, splits the $_ string.  If PATTERN  is also
 6      omitted, splits on whitespace (/[ \t\n]+/).  Anything matching
 7      PATTERN is taken to be a delimiter separating thefields.
 8      (Note that the delimiter may be longer than one character.)
 9      Trailing null fields are stripped, which potential users of pop()
10      would do well to remember.  A pattern matching the null string
11      will split into separate characters.
12
13         Example:
14
15              open(passwd, '/etc/passwd');
16              while (<passwd>) {
17                   ($login, $passwd, $uid, $gid, $gcos, $home, $shell)
18                        = split(/:/);
19                   ...
20              }
21
22     (Note  that $shell above will still have a newline on it.
23     See chop().)  See also join.
24

That's all it had.  Now compare with:

% man 3pl split
 1  split /PATTERN/,EXPR,LIMIT
 2  split /PATTERN/,EXPR
 3  split /PATTERN/
 4  split
 5
 6      Splits a string into a list of strings and returns that list.
 7      By default, empty leading fields are preserved, and empty trailing
 8      ones are deleted.
 9
10      If not in list context, returns the number of fields found and
11      splits into the `@_' array. (In list context, you can force the
12      split into `@_' by using `??' as the pattern delimiters, but
13      it still returns the list value.) The use of implicit split to
14      `@_' is deprecated, however, because it clobbers your subroutine
15      arguments.
16
17      If EXPR is omitted, splits the `$_' string. If PATTERN is
18      also omitted, splits on whitespace (after skipping any leading
19      whitespace). Anything matching PATTERN is taken to be a delimiter
20      separating the fields. (Note that the delimiter may be longer
21      than one character.)
22
23      If LIMIT is specified and positive, splits into no more than
24      that many fields (though it may split into fewer). If LIMIT is
25      unspecified or zero, trailing null fields are stripped (which
26      potential users of `pop' would do well to remember). If LIMIT
27      is negative, it is treated as if an arbitrarily large LIMIT had
28      been specified.
29
30      A pattern matching the null string (not to be confused with a
31      null pattern `//', which is just one member of the set of patterns
32      matching a null string) will split the value of EXPR into separate
33      characters at each point it matches that way.  For example:
34
35          print join(':', split(/ */, 'hi there'));
36
37      produces the output 'h:i:t:h:e:r:e'.
38
39      The LIMIT parameter can be used to split a line partially
40
41          ($login, $passwd, $remainder) = split(/:/, $_, 3);
42
43      When assigning to a list, if LIMIT is omitted, Perl supplies
44      a LIMIT one larger than the number of variables in the list,
45      to avoid unnecessary work. For the list above LIMIT would have
46      been 4 by default. In time critical applications it behooves
47      you not to split into more fields than you really need.
48
49      If the PATTERN contains parentheses, additional list elements
50      are created from each matching substring in the delimiter.
51
52          split(/([,-])/, "1-10,20", 3);
53
54      produces the list value
55
56          (1, '-', 10, ',', 20)
57
58      If you had the entire header of a normal Unix email message
59      in $header, you could split it up into fields and their values
60      this way:
61
62          $header =~ s/\n\s+/ /g;  # fix continuation lines
63          %hdrs   =  (UNIX_FROM => split /^(\S*?):\s*/m, $header);
64
65      The pattern `/PATTERN/' may be replaced with an expression to
66      specify patterns that vary at runtime. (To do runtime compilation
67      only once, use `/$variable/o'.)
68
69      As a special case, specifying a PATTERN of space (`' '') will
70      split on white space just as `split' with no arguments does.
71      Thus, `split(' ')' can be used to emulate awk's default behavior,
72      whereas `split(/ /)' will give you as many null initial fields
73      as there are leading spaces. A `split' on `/\s+/' is like a
74      `split(' ')' except that any leading whitespace produces a null
75      first field. A `split' with no arguments really does a `split('
76      ', $_)' internally.
77
78      Example:
79
80          open(PASSWD, '/etc/passwd');
81          while (<PASSWD>) {
82              ($login, $passwd, $uid, $gid,
83               $gcos, $home, $shell) = split(/:/);
84              #...
85          }
86
87      (Note that $shell above will still have a newline on it. See
88      the chop, chomp, and join entries elsewhere in this document.)

Lots more to read.  Maybe it's time to resurrect the perl1 manpage. :-(

--tom
-- 
     del() { rm -rf "$@"; echo 'Were you sure? \c'; read ans }


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 844
*************************************


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