[7154] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 779 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 25 12:17:50 1997

Date: Fri, 25 Jul 97 09:00:21 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 25 Jul 1997     Volume: 8 Number: 779

Today's topics:
     ? win32::ODBC SQL (Brad Johnson)
     [Q] IO::Socket.pm (Ken Williams)
     Re: Adding months to a date (was Re: Date::Manip odditi (Rahul Dhesi)
     Re: Another Newbie question about s/// <vlad@ace.ulyssis.student.kuleuven.ac.be>
     Re: Array n dimensions <rootbeer@teleport.com>
     Re: Array n dimensions <Uwe.Lammers@astro.estec.esa.nl>
     Re: Delete a file <rootbeer@teleport.com>
     Re: Delete a file <bryan@eai.com>
     Re: Help: cgi script <bryan@eai.com>
     HELP: how to use an array passed to a function? <tbrannon@nunki.usc.edu>
     Re: I'm confused <clark@s3i.com>
     Re: I'm confused <rootbeer@teleport.com>
     Re: Newbie Post! Heads up! (file question) <rootbeer@teleport.com>
     Re: Newbie Post! Heads up! (file question) <rootbeer@teleport.com>
     Re: open error on network drives <rootbeer@teleport.com>
     Re: Perl and Reading Email <rootbeer@teleport.com>
     Re: Q: associative arrays <rootbeer@teleport.com>
     SEMI-URGENT: How to connect to MS-SQL from Perl on Linu (Brian Wheeler)
     Re: System call doesn't work right! <rootbeer@teleport.com>
     Re: thorny little regexp problem <bryan@eai.com>
     Re: thorny little regexp problem <sfairey@adc.metrica.co.uk>
     Re: Too many people in this group are arrogant #*(@# (R (I R A Aggie)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 25 Jul 97 15:43:58 GMT
From: bgjohnso@unix.amherst.edu (Brad Johnson)
Subject: ? win32::ODBC SQL
Message-Id: <33d8c9be.0@amhnt2.amherst.edu>


1: What's the SQL command to delet an entire table (from an 
Acess database), i.e. the opposite of CREATE TABLE?


2: I've got a program in which I have:

# pseudocode:

&someSQLCall();
while($DB->FetchRow()) {
  %art= $DB->DataHash();
  # Do stuff;
  &SQLAddRecord();
}

The obvious problem is that the SQL call inside the loop
screws up the FetchRow that should be from the first call. 
What's the best workaround/solution?
Should I open two connections?

--bradj.
------------------------Nullus Oppidenda Est--------------------------
brad johnson (bgjohnso@unix.amherst.edu)    'Disc, God, Country, Pork'
http://www.amherst.edu/~bgjohnso/             'Chickens! No Cynics!'
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 


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

Date: Fri, 25 Jul 1997 10:52:20 -0400
From: ken@forum.swarthmore.edu (Ken Williams)
Subject: [Q] IO::Socket.pm
Message-Id: <ken-2507971052200001@news.swarthmore.edu>

Hi-

I'm looking for an example of a script that uses IO::Socket.pm and reads
and writes over a socket.  The documentation for IO::Socket doesn't
contain any examples, and I haven't had any luck searching DejaNews.  The
camel book doesn't talk about IO::Socket.

I ask this question because I am trying to write a script that I think
should work, but doesn't.  I have read the section in the camel book on
IPC, and have attempted to implement what I'm trying to do by modifying
the example code given.  However, I don't really understand the
nitty-gritty of how sockets work, and I had hoped that using IO::Socket.pm
would shield me from some of this.

Can anybody point me to a very simple script which reads and writes to a
socket using IO::Socket.pm?  I'm most interested in Unix-domain sockets,
not Internet-domain sockets, but I'll take what I can get.

Thanks for any help you can give.

-Ken Williams
 The Math Forum
 ken@forum.swarthmore.edu


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

Date: 24 Jul 1997 23:25:29 GMT
From: c.c.eiftj@72.usenet.us.com (Rahul Dhesi)
Subject: Re: Adding months to a date (was Re: Date::Manip oddities? (+ 12 months))
Message-Id: <5r8o99$2pb@samba.rahul.net>

In <33D26326.3ED8B1CD@pvo.com> Thomas Winzig <tsw@pvo.com> writes:

>In other words, if you call it with:
>&add_months('5/31/1997', 9);    # add 9 months to 5/31/97

>You will get back:
>2/28/1998

Notice how we began on the 31st of a month and ended up on the 28th.

If you start on the 31st, you might eventually end up on the 28th, 29th,
or 30th, depending on which months you traverse.  What's not nice about
this is that the date on which you end up depends on how many months
at a time you extend.

1. customer pays 6 months at a time.

   5/31 -> 11/30 -> 5/30 -> 11/30

2. customer pays 9 months at a time

   5/31 -> 2/28 -> 11/28

Both customer ended up paying the same amount.  But the one who
paid for longer periods (who ought to be getting the better deal)
got fewer days of service.

Ideally both should end up on the same date.  So your software needs
some memory of where you started, and adjusts up to make up for
adjusting down during shorter months.  This is hard to do right.

It's easier to just adjust down to the 1st of the first month.  From
then on the arithmetic becomes much simpler.
-- 
Rahul Dhesi <dhesi@spams.r.us.com>


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

Date: Fri, 25 Jul 1997 18:54:46 +0100
From: Vladyslav Khlystoun <vlad@ace.ulyssis.student.kuleuven.ac.be>
Subject: Re: Another Newbie question about s///
Message-Id: <33D8E866.7FE6@ace.ulyssis.student.kuleuven.ac.be>

Hi. I've got similar problem and at the end of the experiments concluded
that
the cause of why I unable to do it, is because the substituing with $1,
$2.. 
dosn't works for the $var string situations (the macrosubtitutions wan't 
expended correctly even when s///e.

The solution was to write follow function:

and to call it with strings like i.e.:

   ArrFndRpl( \@paPrgm, 1, $sFnd,
              $gcLT_STR.'a href=' . $psHtmF .$gcGT_STR,
              $gcLT_STR.'/a'.$gcGT_STR
            );

or for 0 args: 
  ArrFndRpl( \@aPrgm, 0, '\>', '&gt;' );
etc for more args.


#----------------------------------------------------------------------
#
#
# Synopsis: ArrFndRpl( \@aStr, $iOpQ, $sFnd, $sRpl )
#----------------------------------------------------------------------
sub ArrFndRpl {
    local( *paArr ) = shift;
    my( $iOpQ ) = shift;
    my( $psFnd, $psRpl ) = @_;

for( $iCrntL = 0; $iCrntL<=$#paArr; $iCrntL++ ){
    if( $iOpQ == 0 ) {
        $paArr[ $iCrntL ] =~ s/$psFnd/$psRpl/g ;

    }elsif( $iOpQ == 1 ) {
        $paArr[ $iCrntL ] =~ s/$psFnd/$_[1]$1$_[2]/g ;
    }elsif( $iOpQ == 2 ) {
        $paArr[ $iCrntL ] =~ s/$psFnd/$_[1]$1$_[2]$2$_[3]/g ;
    }
  };
}


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

Date: Fri, 25 Jul 1997 07:45:38 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Jerome Quelin <quelin@eret.cegelec-red.fr>
Subject: Re: Array n dimensions
Message-Id: <Pine.GSO.3.96.970725074429.9406O-100000@kelly.teleport.com>

On Fri, 25 Jul 1997, Jerome Quelin wrote:

> How can I use (or simulate ?) array of n dimensions ?  How can
> manipulate them ? 

You'll find some good information in the man pages, including perldsc,
perllol, and perlref. If you have perl questions after you've read the
docs and man pages, please post those questions here. Thanks! 

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 25 Jul 1997 17:10:40 +0200
From: Uwe Lammers <Uwe.Lammers@astro.estec.esa.nl>
To: quelin@eret.cegelec-red.fr
Subject: Re: Array n dimensions
Message-Id: <33D8C1F0.456D@astro.estec.esa.nl>

Jerome Quelin wrote:
> 
> Hi,
> 
> How can I use (or simulate ?) array of n dimensions ?
> How can manipulate them ?
>
If you have the Camel book, take a look at the description of the
special variable $;
This is used to mimic multi-dim arrays in Perl which are not
natively supported.

Cheers
Uwe. (ulammers@astro.estec.esa.nl)


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

Date: Fri, 25 Jul 1997 07:33:32 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Peter Kolonelos <pkolonel@mnsi.net>
Subject: Re: Delete a file
Message-Id: <Pine.GSO.3.96.970725073141.9406M-100000@kelly.teleport.com>

On Fri, 25 Jul 1997, Peter Kolonelos wrote:

> I want to check top.htm if it is empty. 

There's a way to do this documented in perlfunc(1).

> If it is NOT empty, I want to delete the file

Why not just delete it anyway? :-)  There's a way to do this that is
documented in perlfunc(1).

> and then create a new file with the same name with new contents
> generated by my script. Is this possible?

Yes, and (you guessed it!) there's a way to do this that you'll find
documented in perlfunc(1).

Once you've read the docs and FAQs, if you have more Perl questions,
please post them here. Thanks! 

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 25 Jul 1997 09:56:03 -0500
From: Bryan Hart <bryan@eai.com>
To: Peter Kolonelos <pkolonel@mnsi.net>
Subject: Re: Delete a file
Message-Id: <33D8BE83.FF6@eai.com>

Peter Kolonelos wrote:
> 
> I have written a perl/cgi script but I need help with the following:
> 
> The script constructs an html file with frames. In one of the frames, I need
> to modify the html file independently. For example, frame1 contains top.htm,
> frame2 contains left.htm, etc.
> 
> I want to check top.htm if it is empty. If it is NOT empty, I want to delete
> the file and then create a new file with the same name with new contents
> generated by my script. Is this possible?
> 
> Any help would be greatly appreciated.

It's possible, but I wonder why you are creating HTML files instead of
just send the output of the CGI in HTML format.

The original CGI outputs HTML creating the frameset, but with top.htm
replaced with another CGI (or the same CGI with different inputs) that
outputs the correct HTML for that frame.

Bryan

-- 
-------------------------------
|  Bryan Hart                 
|  Network Products Engineer  
|  Engineering Animation Inc. 
|  Phone: (515) 296-5979
|  Fax: (515) 296-7025
|  Email: bryan@eai.com              
|  Web: http://www.eai.com/                          
-------------------------------
"A conclusion is simply the place where you got tired of thinking"


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

Date: Fri, 25 Jul 1997 09:26:35 -0500
From: Bryan Hart <bryan@eai.com>
To: "=?iso-8859-1?Q?=2E=B7=B0?= Andreas =?iso-8859-1?Q?=B0=B7=2E?="  <cascioli@geocities.com>
Subject: Re: Help: cgi script
Message-Id: <33D8B79B.1CFB@eai.com>

=2E=B7=B0 Andreas =B0=B7. wrote:
> =

> I need some help with a CGI script in Perl, when executed I'd like the
> script to pop up a an alert window with some text in it, like
> Javascript's "alert()", is that possible? If it is-
> what command should I use?

CGI cannot do this alone - you need something client-side like
Javascript, VBscript, or Java to do the pop-up.  You _can_ however use a
CGI to output Javascript to do the task (if there is some other reason a
CGI is needed).

Bryan

-- =

-------------------------------
|  Bryan Hart                 =

|  Network Products Engineer  =

|  Engineering Animation Inc. =

|  Phone: (515) 296-5979
|  Fax: (515) 296-7025
|  Email: bryan@eai.com              =

|  Web: http://www.eai.com/                          =

-------------------------------
"A conclusion is simply the place where you got tired of thinking"


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

Date: 25 Jul 1997 08:17:56 -0700
From: tbrannon <tbrannon@nunki.usc.edu>
Subject: HELP: how to use an array passed to a function?
Message-Id: <ysizzprbkvof.fsf@nunki.usc.edu>

I would like $gmax to iterate over each value in the array passed in
as the first argument to this function. The function is called as follows:

@ary=(1,2,3)
multi_gmax(@ary,0,999)

sub multi_gmax (\@$$) {
    my $gmax;
    print "\$_[0]: ", $_[0], $/;
    print "\$_[1]: ", $_[1], $/;
    foreach $gmax ($_[0]) {
	print "Working with: ", $gmax, $/;
#	single_line($gmax, $_[1], $_[2]);
    }
}

-- 
o============o  Sending unsolicited commercial e-mail (UCE)  to this address
 Legal Notice   is indication of your consent to pay me $120/hour for 1 hour
o============o  minimum for professional proofreading & technical assessment.
  Terrence Brannon * brannon@quake.usc.edu * http://quake.usc.edu/~brannon


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

Date: 25 Jul 1997 09:44:43 -0400
From: Clark Dorman <clark@s3i.com>
Subject: Re: I'm confused
Message-Id: <dwwmfs0tw.fsf@s3i.com>


Saeba Ryo <zlash@kalron.sby.omah> writes:
> I'm new to perl and I am writing a simple script now.
> It is something like this
> 
> open (IF, "somefile");

Warning warning warning.  Test open statements:

open( IF, "somefile") or die "cannot open the file ($!)";

>  array = &functionA(IF);
> 
> now functionA is something like
> local *IFF = shift;

local or my?  

> my $i=1, @temp;
> while (<IFF>){
>    print "Line num= $i++";
>    push temp, $_;
> }
> return temp;
> 
> OK the program runs exactly like I wanted, it prints the line number
> simultaneously while the functionA reads the file (line by line)
> 
> Then I added more lines of code to the functionA and now when I run the
> program it just wait until it reads the whole file (until EOF) then it
> prints the line numbers as if it's not inside the while loop.
> 
> I need to print the line simultaneously while reading the file since it 
> will tell me the progression of the reading (ie, Reading line 80)
>
> Any advice would be appreciated.

Because printing to the screen is such an intensive task (well, not really,
but compared to other things it is), it gets "buffered" and when the buffer
gets filled, it dumps it in one fell swoop.  
Do this:  
	$|++;
But, first, look it up to understand it. 
 
> ps: Second question, can we find the total number of lines in a file
> from the file handle? (of course without reading the whole file first)
> I want to produce something like Reading line 80/1000

There is not a perl way to do this (that I know of).  Try:

	$numlines = `wc -l filename`;

-- 
Clark Dorman				"Evolution is cleverer than you are."
http://cns-web.bu.edu/pub/dorman/D.html                -Francis Crick


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

Date: Fri, 25 Jul 1997 07:28:51 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Saeba Ryo <zlash@kalron.sby.omah>
Subject: Re: I'm confused
Message-Id: <Pine.GSO.3.96.970725071935.9406L-100000@kelly.teleport.com>

On Fri, 25 Jul 1997, Saeba Ryo wrote:

> Subject: I'm confused

Please check out this helpful information on choosing good subject
lines. It will be a big help to you in making it more likely that your
requests will be answered.

    http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post

> open (IF, "somefile");

You should always check the return value from open, even (or especially!)
in example scripts.

> array = &functionA(IF);

It is better to write Perl, instead of making up a language as you go
along. Maybe you mean this?

    @array = &functionA(IF);

You should probably see about passing a filehandle via a reference.

> now functionA is something like
> local *IFF = shift;
> my $i=1, @temp;

That is bad because it doesn't do what it looks like. @temp is not a my
variable. 

> while (<IFF>){
>    print "Line num= $i++";

Once again, that's not doing what it looks like. Inside quotes, "++" is
just a couple of punctuation marks.

>    push temp, $_;
> }
> return temp;
> 
> OK the program runs exactly like I wanted, it prints the line number
> simultaneously while the functionA reads the file (line by line)
> 
> Then I added more lines of code to the functionA and now when I run the
> program it just wait until it reads the whole file (until EOF) then it
> prints the line numbers as if it's not inside the while loop. 

Sounds like a buffering problem. Check out $| in perlvar(1).

> ps: Second question, can we find the total number of lines in a file
> from the file handle? (of course without reading the whole file first)

No. There's no ESP module which can tell what's in the file without
reading it. :-)

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 25 Jul 1997 07:00:18 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Burt Lewis <burt@ici.net>
Subject: Re: Newbie Post! Heads up! (file question)
Message-Id: <Pine.GSO.3.96.970725065658.9406G-100000@kelly.teleport.com>

On 25 Jul 1997, Burt Lewis wrote:

> This is how I handle opening my files.  You do need the specific path:
> 
> $data = "/files/WWW/vhtdocs/boondoggle/area3/data.txt";
> open(FILE,"$data");

That turns out not to be the case. You don't necessarily need the full
pathname, although that's not a bad thing to include. (And the extra set
of double quotes doesn't help.) But, more importantly, you should always
check the return value from open, _especially_ when you're helping
somebody to learn how to program. 

   open FILE, $data
	or die "Can't open '$data' for read: $!";

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 25 Jul 1997 06:56:20 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: jamie <jamie@comet.net>
Subject: Re: Newbie Post! Heads up! (file question)
Message-Id: <Pine.GSO.3.96.970725065126.9406F-100000@kelly.teleport.com>

On Fri, 25 Jul 1997, jamie wrote:

> Subject: Newbie Post! Heads up! (file question)

Please check out this helpful information on choosing good subject
lines. It will be a big help to you in making it more likely that your
requests will be answered.

    http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post

>  Ok, pardon the shroud of ignorance here and/or if this is a Frequently
> Questioned Answer..... 

I'm puzzled. If you thought it might be in the FAQ, why didn't you check
before you posted?

> when I (or you or we) say:
> 
> open(SOMEFILE,">disfile") || die "no can do"
> open(TINCAN,"tincan") || die "tincan won't open"
> 
>  are the files (disfile and tincan) always assumed by perl to be in the
> directory that the script is in?

No. They are normally assumed (by the _OS_) to be in the current working
directory. For more details, check out your system's docs about the cd
command and related operations. Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 25 Jul 1997 07:10:54 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: santon@gwsmtp.nu.com
Subject: Re: open error on network drives
Message-Id: <Pine.GSO.3.96.970725070654.9406I-100000@kelly.teleport.com>

On Fri, 25 Jul 1997 santon@gwsmtp.nu.com wrote:

> What gives?  

> open (LOG,"> log") or die "Unable to open file...\n";

It's hard for me to guess why that's dying, but it's easy to get perl to
tell you. 

	open LOG, "> log"
	    or die "Can't open 'log' for output: $!";

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 25 Jul 1997 07:18:24 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "Custom Computer Services Inc." <lbj_ccsi@atl.mindspring.com>
Subject: Re: Perl and Reading Email
Message-Id: <Pine.GSO.3.96.970725071801.9406K-100000@kelly.teleport.com>

On Fri, 25 Jul 1997, Custom Computer Services Inc. wrote:

> Does anyone no of any Perl scripts that allow the user to read their
> email?  It is easy to handle the text docs, but decoding the MIME
> formats is not as simple. 

There are modules on CPAN which may help you. Good luck!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 25 Jul 1997 07:49:25 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Uwe Lammers <Uwe.Lammers@astro.estec.esa.nl>
Subject: Re: Q: associative arrays
Message-Id: <Pine.GSO.3.96.970725074817.9406P-100000@kelly.teleport.com>

On Fri, 25 Jul 1997, Uwe Lammers wrote:

> another newbie question: Is there a way to force Perl to iterate over
> the elements in an associative array in the order as it was given in
> the array definition?

    http://www.perl.com/CPAN/doc/FAQs/FAQ/html/perlfaq4/
          How_can_I_always_kep_my_hash_so.html

Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: 25 Jul 1997 15:03:44 GMT
From: bdwheele@indiana.edu (Brian Wheeler)
Subject: SEMI-URGENT: How to connect to MS-SQL from Perl on Linux?
Message-Id: <5raf8g$h48$1@dismay.ucs.indiana.edu>

Hi!
I need to connect to a MSSQL server from my linux box.  I've tried to use
DBI and DBD::ODBC and the iodbc driver, but it doesn't do anything.  I also
don't have any idea how to set up a .odbc.ini.

Any help would be appriciated!

-- 
Brian Wheeler
bdwheele@indiana.edu


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

Date: Fri, 25 Jul 1997 07:43:46 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Jack Tran <Jacktran@webtv.net>
Subject: Re: System call doesn't work right!
Message-Id: <Pine.GSO.3.96.970725073438.9406N-100000@kelly.teleport.com>

On Thu, 24 Jul 1997, Jack Tran wrote:

> I am using the following system call with Perl 5.004:
> 
> system("/usr/bin/cp", "/tmp/bootptab", "/etc/bootptab") == 0 or print
> "failed to copy\n"; 
> 
> The file in /etc is always several lines shorter than the original, and
> the last line doens't have a carriage retuen?  /tmp and /etc are
> different filesystems on a Sparc 5, running Solaris 2.5.1. 

It's hard to see how Perl could be affecting the success of this command.
Does the command do the same thing from the shell? I'd have to say that
you don't have a Perl question, if the same thing happens when Perl isn't
involved. You might get a better or more-complete answer in a non-Perl
newsgroup.

But it may be that you've found a bug in your cp, or your OS. Have you
asked your vendor about it? Or, it may be that another process is
tampering with one or both of those files while you're trying to do the
copy. 

Hope this helps! 

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Fri, 25 Jul 1997 09:50:18 -0500
From: Bryan Hart <bryan@eai.com>
To: Nick Tonkin <tonkin@silcom.com>
Subject: Re: thorny little regexp problem
Message-Id: <33D8BD2A.3F54@eai.com>

Nick Tonkin wrote:
> 
> Hello,
> 
> Anyone figure this out?
> 
> It is supposed to go through a long string of text (arg1, arg2) and
> look for a match with a small string ($str) . Then it is supposed to
> substitute $str with <B>$str</B> (html bold) but ONLY if $str is a
> whole word within arg1 or arg 2. (A previous check has made sure that
> the first char of $str is the first char of a word).
> 
> It works beautifully for $str_bits eq "1", when there is only one
> $str, but it makes every instance of $str_bit bold (even when not a
> whole word) in the while loop underneath.
> 
> What am I too dense to spot??
> 
> Thanks,
> 
> Nick
> 
> _________________________
> 
> &make_bold(arg1,arg2);
> 
> sub make_bold {
>   if ($str_bits eq "1") {
>     $_[0] =~ s/$str(\W)/<B>$str<\/B>\1/g;
>     $_[1] =~ s/$str(\W)/<B>$str<\/B>\1/g;
>   } else {
>     foreach $str_bit(@strs) {
>       $_[0] =~ s/$str_bit(\W)/<B>$str_bit<\/B>\1/g;
>       $_[1] =~ s/$str_bit(\W)/<B>$str_bit<\/B>\1/g;
>     }
>   }
> }
> 

I'm not sure about the reason for the different behavior between the two
parts, but have you tried using \b (word boundary) around your strings? 
This would make your regex lines look like:

$_[0] =~ s/\b$str\b/<B>$str<\/B>/g;

I removed the (\W) and \1 from the string, because I can't see their
purpose, unless this was being used to signify a word break.

Bryan
-- 
-------------------------------
|  Bryan Hart                 
|  Network Products Engineer  
|  Engineering Animation Inc. 
|  Phone: (515) 296-5979
|  Fax: (515) 296-7025
|  Email: bryan@eai.com              
|  Web: http://www.eai.com/                          
-------------------------------
"A conclusion is simply the place where you got tired of thinking"


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

Date: Fri, 25 Jul 1997 16:54:01 +0100
From: Simon Fairey <sfairey@adc.metrica.co.uk>
To: Nick Tonkin <tonkin@silcom.com>
Subject: Re: thorny little regexp problem
Message-Id: <33D8CC19.AFD10BFF@adc.metrica.co.uk>

Nick Tonkin wrote:

> Hello,
>
> Anyone figure this out?
>
> It is supposed to go through a long string of text (arg1, arg2) and
> look for a match with a small string ($str) . Then it is supposed to
> substitute $str with <B>$str</B> (html bold) but ONLY if $str is a
> whole word within arg1 or arg 2. (A previous check has made sure that
> the first char of $str is the first char of a word).
>
> It works beautifully for $str_bits eq "1", when there is only one
> $str, but it makes every instance of $str_bit bold (even when not a
> whole word) in the while loop underneath.
>
> What am I too dense to spot??
>
> Thanks,
>
> Nick
>
> _________________________
>
> &make_bold(arg1,arg2);
>
> sub make_bold {
>   if ($str_bits eq "1") {
>     $_[0] =~ s/$str(\W)/<B>$str<\/B>\1/g;
>     $_[1] =~ s/$str(\W)/<B>$str<\/B>\1/g;
>   } else {
>     foreach $str_bit(@strs) {
>       $_[0] =~ s/$str_bit(\W)/<B>$str_bit<\/B>\1/g;
>       $_[1] =~ s/$str_bit(\W)/<B>$str_bit<\/B>\1/g;
>     }
>   }
> }
>
> __________________________
>
> ============================
> Nick Tonkin
> webmaster@web-ignite.com
> http://www.web-ignite.com

  Firstly you should be using $1 and not \1, turn on warnings and you
will see. Secondly the above function should fail anyway as you can't
modify @_. To check for word boundaries you would be better off using
something like:
  /\b$str\b/

Finally if I copy @_ into some variables in the function and print them
it appears to work fine. With @strs containing 'simon' and 'fred' a
string like 'simon told fred that it was simons not freds' I only get
the 'simon' and 'fred' surrounded by <B> <\B>.

What version of perl are you using?

Simon



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

Date: Fri, 25 Jul 1997 10:40:02 -0500
From: fl_aggie@hotmail.com (I R A Aggie)
Subject: Re: Too many people in this group are arrogant #*(@# (Re: Checking for valid Email...)
Message-Id: <fl_aggie-ya02408000R2507971040020001@news.fsu.edu>

In article <Ook!-ya02408000R2407971404070001@snews.zippo.com>,
annoying@super.zippo.com wrote:

[Editor's note: is this really your address, or are these "anonymous"
 comments? Must be an "anonymous" coward, since you set your followups
 to alt.monkey.cute. Followups reset. So sorry...]

+ Three other points, regarding the 'bot like arrogant autoFAQ reply types. 

Let's see if I got this right...you're complaining that someone actually
*pointed* you at an answer?

+ (You know who you are, most likely you'll even post a follow up to this and
+ auto-identify yourselves, and prove every point made in the original post.)

Nice strawman. Too bad, tho, that it is a strawman...

+ 1) What happens if the person doing the query would like to learn something
+ other than how to use someone else's code? Some of us actually enjoy
+ broadening our skill sets (chefs) instead of just churning out the order on
+ the ticket (short order cooks).

Well, if you want to be a chef, you spend money on cookbooks and tutorials
and classes to *learn*. Both Tom C and Randal teach short classes around
the country -- feel free to avail yourself to their services.

You don't pay me jack for my services, so if the answer happens to be
contained in a document somewhere, *if* I feel inclined to answer, don't
be surprised if I cut the amount of time needed and just point you to that
document...

+ 2) How in the hell are better modules going to get wriiten if the same old
+ stuff keeps getting reused?

Because someone gets annoyed enough at the module they are using to go
ahead an improve it?? In the mean time, why should I waste my time and
re-invent the wheel?

But don't feel constrained to use the CPAN archive. No sir, you should
go out and hand code *every* bit of perl you use. How else are you going
to become the gourmet chef of perl?

+ Insanely Great stuff rarely comes out of the
+ 30th revision by the same author. You either have a good original idea the
+ first time, or you don't.

We're not talking about Insanely Great stuff here, we're talking about
code that _gets_the_job_done_. Let's face it: how much gee-whizzy stuff
can you come up with if you're trying to make an interface to telnet or
ftp?

+ 3) Most of the stuff on CPAN and perldoc is poorly, if not horribly,
+ documented.

You have the statistics to support your assertion? Much of it is well
documented, complete with _working_ examples. Some of it *is* slapped
together, but that's also usually stated.

+ People are really supposed to learn from that? I'd be out of a
+ job if I churned out crap that horribly composed, and seriously consider
+ firing anyone who expected me to accept it as a final draft.

You're encouraged not to use the code that others have worked on _without_
recompense. As the saying goes, you get what you pay for. Sir, how much
*have* you paid for perl, or these modules?

That's what I thought...

+ 4) If the question is really beneath your dignity to reply to, climb off
+ that shining white stallion of yours and ignore it instead of churning out
+ 50 messages a day repeating the CPAN/www.perl.org/stonehenge mantra.

Even if it is a valid *answer* to the question in the post? you really 
should consider climbing off your hobby horse and figure out how to find 
the answers on your own. This isn't the help desk.

Which is part of the reason the FAQ was written...

James - unless this newsgroup got renamed to comp.lang.perl.help.desk when
        I wasn't looking...

-- 
Consulting Minister for Consultants, DNRC
Support the anti-Spam amendment <url:http://www.cauce.org/>
To cure your perl CGI problems, please look at:
<url:http://www.perl.com/perl/faq/idiots-guide.html>


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 779
*************************************

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