[25145] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7394 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 11 18:05:31 2004

Date: Thu, 11 Nov 2004 15:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 11 Nov 2004     Volume: 10 Number: 7394

Today's topics:
        backreferneces in search pattern <mstep@t-online.de>
        FAQ 7.9: How do I create a module? <comdog@panix.com>
    Re: FAQ 9.16: How do I decode a CGI form? <nobull@mail.com>
    Re: FAQ 9.16: How do I decode a CGI form? <uri@stemsystems.com>
    Re: FAQ 9.16: How do I decode a CGI form? <noreply@gunnar.cc>
        How do I get the application path <tom.tingdale@sbcglobal.net>
    Re: how greedy is nongreedy in regexp ? <joe+usenet@sunstarsys.com>
    Re: human nature of perl (new operators etc) ctcgag@hotmail.com
    Re: Need perl+java programmer <dha@panix.com>
    Re: Need perl+java programmer <postmaster@castleamber.com>
    Re: Overloaded stringification lost (Anno Siegel)
        PERL+CGI+PLUG-IN architecture <colo@megapolis.pl>
    Re: PERL+CGI+PLUG-IN architecture <emschwar@pobox.com>
    Re: PERL+CGI+PLUG-IN architecture <colo@megapolis.pl>
    Re: perldoc mirror? <dha@panix.com>
    Re: regexp s// too greedy (bettyann)
    Re: regexp s// too greedy (Anno Siegel)
    Re: regexp s// too greedy <noreply@gunnar.cc>
    Re: Two operations with one last if? <nobull@mail.com>
    Re: Two operations with one last if? <mritty@gmail.com>
    Re: Two operations with one last if? <uri@stemsystems.com>
    Re: Two operations with one last if? <hightec101@hotmail.com>
    Re: Two operations with one last if? <hightec101@hotmail.com>
    Re: Two operations with one last if? <hightec101@hotmail.com>
    Re: Two operations with one last if? <nobull@mail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 11 Nov 2004 22:09:59 +0100
From: Marek Stepanek <mstep@t-online.de>
Subject: backreferneces in search pattern
Message-Id: <BDB993B7.B7FE%mstep@t-online.de>



Hallo all,


I try to set up a Perl-Filter (for BBEdit on Macintosh). I want to match and
print out all gifs needed for a rollover in an HTML-File. The filter should
match 

onmouseover="document.podium.src='../../pix/grafix/hili_podium.gif';

but also beasts like the following :

onmouseover="document.podium.src='../../pix/logos/theembassy1.gif';
document.bios.src='../../pix/logos/theembassy2.gif';
document.addresses.src='../../pix/logos/theembassy3.gif';
document.events.src='../../pix/logos/theembassy4.gif';
document.priwat.src='../../pix/logos/theembassy5.gif';
document.yrpodium.src='../../pix/logos/theembassy6.gif';
document.logo.src='../../pix/logos/hili_pilogo.gif'"


the result should print from the above examples :

'../../pix/grafix/hili_podium.gif',
'../../pix/logos/theembassy1.gif',
'../../pix/logos/theembassy2.gif',
'../../pix/logos/theembassy3.gif',
'../../pix/logos/theembassy4.gif',
'../../pix/logos/theembassy5.gif',
'../../pix/logos/theembassy6.gif',
'../../pix/logos/hili_pilogo.gif',


I am labouring since a long while already on this filter. Could somebody
help me out ? I am beginner and want learn Perl very much.

This filter here produces the following error :


    Modification of a read-only value attempted <> line 1.


(mind line breaks from my email client)


#!/usr/bin/perl -w


while (<>) {
    ($1, $2, $3) = 
m!onmouseover="[^']+'([^']+)'(?:(?:(?:;\s+[^']+)'([^']+)')+)?(?:(?:[^']+)'([
^']+)')?"!g;
    my @results = ($1, $2, $3);
    foreach $i (0..$#results) {
        print "'", $i, "',\n";
        }
}

My question is not about the grep search pattern, but how to put the
backreferences into an array to print it out.

one other try gives :

    Use of uninitialized value in print <> line 2.


#!/usr/bin/perl -w

while (<>) {
   while (
 s!onmouseover="[^']+'([^']+)'(?:(?:(?:;\s+[^']+)'([^']+)')+)?(?:(?:[^']+)'(
[^']+)')?"!!g ) {print "'", $1, "',\n"; print "'", $2, "',\n"; print "'",
$3, "',\n";}
   }

thank you



marek



-- 
______________________________________________________________________
___PODIUM_INTERNATIONAL_//_the_embassy_for_talented_young_musicians___
_______Marek_Stepanek__mstep_[at]_PodiumInternational_[dot]_org_______
__________________http://www.PodiumInternational.org__________________
______________________________________________________________________







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

Date: Thu, 11 Nov 2004 23:03:01 +0000 (UTC)
From: PerlFAQ Server <comdog@panix.com>
Subject: FAQ 7.9: How do I create a module?
Message-Id: <cn0r35$r64$1@reader1.panix.com>

This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with Perl.

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

7.9: How do I create a module?

    A module is a package that lives in a file of the same name. For
    example, the Hello::There module would live in Hello/There.pm. For
    details, read perlmod. You'll also find Exporter helpful. If you're
    writing a C or mixed-language module with both C and Perl, then you
    should study perlxstut.

    The "h2xs" program will create stubs for all the important stuff for
    you:

      % h2xs -XA -n My::Module

    The "-X" switch tells "h2xs" that you are not using "XS" extension code.
    The "-A" switch tells "h2xs" that you are not using the AutoLoader, and
    the "-n" switch specifies the name of the module. See h2xs for more
    details.



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

Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short.  They represent an important
part of the Usenet tradition.  They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.

If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile.  If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.

Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release.  It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.

The perlfaq manual page contains the following copyright notice.

  AUTHOR AND COPYRIGHT

    Copyright (c) 1997-2002 Tom Christiansen and Nathan
    Torkington, and other contributors as noted. All rights 
    reserved.

This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.


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

Date: Thu, 11 Nov 2004 19:26:15 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: FAQ 9.16: How do I decode a CGI form?
Message-Id: <cn0e43$bnd$1@sun3.bham.ac.uk>



brian d foy wrote:

> In article <2vgv25F2lgk92U1@uni-berlin.de>, Gunnar Hjalmarsson
> <noreply@gunnar.cc> wrote:
> 
> 
>>PerlFAQ Server wrote:
>>
>>>    You use a standard module, probably CGI.pm.
> 
> 
>>>    You'll see a lot of CGI programs that blindly read from STDIN the number
>>>    of bytes equal to CONTENT_LENGTH for POSTs, or grab QUERY_STRING for
>>>    decoding GETs. These programs are very poorly written. They only work
>>>    sometimes.
> 
> 
>>>    In short, they're bad hacks. Resist them at all costs.
>>
>>That diatribe is unprofessional, adversely affects the credibility of 
>>this FAQ entry, and should better be dropped. The above suggestion would 
>>be a sufficient replacement.
> 
> 
> I don't think it's unprofessional (I didn't write it).

I concur with Gunnar about this rant adversely affecting credibility. 
(Personal winge: I don't like the use of the word 'unprofessional'.  A 
professional is, by definition, someone getting paid to work on 
something.  The implication of using 'unprofessional' in this way that 
work for which people is paid is necessaritly of a higher quality than 
work that is given freely is anathma to me).

>  It is 
> opinionated, but the so are the people who think they can write their
> own parsing code and get it to work.

People who write (and maintain) their own code are not the real problem. 
  The problem is the cut-and-paste school of code reuse.



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

Date: Thu, 11 Nov 2004 20:01:24 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: FAQ 9.16: How do I decode a CGI form?
Message-Id: <x7lld8noj0.fsf@mail.sysarch.com>

>>>>> "BM" == Brian McCauley <nobull@mail.com> writes:

  BM> I concur with Gunnar about this rant adversely affecting
  BM> credibility. (Personal winge: I don't like the use of the word
  BM> 'unprofessional'.  A professional is, by definition, someone getting
  BM> paid to work on something.  The implication of using 'unprofessional'
  BM> in this way that work for which people is paid is necessaritly of a
  BM> higher quality than work that is given freely is anathma to me).

i disagree with your definition of professional. in my high school drama
class our teacher said that there were professional (paid) productions
that were amateurish and amatuer productions that were professional. i
know many open source coders who i would call professional even without
getting paid and we have all seen paid cow-orkers that shouldn't be in
the coding profession.

so doing something like coding a cgi parser by yourself (or cargo
culting one) is unprofessional whether you get paid or not.

very recently i saw some automatically generated form handling scripts
(the site claims it can generate in multiple web langs. i bet equally
badly). it had a classic cargo culted buggy cgi parser and perl4 style
coding with locals. this is 'shareware' and the author is getting paid
for this cruft. not very professional IMO.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Thu, 11 Nov 2004 21:08:46 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: FAQ 9.16: How do I decode a CGI form?
Message-Id: <2vhv6eF2levcbU1@uni-berlin.de>

Uri Guttman wrote:
> Brian McCauley writes:
>> I concur with Gunnar about this rant adversely affecting
>> credibility. (Personal winge: I don't like the use of the word
>> 'unprofessional'.  A professional is, by definition, someone
>> getting paid to work on something.  The implication of using
>> 'unprofessional' in this way that work for which people is paid is
>> necessaritly of a higher quality than work that is given freely is
>> anathma to me).
> 
> i disagree with your definition of professional. in my high school
> drama class our teacher said that there were professional (paid)
> productions that were amateurish and amatuer productions that were
> professional. i know many open source coders who i would call
> professional even without getting paid and we have all seen paid
> cow-orkers that shouldn't be in the coding profession.

Maybe

     s/unprofessional/unworthy/

to prevent interpretation differences.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Thu, 11 Nov 2004 22:48:53 GMT
From: Tom Tingdale <tom.tingdale@sbcglobal.net>
Subject: How do I get the application path
Message-Id: <isq7p0t5vh5b4mpgv78em2qe490if72muo@4ax.com>

I have a Win32 program that I want to make portable. I have converted
my perl program into an executale. How can I get the absolute path to
my executable application?

Thanks, Tom


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

Date: 11 Nov 2004 15:19:19 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: how greedy is nongreedy in regexp ?
Message-Id: <87bre42l6g.fsf@gemini.sunstarsys.com>

Brian McCauley <nobull@mail.com> writes:

> But since this is a question about canonicalising URLs it would seem more
> appropriate to use the URI module.  However the canonical() method of URI
> doesn't do this.  Is this right or should it be considered a bug in URI?

I think it mostly depends on whether or not the URI is relative 
or absolute.  According to rfc 2396 Section 4:

     URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ]

   The syntax for relative URI is a shortened form of that for absolute
   URI, where some prefix of the URI is missing and certain path
   components ("." and "..") have a special meaning when, and only when,
   interpreting a relative path.  The relative URI syntax is defined in
   Section 5.

Section 5.2 step 6 talks about the semantics of "../", but that's only 
in the narrow context of resolving a relative uri into an absolute one.
AFAICT 2396 discusses "canonicalization" of an absolute URI only as it
relates to %XX escapes.

-- 
Joe Schaefer


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

Date: 11 Nov 2004 22:14:42 GMT
From: ctcgag@hotmail.com
Subject: Re: human nature of perl (new operators etc)
Message-Id: <20041111171442.799$21@newsreader.com>

"I H H" <iohihuh@INVALID.yahoo.com> wrote:
> Hello,
>
> perl's syntax is what it is (as I undertood correctly)  because it was
> supposed to be like human languages.
> Meaning a word or a phrase has context bind meaning. If context changes,
> the meaning changes too.
> Should there be more human nature properties in perl?
>
> Could these be useful? At least might make scripting even more faster.
>
> Division operator in string context would be like 'split':

To the small extent that there is such a thing as "string context"
in Perl, that context is provided by the operator.  The operator
can't be both dependent on and the source of this "context".



>
> @cols=split(/$expression/,$line); <=> @cols=$line/$expression;
>
> ---
> open(F,$file);
> @lines=<F>;
> close(F);
>
>   <=>
>
> @lines<$file>\o /\n;

I'm not sure I understand what you are getting at here.

> ---
> if($x>$y){do_something $arr[$x];}  <=>  $arr[(if($x>$y))]  cond returning
> values that fill it.

I've thought there should be some kind of defined_and or exists_and.

It would short-circuit and return undef if not
defined or exists, and would evaluate to the value of its argument
otherwise.

if (exists $h{$j}{$k}{L}{M}{$n}{$o}{P} and
$h{$j}{$k}{L}{M}{$n}{$o}{P}==7)...

if (exists_and $h{$j}{$k}{L}{M}{$n}{$o}{P} ==7 ) ...

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Thu, 11 Nov 2004 21:07:33 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: Need perl+java programmer
Message-Id: <slrncp7l4l.5c7.dha@panix2.panix.com>

On 2004-11-11, surya <surya_sahu@ao.uscourts.gov> wrote:
> We need help 

You have posted a job posting or a resume in a technical group.

Longstanding Usenet tradition dictates that such postings go into
groups with names that contain "jobs", like "misc.jobs.offered", not
technical discussion groups like the ones to which you posted.

Had you read and understood the Usenet user manual posted frequently to
"news.announce.newusers", you might have already known this. :)  (If
n.a.n is quieter than it should be, the relevent FAQs are available at
http://www.faqs.org/faqs/by-newsgroup/news/news.announce.newusers.html)
Another good source of information on how Usenet functions is
news.newusers.questions (information from which is also available at
http://www.geocities.com/nnqweb/).

Please do not explain your posting by saying "but I saw other job
postings here".  Just because one person jumps off a bridge, doesn't
mean everyone does.  Those postings are also in error, and I've
probably already notified them as well.

If you have questions about this policy, take it up with the news
administrators in the newsgroup news.admin.misc.

http://jobs.perl.org may be of more use to you

Yours for a better usenet,

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
In the silence that followed, Homer was heard to mutter,
"Mmmm... context- dependent semantics..."
	- Darrin Edwards in c.l.p.m.


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

Date: 11 Nov 2004 21:59:44 GMT
From: John Bokma <postmaster@castleamber.com>
Subject: Re: Need perl+java programmer
Message-Id: <Xns959EA2B6BD4Ccastleamber@130.133.1.4>

Laura wrote:
 
> How did you ever get your Perl patform embedded in Java?  What kind of
> a crazy scheme was that?  I would recommend hiring a Java and a Perl
> programmer for this job because Perl is a left-brain language while
> Java is right-brain.  You are not likely to find someone actively at
> the top of their abilities in both languages.

Odd. I try to be that :-)

-- 
John                   Small Perl scripts: http://johnbokma.com/perl/
               Perl programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html
                        


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

Date: 11 Nov 2004 21:50:14 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Overloaded stringification lost
Message-Id: <cn0mqm$ora$2@mamenchi.zrz.TU-Berlin.DE>

Eric <jain@gmx.net> wrote in comp.lang.perl.misc:
> > No, AUTOLOAD isn't the culprit.
> 
> You're right.
> 
> After adding the following code to the _get_scalar method (before
> returning the $value) everything works fine:
> 
>   bless $value, 'Model'
>     if ref $value eq 'Model';
> 
> Weird...

Well, frankly, your class is pretty weird to begin with :)

Anyway, you *may* have hit upon a known bug, not in overload, but
one that shows up in overload under certain conditions.  It's been
a while and I'm hazy on the details, but the workaround was to bless
something into the overloading class to make overloading work as
expected.  That could be the reason why the no-op appears to have
an effect.  Maybe Ilya can add a word to this.

Anno


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

Date: Thu, 11 Nov 2004 23:48:59 +0000
From: Colombo <colo@megapolis.pl>
Subject: PERL+CGI+PLUG-IN architecture
Message-Id: <cn0q1u$qso$2@achot.icm.edu.pl>

Hi,
I'm looking for any information (or example programs) about writing 
programs in perl (cgi) in plug-in architecture. I was searching almost 
everywhere with no result :(.

Colombo


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

Date: Thu, 11 Nov 2004 15:52:55 -0700
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: PERL+CGI+PLUG-IN architecture
Message-Id: <eto3bzgath4.fsf@wilson.emschwar>

Colombo <colo@megapolis.pl> writes:
> I'm looking for any information (or example programs) about writing
> programs in perl (cgi) in plug-in architecture. I was searching almost
> everywhere with no result :(.

I understand English is probably not your first language, but I must
confess I have no idea what you mean by "plug-in architecture".  For
writing CGI in Perl, start with the documentation for CGI.pm and see
how far that gets you.  If you have questions about writing CGI
programs in general, ask around in comp.infosystems.www.authoring.cgi.

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


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

Date: Fri, 12 Nov 2004 00:07:19 +0000
From: Colombo <colo@megapolis.pl>
Subject: Re: PERL+CGI+PLUG-IN architecture
Message-Id: <cn0r4a$rlu$1@achot.icm.edu.pl>

Eric Schwartz wrote:
> I understand English is probably not your first language, but I must
> confess I have no idea what you mean by "plug-in architecture".  For
> writing CGI in Perl, start with the documentation for CGI.pm and see
> how far that gets you.  If you have questions about writing CGI
> programs in general, ask around in comp.infosystems.www.authoring.cgi.
> 
> -=Eric

You don't know what are plugins?
I have to write a program which will load a plugin e.g. written by some
else, and will use it. In windows programing I would use dll libraries
but afaik there is nothing like that in perl. So I ask if anyone knows
how to make this kind of programs.
Yes english isn't my first language, but is it so big problem?

Colombo


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

Date: Thu, 11 Nov 2004 21:10:15 +0000 (UTC)
From: "David H. Adler" <dha@panix.com>
Subject: Re: perldoc mirror?
Message-Id: <slrncp7l9n.5c7.dha@panix2.panix.com>

On 2004-11-11, Matt C <google@digitalbubblebath.com> wrote:
> Thanks for the reply- I'm on site tho and the box I'm working on has
> no docs installed...

I'm guessing this is the time to point out that many feel that a perl
installation that's missing its docs is very broken...

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
"Shrink your opponents' heads before they shrink yours!" - The
Bomboras


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

Date: 11 Nov 2004 12:22:46 -0800
From: bettyann@campbell.com (bettyann)
Subject: Re: regexp s// too greedy
Message-Id: <287ea6c.0411111222.4ad13ce4@posting.google.com>

thanks to everyone who replied -- all suggestions are good.

stuart and gunnar -- using pattern ([^,]*,) rather than (.*?,) works
as i need.  i understand now that i need to use a pattern that
describes the negative of what i want rather than a pattern that
describes what i *do* want.  thanks for the suggestion and the new way
of thinking.

len and anno -- i did consider using split/join but since the CSV file
has thousands of lines, i thought maybe regexp might be faster.  i'm
not sure, tho, as i haven't done a benchmark.

janek -- Text::CSV_XS looks really nice.  i'll certainly investigate
this package more in the future.

one last clarification, i actually have more than two different cases,
ie:

s/^(([^,]*,){5}hold.bmp)/$1,0/;
s/^(([^,]*,){5}go.bmp)/$1,1/;
s/^(([^,]*,){5}slow.bmp)/$1,2/;
s/^(([^,]*,){5}speed.bmp)/$1,3/;
s/^(([^,]*,){5}NaN)/$1,-1/;

so i don't think the "?:" combination would be as straight forward.

thanks for all the help.  greatly appreciated.
- bettyann


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

Date: 11 Nov 2004 21:33:10 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: regexp s// too greedy
Message-Id: <cn0lqm$ora$1@mamenchi.zrz.TU-Berlin.DE>

bettyann <bettyann@campbell.com> wrote in comp.lang.perl.misc:
> thanks to everyone who replied -- all suggestions are good.

[...]

> len and anno -- i did consider using split/join but since the CSV file
> has thousands of lines, i thought maybe regexp might be faster.  i'm
> not sure, tho, as i haven't done a benchmark.

I don't think split will be significantly slower than a regex solution.
While split *implies* the use of a regex for the delimiter, that is
usually a very simple one which will predictably perform well enough.
The rest split does is (in principle, not in detail) what a capturing
regex does too.  The performance of a pure-regex solution is much
harder to predict.

If anything, splice may slow it down a bit, but no more than the actual
substitution slows down the "regex" solution.  I wouldn't expect a
significant difference between split and regex, but if there is, I'd
expect the regex to be slower.

> janek -- Text::CSV_XS looks really nice.  i'll certainly investigate
> this package more in the future.
> 
> one last clarification, i actually have more than two different cases,
> ie:
> 
> s/^(([^,]*,){5}hold.bmp)/$1,0/;
> s/^(([^,]*,){5}go.bmp)/$1,1/;
> s/^(([^,]*,){5}slow.bmp)/$1,2/;
> s/^(([^,]*,){5}speed.bmp)/$1,3/;
> s/^(([^,]*,){5}NaN)/$1,-1/;
> 
> so i don't think the "?:" combination would be as straight forward.

Now this is something that's going slow it down a bit, matching n times
for n possibilities.  A hash lets you do them all in one go.  Quite simple:

    my %replace = (
        'hold.bmp' => 0,
        'go.bmp'   => 1,
        # ...
        NaN        => -1,
    );

Then the five substitutions could become (untested, probably more
the spirit than the real thing)

    s/^(([^,]*,){5}([^,]*))/$1,$replace{ $2}/;

But I can't say I like the regex you're using.  Only a short regex
is a good regex, that one is much too long.  I still favor the
split solution, if only because it works on the actual data, not
their messy representation.  The hash can be used with that too,
in the obvious way.

Anno


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

Date: Thu, 11 Nov 2004 22:43:57 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: regexp s// too greedy
Message-Id: <2vi4pgF2l8o7qU1@uni-berlin.de>

bettyann wrote:
> one last clarification, i actually have more than two different cases,
> ie:
> 
> s/^(([^,]*,){5}hold.bmp)/$1,0/;
> s/^(([^,]*,){5}go.bmp)/$1,1/;
> s/^(([^,]*,){5}slow.bmp)/$1,2/;
> s/^(([^,]*,){5}speed.bmp)/$1,3/;
> s/^(([^,]*,){5}NaN)/$1,-1/;
> 
> so i don't think the "?:" combination would be as straight forward.

No, but in that case you can use a hash instead. Something like:

     my %hash = (
         'hold.bmp'  => ',0',
         'go.bmp'    => ',1',
         'slow.bmp'  => ',2',
         'speed.bmp' => ',3',
         NaN         => ',-1',
     );

     s/^((?:[^,]*,){5}([^,]+))/$1.($hash{$2} or '')/e;

After all, parsing thousands of lines once should reasonably be faster 
than doing it six times.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Thu, 11 Nov 2004 19:03:34 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Two operations with one last if?
Message-Id: <cn0cph$asu$1@sun3.bham.ac.uk>



sam wrote:

>  Is the following "legal" and "sensible?"

 >       while(<LOGFILE>) {
 >          undef($splinter);
 >          @record = split;
 >          $archivesection = $record[6];
 >          ($interestingpart, $junk) = split(/\?/,$archivesection,2);
 >          $userid = $searchpattern{$interestingpart} && $splinter =
 >             $_, last if(defined($searchpattern{$interestingpart}))
 >
 >         if (defined($splinter) &&
 >                (&daily || &weekly || &monthly || &yearly)) {
 >                &add_splinter_to_pile;
 >         }
 >      }

While it is legal to fail to declare all your variables as lexically 
scoped in the smallest applicable scope it is cetainly not sensible to 
do so without a positive reason.

While it is legal to use the Perl4 subroutine calling convention is not 
sensible to do so without a positive reason.

While it is legal to use shared variables to pass information between a 
subroutine and its caller is not sensible to do so without a positive 
reason.

It is legal to save the result of a short expression into a variable 
whose name is longer than the expression and then only use that variable 
once ($archivesection,@record).  It is, of course, not sensible.

It is legal to store data you don't want into a variable you never use 
again ($junk).  It is, of course, not sensible.  (Just don't save it).

It is legal to use && and , to combine multiple expressions into one so 
that they can be goverened by a single 'if' statement qualifier.   It 
can sometimes even be sensible to do so where it aid readability.

It is not legal to attempt to assign to the result of an && opreator. To 
get "Can't modify logical and (&&) in scalar assignment".

I shall assume '&&' should read 'and' or ','.

However once it gets above a very small number of characters it would be 
more sensible just to use a proper 'if' statement.

It is legal to have a variable with a name (%searchpattern) that doesn't 
contain patterns.  It is not sensible.

While it is legal to put unreachable code in your programs it is rarely 
sensible.  I'm 98% sure that condition defined($splinter) can never be 
true.  If you eschewed the obfuscatation this would be more obvious.



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

Date: Thu, 11 Nov 2004 19:06:56 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: Two operations with one last if?
Message-Id: <kLOkd.2295$uT1.2066@trndny03>

"sam" <ramsaram@jpl-devvax.jpl.nasa.gov> wrote in message
news:10p7be4g9o23l5b@news.supernews.com...
> Is the following "legal" and "sensible?"
>
>          while(<LOGFILE>) {
>                  undef($splinter);
>                  @record = split;
>                  $archivesection = $record[6];
>                  ($interestingpart, $junk) =
split(/\?/,$archivesection,2);
>                  $userid = $searchpattern{$interestingpart} &&
$splinter =
>                            $_, last if
(defined($searchpattern{$interestingpart}))

Why would you want to use such a nasty syntax?

if (defined $searchpattern{$interestingpart}){
  $userid = $searchpattern{$interestingpart}
  $splinter = $_;
  last;
}

Saving a few keystrokes (or even a few lines) is not a justifiable
reason to sacrifice the readability of your code.

>                  if (defined($splinter) &&
>                          (&daily || &weekly || &monthly || &yearly)) {
>                          &add_splinter_to_pile;

Why are you using all of those ampersands?  Do you actually want the
sideaffects they give?  If not, lose them.   Read
perldoc perlsub
for more info.



Paul Lalli



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

Date: Thu, 11 Nov 2004 19:16:43 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Two operations with one last if?
Message-Id: <x77josp55w.fsf@mail.sysarch.com>

>>>>> "BM" == Brian McCauley <nobull@mail.com> writes:


  BM> I shall assume '&&' should read 'and' or ','.

i now follow the rule (from peter scott) to use &&/|| in logical
expressions and and/or for logical flow control (as in open or die). it
makes more sense and it usually matches the precedence very well.

so with the multiple assignment i would agree to use and or , but a
proper if block would be clearer IMO. that statement has 3 complete
statements in it and is hard to read.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Thu, 11 Nov 2004 16:00:47 -0500
From: "Steve R." <hightec101@hotmail.com>
Subject: Re: Two operations with one last if?
Message-Id: <10p7hdj3r49rka4@news.supernews.com>

<posted & mailed>

sam wrote:

>  Is the following "legal" and "sensible?"
>  
>          while(<LOGFILE>) {
>                  undef($splinter);
>                  @record = split;
>                  $archivesection = $record[6];
>                  ($interestingpart, $junk) =
>                  split(/\?/,$archivesection,2); $userid =
>                  $searchpattern{$interestingpart} && $splinter =
>                            $_, last if
>                            (defined($searchpattern{$interestingpart}))
>  
>                  if (defined($splinter) &&
>                          (&daily || &weekly || &monthly || &yearly)) {
>                          &add_splinter_to_pile;
>                  }
>          }
> 
>  I want the userid from the associative array and the record that
>  belongs to that userid if I find the piece I'm looking for in that
>  record. Or is there another/better way to do this?

It's certainly "legal".  It might be a bit more readable to write

    if (defined($searchpattern{$interestingpart})) {
 $splinter = $_ if $userid = $searchpattern{$interestingpart};
 last;
    }

assuming you really meant the conditional, or else just

    if (defined($searchpattern{$interestingpart})) {
 $userid = $searchpattern{$interestingpart};
 $splinter = $_;
 last;
    }

---------
Steve R.
Flamingo
Computers
---------


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

Date: Thu, 11 Nov 2004 16:02:15 -0500
From: "Steve R." <hightec101@hotmail.com>
Subject: Re: Two operations with one last if?
Message-Id: <10p7hgainq8j2c2@news.supernews.com>

<posted & mailed>

sam wrote:

>  Is the following "legal" and "sensible?"
>  
>          while(<LOGFILE>) {
>                  undef($splinter);
>                  @record = split;
>                  $archivesection = $record[6];
>                  ($interestingpart, $junk) =
>                  split(/\?/,$archivesection,2); $userid =
>                  $searchpattern{$interestingpart} && $splinter =
>                            $_, last if
>                            (defined($searchpattern{$interestingpart}))
>  
>                  if (defined($splinter) &&
>                          (&daily || &weekly || &monthly || &yearly)) {
>                          &add_splinter_to_pile;
>                  }
>          }
> 
>  I want the userid from the associative array and the record that
>  belongs to that userid if I find the piece I'm looking for in that
>  record. Or is there another/better way to do this?

It's certainly "legal".  It might be a bit more readable to write

    if (defined($searchpattern{$interestingpart})) {
 $splinter = $_ if $userid = $searchpattern{$interestingpart};
 last;
    }

assuming you really meant the conditional, or else just

    if (defined($searchpattern{$interestingpart})) {
 $userid = $searchpattern{$interestingpart};
 $splinter = $_;
 last;
    }

---------
Steve R.
Flamingo
Computers
---------


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

Date: Thu, 11 Nov 2004 16:04:54 -0500
From: "Steve R." <hightec101@hotmail.com>
Subject: Re: Two operations with one last if?
Message-Id: <10p7hl9og88ecf8@news.supernews.com>

<posted & mailed>

Steve R. wrote:

> <posted & mailed>
> 
> sam wrote:
> 
>>  Is the following "legal" and "sensible?"
>>  
>>          while(<LOGFILE>) {
>>                  undef($splinter);
>>                  @record = split;
>>                  $archivesection = $record[6];
>>                  ($interestingpart, $junk) =
>>                  split(/\?/,$archivesection,2); $userid =
>>                  $searchpattern{$interestingpart} && $splinter =
>>                            $_, last if
>>                            (defined($searchpattern{$interestingpart}))
>>  
>>                  if (defined($splinter) &&
>>                          (&daily || &weekly || &monthly || &yearly)) {
>>                          &add_splinter_to_pile;
>>                  }
>>          }
>> 
>>  I want the userid from the associative array and the record that
>>  belongs to that userid if I find the piece I'm looking for in that
>>  record. Or is there another/better way to do this?
> 
> It's certainly "legal".  It might be a bit more readable to write
> 
>     if (defined($searchpattern{$interestingpart})) {
>  $splinter = $_ if $userid = $searchpattern{$interestingpart};
>  last;
>     }
> 
> assuming you really meant the conditional, or else just
> 
>     if (defined($searchpattern{$interestingpart})) {
>  $userid = $searchpattern{$interestingpart};
>  $splinter = $_;
>  last;
>     }
> 
> ---------
> Steve R.
> Flamingo
> Computers
> ---------

sorry, my newsreader messed up


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

Date: Thu, 11 Nov 2004 20:56:42 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Two operations with one last if?
Message-Id: <cn0jd8$dtv$1@sun3.bham.ac.uk>



Uri Guttman wrote:

>>>>>>"BM" == Brian McCauley <nobull@mail.com> writes:
> 
>   BM> I shall assume '&&' should read 'and' or ','.
> 
> i now follow the rule (from peter scott) to use &&/|| in logical
> expressions and and/or for logical flow control (as in open or die).

Me too!

> so with the multiple assignment i would agree to use and or , but a
> proper if block would be clearer IMO. that statement has 3 complete
> statements in it and is hard to read.

Yes, I also made that point elsewhere in my response.



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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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