[10652] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4244 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 18 01:07:36 1998

Date: Tue, 17 Nov 98 22:00:16 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 17 Nov 1998     Volume: 8 Number: 4244

Today's topics:
    Re: Holy Abounding Books, Batman! (Rich)
    Re: Holy Abounding Books, Batman! <crn@itga.com.au>
        How do I make an EXE in Win 98? <gcleaves@bigfoot.com>
    Re: how to get `date` in perl for win32 (newbie) (Ronald J Kimball)
    Re: Intermediate Perl questions (Clay Irving)
    Re: Intermediate Perl questions (Sam Holden)
    Re: Learning <mlabor@mexico.com>
        Parsing Success & Error <Webmaster@Freeness.net>
    Re: Passing value to shell script (Clay Irving)
        Perl Array Question? Anybody... shazad@my-dejanews.com
    Re: Perl Usage Survey - interpretations, anyone? (David Formosa)
    Re: Perl Usage Survey - interpretations, anyone? <uri@sysarch.com>
    Re: Perl vs C (Ronald J Kimball)
    Re: Perl5 (Rich)
        Trying to use ep3 module to build a c preprocessor emul pramsey@iname.com
        Two-Part RE question <nospam.gear4u@hotmail.com>
    Re: Two-Part RE question (Sam Holden)
    Re: Two-Part RE question <uri@sysarch.com>
    Re: Win32 executing a .pl or .cgi (Tom McGee)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: 18 Nov 1998 05:06:55 GMT
From: richm@ucesucks.mulveyr.roc.servtech.com (Rich)
Subject: Re: Holy Abounding Books, Batman!
Message-Id: <slrn754ldf.31i.richm@ll.aa2ys.ampr.org>

On 17 Nov 1998 22:32:18 GMT, Tom Christiansen <tchrist@mox.perl.com> wrote:
>In comp.lang.perl.misc, Helen Rice @ foothill.net writes:
>:I don't recommend Programming Perl, too encyclopedic and absolutely useless
>:for learning. Once you know it, it might be a good reference book. Not
>:enough examples.
>
>After reading your astonishing message, I flipped through Programming
>Perl in search of long stretches of text devoid of examples.  I came up
>empty handed though -- virtually every page has code example, usually
>indented and in a constant-width font.
>
>If you could please indicate which parts don't have enough examples,
>I will do my very best to fix this in the next edition.  Right now,
>though, I am at a complete loss to help you, because as far as I can see,
>it's simply jammed full of them all the way from stem to stern.
>
>I realize I'm probably too close to the problem to see it.  So, if you
>could please point out to me what's not where, I'm sure that everyone
>will be happier.
>

   I suspect that the previous poster was commenting on the 
apparent assumption made in PP that the reader has at least a
passing familiarity with computer programming, in general.  I.E.
you don't explain what a variable is, what a loop is, etc.  ( As
opposed to describing the Perl syntax for loops ).

   Otherwise, I haven't a clue about what brought about the complaint.
I'm using PP, as well as a fair amount of time at the keyboard, to learn
Perl, and have no problems with the structure or content of the book.
There are a couple of forward references, but the ones that I recall also
note where the full description of the item can be found.  The only
point of confusion that pops up is that occasionally I will have to look
up the meaning of some bit of line noise ( the $# prefix, for example )
that I had forgetten about.  Nothing that a quick peek at the index doesn't
cure.

Of course, I also learned C from the original K&R book, which, according
to popular opinion, is also supposed to be impossible.  You may consider
that to be the compliment that I intended it to be.  :-)

- Rich

--
Rich Mulvey                                         
My return address is my last name, 
   followed by my first initial, @mulveyr.roc.servtech.com        
http://mulveyr.roc.servtech.com
Amateur Radio: aa2ys@wb2wxq.#wny.ny.usa


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

Date: 18 Nov 1998 16:47:19 +1100
From: Clive Newall <crn@itga.com.au>
Subject: Re: Holy Abounding Books, Batman!
Message-Id: <v57lwteemw.fsf@itga.com.au>

richm@ucesucks.mulveyr.roc.servtech.com (Rich) writes:

 ...
> I'm using PP, as well as a fair amount of time at the keyboard, to learn
> Perl, and have no problems with the structure or content of the book.
 ... 
> Of course, I also learned C from the original K&R book, which, according
> to popular opinion, is also supposed to be impossible.  You may consider
> that to be the compliment that I intended it to be.  :-)

Oh my. I thought that was how everyone (except those that pre-dated
K&R1) learnt C. I still remember day 1 of Software Engineering (81 or 82):
"Here is your project. This is K&R. Buy it. Read it. Submissions on Friday"
I think there was some mention of "enum" that wasn't in the book...

-- 
Clive Newall <crn@itga.com.au> / ITG Australia Ltd, Melbourne Australia
"I think Casper is the ghost of Richie Rich. I wonder how Richie died?"
"Perhaps he realized how hollow the pursuit of money is and took his own life"
  --Bart and Lisa Simpson


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

Date: Wed, 18 Nov 1998 05:03:21 GMT
From: Geoffrey Cleaves <gcleaves@bigfoot.com>
Subject: How do I make an EXE in Win 98?
Message-Id: <3652554E.EAC95807@bigfoot.com>

Can somebody please lead me in the right direction, please.  I am
(fairly) new to Perl, so I kindly ask for a little detail and maybe an
example or two.  I'm not looking to compile my scripts to hide them from
anybody, I just want to make it easier to run them and I'm just curious
to know if it is possible.  Thanks for any help.



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

Date: Tue, 17 Nov 1998 23:31:29 -0500
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: how to get `date` in perl for win32 (newbie)
Message-Id: <1dinuhk.4shwhev7py40N@bay1-380.quincy.ziplink.net>

<j9feng@my-dejanews.com> wrote:

> Is there a way to get the current date?

localtime()

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: 17 Nov 1998 23:10:10 -0500
From: clay@panix.com (Clay Irving)
Subject: Re: Intermediate Perl questions
Message-Id: <72thb2$kqi@panix.com>

In <72s5sg$rab$1@hades.rz.uni-sb.de> "Markus Kaiser" <m.kaiser@sz-sb.de> writes:

>looking 4 a efficient way to look at each char of a string.
>At the moment I'm using substr( $_, -1, 1 ) in a while loop
>and of course regexp would be possible too.
>But I'm curious: Is there a better (means faster) way ?

Why not this?

   #!/usr/local/bin/perl5
   
   $string = "This is my string";
   
   @chars = split //, $string;
   
   foreach $char(@chars) {
       print "$char\n";
   }

It prints:

   T
   h
   i
   s
   
   i
   s
   
   m
   y
   
   s
   t
   r
   i
   n
   g

>Another issue occured some days ago: How do I break out of
>a "do { ... } while( ... );" construction. Could'nt find a solution using
>'next' or 'last'.

until? :)

-- 
Clay Irving
clay@panix.com


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

Date: 18 Nov 1998 05:04:04 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Intermediate Perl questions
Message-Id: <slrn754la4.d9r.sholden@pgrad.cs.usyd.edu.au>

On 17 Nov 1998 23:10:10 -0500, Clay Irving <clay@panix.com> wrote:
>In <72s5sg$rab$1@hades.rz.uni-sb.de> "Markus Kaiser" <m.kaiser@sz-sb.de> writes:
>
>>looking 4 a efficient way to look at each char of a string.
>>At the moment I'm using substr( $_, -1, 1 ) in a while loop
>>and of course regexp would be possible too.
>>But I'm curious: Is there a better (means faster) way ?

I missed the first post. Surely 'substr( $_, -1, 1 )' returns the last
character in the string, so I assume you then delete that character,
or am I completely wrong???

>
>Why not this?
>
>   #!/usr/local/bin/perl5
>   
>   $string = "This is my string";
>   
>   @chars = split //, $string;
>   
>   foreach $char(@chars) {
>       print "$char\n";
>   }

I believe he said 'faster'... surely you don't think that could possibly be
fast... what if $string is really long? I can think of at least two ways
that should be faster...(some time later)...

Benchmark: timing 1000000 iterations of regex, split, substr...
     regex: 120 wallclock secs (120.19 usr +  0.03 sys = 120.22 CPU)
     split: 166 wallclock secs (165.61 usr +  0.08 sys = 165.69 CPU)
    substr: 76 wallclock secs (77.47 usr +  0.05 sys = 77.52 CPU)

I know which I would prefer... 

---code---
use Benchmark;
$string = "This is my string";
timethese(1000000, {
                "split" => \&use_split,
                "regex" => \&use_regex,
                "substr" => \&use_substr,
                });
sub use_split {
   foreach $char (split //, $string) {
                $c = $char;
   }
}
sub use_regex {
        while ($string=~/(.)/g) {
                $c =  $1;
        }
}
sub use_substr {
        $length = length $string;
        for($i=0;$i<$length;$i++) {
                $c = substr($string,$i,1);
        }
}
-- 
Sam

Simple rule: include files should never include include files.
	--Rob Pike


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

Date: Tue, 17 Nov 1998 22:05:22 -0500
From: "Manuel Labor" <mlabor@mexico.com>
Subject: Re: Learning
Message-Id: <72tdga$ed2$1@oak.prod.itd.earthlink.net>

heres a good one
http://www.netcat.co.uk/rob/perl/win32perltut.html

Ross Milton wrote in message <72sthj$hfs$1@oak.prod.itd.earthlink.net>...
>I am interested in Learning Perl. Where should I start. Are there any good
>tutorials on the web?
>
>Thank You
>
>
>





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

Date: Tue, 17 Nov 1998 21:40:18 -0500
From: "Freeness" <Webmaster@Freeness.net>
Subject: Parsing Success & Error
Message-Id: <72tc5k$bp2$1@oak.prod.itd.earthlink.net>

Hey -- I've been working on an online stats TEST. I setup 2 links that goto
something like:  whatever.cgi?account=04&ad=ad1- the script then pulls out
the account & ad into $Data{'account'} and $Data{'ad'}   then it opens that
account's text file (04.txt) and imports all of it, looks like this:
ad1=5
ad2=3
then number refering to the hits.  then for each line splits it by the =
sign, and it compares $Data{'ad'} to the ad number in the line, and if
they're equal it increases the hits then writes the line.  if it isn't equal
it just writes the line as it was imported.  the script then goes to a
cetain URL depending on the account number.  When I run the script in IE i
get a 500 Error and "Cannot Open The Page". when I edit the text file the #
has been increased, so I thought the url was written wrong so I put a #
before the line a re-ran the script, same problem, but hits was increased
again. so I went to telnet and typed perl -w whatever.cgi and got back erros
on the line that reads the $ENV for post and the line that reads it for get.
What am I doing wrong? Webmaster@Freeness.net





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

Date: 17 Nov 1998 22:58:15 -0500
From: clay@panix.com (Clay Irving)
Subject: Re: Passing value to shell script
Message-Id: <72tgkn$jrk@panix.com>

In <36518d0f.28553547@newsXgn.telecom.ptt.nl> s.a.j.m.vandijk@kpn-telecom.nl (Sebastiaan van Dijk) writes:

>Perhaps a stupid question, but is it possible to pass a value from a
>perl script to a shell script

>ksh:
>value=`perl script.pl`

>Does anybody know how this can be done? The 'exit' does not do the
>job.

The Perl script:

  #!/usr/local/bin/perl5

  print "bar";
  
The result:

  [panix] ~% value=`perl foo.pl`
  value=bar: Command not found.

Looks like it passed the value. :)

-- 
Clay Irving
clay@panix.com


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

Date: Wed, 18 Nov 1998 04:35:46 GMT
From: shazad@my-dejanews.com
Subject: Perl Array Question? Anybody...
Message-Id: <72tir2$5k0$1@nnrp1.dejanews.com>

Hi perl people....

Well, I am trying to compare two files which arrive randomly.  Both file have
the name harry common, but object and rules are different.(example below:)

Subject: harry object  # File1

Subject: harry rules   # File2

WHen I run my perl script, I need to store:
@myarray=("harry","object");

After, the second file comes, I need to APPEND rules into @myarray, when it
matches harry as the common field.

But each time the second file parses...it overwrites
@myarray=("harry","object");
with
@myarray=("harry","rules");

How can I APPEND the second file "rules", so that
@myarray=("harry","object","rule");

I have tries pop(@mtarray,$a), unshift(@mtarray,$a)...but nothing seems to
work!!  Anybody!!!

IN SIMPLE ENGLISH!! How can I restore the context of @myarray each time I run
my script.


-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 18 Nov 1998 03:46:40 GMT
From: dformosa@zeta.org.au (David Formosa)
Subject: Re: Perl Usage Survey - interpretations, anyone?
Message-Id: <slrn754gp0.p6e.dformosa@godzilla.zeta.org.au>

In article <x7lnl94vyj.fsf@sysarch.com>, Uri Guttman wrote:
>>>>>> "DF" == David Formosa <dformosa@zeta.org.au> writes:

[...]

>  DF> You can have remote powermainigment systems where you can push the
>  DF> big red button remotely.
>
>is it failsafe?

It has its own modem so access is indepenent of the network going down.  I 
don't know exactly what heppens when it fails.


-- 
Please excuse my spelling as I suffer from agraphia. See
http://www.zeta.org.au/~dformosa/Spelling.html to find out more.



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

Date: 18 Nov 1998 00:12:53 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Perl Usage Survey - interpretations, anyone?
Message-Id: <x7emr14m96.fsf@sysarch.com>

>>>>> "AT" == Adam Turoff <ziggy@panix.com> writes:

  AT> Uri Guttman  <uri@fastengines.com> wrote:
  >> but this thread is getting off perl and the usage survey. i never heard
  >> much about my conjecture that commercial unix users are more likely to
  >> know and use perl than linux users because of their more professional
  >> background. 

  AT> While I accept that you have a very bad impression about linux
  AT> users, they're not really the great unwashed you make them out to
  AT> be.  I seem to remember that a certain Mr. Wall and a certain
  AT> Mr. Christiansen count themselves among the ever-increasing
  AT> numbers of linux users.  :-)

  AT> Your argument seems to have the unstated basis that anyone who
  AT> uses/has used solaris is a solaris user and more likely to be
  AT> profesional, whether or not they use linux.

i am not as anti-linux or pro-solaris as you think i am. i was just
commenting on the data from the survey and why so many sun users
(solaris and sunos) are using perl vs linux vs. other unix vs nt. i was
not making any comment on the users but on their demographics. my
impression is that you don't have that many kids (< 40 years :-) hacking
solaris whereas they may hack linux. professional computer and unix
geeks who have been in the business for over 10 years (before linux AND
perl) probably have been exposed to sunos/solaris. they also might have
been using perl for a long time. i learned it over 8 years ago, way
longer than most perl hackers. i go back to before camel 1, circa
4.0[12]0. i learned perl from the SINGLE man page (40 pages printed). my
take on linux in the real world is more younger types use it for various
reasons, price, source code, anti-u$hit, etc. i am all for that. but
they don't all have the years of C, shells, sed, awk that begat perl,
while us geezers do. so i feel more of us sun hackers would gravitate to
using perl than you young'uns. just statistics, not bigotry. there are
other choices (i won't mention them but you know what they are) so newer
unix hackers may choose them over perl. long time hackers would stick
with perl. i could use those brand x scripting tools, but i stay with
the one i brung to the dance!

the bottom line is that i think the average sun user will more likely
use perl than the average linux user. i think there are many more linux
boxes out there than suns, but there were almost equal numbers of perl
users in the survey. that means a higher percentage of sun users use
perl than linux users. this correlation is the gist of my argument.

that is what i have been trying (unsuccessfully) to say. the sun numbers
were very high and i feel rightly so. sun users know a good tool when we
see one!

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire  ----------------------  Perl, Internet, UNIX Consulting
uri@sysarch.com  ------------------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Tue, 17 Nov 1998 23:31:32 -0500
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Perl vs C
Message-Id: <1dinuju.1ydzsk2usjtdsN@bay1-380.quincy.ziplink.net>

Nathan V. Patwardhan <nvp@shore.net> wrote:

> I'm sure that Hilter could've taken every last square mile of Europe
> and maybe even Asia by the time this thread will have come to an end.

"Ooh planning a little excursion are we Mr Hilter?"

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: 18 Nov 1998 05:10:27 GMT
From: richm@ucesucks.mulveyr.roc.servtech.com (Rich)
Subject: Re: Perl5
Message-Id: <slrn754lk6.31i.richm@ll.aa2ys.ampr.org>

On Tue, 17 Nov 1998 16:56:26 -0800, Paul Deshaies <pauljr@nt.com> wrote:
>Hi everyOne,
>	I just sent a message asking for help. I'm pretty sure installing PERL5
>on my UNIX server would get me rid of my problem. My question now is how
>long does it take to install PERL5 and what problems can I expect?
>

   Well, I've installed Perl 5 on Linux, SunOS4_1_3, and Solaris 7 boxes.  None of
them took more than about 1/2 hour to build.  If you're confused by some of the
configuration questions, just accept the defaults - they'll probably work. 

- Rich


--
Rich Mulvey                                         
My return address is my last name, 
   followed by my first initial, @mulveyr.roc.servtech.com        
http://mulveyr.roc.servtech.com
Amateur Radio: aa2ys@wb2wxq.#wny.ny.usa


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

Date: Fri, 13 Nov 1998 23:23:23 GMT
From: pramsey@iname.com
Subject: Trying to use ep3 module to build a c preprocessor emulator
Message-Id: <364cbe84.1557274342@news>

I'm having some trouble getting ep3 to emulate the c preprocessor.
I have a ton of old stuff that uses cpp for macro processing totally 
unrelated to c.  I now have to move it all to Windoze NT, and 
would like to be able to duplicate all my old results using ep3.

Here's the catch:

The existing cpp directives very often contain stuff that looks like
this

#ifndef problem
#define problem trouble
#endif

That way, I can use the normal redefiniton of problem as trouble
most of the time.  Sometimes, however, I need to define problem
to be something else, using -Dproblem=opportunity on the
command line.  (Actually, it's much more complicated than this, 
because I include files that contain #ifndef blocks, etc., but this
explanation should suffice for now.)

So I put some command line parsing code in my ep3
script to fill up a hash, culminating in 
 
while (($was, $is) = each %command_line_hash) {
  $file->ep3_defines("$was=$is");
}

This code successfully redefines an individual word as expected, 
but the #ifndef block above still gets executed.

  from here on out, my comments are indented 2
  while file text is left-justified.
  As a stripped down example, the following code 

require 5;
use Text::EP3;
# $was = 'problem';
# $is = 'challenge';
my $file = Text::EP3->new;
$file->ep3_delimeter('#');
# $file->ep3_defines("$was=$is");
$file->ep3_execute;
1;
}

  operating on the following file

#ifndef problem
#define problem trouble
#endif

this is a problem for that boy

  produces

this is a trouble for that boy

  As expected.  Uncommenting the $was, $is and ep3_defined
  lines from the code while removing the #ifndef block produces

this is a challenge for that boy

  Again as expected, but if both the $is, $was and the
  #ifndef block are included, the result is

this is a trouble for that boy


  It appears as though problem is not defined to be challenge
  until after it has already been defined to be trouble,
  which is not what I need done.

  1.  Is this a bug or a feature?
  2.  Any suggestions on how to work around this, with
  great preference given to not having to modify the existing
  cpp directives?

  A lot of these sorts of things can go away if I re-write
  the cpp stuff using ep3 features, which will happen in the
  future, but for now I have to get all this legacy code
  working so I can get everybody else moving in the right 
  direction.




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

Date: Tue, 17 Nov 1998 22:53:09 -0500
From: sara starre <nospam.gear4u@hotmail.com>
Subject: Two-Part RE question
Message-Id: <365244A5.33609DA8@hotmail.com>

OK, this is a two-part question. The first part is only for the perl
newsgroup hoseheads who flame everyone who asks a question. Here is your
part, put your might brain to work on it and post your solution to
alt.whocares:

                  interpret this special RE I designed expecially for
you: $x =~ [4q];

Now, for the 90% of you out there who are here to help the less-gifted
(like me) here is my question:

I wish to extract a string between two different characters from a
larger
string. For example, I want to extract everything between "[" and "]",
such as extract man from cat[man]dog.

Now, I brute (in my case brute-ette?) forced a solution:
#!/usr/bin/perl -w
#
# Created by sara starre, 11/98
#
# ---------------------------------------------------------------------
#
  $x = 'cat[man]dog';
  $i1=index($x,"\[");
  $i2=index($x,"\]");
  $y =substr($x,$i1+1,$i2-$i1-1);
  print "input: $x\noutput: $y\n";

]$ perl x.pl
input: cat[man]dog
output: man

Isn't there an easier way to accomplish this?

I looked in the perl FAQ- a search on "extract" only produced substr,
which is what I'm already using.

I read my Tom C book- I think this is a little advanced for that text.

This isn't a homework assignment, no school would have me after my
performance on my first two masters'!

I made this test case that works, but I want something pretty and
elegante'! OK your turn...

HUG,
S



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

Date: 18 Nov 1998 04:30:21 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Two-Part RE question
Message-Id: <slrn754jat.d9r.sholden@pgrad.cs.usyd.edu.au>

On Tue, 17 Nov 1998 22:53:09 -0500, sara starre <nospam.gear4u@hotmail.com>
	wrote:
>OK, this is a two-part question. The first part is only for the perl
>newsgroup hoseheads who flame everyone who asks a question. Here is your
>part, put your might brain to work on it and post your solution to
>alt.whocares:
>
>                  interpret this special RE I designed expecially for
>you: $x =~ [4q];

I hope you feel better, but you have just switched off a large 
number of people who might actually have the answer you want...

Anyway what do you think is wrong with your question :
1. you ask a straight forward question.
2. you post code that does the job, but are curious as to other ways.
3. you indicate that you have RTFM already.

So why do you expect to get flamed. It would have been an almost perfect 
post but you had to go and alienate people anyway.

Very strange...

>
>Now, for the 90% of you out there who are here to help the less-gifted
>(like me) here is my question:
>
>I wish to extract a string between two different characters from a
>larger
>string. For example, I want to extract everything between "[" and "]",
>such as extract man from cat[man]dog.
>
>Now, I brute (in my case brute-ette?) forced a solution:
>#!/usr/bin/perl -w
>#
># Created by sara starre, 11/98
>#
># ---------------------------------------------------------------------
>#
>  $x = 'cat[man]dog';
>  $i1=index($x,"\[");
>  $i2=index($x,"\]");
>  $y =substr($x,$i1+1,$i2-$i1-1);
>  print "input: $x\noutput: $y\n";
>
>]$ perl x.pl
>input: cat[man]dog
>output: man
>
>Isn't there an easier way to accomplish this?

You could try 
$x=~/\[(.*?)\]/ and $y = $1;

And I'm sure there are some other ways as well (this is perl after all).

Of course you would add error checking to you code before you actually used 
it (what if there is no [ or ]?). Also if nesting of []s is possible then
a whole new approach would be needed.

Which of the above two solutions you prefer depends on if you are going to
do this lots and runtime is a concern (in which case use substr), or you
find regular expressions more readable (in which case use a regex).

Of course I'm sure there is a faster and more readable way to do this 
(chances are those who know it won't reply (except to the first question)
due to your strange approach at the top of the post).

As for the speed difference :
Benchmark: timing 1000000 iterations of regex, substr...
     regex: 38 wallclock secs (37.19 usr +  0.08 sys = 37.27 CPU)
    substr: 23 wallclock secs (22.60 usr +  0.04 sys = 22.64 CPU)

Replace the string to be searched with 'cat['.("abc"x1000).'man]dog' and the
difference is more noticable.

Benchmark: timing 10000 iterations of regex, substr...
     regex: 16 wallclock secs (16.37 usr +  0.00 sys = 16.37 CPU)
    substr:  1 wallclock secs ( 0.67 usr +  0.00 sys =  0.67 CPU)


Just in case someone wants to point out my error in the my benchmark code
(I'm good at getting these worng and thus getting the opposite results 
than reality would indicate)...

use Benchmark;
$x = 'cat[man]dog';
timethese(10000, {
                "substr" => \&use_substr,
                "regex" => \&use_regex,
                });
sub use_substr {
        $i1=index($x,"\[");
        $i2=index($x,"\]");
        $y =substr($x,$i1+1,$i2-$i1-1);
}
sub use_regex {
        $x=~/\[(.*?)\]/ and $y = $1;
}
-- 
Sam

You are bordering on ridiculous if you think you need to support your
premises.  Such an argument is an infinite regression.
 	--George Reese in <wv0O1.1521$Ge.4809664@ptah.visi.com>


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

Date: 18 Nov 1998 00:47:53 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Two-Part RE question
Message-Id: <x7af1p4kmu.fsf@sysarch.com>

>>>>> "ss" == sara starre <gear4u@hotmail.com> writes:

despam protected so i could email a response and those fine folks can
email you too!

  ss> OK, this is a two-part question. The first part is only for the perl
  ss> newsgroup hoseheads who flame everyone who asks a question. Here is your
  ss> part, put your might brain to work on it and post your solution to
  ss> alt.whocares:
      ^^^^^^^^^^^^
my isp doen't carry that group!

  ss>                   interpret this special RE I designed expecially for
  ss> you: $x =~ [4q];

this matches '4' or 'q'. any more interpretation needed?

  ss> Now, for the 90% of you out there who are here to help the less-gifted
  ss> (like me) here is my question:

and you will stay that way with your attitude too. we don't dislike
answering questions, just FAQ's and for people who haven't done their
homework. or who don't submit sample code and data. or who use bad
subject lines. or who demand help immediately. 

but since you seem to be such a nice chick (slur intended), and your
subject was decent, and you actually showed code you wrote (and it
works!!), and you asked a real question that is not directly asnwered in
the faq, i will bestow upon you some answers. you may consider yourself
blessed into a class.

:-)

<snip of working substr code>

substr is fine for this task, it might even be faster than regexes in
some cases.

  ss> Isn't there an easier way to accomplish this?

define easier.

  ss> I looked in the perl FAQ- a search on "extract" only produced substr,
  ss> which is what I'm already using.

how about a one liner with substr (assuming the string is in $_:

$x = substr( $_, index ($_, '[') + 1, rindex( $_, ']' ) - length );

  ss> I read my Tom C book- I think this is a little advanced for that text.

???

more likely the opposite. you want a simple regex and the cookbook
is more about idioms and problem solving.

  ss> I made this test case that works, but I want something pretty and
  ss> elegante'! OK your turn...

you didn't define whether there can be no chars between the []? or
whether there can be more than one [] or isolated [ or ] in the
string. i will assume on matched pair of [] for this answer.

how about a simple regex?

	$x = 'cat[man]dog';
	$x =~ /\[(.*)]/ ;
	print "input: $x\noutput: $1\n";

or a more complex one that works with extra [ or ] (depending on your
needs you can fine tune this).

this will do a minimal match (shortest string between the [])

	$x =~ /\[(.*?)]/ ;

perl -lpe '/\[(.*?)]/; $_ = $1'
js[jwj]ejej]
jwj
jjwhre[kwk[djeje]
kwk[djeje
wjwj[sjsj[djjd]jej3]
sjsj[djjd

but that doesn't work well if you want no [] in the result.
so we change the regex to explicitly not allow [ in the match:

perl -lpe '/\[([^[]*?)]/; $_ = $1'
jsjs[wjwjw[dje]wjw]rjr
dje
sjs[ejw][djwe]kwkw
ejw
hjs[jdjd[wjwjw[wjwj]
wjwj


  ss> HUG,

sorry, i am married. you have to kiss me. or apply the first regex you
mention at the top of the post!!

hth,

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire  ----------------------  Perl, Internet, UNIX Consulting
uri@sysarch.com  ------------------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Wed, 18 Nov 1998 03:30:12 GMT
From: tamcgee@home.com (Tom McGee)
Subject: Re: Win32 executing a .pl or .cgi
Message-Id: <tamcgee-1711982231070001@cc1017583-a.union1.nj.home.com>

I run Website professional on an NT4 box, and I too can't just type the
name of the scriptr. I have to type "perl myscript.pl" for it to run from
the command line.

But that doesn't stop my server from running cgi properly. 

Your command prompt issue is a red herring. Check your server docs.

--Tom



In article <72t1eb$9op$1@news.hoosier.net>, "Rambler"
<rambler@bloomington.in.us> wrote:

>>I have associated the .pl and .cgi file extensions with perl.exe on my
>>system and can double click on the file in the explorer and the program
>>runs.  I can also at the dos prompt tyep 'perl test.pl' and the program runs
>>but I can't just type test.pl.  All I get is "Bad command or file name
>>".  This is obviously preventing anything to work from a web page.
>>
>>Can anyone tell me what I am doing wrong?  All I can find anyplace I have
>>search says I must simply associat the pl and cgi extensions with perl.exe.
>>
>>--
>>Rambler


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

Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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

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