[18015] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 175 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jan 30 14:06:55 2001

Date: Tue, 30 Jan 2001 11:05:18 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <980881517-v10-i175@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 30 Jan 2001     Volume: 10 Number: 175

Today's topics:
        $<,  $( <mourad@ontariotek.com>
    Re: $<,  $( nobull@mail.com
    Re: <>, tie *STDIN or *ARGV nobull@mail.com
    Re: [OT] What other languages do you know? <mischief@velma.motion.net>
        ask help to perl a socket <alexchens@hktrade.com>
        assistance reqd with perl cgi ($) <jacob@the-enigma.co.uk>
        Audio Video feed <bGhassemlou@home.com>
    Re: bundle Perl or use C? <mischief@velma.motion.net>
    Re: bundle Perl or use C? bits101010@my-deja.com
        calling variable subroutines <neil@alaweb.com>
    Re: Can't copy a database handle using DBI <tore@extend.no>
        copying an array of hashes <philblandford@lineone.net>
    Re: copying an array of hashes <uri@sysarch.com>
    Re: Creating calendar (reminder) class <marc.beck@bigfoot.com>
    Re: Finding a char in string <amonotod@netscape.net>
    Re: Finding a char in string <godzilla@stomp.stomp.tokyo>
    Re: Finding a char in string <joe+usenet@sunstarsys.com>
    Re: Finding a char in string <amonotod@netscape.net>
    Re: Finding a char in string <godzilla@stomp.stomp.tokyo>
        Fish v Fishing lessons - again! (was: Installing and us nobull@mail.com
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 30 Jan 2001 12:03:22 -0500
From: "Mourad" <mourad@ontariotek.com>
Subject: $<,  $(
Message-Id: <9uCd6.124820$Z2.1574648@nnrp1.uunet.ca>

Hello,

I am attempting to run a CGI script from web (nobody:nobody) which needs to
access user's files.  I need to change the UID of the script at execution
time.  (I don't care whether the script is ran as 'root' or the appropriate
user who's files are being used as long as proper access is granted).
I am not using 'setuid' on the file, I understand this can be accomplished
with proper manipulation of the '$<', '$>' variables for the UID.
Your input is highly appreciated.

Sincerely,

Mourad K.
Chief Information Officer
Ontariotek.com Inc.




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

Date: 30 Jan 2001 18:12:44 +0000
From: nobull@mail.com
Subject: Re: $<,  $(
Message-Id: <u9elxkrjs3.fsf@wcl-l.bham.ac.uk>

"Mourad" <mourad@ontariotek.com> writes:

> I am attempting to run a CGI script from web (nobody:nobody) which needs to
> access user's files.  I need to change the UID of the script at execution
> time.  (I don't care whether the script is ran as 'root' or the appropriate
> user who's files are being used as long as proper access is granted).
> I am not using 'setuid' on the file, I understand this can be accomplished
> with proper manipulation of the '$<', '$>' variables for the UID.
> Your input is highly appreciated.

You must either use setuid-root scripts or configure you web server to
run CGI scripts as root.  Neither of these is a very good idea
security wise.  It would probably be safer to have the CGI script run
or communicate with some sort of setuid helper program.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 30 Jan 2001 17:53:59 +0000
From: nobull@mail.com
Subject: Re: <>, tie *STDIN or *ARGV
Message-Id: <u9k87dq62w.fsf@wcl-l.bham.ac.uk>

"John Lin" <johnlin@chttl.com.tw> writes:

> In the following program, my intension is:
> when @ARGV is provided, print those files in @ARGV as normal
> otherwise...

> BEGIN { tie *ARGV,'A' }

> Hmm... What's the modification I need here?

Is this a trick question?  Your intension is that your code should
alter the semantics of *ARGV only if @ARGV is empty.  In that case
then you should probably alter the semantics of *ARGV only if @ARGV is
empty.  Or am I missing some subtlties?

BEGIN { tie *ARGV,'A' unless @ARGV }

Note: tieing ARGV cannot replace the sematics of the special function
of eof().  (eof()) is, perversely, actually different from (eof) and
there's no way I know that you can alter the semantics of (eof()).

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Tue, 30 Jan 2001 17:58:17 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: [OT] What other languages do you know?
Message-Id: <t7e05pqfeen7f@corp.supernews.com>

Mario <m_ario@my-deja.com> wrote:
> Just curious to know what other languages are popular in the Perl
> community.

I would imagine that the languages from which Perl borrows most
heavily would be the most popular "other languages" for Perl
programmers. These are, as far as I can tell from experience and
the documents explaining Perl's history:

   C (which, loosely defined, includes the C++ and Objective C derivatives)
   sed
   awk
   sh

Python and Ruby seem to be gaining popularity, and of course Java
is pretty popular in the programming (or at least programming
management) community as a whole. SQL is a very popular language,
and is often used in conjunction with other langauges. The Perl
DBI makes Perl and SQL a pretty popular combination.

I use Perl almost exclusively at work, with just a little sh (bash,
actually) and a little C (sometimes using flex and bison to help
C along with text scanning), I occaisionally use the DBI to tie into
an SQL database, but I'm not proficient with that yet for various
reasons.

At home, where I play around a little more and don't need to be
proficient with my tools (toys, really, in this case), I still use
mostly Perl. I do, however, also use amounts of EBNF (for bison),
flex (which is largely regexes), C, x86 assembly, Prolog ( because
I want to learn it), Lisp (also because I want to learn it), Scheme
(ditto), and a few toy languages I've developed for certain tasks.
My play with languages at home will soon include Java, Fortran, and
perhaps a couple of small specialty languages.

I used to use some Pascal (Turbo and ISO), RPG, COBOL, Ada, a few
flavors of Basic, DOS batch language, 6809 assembly, several specialty
languages for talker/MUD creation and administration, and several
application-specific scripting languages (especially the one in Telemate
for DOS, a nice shareware terminal emulator) because those were either
mandated or the only tools available to me. Oh, how I loathe most of those
languages.

Languages I used to actually choose to use or play with but no longer
do include Forth dialects, 8051 assembly, Rexx (mostly because it was
stock on OS/2 and I could get interpreters for other platforms as well
and because I could evaluate dynamically constructed code segments),
Intercal (but I might start playing with that again in my spare time),
C--, and 68000 assembly.

Languages I've tried of my own volition and didn't like are Python,
loor, ABC, JORF, Euphoria, Oberon, and Z, among others.

Langauges I've been tempted to try either for fun or for possible
real use but haven't include Ruby, Caml, Haskell, Snobol, Smalltalk,
APL, and Eiffel.

Of all of these languages, Perl is my favorite with which to do
serious work. My favorites for hobby projects and such include
Perl and the toy languages I create (which are jsut a hobby right
now themselves and are often implemented largely in Perl [1]).

Chris

[1] I'm working on a toy language and a couple of domain-specific
    languages right now which use Perl and C for implementation.
    I use Perl for lexing and minimally parsing into a thoroughly
    annotated token stream which is saved in a temp file. Another
    Perl program then takes the temp file, does some additional
    parsing work and attempts to turn it into ANSI C, with the flow
    control and certain other simpler functions translated directly
    and with certain functions of the original source language being
    implemented as C functions included from headers. My steps are
    a little muddled and the implementation is slightly buggy, but
    I've got a few programs in these languages that run. ;)

-- 
Christopher E. Stith

Get real!  This is a discussion group, not a helpdesk. You post
something, we discuss its implications. If the discussion happens to
answer a question you've asked, that's incidental. -- nobull, clp.misc



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

Date: Wed, 31 Jan 2001 00:49:04 +0800
From: "alex chen" <alexchens@hktrade.com>
Subject: ask help to perl a socket
Message-Id: <956r7c$ooq10@rain.i-cable.com>

i am writing a perl script for setting up  a listen socket port for real
time chat.
the problem that i am facing is that, how can i send all the connecting port
the chat message is going on?

i mean which method for example. to get all the connection sockets.
 i use socket::INET modules.

thanks
--
alexchen
hongkong




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

Date: Tue, 30 Jan 2001 17:28:19 +0000
From: Jacob Jay - Enigma <jacob@the-enigma.co.uk>
Subject: assistance reqd with perl cgi ($)
Message-Id: <B69CAA33.6A06%jacob@the-enigma.co.uk>

A client has just provided us with their old site to host on our servers,
one PERL script of which is generating errors which are well beyond my [non
existent] knowledge of PERL and mod_perl. We need someone who is prepared to
take a look at the script and get it running on our server (FreeBSD), if
you're up for it let me know your hourly rate and I'll send you the error
log and a copy of the script for you to get an idea of how long it might
take. The script was previously running under NT.

Please reply to me by email and not to the newsgroup(s).

>>/Jacob.

-- 
Jacob Jay <mailto:jacob@the-enigma.co.uk>
IT Director - Cyberspatial Architect
Enigma Publishing Ltd. <http://www.the-enigma.co.uk>
Fax: +442075533251 ICQ: 16503881



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

Date: Tue, 30 Jan 2001 16:08:11 GMT
From: "News at home" <bGhassemlou@home.com>
Subject: Audio Video feed
Message-Id: <LFBd6.20293$KP3.6190112@news3.rdc1.on.home.com>

I am trying to setup a Video feed (from a Camera or a SP3 file) Is there
anywhere I can find instruction how to set it up using perl?
I am usning Win. NT4 & IIS for this purpose.
Thanks
Behzad
You may reply to bGhassemlou@home.com





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

Date: Tue, 30 Jan 2001 16:09:22 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: bundle Perl or use C?
Message-Id: <t7dppisbdb8g81@corp.supernews.com>

Thomas Brusca <tebrusca@oakland.edu> wrote:
> I must support an HTTP POST program on all flavors 
> of UNIX.  I can not rely on Perl being installed on the
> systems.  Currently my "superiors" are insisting that we
> use a C binary, but I'm in favor of making Perl part of
> the installation of our POST program.  Please tell me 
> your opinion or experiences with similar problems.

Not all flavors of Unix are even capable of running on the
same hardware. You can't run Irix on a PC nor can you run
SCO on an SGI. You can't run Solaris on an Apollo (not that
you want to run anything on an Apollo these days ;-).
Why do you think a binary would run on a PC, a Sun UltraSparc,
an SGI machine, an Alpha, an IBM RS6000, and an IBM S/390
without major changes? Even if you used a completely ANSI and
POSIX compliant source, you'd still need to compile that
source for each platform.

> KSH comes to mind but the POST program is a little too complex.

Don't count on KSH being installed on "all flavors of UNIX".
By default, only bash and tcsh are instaleld by Red Hat Linux.
Whether or not Linux qualifies as a flavor of Unix or is only a
clone is beyond the scope of this post, and is left as an
exercise to the reader (I'm sick to death of arguments over this
silly point. If it walks like a Unix and quacks like a Unix...)

> Do you think bundling Perl will be as difficult as maintaining
> the C binary of the POST program?

What flavors of Unix do you use which don't already have a
Perl binary available on the system? Of those, which don't
have a binary available on CPAN? Of those, which fail to
compile Perl from the sources using configure, make, make test,
and make install? Perl is already portable. You should be able to
compile the source once for each target platform (platform here
meaning both same hardware platform and Unix flavor).

> In other words, I would rather maintain the Perl binary and 
> ship it with my program, but I don't think doing this is very
> easy.  Or is it?

That depends. Do you already have a makefile or an install
script for your program? I assume if you're going to use C
that you'll either ship source and a makefile or at least
have an install script capability. If you were planning on
using a makefile and the local C compiler, then using Perl
wouldn't be much more difficult, because its makefile uses
the local C compiler as well. 

> What issues do I face just copying Perl to a system instead
> of installing it?

If two systems are the same version of the same OS on the same
hardware and you've built it on system A, then you should be
able to copy it to system B, as long as you copy all the
needed portions to the right places.


Chris

-- 
Christopher E. Stith

Product shown enlarged to make you think you're getting more.



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

Date: Tue, 30 Jan 2001 16:43:43 GMT
From: bits101010@my-deja.com
Subject: Re: bundle Perl or use C?
Message-Id: <956qvs$9ma$1@nnrp1.deja.com>

perl2exe compiles your perl script into binaries that DO NOT require
the perl interpreter. And quite many Unix platforms are supported. Take
a look:
http://www.indigostar.com/perl2exe.htm

Good luck.

Winston.

In article <94vd1s$l1c$1@news2.acs.oakland.edu>,
  tebrusca@oakland.edu (Thomas Brusca) wrote:
> I must support an HTTP POST program on all flavors
> of UNIX.  I can not rely on Perl being installed on the
> systems.  Currently my "superiors" are insisting that we
> use a C binary, but I'm in favor of making Perl part of
> the installation of our POST program.  Please tell me
> your opinion or experiences with similar problems.
>
> KSH comes to mind but the POST program is a little too complex.
>
> Do you think bundling Perl will be as difficult as maintaining
> the C binary of the POST program?
>
> In other words, I would rather maintain the Perl binary and
> ship it with my program, but I don't think doing this is very
> easy.  Or is it?
>
> What issues do I face just copying Perl to a system instead
> of installing it?
>
> Thanks for any advice.
>


Sent via Deja.com
http://www.deja.com/


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

Date: Tue, 30 Jan 2001 12:22:19 -0600
From: "Neil" <neil@alaweb.com>
Subject: calling variable subroutines
Message-Id: <t7e1i8rb1socb@corp.supernews.com>

Hello,

What I would like to do is create a loop in the manner of


####### code start ######

# while we are not done
while ($return_vars{status} ne "done)
   {

    # do the sub we ask with the params we ask, and return the results
    # assume that we have variable number and types for the return and send
vars
    # and that sub_to do can be one of hundreds we have in a lib

    (%return_vars) = &do_sub (%send_vars,&sub_to_do);
    if ($debug)
       {
       &debug_routine (%send_vars,%return_vars,%messages);
       }
    }

sub do_sub
{
# warning pseudo code ahead
1.) process incoming params so we can pass em to
our sub_to_do
2.) do sub_to_do(%send_vars)
3.) return %return_vars
}
####### code end ######

Any help - or pointers in the right direction appreciated ... I *have*
looked over the perldocs ... but can't seem to pinpoint what I'm after ....
and maybe it is because ... it can't be done....I assume that I would pass
callback type subs ? ..maybe ??

Anyhow, I appreciate any and all help !
Neil





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

Date: Tue, 30 Jan 2001 19:15:33 +0100
From: Tore Aursand <tore@extend.no>
Subject: Re: Can't copy a database handle using DBI
Message-Id: <MPG.14e1232fe4ca65ce989873@news.online.no>

In article <956iik$1ip$1@nnrp1.deja.com>, mwarnes7676@my-deja.com 
says...
> my $dbh1 = DBI::connect("DBI:ODBC:source1"....);
> my $dbh2 = DBI::connect("DBI:ODBC:source2"....);

Haven't I already answered this question? :)  Anyway; I would go for a 
solution where you the different DB handles into a hash;

  $dbh->{'source_1'} = DBI->connect(...);
  $dbh->{'source_2'} = DBI->connect(...);

Comment: 'source_1' and 'source_2' is for examples only.  You _should_ 
use a variable instead.

If you several DB sources, you could use the 'map' function to simplify 
the task above.  Check 'perldoc -f map' for more information.

A good thing is to check for errors when trying to connect;

  DBI->connect(...) or die $DBI::errstr;

Good luck!


-- 
Tore Aursand - tore@extend.no - http://www.extend.no/~tore/


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

Date: Tue, 30 Jan 2001 18:37:38 GMT
From: Philip Blandford <philblandford@lineone.net>
Subject: copying an array of hashes
Message-Id: <9571lh$gjo$1@nnrp1.deja.com>



I have an array of hashes @x, and want to create a spare copy @y so that
changes I make to the hashes in @x don't affect @y.

Obviously,

@y = @x

is hopeless, as that copies all the references, whereas I just want
copies of the values.

I realise there's probably a messy way to do it by dereferencing each
field in the hash in turn, but this needs to be inside a repeating loop,
so that could get VERY time consuming.

Is there no Perl equivalent of memcpy?


Sent via Deja.com
http://www.deja.com/


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

Date: Tue, 30 Jan 2001 18:56:22 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: copying an array of hashes
Message-Id: <x7vgqwswbu.fsf@home.sysarch.com>

>>>>> "PB" == Philip Blandford <philblandford@lineone.net> writes:

  PB> I have an array of hashes @x, and want to create a spare copy @y
  PB> so that changes I make to the hashes in @x don't affect @y.

  PB> I realise there's probably a messy way to do it by dereferencing each
  PB> field in the hash in turn, but this needs to be inside a repeating loop,
  PB> so that could get VERY time consuming.

  PB> Is there no Perl equivalent of memcpy?

if your structures are deep then something like Data::Dumper or Storable
would be one way to do it. i think there are other modules that do
similar things. but if your list of hashes is only that and none of the hash
elements are refs, then this should do the trick:

	@copy = map { { %{$_} } } @orig ;

you just make new anonymous copies of each hash in the map.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Tue, 30 Jan 2001 20:03:26 +0100
From: Marc Beck <marc.beck@bigfoot.com>
Subject: Re: Creating calendar (reminder) class
Message-Id: <c23e7tgnnj46b37r56djh5vrb2p8sjccdd@4ax.com>

>>my $reminder = Event::timer->new({ at => $time });
>
> Event->timer( cb => \&msg, at => $time );
>
>An event cannot be scheduled without a call-back defined.  The
>constructor is `timer', not `new'.  The constructor expects a list
>(hash) -- not a reference to a hash.  
>
Ok, the hash reference was my second try ... because it didn't work.
But perldoc Event says:
       Event Watcher Constructors

       All watchers are constructed in one of the following ways:

         $w = Event->flavor( [attr1 => $value,]... );

         $w = Event::flavor($Class, [attr1 => $value,]...);

         $w = Event::flavor->new([attr1 => $value,]...);

What about the last one? That's the one I used.

>>$reminder->cb(\&msg);
>
It was worth a try! :)

After changing my script so it uses the first construction option it
works. Thanx.

How can I code this that it will work?
my $reminder = Event->timer( at => $time, cb => \&msg('World') );
sub msg()
{
        print "Hello $_[0]!";
}

cu Marc

cu Marc


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

Date: Tue, 30 Jan 2001 16:43:24 GMT
From: amonotod <amonotod@netscape.net>
Subject: Re: Finding a char in string
Message-Id: <956qv9$9lv$1@nnrp1.deja.com>

In article <3A74B1AE.FDB71B78@stomp.stomp.tokyo>,
  "Godzilla!" <godzilla@stomp.stomp.tokyo> wrote:
> The question is,
>
> "Which is faster and more efficient to eliminate all
> characters after a semicolon within a string?"

Yes, but not with a single input line of 31 chars.  I feel quite sure
that if the OP had a single repeating input of 31 static chars he could
use other methods to fix his data, many of which would be faster than
debating with a freaking idiot wanna-be intellectual like you for three
days in a newsgroup.


> You have unscientifically meandered far from the
> question to be tested. Your methods and results
> are invalid.
Uhmm... Whatever...

>
> This razor held by Sir William of Ockham, not only
> trims away excess fat of explanation,
Please remember to apply Sir Ockam's razor to your future replies.

> it also trims away excess ignorance of Scientific
> Method. Your methods insult the intelligence of
> this well trained and seasoned scientist.
Scientist?  You?

> I am well credentialed.
From Websters II New Riverside University Dictionary:
credential - A factor entitling one to confidence, credit, or authority.
credentials - Evidence attesting one's right to credit, confidence, or
authority.

Well, lets see your credentials.  Stop hiding behind your claims, and
produce some evidence.  Lets see a real college diploma (with GPA
documentation), or company/industry/scientific certificate of
recongition or achievement.  I'm sure you have a scanner, scan one in
and post it on your lame website.

Before you say you've got nothing to prove to me by scanning and
posting: Yes, you do have something to prove; prove you're not the
lying, conniving, trolling ignoramous that we all think you are.

>
> A test, in this case a question, is to be addressed
> directly and strictly, employing factual data and
> making use of the strictest of controls, especially
> for a comparison methodology.
Yeah, with the same exact 31 character input string, whee!


> You know the question. Factual data is simply an
> input string which is precisely duplicated for
> each method of comparison.
Did the OP share a "factual" example of his input with you that none of
us saw?  If not, your input is also conjecture, and your tests are also
invalidated.


> Strict controls are
> simply no external factors. Each method is
> addressed directly, precisely and exactly. My
> method is to compare two very common methods,
> two methods most often employed and, only
> those under strict controls.
Yes, well strict controls are not always the answer.  Nobody is highly
concerned with how well tires grip the road at 15 miles an hour on dry
pavement.  They want to know about snow at 35mph, and rain at 55mph, and
gravel at 40mph (I had to throw in a completely unrelated example to
make up for your moronic inclusion of LA light sampling.).  You *have*
to vary the input and the testing before you can get a true
determination of speed, usefulness and effeciency.


> Your method has too many externalities, too few controls,
> does not address the question directly and displays
> changing parameters, although each test case more than
> validates what I have stated and Dominus ignorantly
> claims is untrue. Nevertheless, your article is invalid
> although your basic premises are moderately valid.
What?  How can my tests prove you right if they were all invalid?  What
you're saying is "amonotod's tests were completely invalid; flawed from
concept through delivery with a total lack of scientific basis.
However, they validate my claims, and prove Jason Dominus incorrect."
Once again, you're just not making sense... But that's nothing new, is
it?

> Below my signature you will discover very exacting
> scientific method, with strict controls and repeating
> tests to validate results beyond quirk or quark.
Hmm.. sure.  But you changed your substring statement from this:
$string = substr ($string, 0, index ($string, ";"));
to this:
$string = substr ($string, 0, index ($string, ";") + 1);

And I assume that was because you realized I was right about the last
character being lopped off when no semicolon was encountered.  But did
you say something like "Oh, hey thanks amonotod, I didn't realize
that."? No, instead you came back with 6 pages of half witted diatribe
about scientific testing.  Whatever...

> I believe this standard method of publishing a
> hypothesis, calling for data input from our scientific
> community, test replication and discussion, before
> publishing a theory to test, can be dismissed for
> something this simple.
My personal opinion is that the vast majority of c.l.p.m does not care
about hypothesis based on a single line of input, and very likely most
participants in this group would not refer to it as a scientific
community.  But, it is quite obvious that your perception of the world
is rather skewed, so you might have different opinions than I.

>
> Godzilla!
> --

c.l.p.m,
I apologize for my participation in trolling with the troll, and hope
you will forgive my infractions,
amonotod

--
    `\|||/                     amonotod@
      (@@)                     netscape.net
  ooO_(_)_Ooo________________________________
  _____|_____|_____|_____|_____|_____|_____|_____|


Sent via Deja.com
http://www.deja.com/


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

Date: Mon, 29 Jan 2001 09:12:00 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Finding a char in string
Message-Id: <3A75A460.1E55EB27@stomp.stomp.tokyo>

amonotod wrote:
 
>   Godzilla! wrote:

> > The question is,

> > "Which is faster and more efficient to eliminate all
> > characters after a semicolon within a string?"
 

(snipped blatherings unfit even for a crackhead)


> Hmm.. sure.  But you changed your substring statement from this:

> $string = substr ($string, 0, index ($string, ";"));

> to this:

> $string = substr ($string, 0, index ($string, ";") + 1);
 
> And I assume that was because you realized I was right about the last
> character being lopped off when no semicolon was encountered.  But did
> you say something like "Oh, hey thanks amonotod, I didn't realize
> that."? No, instead you came back with 6 pages of half witted diatribe
> about scientific testing.  Whatever...


It is very clear, you, like almost all other regulars here,
face both challenges in education and challenges in primary
level reading comprehension. From my original article:

"

 For my test script below, if you wish to retain
 your semicolon, add one to the index function inside
 my substring function. This will grab your semicolon
 along with your other preceding data:

 ... index ($string, ";") + 1));

"


Whew... they just don't make kids like they use to.


Godzilla!


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

Date: 30 Jan 2001 13:15:34 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Finding a char in string
Message-Id: <m3hf2gaou1.fsf@mumonkan.sunstarsys.com>

amonotod <amonotod@netscape.net> writes:

> In article <3A74B1AE.FDB71B78@stomp.stomp.tokyo>,
>   "Godzilla!" <godzilla@stomp.stomp.tokyo> wrote:
> 
> > Below my signature you will discover very exacting
> > scientific method, with strict controls and repeating
> > tests to validate results beyond quirk or quark.
> Hmm.. sure.  But you changed your substring statement from this:
> $string = substr ($string, 0, index ($string, ";"));
> to this:
> $string = substr ($string, 0, index ($string, ";") + 1);
> 
> And I assume that was because you realized I was right about the last
> character being lopped off when no semicolon was encountered.  

No, adding 1 will not help.  The problem is that index returns -1 
whenever the substring is not matched, and substr will leave 1 
character off the end of the string in such cases.  Adding 1 will 
drop the entire string.

See

% perldoc -f index
% perldoc -f substr

for details.

FWIW, Godzilla's original post offers a choice of methods, depending 
on whether or not ";" is needed in the result.  Using a regexp for 
this is yet another choice, and is arguably more robust for the 
reasons you pointed out.  The equivalent statement comparing regexp's 
and substr would be something like

    (my $result = $string) =~ s/;.*/;/s;

                   equals

    my $i = index($string, ";");
    my $result = ($i == -1) ? $string : substr( $string, 0, $i+1 );

AFAICT, there isn't any significant performance/memory difference 
between these two, under any reasonable conditions.

However, if you are certain that the ";" is in there somewhere, 
just using

    my $result = substr( $string, 0, index($string, ";") + 1 );

doesn't strike me as being inherently evil; in fact, it matches 
OP's intuition pretty well.

However, benchmarking these expressions to determine which is 
"better" strikes me as being penny-wise, yet pound-foolish.  IMHO, 
this type of argument is all too common in clp.misc.

btw- this is a comp.* group. ad hominem shit (both pro and con)
     is unwelcome here, as it is just more noise that almost 
     always drowns out the signal.  

-- 
Joe Schaefer



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

Date: Tue, 30 Jan 2001 18:14:47 GMT
From: amonotod <amonotod@netscape.net>
Subject: Re: Finding a char in string
Message-Id: <9570ad$f8e$1@nnrp1.deja.com>

In article <3A75A460.1E55EB27@stomp.stomp.tokyo>,
  "Godzilla!" <godzilla@stomp.stomp.tokyo> wrote:
> amonotod wrote:
>
> >   Godzilla! wrote:
>
> > > The question is,
>
> > > "Which is faster and more efficient to eliminate all
> > > characters after a semicolon within a string?"
>
> (snipped blatherings unfit even for a crackhead)
*You* accuse me of blathering?  Do you prefer to be called kettle or
pot?  By the way, "<snip>" isn't exactly the way to respond to a point.
Debate team material you're not.

>
> > Hmm.. sure.  But you changed your substring statement from this:
>
> > $string = substr ($string, 0, index ($string, ";"));
>
> > to this:
>
> > $string = substr ($string, 0, index ($string, ";") + 1);
>
> > And I assume that was because you realized I was right about the
last
> > character being lopped off when no semicolon was encountered.  But
did
> > you say something like "Oh, hey thanks amonotod, I didn't realize
> > that."? No, instead you came back with 6 pages of half witted
diatribe
> > about scientific testing.  Whatever...
>
> It is very clear, you, like almost all other regulars here,
> face both challenges in education and challenges in primary
> level reading comprehension. From my original article:

I think the same can be said of you.  Re-read what I wrote, and then
repond to it, in context.

>
> "
>
>  For my test script below, if you wish to retain
>  your semicolon, add one to the index function inside
>  my substring function. This will grab your semicolon
>  along with your other preceding data:
>
> ... index ($string, ";") + 1));
>
> "
>

Here's the rest of your post:
<quote>

 TEST SCRIPT:
 ____________


 #!perl

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

 $string ="Save This Info; Toss This Info";

 $new_string = substr ($string, 0, index ($string, ";"));

 print $new_string;

 exit;
</quote>

Neither example of your code makes allowance for a string NOT containing
a semicolon.  Fix it (without a regex, and without the grep() since that
was my fix), or shut up (very faint hope, there).


> Whew... they just don't make kids like they use to.
Yes, I too am thankful that I was not born or raised to be like you.
Now, like I said, re-read what I wrote, and reply in context.


>
> Godzilla!
>

You're still a self-contradicting, crap-code-spewing, nonsensical,
blathering, moronic troll, IMHO.  Every time you respond to a post by
omitting half or more of the points made in the post you're just
reinforcing my opinion that you're an idiot, unable to effectively
debate or respond to criticism. Yes, I was addressed about my ability to
respond to criticism, and I learned from it; you should do the same.

amonotod

P.S.
Boy, I'm sure impressed with your credentials.  Thanks for posting them.

--
    `\|||/                     amonotod@
      (@@)                     netscape.net
  ooO_(_)_Ooo________________________________
  _____|_____|_____|_____|_____|_____|_____|_____|


Sent via Deja.com
http://www.deja.com/


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

Date: Tue, 30 Jan 2001 10:43:39 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Finding a char in string
Message-Id: <3A770B5B.E9FB18CD@stomp.stomp.tokyo>

Joe Schaefer wrote:
 
> amonotod <amonotod@netscape.net> writes:
> >  Godzilla! wrote:

(snippage)

> No, adding 1 will not help.  The problem is that index returns -1
> whenever the substring is not matched, and substr will leave 1
> character off the end of the string in such cases.  Adding 1 will
> drop the entire string.


Irrelevant. Your comments do not comply with the
original clearly stated parameters.

Godzilla!


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

Date: 30 Jan 2001 17:46:58 +0000
From: nobull@mail.com
Subject: Fish v Fishing lessons - again! (was: Installing and using modules when you're not root?)
Message-Id: <u9snm1q6el.fsf@wcl-l.bham.ac.uk>

Daniel Berger <djberge@uswest.com> writes:

> > I can even tell you how to find the answer yourself.

> > Easy, huh?

> Then again, it's not as easy as just giving him the answer:

If you give a man fish he won't go hungy today.  If you teach a man to
fish he'll won't go hungry until the fish stocks are exhaused.  The
Perl manuals are well-stocked rivers.

Please do _not_ hand out fish to the newcommers.  They'll just come
back hungry tomorrow, and the day after.  Worse, when people finally
say "why don't you go catch your own fish" they'll become defensive
and/or abusive.  They'll tell us that the purpose of this place is to
provide hand-outs of free fish to people like them.  They'll add that
if we don't like it we should leave.

Do not take my word for it - go to deja.com and see the evidence for
yourself.

If you really cannot resist the tempation to take the path of least
resistance hand out fish then at the very least do not criticise those
of us who make the effort and try to teach the newcommers to fish.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

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 V10 Issue 175
**************************************


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