[18298] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 466 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Mar 11 21:05:59 2001

Date: Sun, 11 Mar 2001 18: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: <984362718-v10-i466@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 11 Mar 2001     Volume: 10 Number: 466

Today's topics:
        Beginners question <julg@sympatico.ca>
    Re: binary to decimal conversion: FAQ answer is not goo <johnlin@chttl.com.tw>
    Re: Can a regex do this? <tinamue@zedat.fu-berlin.de>
    Re: Can a regex do this? <tinamue@zedat.fu-berlin.de>
    Re: cgi redirect not working (BUCK NAKED1)
    Re: CGI RESET problem solved (BUCK NAKED1)
        different results depending on the way the script is in Robert.Groenewegen@ordina.nl
    Re: different results depending on the way the script i <uri@sysarch.com>
    Re: Got the number format working <m0rejunkmail@home.com>
        grabbing last word of a string <dgargan@lucent.com>
    Re: grabbing last word of a string <wyzelli@yahoo.com>
    Re: grabbing last word of a string <dgargan@lucent.com>
    Re: grabbing last word of a string <wyzelli@yahoo.com>
    Re: grabbing last word of a string <godzilla@stomp.stomp.tokyo>
    Re: grabbing last word of a string <tinamue@zedat.fu-berlin.de>
    Re: grabbing last word of a string <uri@sysarch.com>
    Re: grabbing last word of a string <godzilla@stomp.stomp.tokyo>
    Re: grabbing last word of a string <tinamue@zedat.fu-berlin.de>
    Re: grabbing last word of a string <godzilla@stomp.stomp.tokyo>
    Re: grabbing last word of a string <tinamue@zedat.fu-berlin.de>
    Re: grabbing last word of a string (Craig Berry)
    Re: grabbing last word of a string <tinamue@zedat.fu-berlin.de>
    Re: grabbing last word of a string <godzilla@stomp.stomp.tokyo>
    Re: grabbing last word of a string <godzilla@stomp.stomp.tokyo>
    Re: grabbing last word of a string <tinamue@zedat.fu-berlin.de>
    Re: How can I create files in directories other than th <costas@seleucia.tamu.edu>
    Re: How can I create files in directories other than th <tinamue@zedat.fu-berlin.de>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Mon, 12 Mar 2001 01:57:50 GMT
From: Julien Gauthier <julg@sympatico.ca>
Subject: Beginners question
Message-Id: <3AAC2E70.581B184E@sympatico.ca>

Is there a command line that will ask the user to press a given key
before continuing?

Right now I'm doing my first steps in Perl using the Window(*)
environment and my problem is as follow : every time I run a perl
script, it immediatly dissapear without giving me a chance to see wether
the appropriate result is good. It will wait for imputs, but I can't see
the final result.


Thanks,

JG

(*) I know, thats the problem ...Asking me to switch to linux is not
exactly an option because I most often work at the uni where I don't
really have the choice.



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

Date: Mon, 12 Mar 2001 09:25:29 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: binary to decimal conversion: FAQ answer is not good
Message-Id: <98h8fn$8n3@netnews.hinet.net>

"Chris Stith" wrote
> Martien Verbruggen wrote:
> > Nope. Where I come from the 1-bit bytes are sold out.
> Wow, who's still paying 12.5 cents per byte? [1]
>
> [1] Note to the international audience:
> a "bit" is an archaic form of US money equal to an
> eighth of a dollar

I thought you were talking about stocks [BYTE]...

John Lin





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

Date: 12 Mar 2001 01:10:19 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: Can a regex do this?
Message-Id: <98h7lr$1td9l$4@fu-berlin.de>

hi,
Martien Verbruggen <mgjv@tradingpost.com.au> wrote:

> You have been shown several ways to do this. You're making up arbitrary
> restrictions, which make no sense (only a regex!). The following would
> also definitely prohibit it:

> 1 - It has to be Wednesday for all values of test.
> 2 - The banana has to be peeled
> 3 - You can't use Perl
> 4 - It has to be done in Perl
> 5 - You can't use number 6
> 7 - You can't use letters d, g, r, s, w, and y
> 8 - It has to be exactly 3.14159265358979 lines long.
> 9 - You have to be standing on one leg, singing the national anthem of
>     Macedonia, while drinking a glass of water and balancing an unbrella
> 	on your nose.
> 10- But most importantly, you can't do it! because I say so!

sounds like programming under windoze... =)
SCNR
tina

-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \ _,_\ __/\ __/_| /__/ perception
please don't email unless offtopic or followup is set. thanx


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

Date: 12 Mar 2001 01:15:16 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: Can a regex do this?
Message-Id: <98h7v4$1td9l$5@fu-berlin.de>

blahblah <blah@blah.com> wrote:
> I am looking for a regex that will do two replacements on the same
> line. For example:

> $test = "test1 test2 test3";
> $test =~ s/1/a/g;
> $test =~ s/2/b/g;
> $test =~ s/3/c/g;
> print $test;

> The effect is that 1, 2 and 3 will be changed to a, b and c.

> Can this be done on the same line?

$test =~ s/1(.*)2(.*)3/a$1b$2c/;

what's so difficult about it?
-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \ _,_\ __/\ __/_| /__/ perception
please don't email unless offtopic or followup is set. thanx


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

Date: Sun, 11 Mar 2001 14:07:06 -0600 (CST)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: cgi redirect not working
Message-Id: <6239-3AABDAEA-179@storefull-244.iap.bryant.webtv.net>

Make sure that you don't print out a content header first, whether you
are using something like...
print "Location: http://dingdong.com\n\n";
or cgi.pm's 
redirect->('http://dingdong.com');


If that's not the problem, as someone recently suggested to me, try
using the HTTP::Headers module referer to make the referer the same as
the URL you're trying to grab. Use the LWP::UserAgent module to grab the
URL.

$headers->referer('http://dingdong.com');

HTH,
--Dennis



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

Date: Sun, 11 Mar 2001 14:18:05 -0600 (CST)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: CGI RESET problem solved
Message-Id: <26365-3AABDD7D-180@storefull-243.iap.bryant.webtv.net>

Maybe sometimes CGI.pm isn't the best way? :-) I got this to work by
using a sub. I know I should've coded the last elsif as else, and not
used the last else{}.. oh well... it works. 


#!/usr/bin/perl -w
use CGI qw(:param);
print "Content-type: text/html\n\n"; 
if(!param()) {
$ref=$ENV{HTTP_REFERER} 
} 
elsif(param('reset')) {
$ref="" 
} 
elsif(param('do_it')) {
print &do_it 
} 
else{}; 

print "<HTML><BODY>
<form method=post>
<input type=text name=url value=$ref> 
<input type=submit name=do_it value=Submit> <input type=submit
name=reset value=Reset> 
</form> </BODY></HTML>"; 

sub do_it {"doing the work now\n" }; 

Regards,
--Dennis



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

Date: Sun, 11 Mar 2001 23:46:20 +0100
From: Robert.Groenewegen@ordina.nl
Subject: different results depending on the way the script is invoked
Message-Id: <984350968.890069@newsreader2.wirehub.nl>


<br><font size=1 face="sans-serif">I have a simple script (copied from perlfaq) to count the number of newlines in a textfile.</font>
<br><font size=1 face="sans-serif">perl countlines.pl &lt; foo.txt works great</font>
<br><font size=1 face="sans-serif">countlines.pl &lt; foo.txt gives 0 as result.</font>
<br>
<br><font size=1 face="sans-serif">I am using W2K and all my scripts work fine when activated with or without &quot;perl&quot; in the command line.</font>
<br><font size=1 face="sans-serif">Also other scripts that use STDIN. Only this one fails. Hope anyone can help me?</font>
<br>
<br>
<br><font size=1 face="sans-serif">use strict;</font>
<br>
<br><font size=1 face="sans-serif">my $count=0;</font>
<br><font size=1 face="sans-serif">while (&lt;STDIN&gt;) { $count += tr/\n//; }</font>
<br><font size=1 face="sans-serif">print $count;</font>


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

Date: Sun, 11 Mar 2001 23:10:26 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: different results depending on the way the script is invoked
Message-Id: <x7itlfc36m.fsf@home.sysarch.com>


try posting in plain text. usenet is not an html medium.

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: Sun, 11 Mar 2001 21:07:55 GMT
From: FORM Rookie <m0rejunkmail@home.com>
Subject: Re: Got the number format working
Message-Id: <3AABEE09.1F43A83A@home.com>

Got it working. 

Thanks to Tad and Uri.

FORM Rookie


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

Date: Sun, 11 Mar 2001 16:49:11 -0700
From: Dave Gargan <dgargan@lucent.com>
Subject: grabbing last word of a string
Message-Id: <3AAC0EF7.E3F3519D@lucent.com>


I need to grab the last work of a string and assign it to
a variable so I can work with it.  For instance, I
want to grab the word stickler from this string...

Subject: ITO: major: problem on node stickler

Basically I am putting an entire e-mail into an array and
I need to grab that last word of the subject line so that
I can do a name lookup on it (it's a host name).

I can grab the line I need by searching and assigning it
to a scalar ($SUBJECT).  Now how do I slice up the line so 
I can assign the last word to the scalar $HOST?  I've tried
using  $HOST = ($SUBJECT =~ /\w+$/); but it's returing
the number 1 every time.

Any help would be appreciated...


-- 
Dave Gargan              IBM Global Services
Unix Sysadmin             Lucent Account


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

Date: Mon, 12 Mar 2001 09:29:30 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: grabbing last word of a string
Message-Id: <P7Uq6.3$_S2.3063@vic.nntp.telstra.net>

"Dave Gargan" <dgargan@lucent.com> wrote in message
news:3AAC0EF7.E3F3519D@lucent.com...
>
> I need to grab the last work of a string and assign it to
> a variable so I can work with it.  For instance, I
> want to grab the word stickler from this string...
>
> Subject: ITO: major: problem on node stickler
>
> Basically I am putting an entire e-mail into an array and
> I need to grab that last word of the subject line so that
> I can do a name lookup on it (it's a host name).
>
> I can grab the line I need by searching and assigning it
> to a scalar ($SUBJECT).  Now how do I slice up the line so
> I can assign the last word to the scalar $HOST?  I've tried
> using  $HOST = ($SUBJECT =~ /\w+$/); but it's returing
> the number 1 every time.

You need to add the parens to capture, as it is the number 1 is the
number of matches.

I would also suggest an 'if' test, because in the event of an
unsuccessful match, $1 would still be set to whatever it was last time.

Therefore I suggest to use:

$HOST = $1 if ($SUBJECT =~ /(\w+)$/);

You should also read up on perlstyle.  All caps variable names are
frowned upon ( not illegal, just icky).

Wyzelli
--
push@x,$_ for(a..z);push@x,' ';
@z='092018192600131419070417261504171126070002100417'=~/(..)/g;
foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;




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

Date: Sun, 11 Mar 2001 17:08:11 -0700
From: Dave Gargan <dgargan@lucent.com>
Subject: Re: grabbing last word of a string
Message-Id: <3AAC136B.4DF3E31C@lucent.com>

Wyzelli wrote:
> 
> 
> You need to add the parens to capture, as it is the number 1 is the
> number of matches.
> 
> I would also suggest an 'if' test, because in the event of an
> unsuccessful match, $1 would still be set to whatever it was last time.
> 
> Therefore I suggest to use:
> 
> $HOST = $1 if ($SUBJECT =~ /(\w+)$/);
> 
> You should also read up on perlstyle.  All caps variable names are
> frowned upon ( not illegal, just icky).
> 
> Wyzelli
> --
> push@x,$_ for(a..z);push@x,' ';
> @z='092018192600131419070417261504171126070002100417'=~/(..)/g;
> foreach $y(@z){$_.=$x[$y]}y/jp/JP/;print;


Works great.  Thanks!

Where should I read up on style?  I'm a ksh programmer that's trying
to become proficient in perl...  

-- 
/*
Dave Gargan              IBM Global Services
Unix Sysadmin             Lucent Account


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

Date: Mon, 12 Mar 2001 10:08:26 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: grabbing last word of a string
Message-Id: <AIUq6.5$_S2.3152@vic.nntp.telstra.net>

"Dave Gargan" <dgargan@lucent.com> wrote in message
news:3AAC136B.4DF3E31C@lucent.com...
> Wyzelli wrote:
>
> Where should I read up on style?  I'm a ksh programmer that's trying
> to become proficient in perl...
>

at the shell prompt, you should be able to type

perldoc perldoc

That should give you the pointers you need.

The section of documantation referring to style hints, is called
perlstyle, and to access it you do

perldoc perlstyle

HTH

Wyzelli
--
@x='07411711511603209711011111610410111403208010111410803210409709910710
1114'=~/(...)/g;
print chr for @x;




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

Date: Sun, 11 Mar 2001 16:31:07 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: grabbing last word of a string
Message-Id: <3AAC18CB.6F5BCEA1@stomp.stomp.tokyo>

Dave Gargan wrote:
 
> I need to grab the last work of a string and assign it to
> a variable so I can work with it.  For instance, I
> want to grab the word stickler from this string...
 
> Subject: ITO: major: problem on node stickler

(snipped)


Quickest most efficient way to do this is to use
a substring method.

$string = "Subject: ITO: major: problem on node stickler";
$host = substr ($string, rindex ($string, " ") + 1);

You will notice my method below my signature is an
average eight-hundred percent more efficient than
a popular regex / match method.

Godzilla!
-- 

TEST SCRIPT:
____________

#!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 (1000000, 
   {
    'name1' =>
    '$string = "Subject: ITO: major: problem on node stickler";
     $host = $1 if ($string =~ /(\w+)$/);',

    'name2' =>
    '$string = "Subject: ITO: major: problem on node stickler";
     $host = substr ($string, rindex ($string, " ") + 1);',
    }
  );
 }


PRINTED RESULTS:
________________

Run One:

Benchmark: timing 1000000 iterations of name1, name2...
 name1: 18 wallclock secs (17.64 usr +  0.00 sys = 17.64 CPU) @ 56689.34/s
 name2:  2 wallclock secs ( 2.14 usr +  0.00 sys =  2.14 CPU) @ 467289.72/s


Run Two:

Benchmark: timing 1000000 iterations of name1, name2...
 name1: 18 wallclock secs (17.74 usr +  0.00 sys = 17.74 CPU) @ 56369.79/s
 name2:  2 wallclock secs ( 2.26 usr +  0.00 sys =  2.26 CPU) @ 442477.88/s


Run Three:

Benchmark: timing 1000000 iterations of name1, name2...
 name1: 18 wallclock secs (17.74 usr +  0.00 sys = 17.74 CPU) @ 56369.79/s
 name2:  2 wallclock secs ( 2.19 usr +  0.00 sys =  2.19 CPU) @ 456621.00/s


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

Date: 12 Mar 2001 00:59:56 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: grabbing last word of a string
Message-Id: <98h72c$1td9l$3@fu-berlin.de>

hi,
Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
> Dave Gargan wrote:
>  
>> I need to grab the last work of a string and assign it to
>> a variable so I can work with it.  For instance, I
>> want to grab the word stickler from this string...
>  
>> Subject: ITO: major: problem on node stickler

> Quickest most efficient way to do this is to use
> a substring method.

> $string = "Subject: ITO: major: problem on node stickler";
> $host = substr ($string, rindex ($string, " ") + 1);

okay, but let's assume the subject line is
"Subject: ITO: major: problem on node(stickler)"

the "last word" for me means anything following
a word limit, which can be a space, tab, "(", ".", ...
the regex below doesn't do that as well, so i'd suggest
/(\w+)(\W+|\Z)$/
that should do it.

tina

-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \ _,_\ __/\ __/_| /__/ perception
please don't email unless offtopic or followup is set. thanx


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

Date: Mon, 12 Mar 2001 01:12:05 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: grabbing last word of a string
Message-Id: <x7bsr7bxjv.fsf@home.sysarch.com>

>>>>> "TM" == Tina Mueller <tinamue@zedat.fu-berlin.de> writes:

  TM> Godzilla! <godzilla@stomp.stomp.tokyo> wrote:

  >> Quickest most efficient way to do this is to use
  >> a substring method.

  >> $string = "Subject: ITO: major: problem on node stickler";
  >> $host = substr ($string, rindex ($string, " ") + 1);

  TM> okay, but let's assume the subject line is
  TM> "Subject: ITO: major: problem on node(stickler)"

  TM> the "last word" for me means anything following
  TM> a word limit, which can be a space, tab, "(", ".", ...
  TM> the regex below doesn't do that as well, so i'd suggest
  TM> /(\w+)(\W+|\Z)$/
  TM> that should do it.

typical of moronzilla who can't get most things correct, should be
focusing on efficiency. her scripts are never used under any load so who
cares? she has this function of the month compulsion with substr and has
recently posted a mess of substr answers that are barely functional and
totally inflexible as compared to regex solutions. all to save a
millisecond a run.

she is suffering from premature optimization among her other mental
disorders.

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: Sun, 11 Mar 2001 17:14:38 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: grabbing last word of a string
Message-Id: <3AAC22FE.3219E29D@stomp.stomp.tokyo>

Tina Mueller wrote:

> Godzilla! wrote:
> > Dave Gargan wrote:

(snippage)

> okay, but let's assume the subject line is
> "Subject: ITO: major: problem on node(stickler)"


Irrelevant. Your comments do not comply with
the author's stated parameters. Do try to
stay on topic when posting or make an 
"off topic" note in the subject line.

Godzilla!
--

* maniacal laughter *

$string = "Subject: ITO: major: problem on node(stickler)";
$host = substr ($string, rindex ($string, "(") + 1);
chop $host;


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

Date: 12 Mar 2001 01:24:41 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: grabbing last word of a string
Message-Id: <98h8gp$1td9l$7@fu-berlin.de>

Uri Guttman <uri@sysarch.com> wrote:
>>>>>> "TM" == Tina Mueller <tinamue@zedat.fu-berlin.de> writes:

> typical of moronzilla who can't get most things correct, should be
> focusing on efficiency. her scripts are never used under any load so who
> cares? she has this function of the month compulsion with substr and has
> recently posted a mess of substr answers that are barely functional and
> totally inflexible as compared to regex solutions. all to save a
> millisecond a run.

> she is suffering from premature optimization among her other mental
> disorders.

oh, okay. I started to read this NG again today; and as I
believe in the goodness of human beings (is this the correct
english expression?), I posted this posting, but as I
can see nothing has changed. the only answer I got from
moronzilla is that my posting is irrelevant.
oh well, I guess it's hopeless. (I just can't
resist sometimes to feed the trolls... =)

greetings,
tina
f'up2poster
-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \ _,_\ __/\ __/_| /__/ perception
please don't email unless offtopic or followup is set. thanx


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

Date: Sun, 11 Mar 2001 17:33:28 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: grabbing last word of a string
Message-Id: <3AAC2768.23311510@stomp.stomp.tokyo>

Tina Mueller wrote:

> Godzilla! wrote:
> > Dave Gargan wrote:

(snippage)

> > Quickest most efficient way to do this is to use
> > a substring method.
 
> > $string = "Subject: ITO: major: problem on node stickler";
> > $host = substr ($string, rindex ($string, " ") + 1);
 
> okay, but let's assume the subject line is
> "Subject: ITO: major: problem on node(stickler)"
 
> the "last word" for me means anything following
> a word limit, which can be a space, tab, "(", ".", ...
> the regex below doesn't do that as well, so i'd suggest
> /(\w+)(\W+|\Z)$/
> that should do it.


* twiddles her thumbs *

My method is an average one-thousand-three-hundred percent
more efficient than what you suggest. Wanna play again?


Godzilla!
--

TEST SCRIPT:
____________

#!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 (1000000, 
   {
    'name1' =>
    '$string = "Subject: ITO: major: problem on node(stickler)";
     $host = $1 if ($string =~ /(\w+)(\W+|\Z)$/);',

    'name2' =>
    '$string = "Subject: ITO: major: problem on node(stickler)";
     $host = substr ($string, rindex ($string, "(") + 1);
     chop $host;',
    }
  );
 }


PRINTED RESULTS:
________________

Run One:

Benchmark: timing 1000000 iterations of name1, name2...
 name1: 35 wallclock secs (35.31 usr +  0.00 sys = 35.31 CPU) @ 28320.59/s
 name2:  3 wallclock secs ( 2.80 usr +  0.00 sys =  2.80 CPU) @ 357142.86/s


Run Two:

Benchmark: timing 1000000 iterations of name1, name2...
 name1: 36 wallclock secs (35.60 usr +  0.00 sys = 35.60 CPU) @ 28089.89/s
 name2:  3 wallclock secs ( 2.74 usr +  0.00 sys =  2.74 CPU) @ 364963.50/s


Run Three:

Benchmark: timing 1000000 iterations of name1, name2...
 name1: 36 wallclock secs (35.65 usr +  0.00 sys = 35.65 CPU) @ 28050.49/s
 name2:  3 wallclock secs ( 2.75 usr +  0.00 sys =  2.75 CPU) @ 363636.36/s


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

Date: 12 Mar 2001 01:36:13 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: grabbing last word of a string
Message-Id: <98h96d$1td9l$8@fu-berlin.de>

I know I shouldn't but I CNR
Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
> Tina Mueller wrote:

>> Godzilla! wrote:
>> > Dave Gargan wrote:

>> okay, but let's assume the subject line is
>> "Subject: ITO: major: problem on node(stickler)"

> Irrelevant.

oh, is it?

> Your comments do not comply with
> the author's stated parameters.

the "parameters" were: the last word in a line.
I just made a suggestion how to improve the matching
if a line like the above appears.

> Do try to
> stay on topic when posting or make an 
> "off topic" note in the subject line.

okay, I'm sorry. would you please tell me where
exactly my posting became offtopic? then I'll
promise I won't do that again.

> $string = "Subject: ITO: major: problem on node(stickler)";
> $host = substr ($string, rindex ($string, "(") + 1);

okay, do that for ".", "(", "\t", ",", ":", ")", ";", etc.
but how can you know then, which one is the right one?
really, I'd prefer substr() wherever it's possible,
but would you let all of us know how to use
your solution for all possible inputs?
c'mon, we all wanna see it.

as stated above, my solution was for the original
posting with the subject "grabbing last word of a string".
yours was for the example given in the posting,
and you ignored other possible inputs.

-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \ _,_\ __/\ __/_| /__/ perception
please don't email unless offtopic or followup is set. thanx


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

Date: Mon, 12 Mar 2001 01:38:35 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: grabbing last word of a string
Message-Id: <taoa4r6eane96b@corp.supernews.com>

Tina Mueller (tinamue@zedat.fu-berlin.de) wrote:
: the "last word" for me means anything following
: a word limit, which can be a space, tab, "(", ".", ...
: the regex below doesn't do that as well, so i'd suggest
: /(\w+)(\W+|\Z)$/

My prefered method would be

  $lastword = (m/(\w+)/g)[-1];

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "When the going gets weird, the weird turn pro."
   |               - Hunter S. Thompson


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

Date: 12 Mar 2001 01:48:33 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: grabbing last word of a string
Message-Id: <98h9th$1td9l$10@fu-berlin.de>

Godzilla! <godzilla@stomp.stomp.tokyo> wrote:
> Tina Mueller wrote:

>> okay, but let's assume the subject line is
>> "Subject: ITO: major: problem on node(stickler)"

>     'name2' =>
>     '$string = "Subject: ITO: major: problem on node(stickler)";
>      $host = substr ($string, rindex ($string, "(") + 1);

I know a better one:
$string = 'Subject: ITO: major: problem on node(stickler)';
$host = 'stickler';
haven't benchmarked, but it should be obviously the fastest
one.

now it's your turn to recognize my followup-to-header,
it has become a little bit boring.

(sorry to all, I know I'm feeding the troll. so I'm
going to bed now and stop this, it's almost 3am, anyway)

tina
-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \ _,_\ __/\ __/_| /__/ perception
please don't email unless offtopic or followup is set. thanx


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

Date: Sun, 11 Mar 2001 17:56:01 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: grabbing last word of a string
Message-Id: <3AAC2CB1.151D020E@stomp.stomp.tokyo>

Tina Mueller wrote:

> Godzilla! wrote:
> > Tina Mueller wrote:
> > > Godzilla! wrote:
> > > > Dave Gargan wrote:
 
(lots of snippage)

> okay, do that for ".", "(", "\t", ",", ":", ")", ";", etc.
> but how can you know then, which one is the right one?

Quite simple really. I do not allow garbage to enter
my programs. My presumption is you are not careful
about controlling what data characters are allowed
to enter your program nor careful about formatting
your data bases correctly. This is not wise. 

> really, I'd prefer substr() wherever it's possible,
> but would you let all of us know how to use
> your solution for all possible inputs?
> c'mon, we all wanna see it.

Why bother? You know I will just toss in a
transliteration operator and still come in
a guesstimated one-thousand percent better
efficiency than your regex / match method.

Use of a regex match, use of a regex substitution,
is quite appropriate when other methods cannot
meet unique parameters. However, a substring
method will beat a regex in all cases, when
it can be used effectively, which is often.

You know better than to play the,

"Switch Parameters And Criticize Game"

with me. This game, played by most here,
is indicative of people whose only intent
is to spread discontent and, masturbate
their respective egos.

Godzilla!


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

Date: Sun, 11 Mar 2001 17:58:17 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: grabbing last word of a string
Message-Id: <3AAC2D39.8E26099A@stomp.stomp.tokyo>

Tina Mueller wrote:
 
> Godzilla! wrote:
> > Tina Mueller wrote:
 
(snippage)

> I know a better one:
> $string = 'Subject: ITO: major: problem on node(stickler)';
> $host = 'stickler';
> haven't benchmarked, but it should be obviously the fastest
> one.

* laughs *

Ok, I concede. You darn well beat me on this one.

Godzilla!
--
* Should have known she would pull a Captain Jamie Kirk *


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

Date: 12 Mar 2001 02:01:20 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: grabbing last word of a string
Message-Id: <98halg$1td9l$11@fu-berlin.de>

hi,
Craig Berry <cberry@cinenet.net> wrote:
> Tina Mueller (tinamue@zedat.fu-berlin.de) wrote:
> : the "last word" for me means anything following
> : a word limit, which can be a space, tab, "(", ".", ...
> : the regex below doesn't do that as well, so i'd suggest
> : /(\w+)(\W+|\Z)$/

> My prefered method would be

>   $lastword = (m/(\w+)/g)[-1];

that's nice, too. it's also faster.
so i'll try to defend mine, which, btw, can be shortened
to /(\w+)\W*$/.
like this, it's just a little bit slower, but
quicker for larger inputs like "word "x1000.
(but okay, this wasn't the question)

=)

tina

-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \ _,_\ __/\ __/_| /__/ perception
please don't email unless offtopic or followup is set. thanx


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

Date: Sun, 11 Mar 2001 19:56:46 -0600
From: Costas Tzimeas <costas@seleucia.tamu.edu>
Subject: Re: How can I create files in directories other than the one that the   perl  script executes from?
Message-Id: <3AAC2CDE.823A4B6@seleucia.tamu.edu>

Thank you all for your suggestions on the matter,


Costas



Tina Mueller wrote:

> > I get the path of
> > the executing script by using a system call of "pwd" and with some string
> > editing,
> > I get it to work.
> > Is there a better way of doing this?
>
> yes:
> perldoc FindBin
>
> hth,
> tina
>
> --
> http://tinita.de    \  enter__| |__the___ _ _ ___
> tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
> search & add comments \    \ _,_\ __/\ __/_| /__/ perception
> please don't email unless offtopic or followup is set. thanx





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

Date: 11 Mar 2001 23:39:08 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: How can I create files in directories other than the one that the  perl  script executes from?
Message-Id: <98h2ar$1td9l$1@fu-berlin.de>

hi,
Costas Tzimeas <costas@seleucia.tamu.edu> wrote:

> since I want the script to be as general as possible, in order to move it to

> many different directories (with subtle variable changes), I get the path of

> the executing script by using a system call of "pwd" and with some string
> editing,
> I get it to work.
> Is there a better way of doing this?

yes:
perldoc FindBin

hth,
tina

-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \ _,_\ __/\ __/_| /__/ perception
please don't email unless offtopic or followup is set. thanx


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

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


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