[19416] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1611 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Aug 25 14:05:23 2001

Date: Sat, 25 Aug 2001 11:05:06 -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: <998762706-v10-i1611@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 25 Aug 2001     Volume: 10 Number: 1611

Today's topics:
        2-Open Directory problem <edd@texscene.com>
    Re: confused about 4 argument select (Anno Siegel)
        global and local variables <jens@irs-net.com>
    Re: how to get named constants in Perl <godzilla@stomp.stomp.tokyo>
    Re: need help with regexp... (John Wentzcovitch)
        No HTML submitted via form (Alexey Lysenkov)
    Re: No HTML submitted via form <kent@erix.ericsson.se>
    Re: one character at a time <godzilla@stomp.stomp.tokyo>
        open directory problem <edd@texscene.com>
    Re: open directory problem <jens@irs-net.com>
    Re: pl or not pl, that is the question (remove the obvious)
        Question about GD <barna@megapage.ch>
    Re: quick(?) programming question for perl newbie (Nathan McDannold)
    Re: Read/write specific line of file (Mario Rizzuti)
    Re: round off operator on Perl? <mark.riehl@agilecommunications.com>
    Re: Self-Searchable Perl documention - Extremely Useful (Yves Orton)
    Re: Self-Searchable Perl documention - Extremely Useful (Yves Orton)
    Re: Statement modifiers?? (Anno Siegel)
    Re: String replacements using s/// <info@fruiture.de>
    Re: String replacements using s/// <godzilla@stomp.stomp.tokyo>
    Re: String Substitution across two files (Anno Siegel)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 25 Aug 2001 18:38:48 +0100
From: "Edd" <edd@texscene.com>
Subject: 2-Open Directory problem
Message-Id: <3b87e0ff@news-uk.onetel.net.uk>

I want to do a series of tasks if a particular diurectory fails to open. To
do this I wrote the code below. But it generates error. Why is that? Is
there a way around it please?

$isitopen="YES";
opendir (LOGDIR, "/home/../..$path") || $isitopen="NO";
if ($isitopen eq "NO") {
   print "$path doesn't exit" ;
   &subroutine1;
   &subroutine2;
   ...
}

The error it generates is :

"scalar can't be modified near "NO";

Thanks

Ed




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

Date: 25 Aug 2001 15:36:48 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: confused about 4 argument select
Message-Id: <9m8gmg$feq$2@mamenchi.zrz.TU-Berlin.DE>

According to Alex Hart  <news@althepal#nospam#.com>:

[...]
 
> Also, is this the only method of timing out a read? Will <> ever time
> out, or is it forever?

Diamonds are forever.

Anno


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

Date: Sat, 25 Aug 2001 17:28:50 +0200
From: "Jens Luedicke" <jens@irs-net.com>
Subject: global and local variables
Message-Id: <pan.2001.08.25.17.28.47.464.7527@irs-net.com>

Hi there ...

I have two modules that don't belong to a special package.
Within those modules I use only variables that are declared
in the main program with "our (...)". When I include "use strict"
in those modules I get lots of errors like:

Variable "%widgets" is not imported at /usr/local/lib/pmc/PMC/MainWindow.pm line 23.
Global symbol "%widgets" requires explicit package name at /usr/local/lib/pmc/PMC/MainWindow.pm line 162.
G

Am I missing something here?

jens


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

Date: Sat, 25 Aug 2001 08:40:11 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: how to get named constants in Perl
Message-Id: <3B87C6DB.ADB62D00@stomp.stomp.tokyo>

Joachim Ziegler wrote:

(snipped)

> how do i create named constants in Perl?


Godzilla!
--
Source: Programming Perl, copyright O'Reilly 2001

31.7. use constant

     use constant BUFFER_SIZE    => 4096;
     use constant ONE_YEAR       => 365.2425 * 24 * 60 * 60;
     use constant PI             => 4 * atan2 1, 1;
     use constant DEBUGGING      => 0;
     use constant ORACLE         => 'oracle@cs.indiana.edu';
     use constant USERNAME       => scalar getpwuid($<);
     use constant USERINFO       => getpwuid($<);

     sub deg2rad { PI * $_[0] / 180 }

     print "This line does nothing"      unless DEBUGGING;

     # references can be declared constant
     use constant CHASH          => { foo => 42 };
     use constant CARRAY         => [ 1,2,3,4 ];
     use constant CPSEUDOHASH    => [ { foo => 1}, 42 ];
     use constant CCODE          => sub { "bite $_[0]\n" };

     print CHASH->{foo};
     print CARRAY->[$i];
     print CPSEUDOHASH->{foo};
     print CCODE->("me");
     print CHASH->[10];                          # compile-time error

This pragma declares the named symbol to be an immutable constant[2] with
the given scalar or list value. You must make a separate declaration for
each symbol. Values are evaluated in list context. You may override this
with scalar as we did above.

[2] Implemented as a subroutine taking no arguments and returning the 
    same constant each time.

Since these constants don't have a $ on the front, you can't interpolate
them directly into double-quotish strings, although you may do so indirectly: 

     print "The value of PI is @{[ PI ]}.\n";

Because list constants are returned as lists, not as arrays, you must subscript
a list-valued constant using extra parentheses as you would any other list expression: 

     $homedir = USERINFO[7];             # WRONG
     $homedir = (USERINFO)[7];           # ok

Although using all capital letters for constants is recommended to help them stand
out and to help avoid potential collisions with other keywords and subroutine names,
this is merely a convention. Constant names must begin with a letter, but it need
not be a capital one.

Constants are not private to the lexical scope in which they occur. Instead, they are
simply argumentless subroutines in the symbol table of the package issuing the declaration.
You may refer to a constant CONST from package Other as Other::CONST. Read more about
compile-time inlining of such subroutines in the section "Inlining Constant Functions" in
Chapter 6, "Subroutines".

As with all use directives, use constant happens at compile time. It's therefore misleading
at best to place a constant declaration inside a conditional statement, such as
  if ($foo) { use constant ... }.

Omitting the value for a symbol gives it the value of undef in scalar context or the 
empty list, (), in a list context. But it is probably best to declare these explicitly: 

     use constant CAMELIDS       => ();
     use constant CAMEL_HOME     => undef;

31.7.1. Restrictions on use constant

List constants are not currently inlined the way scalar constants are. And it is not
possible to have a subroutine or keyword with the same name as a constant. This is
probably a Good Thing.

You cannot declare more than one named constant at a time: 

     use constant FOO => 4, BAR => 5;    # WRONG

That defines a constant named FOO whose return list is (4, "BAR", 5). You need this instead: 

     use constant FOO => 4
     use constant BAR => 5;

You can get yourself into trouble if you use a constant in a context that automatically quotes
bare names. (This is true for any subroutine call, not just constants.) For example, you can't
say $hash{CONSTANT} because CONSTANT will be interpreted as a string. Use $hash{CONSTANT()}
or $hash{+CONSTANT} to prevent the quoting mechanism from kicking in. Similarly, since the
=> operator quotes its left operand if that operand is a bare name, you must say
CONSTANT() => 'value' instead of
CONSTANT => 'value' .

At some point, you'll be able to use a constant attribute on variable declarations: 

     my $PI : constant = 4 * atan2(1,1);

This has all the advantages of being a variable rather than a subroutine. It has all
the disadvantages of not being implemented yet.


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

Date: 25 Aug 2001 10:54:24 -0700
From: wentzcovitch@hotmail.com (John Wentzcovitch)
Subject: Re: need help with regexp...
Message-Id: <405f748b.0108250954.10f07e57@posting.google.com>

"John W. Krahn" <krahnj@acm.org> wrote in message news:<3B86A695.AB107825@acm.org>...
> 
> (?i:LINE (\d+) OF ([A-Z]:[^:]+):)
> 
> 
> 
> John

Many thanks John, it worked with a little modification:

(?:\*\*\* ERROR \d+ IN LINE (\d+) OF ([A-Z]:[^:]+):.*)

The expression had to be an exact match.
A very useful regexp tester can be found at
http://www.savarese.org/oro/demos/OROMatcherDemo.html .

Thanks again, John


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

Date: 25 Aug 2001 10:39:09 -0700
From: a_pop@my-deja.com (Alexey Lysenkov)
Subject: No HTML submitted via form
Message-Id: <e39b8fbf.0108250939.5c6188ae@posting.google.com>

Hi all,

I guess, it is probably a bit off topic here, but I know, that Perl
people are kind people :)) and they surely know hot to help :))

Anyway.
I want to block html tags which where submitted via a form. In other
words, if someone types "<b>blah</b>" in a form and submits it, then
it is shown in html page like "<b>blah</b>" and not like a bold "b" (a
simple guestbook, you know..). I am no perl programmer, so if you just
help me with general concepts, I will really appreciate it.

Sorry, if I disturbed you a lot, guys.

Best regards
Alex


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

Date: 25 Aug 2001 19:54:59 +0200
From: Kent Boortz <kent@erix.ericsson.se>
Subject: Re: No HTML submitted via form
Message-Id: <d2itfcvxcc.fsf@erix.ericsson.se>


a_pop@my-deja.com (Alexey Lysenkov) writes:
> I guess, it is probably a bit off topic here, but I know, that Perl
> people are kind people :)) and they surely know hot to help :))
> 
> Anyway.
> I want to block html tags which where submitted via a form. In other
> words, if someone types "<b>blah</b>" in a form and submits it, then
> it is shown in html page like "<b>blah</b>" and not like a bold "b" (a
> simple guestbook, you know..). I am no perl programmer, so if you just
> help me with general concepts, I will really appreciate it.

For each field do something like

  $data =~ s/</&lt;/g;
  $data =~ s/>/&gt;/g;

i.e. convert <tag> to &lt;tag&gt; that will be viewed by the browser
as <tag>, not interpreted as a HTML tag.

kent


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

Date: Sat, 25 Aug 2001 08:28:51 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: one character at a time
Message-Id: <3B87C433.EEA3A559@stomp.stomp.tokyo>

Yves Orton wrote:
 
> Benjamin Goldberg wrote:
> > Ken wrote:

> > my $string = "my little string";
> > while( /(.)/gs ) {
> >       print $1, "\n";
> > }
 
> print $1."\n" while ($string=~/(.)/gs );
 


$string = "my little string";
do
 { print substr ($string, 0, 1, ""), "¦"; }
until (!$string);


Godzilla!
--

#!perl

print "Content-type: text/plain\n\n";

use Benchmark;

print "Run One:\n\n";
&Time;

print "\n\nRun Two:\n\n";
&Time;

print "\n\nRun Three:\n\n";
&Time;


sub Time
 {
  timethese (100000,
  {
   'name1' =>
   '$string = "my little string";
    do
     { $output = substr ($string, 0, 1, ""); }
    until (!$string);',

   'name2' =>
   '$string = "my little string";
    $output = $1 while ($string=~/(.)/gs );',

  } );
 }

PRINTED RESULTS:
________________

Run One:

Benchmark: timing 100000 iterations of name1, name2...
 name1:  3 wallclock secs ( 3.47 usr +  0.00 sys =  3.47 CPU) @ 28818.44/s
 name2:  6 wallclock secs ( 5.72 usr +  0.00 sys =  5.72 CPU) @ 17482.52/s


Run Two:

Benchmark: timing 100000 iterations of name1, name2...
 name1:  4 wallclock secs ( 4.06 usr +  0.00 sys =  4.06 CPU) @ 24630.54/s
 name2:  5 wallclock secs ( 5.71 usr +  0.00 sys =  5.71 CPU) @ 17513.13/s


Run Three:

Benchmark: timing 100000 iterations of name1, name2...
 name1:  3 wallclock secs ( 4.07 usr +  0.00 sys =  4.07 CPU) @ 24570.02/s
 name2:  6 wallclock secs ( 5.71 usr +  0.00 sys =  5.71 CPU) @ 17513.13/s


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

Date: Sat, 25 Aug 2001 18:34:02 +0100
From: "Edd" <edd@texscene.com>
Subject: open directory problem
Message-Id: <3b87dfe4@news-uk.onetel.net.uk>


I want to do a series of tasks if a particular diurectory fails to open. To
do this I wrote the code below. But it generates error. Why is that? Is
there a way around it please?

$isitopen="YES";
opendir (LOGDIR, "/home/../..$path") || $isitopen="NO";
if ($isitopen eq "NO") {
   print "$path doesn't exit" ;
   &subroutine1;
   &subroutine2;
   ...
}







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

Date: Sat, 25 Aug 2001 19:39:26 +0200
From: "Jens Luedicke" <jens@irs-net.com>
Subject: Re: open directory problem
Message-Id: <pan.2001.08.25.19.39.25.911.11488@irs-net.com>

hi ...

let's try it that way:

opendir (LOGDIR, "/home/../..$path") || &diropen_failed; 

sub diropen_failed {
	print "$path doesn't exit" ;
	&subroutine1;
	&subroutine2;
	# ...
}

jens

In article <3b87dfe4@news-uk.onetel.net.uk>, "Edd" <edd@texscene.com>
wrote:

> I want to do a series of tasks if a particular diurectory fails to open.
> To do this I wrote the code below. But it generates error. Why is that?
> Is there a way around it please?
> 
> $isitopen="YES";
> opendir (LOGDIR, "/home/../..$path") || $isitopen="NO"; if ($isitopen eq
> "NO") {
>    print "$path doesn't exit" ;
>    &subroutine1;
>    &subroutine2;
>    ...
> }


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

Date: Sat, 25 Aug 2001 16:26:18 GMT
From: "--Rick" <no_trick@my-de(remove the obvious)ja.com>
Subject: Re: pl or not pl, that is the question
Message-Id: <KkQh7.25809$Ki1.2110558@bgtnsc06-news.ops.worldnet.att.net>


"Randal L. Schwartz" <merlyn@stonehenge.com> wrote in message
news:m13d6hx8rk.fsf@halfdome.holdit.com...
<...discussion of script extensions...>
| I'm of the firm belief that a *command* (aka "program") should *not*
| have the implementation language embedded in the path.  And I'm not
| the only one out there.  Why should I care when I invoke your program
| that it was shell or Perl or C originally?  I just care about the
| interface!
|
<... lots of useful comments...>

Hmm...  I'm grinding my way through a book that suggests the extension
(.plx).  ;)

--
--Rick






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

Date: Sat, 25 Aug 2001 19:43:38 +0200
From: Bernhard Schelling <barna@megapage.ch>
Subject: Question about GD
Message-Id: <3B87E3CA.F6E57C62@megapage.ch>

Hi all,

I have a really big image, and i only need a piece of the big image
everytime a web page is accessed.
Now im not sure what's the fastest way to cut it out.

I have infinite diskspace and a mysql database on a linux system, so I
ask you, what should i do?
- Use one big PNG file, load it, and copy the piece into another image
($image->copy(..)) (really slow, I tried that first)
- Use one big GD file, and do it like the one above
- Use more smaller PNG file, load only the needed one (or multiple files
if its over a border) and copy them together (thats what i'm doing now
:-)
- Use a GD2 File and use ->newFromGd2Part(..) (is that fast??)
- Copy the big PNG file in the database as GD Format and load it with
GD::Image->new($datafromdatabase) and copy the piece
- another way?

Thank you very much in advance for your time and any help!

Bye

Greetings
Bernhard Schelling, Switzerland





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

Date: 25 Aug 2001 08:06:10 -0700
From: nmcdannold@yahoo.com (Nathan McDannold)
Subject: Re: quick(?) programming question for perl newbie
Message-Id: <58f70619.0108250706.7357f450@posting.google.com>

John, David, and everyone else who posted,

The code works, and I want to thank you so much for your help. You
saved me countless hours trying to learn this the hard way, which
would have been fun, but not since I'm crunched for time. I really
appreciate it. I hope some day to really learn perl now!

-Nathan


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

Date: 25 Aug 2001 10:37:43 -0700
From: mariorizzuti@yahoo.com (Mario Rizzuti)
Subject: Re: Read/write specific line of file
Message-Id: <42f3ee2.0108250937.7540ed5a@posting.google.com>

Philip Newton <pne-news-20010825@newton.digitalspace.net> wrote in message news:<6rjeotsfomm78m7rhpmru9rmdgnj4u1417@4ax.com>...
> On Sat, 25 Aug 2001 06:03:56 +0200, "GOGAR" <angenent@kabelfoon.nl>
> wrote:
> 
> > i'm fairly new to perl and ..umm i was just wondering if it was possible to
> > read or write a specific line of a file instead of having to go through the
> > whole file..
-
> Depends. One way is to use DB_File with DB_RECNO which allows tied
> access to the file as if it were an array of lines.
- 
> > my guess is that it's something with  sysread and syswrite  but i'm not sure
> > how to approach this,
-
> This will work if all your lines are exactly the same length. Otherwise
> I don't know of a better stand-alone approach than reading in the file
> (a line at a time or a chunk at a time) until you've got the line you
> want.
> 
> If you can make extra files, you could create an index file which maps
> line numbers to file offsets; then you could seek() to the desired place
> in your file quickly (and since the index file entries would have
> constant length, finding the right one also only requires a seek() and a
> read()).

Mantaining an index file has just a problem: when the length of a
record changes, all the offsets of the records following need to be
updated. This can be an huge task if the records are a lot.

I was wondering how, assuming that the each record has a LINE_NUMBER
field, one could find the 'record_start' and 'record_end' byte
positions of a given line and then reading the record in a
fixed-length-records fashion.

I just can think of some pseudo binary search:
You make an estimates of the middle record (filesize/2) position, and
seek there.You are probably not at the beginning of a record so you
read until you find a "\n". At this point you start reading until the
next "\n" and have a record in memory. Compare the LINE_NUMBER field
with the one you are looking for, and go to 3/4*filesize or
1/4*filesize and so on.

What I miss is the "read until a \n". As an alternative one could read
small blocks (50-100 bytes) and index() the new_line_char.

--
Mario Rizzuti


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

Date: Sat, 25 Aug 2001 16:43:25 GMT
From: "Mark Riehl" <mark.riehl@agilecommunications.com>
Subject: Re: round off operator on Perl?
Message-Id: <NAQh7.8$Ia1.11365@typhoon1.gnilink.net>

What about ceil and floor?  Look at perldoc posix.

Mark
"Valentin 30IR976" <radiotito@yahoo.com> wrote in message
news:3B875D00.37D0B96D@yahoo.com...
> OK, many thanks to all. I will try
>
> $x=87.9;
> my $x=int($x);
>
> It works fine...
>
> Thank you...
>
> Ilya Martynov wrote:
>
> > >>>>> On Fri, 24 Aug 2001 19:57:36 +0200, Valentin 30IR976
<radiotito@yahoo.com> said:
> >
> > V3> Hello. I have results on my Perl program like 2.5, 87.9, and I want
to
> > V3> have only the "integer" part of this number. I know I can do
something
> > V3> like:
> >
> > V3> printf("%d",87.9);
> >
> > V3> and it prints 87 (what I want), but my question is if Perl has any
> > V3> operator/function that make this thing automatic. I know in C
exists,
> > V3> but...in Perl?
> >
> > int(). See 'perldoc -tf int'
> >
> > --
>
  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> > | Ilya Martynov (http://martynov.org/)
|
> > | GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B
DEE6 |
> > | AGAVA Software Company (http://www.agava.com/)
|
>
  -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
>
> --
> 73 de Valentin 30IR976 (161 DXCC) ICQ # 86220598 Firetalk # 1626864
>
> web 30IR976:  http://www.geocities.com/titoradio
> IR Members: Promote your IR-related-Website at:
> http://www.topsitelists.com/bestsites/topir976list/topsites.html
> web personal: http://get.to/zamora
> SEMANA SANTA ZAMORA http://www.geocities.com/semanasantazamora
>
>




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

Date: 25 Aug 2001 08:15:16 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: Self-Searchable Perl documention - Extremely Useful!
Message-Id: <74f348f7.0108250715.3482beb6@posting.google.com>

coldwave@bigfoot.com (John Holdsworth) wrote in message news:<2a46b11e.0108170113.4b644705@posting.google.com>...
> demerphq@hotmail.com (Yves Orton) wrote in message news:<74f348f7.0108120702.662a6771@posting.google.com>...
SNIP

> Thanks!
> 
> I'd like to but how does one go about doing this??
> I emailed modules@perl.org in July but have been
> answered by what can only be described as a long 
> "pause".

Weird.  It was pretty fast for me.  I assume you have filled out a
registration form? Start from http://pause.perl.org/pause/query if
not....

Yves


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

Date: 25 Aug 2001 08:43:46 -0700
From: demerphq@hotmail.com (Yves Orton)
Subject: Re: Self-Searchable Perl documention - Extremely Useful!
Message-Id: <74f348f7.0108250743.2631f2e1@posting.google.com>

dkcombs@panix.com (David Combs) wrote in message news:<9ll790$fvi$2@news.panix.com>...
> In article <74f348f7.0108120702.662a6771@posting.google.com>,
> Yves Orton <demerphq@hotmail.com> wrote:
> >...
> >Incidentally, I stayed up all night enhancing your activestate search
> >engine (found a couple of minor gliitches, but who cares).  Check your
> >mails for a copy of my mods.
> >
> 
> How about posting it here so everyone can
> see it too.
> 
> Good or bad idea?

Umm. Sure. Ehr. I didnt do _that_ much.  Anyway, im not sure the
usenet is the place to post a 600line script. I have sent it on just
now to both of you.  Perhaps if John likes the changes he will post it
at his site.

The key :) bug is that if you do a search for 'keys' then you wont
find the entry in perlfunc. I fixed that up, added some weighting
functions to get hits from certain docs to come up top, things like
that.

Anyway, sorry it took so long to reply.
Yves


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

Date: 25 Aug 2001 17:43:36 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Statement modifiers??
Message-Id: <9m8o48$rns$1@mamenchi.zrz.TU-Berlin.DE>

According to David Combs <dkcombs@panix.com>:
 
[...]

> (But of course perl 5 or 6 will NEVER EVER have macros;
> on those tablets Larry brought down from that mountain,
> item one is: THOU SHALT HAVE NO MACROS,
> and, well, that's just the way it is.   :-(

You forgot to quote the footnote (in fine chiseling on the back of the
tablet).  It reads: If thou needest macros thou shalt implement thine
own fscking macros.

Comment on this bit of scripture:

As the Filter:: modules show it is quite possible to have a module
process the (rest of) the source code before the Perl interpreter
sees it.  This is all a macro processor has to do.

The crux, of course, lies elsewhere.  If you want macro parameters
to be bits of Perl code (as in the assertion example I snipped), you
will have to parse that much Perl (if only to know where it ends).
That is probably why we don't see many such macro modules around.

Anno


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

Date: Sat, 25 Aug 2001 18:02:50 +0200
From: "fruiture" <info@fruiture.de>
Subject: Re: String replacements using s///
Message-Id: <9m8ikv$f2u$05$1@news.t-online.com>


"Jeff Snoxell" <Jeff@aetherweb.co.uk> wrote:
> Hi,
>
> Can anyone explain why this:
>
> $start = "This is a string, which I want, hopefully, to turn into a
keyword
> list. Hopefully."
>
> $commaspace = ', ';
> $dotspace       = '. ';
> $dot               = '.';
> $space            = ' ';
>
> $start =~ s/$commaspace/$space/g;
> $start =~ s/$dotspace/$space/g;
> $start =~ s/$dot/$space/g;
> $start =~ s/$space/$commaspace/g;
>

the problem is
a) you don't use quotemeta
b) you do theses substitutions after each other

my idea is this sub (i am a lazy programmer and want to re-use everything)

sub subtitute (@) {
    my $string = shift;
    my %subhash = @_;

    my $reg = '(';
    $reg .= quotemeta($_).'|' foreach keys %subhash;
    chop $reg;
    $reg .= ')';

    $string =~ s/$reg/$subhash{$1} || $1/eg;
    return $string;
}

my $start = "This is a string, which I want, hopefully, to turn into a
keyword
list. Hopefully."

$start = substitute($start,  ', ' => ' ' ,
                             '. ' => ' ' ,
                             '.'  => ' ' ,
                             ' '  => ', ' );

i mean, i hope i understood you right ...


--
do something for your health
______fruiture.de___yeah!_












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

Date: Sat, 25 Aug 2001 09:50:50 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: String replacements using s///
Message-Id: <3B87D76A.D88C797B@stomp.stomp.tokyo>

Jeff Snoxell wrote:

(snipped)

> $start = "This is a string, which I want, hopefully, to turn into a keyword
> list. Hopefully."
 
> $commaspace = ', ';
> $dotspace       = '. ';
> $dot               = '.';
> $space            = ' ';
 
> $start =~ s/$commaspace/$space/g;
> $start =~ s/$dotspace/$space/g;
> $start =~ s/$dot/$space/g;
> $start =~ s/$space/$commaspace/g;
 
> instead of what I want which is:
 
> $start = "This, is, a, string, which, I, want, hopefully, to, turn, into, a,
> keyword, list, Hopefully, ";
 

Use transliteration whenever possible in place of a regex substition.
Invoking a regex engine is memory wasteful and slows a script. A regex
should be a second choice to using transliteration. Use of an array or
use of a hash, for these circumstances, is not a viable option, not
an efficient option, per your stated parameters.


$start ="$start ";

Remove this line if you do not want a trailing comma.


Godzilla!
--

#!perl

print "Content-Type: text/plain\n\n";

$start = "This is a string, which I want, hopefully,
to turn into a keyword list. Hopefully.";

$start =~ tr/\n/ /;
$start =~ tr/.//d;
$start =~ tr/,//d;
$start ="$start ";
$start =~ s/ /, /g;

print $start;

exit;


PRINTED RESULTS:
________________

This, is, a, string, which, I, want, hopefully, to, turn, into, a, keyword, list, Hopefully,


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

Date: 25 Aug 2001 17:03:00 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: String Substitution across two files
Message-Id: <9m8lo4$oop$1@mamenchi.zrz.TU-Berlin.DE>

According to Pularis <pularis@go.com>:
> I have two very long multi column text files. Is it possible to
> somehow look at one of the columns in one file and then substitue an
> entry from that file to the other file if  a match is found. Both
> files have a common column, I want to replace other entries in one of
> the columns if a match is found. I would greatly appreciate any help.

That seems to be a kind of database join operation.  I'd look in
that direction.

Anno


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

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


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