[24460] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6643 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jun 2 11:05:51 2004

Date: Wed, 2 Jun 2004 08:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 2 Jun 2004     Volume: 10 Number: 6643

Today's topics:
    Re: about Net::DNS 0.47 (Michael Fuhr)
    Re: about Net::DNS 0.47 (Michael Fuhr)
    Re: Am I a programmer or a scripter? <iohihuh@INyaVAhooLID.com>
    Re: Am I a programmer or a scripter? lvirden@gmail.com
    Re: CSV dB script help <gnari@simnet.is>
    Re: CSV dB script help <usenet@morrow.me.uk>
    Re: CSV dB script help <tadmc@augustmail.com>
    Re: Filtering control characters from text <gnari@simnet.is>
        help with tk programming (Avinash)
    Re: help with tk programming <gnari@simnet.is>
    Re: help with tk programming <ittyspam@yahoo.com>
    Re: help with tk programming <ittyspam@yahoo.com>
    Re: help with tk programming moller@notvalid.se
        how to make a form bith post and get HELP (Rhys Holden)
    Re: how to make a form bith post and get HELP <nobull@mail.com>
    Re: I am looking for PERL coder... <tadmc@augustmail.com>
        Installation of CPAN modules under Darwin (Jim Keenan)
    Re: Installation of CPAN modules under Darwin <usenet@morrow.me.uk>
    Re: Invisible Array Loop Counter? <david@tvis.co.uk>
    Re: Invisible Array Loop Counter? <lord-jacob@comcast.net>
    Re: Invisible Array Loop Counter? <krahnj@acm.org>
    Re: Invisible Array Loop Counter? <ittyspam@yahoo.com>
    Re: Invisible Array Loop Counter? <usenet@morrow.me.uk>
    Re: Invisible Array Loop Counter? <ittyspam@yahoo.com>
    Re: Invisible Array Loop Counter? <ittyspam@yahoo.com>
    Re: Invisible Array Loop Counter? <david@tvis.co.uk>
    Re: Invisible Array Loop Counter? <ittyspam@yahoo.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 2 Jun 2004 06:46:45 -0600
From: mfuhr@fuhr.org (Michael Fuhr)
Subject: Re: about Net::DNS 0.47
Message-Id: <40bdcc35$1_4@omega.dimensional.com>

Sun Guonian <sun@cnnic.cn> writes:

> Base.pm_00 is original Base.pm file of Net-DNS-0.47,
> Base.pm if my updated version.
> # diff -c Base.pm_00 Base.pm
> *** Base.pm_00  Sat Feb 21 20:45:27 2004
> --- Base.pm     Sun May 30 10:28:51 2004
> ***************
> *** 430,436 ****
>
>         my $ans = $self->send($packet);
>
> !       return $ans && $ans->header->ancount   ? $ans : undef;
>   }
>
>
> --- 430,436 ----
>
>         my $ans = $self->send($packet);
>
> !       return $ans ? $ans : undef;
>   }
>
> My question is why it check $ans->header->ancount,
> for some authority-only server, its reply has no answer
> record, and we think it is right answer. for example,

The code you modified belongs to the resolver's "query" method.
That method is intended to mimic the C library's res_query()
function, which returns an error if the DNS response packet
contains no answers.  This behavior is documented in the
Net::DNS::Resolver manual page.

If you need to examine the response packet regardless of
whether it contains any answers, then use the "send" method.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/


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

Date: 2 Jun 2004 07:08:14 -0600
From: mfuhr@fuhr.org (Michael Fuhr)
Subject: Re: about Net::DNS 0.47
Message-Id: <40bdd13e$1_1@omega.dimensional.com>

mfuhr@fuhr.org (Michael Fuhr) writes:

> Sun Guonian <sun@cnnic.cn> writes:
[snip]
> > My question is why it check $ans->header->ancount,
> > for some authority-only server, its reply has no answer
> > record, and we think it is right answer. for example,
>
> The code you modified belongs to the resolver's "query" method.
> That method is intended to mimic the C library's res_query()
> function, which returns an error if the DNS response packet
> contains no answers.  This behavior is documented in the
> Net::DNS::Resolver manual page.
>
> If you need to examine the response packet regardless of
> whether it contains any answers, then use the "send" method.

I forgot that this is also mentioned in Net::DNS::FAQ:

  Why does Net::DNS::Resolver::query() return undef when the ANSWER
  section is empty?

  The short answer is, don't use query().  Net::DNS::Resolver::send()
  will always return the answer packet, as long as an answer was
  received.

  The longer answer is that query() is modeled after the res_query()
  function from the libresolv C library, which has similar behaviors.

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/


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

Date: Wed, 02 Jun 2004 13:40:27 GMT
From: "I H H" <iohihuh@INyaVAhooLID.com>
Subject: Re: Am I a programmer or a scripter?
Message-Id: <fNkvc.18012$g4.347049@news2.nokia.com>


"John Bokma" <postmaster@castleamber.com> wrote in message
news:40bb9bd8$0$199$58c7af7e@news.kabelfoon.nl...
> Anno Siegel wrote:
>
> > Tad McClellan  <tadmc@augustmail.com> wrote in comp.lang.perl.misc:
> >
> >>krakle <krakle@visto.com> wrote:
> >>
> >>
> >>>Well a lot of folks consider an interputed language scripting and a
> >>>language that needs to be compiled programming.
> >>
> >>
> >>Perl is compiled.
> >
> > ...and interputed!
>
> So we are script programmers :-D. We should be paid extra since we do

I am just humble pimple on camel's hump, Tool used by Universe, A Script
Editor, perl just flows trough me.)

> two things at the same time ;-)
>
> --
> John                               MexIT: http://johnbokma.com/mexit/
>                             personal page:       http://johnbokma.com/
>     Experienced Perl programmer available:     http://castleamber.com/




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

Date: 2 Jun 2004 13:57:11 GMT
From: lvirden@gmail.com
Subject: Re: Am I a programmer or a scripter?
Message-Id: <c9kmbn$6jt$2@srv38.cas.org>


:On Tue, 25 May 2004 12:09:20 +0000, Mothra scribbled furiously:
:
:> I encounter some snobbery from time to time with programmers telling me 
:> that what I'm doing is "just scripting", whereas the stuff they write 
:> (in Java, ColdFusion, C++ etc) is "real programming".

Interesting - I've had people say the same general thing about ColdFusion
as well.  In fact, this person basically said that someone doing
ColdFusion, Perl, Tcl, Shell, etc. wasn't doing 'real programming' and
would need to get experience with a 'real language' like Java.

-- 
<URL: http://wiki.tcl.tk/ > In God we trust.
Even if explicitly stated to the contrary, nothing in this posting
should be construed as representing my employer's opinions.
<URL: mailto:lvirden@yahoo.com > <URL: http://www.purl.org/NET/lvirden/ >


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

Date: Wed, 2 Jun 2004 10:44:49 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: CSV dB script help
Message-Id: <c9kavi$bgo$1@news.simnet.is>

"James Hunt" <jameskorea2003@hotmail.com> wrote in message
news:C7idnWmMlvVCzSDdRVn-jw@comcast.com...
> Ok this is kinda long ... so i will get to the point ... A friend of mine
> started perl script to handle a csv database.  And now I am trying to
finish
> it.  I am currently working on the search records feature.  For some
reason
> it always returns all of the records.  I have dug through to code and I
can
> not seem to figure out why it returns all of the records.  at the bottom I
> have included the script .....  the search form ... and then the csv file
> that i built as a test.

[ snip lengthy cgi script without strict or warnings, using CGI.pm but
still doing weird things to querystring]

some advice:
your problem is with the search part, so do not bother us
with the gory details of your unusual querystring technique.
in fact we do not want to see any cgi stuff at all, unless
you have determined that the problem lies there, and in that case,
we would rather not see your csv stuff. so:
create a non-cgi script especially to demonstrate your problem,
with an example of usage that fails, and tell us what you expected
to happen.

this should be possible to do in 10-15 lines of code.

including strictures and warnings would also really
warm our cold hearts.

gnari





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

Date: Wed, 2 Jun 2004 13:22:22 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: CSV dB script help
Message-Id: <c9kkae$fdb$1@wisteria.csv.warwick.ac.uk>


Quoth "James Hunt" <jameskorea2003@hotmail.com>:
> -=-=-=-=-=-
> [Alternative: text/html]
> -=-=-=-=-=-

Don't EVER do that again.

> #!/usr/bin/perl

use strict;
use warnings;

> use CGI ':all';
> 
> # The path and file name must be passed as the first two element in a comma group.
> # i.e. ....scriptname.pl?/path/,file_name.csv
> # $param[0] is the path name
> # $param[1] is the file name
> 
> $searchpage = "query.html";
> 
> @params = split(/\,/,$ENV{'QUERY_STRING'});

Use CGI.pm's facilities for doing this. Don't do it yourself.

<snip>
> sub writeupdate
> {
>         my($array,$dir,$file)=@_;
> 
>         # Open it or die with custom error
>         open(UPDATEME,">$dir$file") || die "Cannot Open $fname for Writing: $!";
> 
>         # Select the file for writing
>         select(UPDATEME);
> 
>         # Print the keys (col names)
>         print join(',',@key);
>         print "\n";
> 
>         # Print the entry
>         foreach $imakey(@key)
>         {
>                 # Do each key
>                 foreach $imakey(@key)
>                 {
>                         print $$array[$i]{$imakey}.',';

This will fail when you have commas in the data. I would strongly
suggest using one of the CSV modules from CPAN, probably DBI and
DBD::CSV.

>                 }
>                 print "\n";
>         }
> 
>         select(STDIO);

You what? There is no handle 'STDIO'.

<snip>
> sub quicksort

Perl has a build in sort. Use it.

Ben

-- 
  Joy and Woe are woven fine,
  A Clothing for the Soul divine       William Blake
  Under every grief and pine          'Auguries of Innocence'
  Runs a joy with silken twine.                                ben@morrow.me.uk


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

Date: Wed, 2 Jun 2004 08:26:06 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: CSV dB script help
Message-Id: <slrncbrlbe.2ur.tadmc@magna.augustmail.com>

James Hunt <jameskorea2003@hotmail.com> wrote:

> Ok this is kinda long ... 


[ snip 500! lines ]


Have you seen the Posting Guidelines that are posted here frequently?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Wed, 2 Jun 2004 08:33:05 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: Filtering control characters from text
Message-Id: <c9k38i$am3$1@news.simnet.is>

"John W. Krahn" <krahnj@acm.org> wrote in message
news:40BD1D84.2631813D@acm.org...
> zzapper wrote:
> >
> > On Tue, 1 Jun 2004 13:32:35 +0100, wrote:
> > >>
> > >> $str =~ s/[^\x20-\x7F]//g;
> > >
> > >$str =~ s/[[:cntrl:]]//g;
> >
> > That's cool but are they exactly equivalent?
>
> No, but this is:
>
> $str =~ s/[[:^graph:]]//g;

I beg to differ. \x7f is not a member of [:graph:]

gnari





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

Date: 2 Jun 2004 03:30:36 -0700
From: avishivani@rediffmail.com (Avinash)
Subject: help with tk programming
Message-Id: <50f061fc.0406020230.5a154c63@posting.google.com>

Dear Sir,
please help me getting started with tk programming on windows platform.  

any book reference or site names will be welcome.

regards
Avinash


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

Date: Wed, 2 Jun 2004 10:50:11 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: help with tk programming
Message-Id: <c9kb9k$bht$1@news.simnet.is>

"Avinash" <avishivani@rediffmail.com> wrote in message
news:50f061fc.0406020230.5a154c63@posting.google.com...
> Dear Sir,
> please help me getting started with tk programming on windows platform.
>
> any book reference or site names will be welcome.

google is your friend

http://www.google.com/search?q=tcl+tk+windows+tutorial

gnari





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

Date: Wed, 2 Jun 2004 07:16:27 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: help with tk programming
Message-Id: <20040602071114.I8971@dishwasher.cs.rpi.edu>

On Wed, 2 Jun 2004, Avinash wrote:

> Dear Sir,
> please help me getting started with tk programming on windows platform.
>
> any book reference or site names will be welcome.

From perldoc perlfaq2:
        Mastering Perl/Tk
	by Steve Lidie and Nancy Walsh
	ISBN 1-56592-716-8 [1st edition January 2002]
	http://www.oreilly.com/catalog/mastperltk/

Also try http://www.perltk.org and
perldoc Tk
(or http://search.cpan.org/~ni-s/Tk-804.027/pod/overview.pod if you don't
have Perl/Tk already installed)

BTW, Google'ing for "Perl/Tk tutorial" turns this up from perl.com:
http://www.perl.com/pub/a/1999/10/perltk/


Paul Lalli


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

Date: Wed, 2 Jun 2004 07:17:35 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: help with tk programming
Message-Id: <20040602071651.S8971@dishwasher.cs.rpi.edu>

On Wed, 2 Jun 2004, gnari wrote:

> "Avinash" <avishivani@rediffmail.com> wrote in message
> news:50f061fc.0406020230.5a154c63@posting.google.com...
> > Dear Sir,
> > please help me getting started with tk programming on windows platform.
> >
> > any book reference or site names will be welcome.
>
> google is your friend
>
> http://www.google.com/search?q=tcl+tk+windows+tutorial
>
> gnari

Out of curiousity, why are you sending the OP posts about Tcl/Tk in a Perl
newsgroup?  Would not a pointer to Perl/Tk be better?

Paul Lalli


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

Date: Wed, 02 Jun 2004 12:12:20 GMT
From: moller@notvalid.se
Subject: Re: help with tk programming
Message-Id: <u7juqxiol.fsf@notvalid.se>

avishivani@rediffmail.com (Avinash) writes:

> Dear Sir,
> please help me getting started with tk programming on windows platform.  
> 
> any book reference or site names will be welcome.

Check out comp.lang.perl.tk it's a friendly place.

Mastering Perl/Tk by Steve Lidie and Nancy Walsh is a good book.
http://www.oreilly.com/catalog/mastperltk/


http://www.perltk.org/  is a decent site with lots of example scripts.


And finaly google is your friend
http://www.google.com/search?q=perl+tk+tutorial

Good luck.



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

Date: 2 Jun 2004 04:06:20 -0700
From: rhysholden@rhysholden.com (Rhys Holden)
Subject: how to make a form bith post and get HELP
Message-Id: <c5025fd3.0406020306.381f5022@posting.google.com>

I have a web form which is acting as an order form for my website. I
want to be able to email the data to myself and also to send the field
variables into the url so that it can be used when redirecting the
payee to the payment site, like paypal. I was using formmail.php which
works great but I also need to be able to send the form feilds like
"amount" into the url i.e.
"http://paypal/paymentgateway/user?name=john&amount=30"

I'd really appreciate your help


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

Date: 02 Jun 2004 12:52:06 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: how to make a form bith post and get HELP
Message-Id: <u9u0xufa8p.fsf@wcl-l.bham.ac.uk>

rhysholden@rhysholden.com (Rhys Holden) writes:

> I have a web form which is acting as an order form for my website. I
> want to be able to email the data to myself and also to send the field
> variables into the url so that it can be used when redirecting the
> payee to the payment site, like paypal. I was using formmail.php which
> works great but I also need to be able to send the form feilds like
> "amount" into the url i.e.
> "http://paypal/paymentgateway/user?name=john&amount=30"
> 
> I'd really appreciate your help

In Perl's GCI module there are param() and url_param() methods.

But I suspect you are not using Perl. 

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


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

Date: Wed, 2 Jun 2004 08:32:13 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: I am looking for PERL coder...
Message-Id: <slrncbrlmt.2ur.tadmc@magna.augustmail.com>

PHP2 <gp@nospm.hr> wrote:
> my friend has open bid by Rentacoder.com.. I expect that I am not bother any
> peron here if I post info about that.. 


Your expectations are incorrect.


> I am looking for PERL coder 


This is a discussion newsgroup, not a jobs newsgroup.

Newsgroups with "job" in their name are where you should post jobs.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 2 Jun 2004 07:50:37 -0700
From: jkeen_via_google@yahoo.com (Jim Keenan)
Subject: Installation of CPAN modules under Darwin
Message-Id: <196cb7af.0406020650.21a37d45@posting.google.com>

In a previous posting I described how I installed Perl 5.8.4 from
source on a new iBook G4.  I now request assistance in installling
modules downloaded from CPAN on the same system.

I have previously installed my own CPAN module List::Compare on both
Windows and Linux.  On both those OSs, I would simply switch to the
directory where I had unpacked the module and follow the standard
installation instructions:

    perl Makefile.PL
    make
    make test
    make install

On RedHat Linux 7.2, I had learned that in order to get the man and
info pages for any module, I had to modify the first command above as
follows:

    perl makefile.PL INSTALLSITEMAN3DIR=/usr/share/man/man3

I followed the 4-command procedure above this morning, but did not get
the desired results.  This is what appeared:

    [List-Compare-0.3 427]$ sudo make install
    Password:
    Writing ///Library/Perl/5.8.1/darwin-thread-multi-2level/auto/List/Compare/.packlist
    Appending installation info to 
        ///System/Library/Perl/5.8.1/darwin-thread-multi-2level/perllocal.pod
    [List-Compare-0.3 428]$ cd
    [jimk 429]$ perldoc List::Compare
    <standard input>:1473: warning [p 19, 0.3i]: can't break line
    standard input>:1493: warning [p 19, 4.2i]: can't break line
    jimk 430]$ man List::Compare
     manual entry for List::Compare
    jimk 431]$ info List::Compare    
         # info help page appeared, along with message saying 
        # no info page for List::Compare was located

As you can see, the first problem is that the regular procedure
installed the module relative to the Perl 5.8.1 that came with the
iBook -- but I want it installed relative to the Perl 5.8.4 that I
just installed.

The second problem is that I got nothing when calling 'perldoc
List::Compare'.  This really surprised me, because while I've
sometimes had problems with the man and info calls (as suggested
above), I've always been able to call perldoc immediately after
installing a module and use that as a test for successful
installation.  I have no idea what the "can't break line" warnings
mean, as I've never gotten this message on any of the many
installations and upgrades of this module which I've done.

So, to my questions:

1) What did I do wrong in the above example?

2) Is there any way I can set my system up to say:  From this day
forward, consider my Perl 5.8.4 (installed under /usr/local/bin) to be
my default Perl for the purpose of installing modules, whether by the
manual procedure used above or by use of the CPAN.pm shell?  (I
understand that I now have to code the shebang line as
#!/usr/local/bin/perl rather than #!/usr/bin/perl -- but that applies
only to Perl scripts.)

Thanks in advance.

Jim Keenan


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

Date: Wed, 2 Jun 2004 14:55:24 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Installation of CPAN modules under Darwin
Message-Id: <c9kpos$jq1$1@wisteria.csv.warwick.ac.uk>


Quoth jkeen_via_google@yahoo.com (Jim Keenan):
> In a previous posting I described how I installed Perl 5.8.4 from
> source on a new iBook G4.  I now request assistance in installling
> modules downloaded from CPAN on the same system.
> 
> I have previously installed my own CPAN module List::Compare on both
> Windows and Linux.  On both those OSs, I would simply switch to the
> directory where I had unpacked the module and follow the standard
> installation instructions:
> 
>     perl Makefile.PL
>     make
>     make test
>     make install
> 
> On RedHat Linux 7.2, I had learned that in order to get the man and
> info pages for any module, I had to modify the first command above as
> follows:
> 
>     perl makefile.PL INSTALLSITEMAN3DIR=/usr/share/man/man3
> 
> I followed the 4-command procedure above this morning, but did not get
> the desired results.  This is what appeared:
> 
>     [List-Compare-0.3 427]$ sudo make install
>     Password:
>     Writing ///Library/Perl/5.8.1/darwin-thread-multi-2level/auto/List/Compare/.packlist
>     Appending installation info to 
>         ///System/Library/Perl/5.8.1/darwin-thread-multi-2level/perllocal.pod
>     [List-Compare-0.3 428]$ cd
>     [jimk 429]$ perldoc List::Compare
>     <standard input>:1473: warning [p 19, 0.3i]: can't break line
>     standard input>:1493: warning [p 19, 4.2i]: can't break line
>     jimk 430]$ man List::Compare
>      manual entry for List::Compare
>     jimk 431]$ info List::Compare    
>          # info help page appeared, along with message saying 
>         # no info page for List::Compare was located
> 
> As you can see, the first problem is that the regular procedure
> installed the module relative to the Perl 5.8.1 that came with the
> iBook -- but I want it installed relative to the Perl 5.8.4 that I
> just installed.

In that case you have to say

/usr/local/bin/perl Makefile.PL

> 2) Is there any way I can set my system up to say:  From this day
> forward, consider my Perl 5.8.4 (installed under /usr/local/bin) to be
> my default Perl for the purpose of installing modules, whether by the
> manual procedure used above or by use of the CPAN.pm shell?  (I
> understand that I now have to code the shebang line as
> #!/usr/local/bin/perl rather than #!/usr/bin/perl -- but that applies
> only to Perl scripts.)

Probably the best soln to this is to puth /usr/local/bin first in your PATH.

Ben

-- 
Like all men in Babylon I have been a proconsul; like all, a slave ... During
one lunar year, I have been declared invisible; I shrieked and was not heard,
I stole my bread and was not decapitated.
~ ben@morrow.me.uk ~                   Jorge Luis Borges, 'The Babylon Lottery'


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

Date: Wed, 02 Jun 2004 09:00:18 +0100
From: zzapper <david@tvis.co.uk>
Subject: Re: Invisible Array Loop Counter?
Message-Id: <u52rb01r907d34v9dpgqpr6hqil45vkdj8@4ax.com>

On Wed, 02 Jun 2004 01:00:34 GMT, wrote:

>zzapper wrote:
>> 
John
>
>@t = grep { $_ ne 'fred' } @t;
>
>
Are these the same?

@e = grep { $_ !~ /fred/ } @e;
@e = grep !/fred/ ,@e;

zzapper (vim, cygwin, wiki & zsh)
--

vim -c ":%s.^.CyrnfrTfcbafbeROenzSZbbyranne.|:%s/[R-T]/ /Ig|:normal ggVGg?"

http://www.vim.org/tips/tip.php?tip_id=305  Best of Vim Tips


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

Date: Wed, 02 Jun 2004 08:47:11 GMT
From: Jacob Heider <lord-jacob@comcast.net>
Subject: Re: Invisible Array Loop Counter?
Message-Id: <fef8b37831c188fa57aac51f50d0dd7e@news.teranews.com>

On Wed, 02 Jun 2004 09:00:18 +0100, a posting issued forth from zzapper...
> On Wed, 02 Jun 2004 01:00:34 GMT, wrote:
> 
>>zzapper wrote:
>>> 
> John
>>
>>@t = grep { $_ ne 'fred' } @t;
>>
>>
> Are these the same?
> 
> @e = grep { $_ !~ /fred/ } @e;
> @e = grep !/fred/ ,@e;
> 
> zzapper (vim, cygwin, wiki & zsh)
> --
> 
> vim -c ":%s.^.CyrnfrTfcbafbeROenzSZbbyranne.|:%s/[R-T]/ /Ig|:normal ggVGg?"
> 
> http://www.vim.org/tips/tip.php?tip_id=305  Best of Vim Tips


Try them with the data set:

joe
bob
fred
frederick
tom

and see...

Jacob


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

Date: Wed, 02 Jun 2004 10:24:50 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Invisible Array Loop Counter?
Message-Id: <40BDAAED.7105E735@acm.org>

zzapper wrote:
> 
> On Wed, 02 Jun 2004 01:00:34 GMT, wrote:
> 
> >zzapper wrote:
> >>
> John
> >
> >@t = grep { $_ ne 'fred' } @t;
> >
> >
> Are these the same?
> 
> @e = grep { $_ !~ /fred/ } @e;
> @e = grep !/fred/ ,@e;

If you anchor the pattern it will be the same:

@e = grep !/\Afred\z/, @e;


John
-- 
use Perl;
program
fulfillment


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

Date: Wed, 2 Jun 2004 07:07:19 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Invisible Array Loop Counter?
Message-Id: <20040602070135.I8971@dishwasher.cs.rpi.edu>

On Wed, 2 Jun 2004, John W. Krahn wrote:

> zzapper wrote:
> >
> > On Wed, 02 Jun 2004 01:00:34 GMT, John wrote:
> >
> > >
> > >@t = grep { $_ ne 'fred' } @t;
> > >
> > >
> > Are these the same?
> >
> > @e = grep { $_ !~ /fred/ } @e;
> > @e = grep !/fred/ ,@e;
>
> If you anchor the pattern it will be the same:
>
> @e = grep !/\Afred\z/, @e;


Things are getting confused, with people saying "these" and not being
clear which "these" we're talking about.  Let's be explicit.


@e = grep { $_ !~ /fred/ } @e;
is equivalent to
@e = grep !/fred/, @e;

The statement
@e = grep { $_ ne 'fred' } @e;
is equivalent to:
@e = grep !/^fred$/, @e;
which is also equivalent to
@e = grep !/\Afred\Z/, @e;


To sum up, the first two listed here weed out any elements which *contain*
'fred'.  The last three week out any elements that are *string-equal* to
'fred'.

Hopefully this clears things up a bit.

Paul Lalli


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

Date: Wed, 2 Jun 2004 13:25:22 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Invisible Array Loop Counter?
Message-Id: <c9kkg2$fdb$2@wisteria.csv.warwick.ac.uk>


Quoth Paul Lalli <ittyspam@yahoo.com>:
> On Wed, 2 Jun 2004, John W. Krahn wrote:
> 
> > zzapper wrote:
> > >
> > > On Wed, 02 Jun 2004 01:00:34 GMT, John wrote:
> > >
> > > >
> > > >@t = grep { $_ ne 'fred' } @t;
> > > >
> > > >
> > > Are these the same?
> > >
> > > @e = grep { $_ !~ /fred/ } @e;
> > > @e = grep !/fred/ ,@e;
> >
> > If you anchor the pattern it will be the same:
> >
> > @e = grep !/\Afred\z/, @e;
> 
> 
> Things are getting confused, with people saying "these" and not being
> clear which "these" we're talking about.  Let's be explicit.
> 
> 
> @e = grep { $_ !~ /fred/ } @e;
> is equivalent to
> @e = grep !/fred/, @e;
> 
> The statement
> @e = grep { $_ ne 'fred' } @e;
> is equivalent to:
> @e = grep !/^fred$/, @e;
> which is also equivalent to
> @e = grep !/\Afred\Z/, @e;

Neither of these are equivalent to { $_ ne 'fred' }: both $ and \Z will
match before a newline before the end of the string.

@e = grep !/^fred\z/, @e;

Ben

-- 
"The Earth is degenerating these days. Bribery and corruption abound.
Children no longer mind their parents, every man wants to write a book,
and it is evident that the end of the world is fast approaching."
     -Assyrian stone tablet, c.2800 BC                         ben@morrow.me.uk


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

Date: Wed, 2 Jun 2004 09:42:04 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Invisible Array Loop Counter?
Message-Id: <20040602093906.D8971@dishwasher.cs.rpi.edu>

On Wed, 2 Jun 2004, Ben Morrow wrote:

> Quoth Paul Lalli <ittyspam@yahoo.com>:

> > The statement
> > @e = grep { $_ ne 'fred' } @e;
> > is equivalent to:
> > @e = grep !/^fred$/, @e;
> > which is also equivalent to
> > @e = grep !/\Afred\Z/, @e;
>
> Neither of these are equivalent to { $_ ne 'fred' }: both $ and \Z will
> match before a newline before the end of the string.
>
> @e = grep !/^fred\z/, @e;

I knew someone was going to say that.  The three statements I listed
above, exactly as written, *are* equivalent.  This is not true for the
general case when the search string (here represented by 'fred') is not
known and/or may contain newline characters.  There are further
divergences if one chooses to use the /m modifier on the regexp and there
are new line characters.

I should have been more explicit in my post, I grant you.  I simply meant
that those three exact statements are equivalent, because the string
'fred' contains no newlines.

Paul Lalli


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

Date: Wed, 2 Jun 2004 09:51:39 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Invisible Array Loop Counter?
Message-Id: <20040602095004.V8971@dishwasher.cs.rpi.edu>

On Wed, 2 Jun 2004, Paul Lalli wrote:

> On Wed, 2 Jun 2004, Ben Morrow wrote:
>
> > Quoth Paul Lalli <ittyspam@yahoo.com>:
>
> > > The statement
> > > @e = grep { $_ ne 'fred' } @e;
> > > is equivalent to:
> > > @e = grep !/^fred$/, @e;
> > > which is also equivalent to
> > > @e = grep !/\Afred\Z/, @e;
> >
> > Neither of these are equivalent to { $_ ne 'fred' }: both $ and \Z will
> > match before a newline before the end of the string.
> >
> > @e = grep !/^fred\z/, @e;
>
> I knew someone was going to say that.  The three statements I listed
> above, exactly as written, *are* equivalent.  This is not true for the
> general case when the search string (here represented by 'fred') is not
> known and/or may contain newline characters.  There are further
> divergences if one chooses to use the /m modifier on the regexp and there
> are new line characters.
>
> I should have been more explicit in my post, I grant you.  I simply meant
> that those three exact statements are equivalent, because the string
> 'fred' contains no newlines.

And one minute later, I realize I got myself completely turned around.
What I should have said was that for the original data set:
@e = qw(fred joe freddy sick)
the statements are equivalent, because none of *those* strings contain
newlines.  The search string is irrelevant.

Please forgive my haste in replying before thinking.

Paul Lalli


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

Date: Wed, 02 Jun 2004 15:36:07 +0100
From: zzapper <david@tvis.co.uk>
Subject: Re: Invisible Array Loop Counter?
Message-Id: <6aprb0dlq601rm7qrnnp8df2i64ht411hh@4ax.com>

On Wed, 02 Jun 2004 09:00:18 +0100, wrote:

>>
>>@t = grep { $_ ne 'fred' } @t;

>
>@e = grep { $_ !~ /fred/ } @e;

I'm still curious about this "grep {..} @t" syntax.

Are the {} just a container or does it imply that you can put  a
pretty complex expression in there??

zzapper (vim, cygwin, wiki & zsh)
--

vim -c ":%s.^.CyrnfrTfcbafbeROenzSZbbyranne.|:%s/[R-T]/ /Ig|:normal ggVGg?"

http://www.vim.org/tips/tip.php?tip_id=305  Best of Vim Tips


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

Date: Wed, 2 Jun 2004 10:45:32 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Invisible Array Loop Counter?
Message-Id: <20040602103717.J8971@dishwasher.cs.rpi.edu>

On Wed, 2 Jun 2004, zzapper wrote:

> I'm still curious about this "grep {..} @t" syntax.
>
> Are the {} just a container or does it imply that you can put  a
> pretty complex expression in there??

perldoc -f grep

grep takes either an expression or a block.  So yes, you can put an
arbitrarily complex piece of code inside the block.  The current element
of the array will be added to the returned list if and only if the block
itself returns a true value (which generally means the last line of the
block is a true value, but really means the last line *evaluated* is a
true value).

This is valid syntax, for example:
my @nums = (1..10);

my @evens = grep {
                if ($_ % 2 == 0){
                       1;
                } else {
                        0;
                }
} @nums;
print "Evens: @evens\n";


This is so easy to shorten, however, you would never see it like that.
Instead, you'll see;

my @evens = grep { $_ % 2 == 0 } @nums;
or maybe
my @evens = grep { !($_ % 2) } @nums;

These expressions are equivalent to the expression syntax:
my @evens = grep $_%2 == 0, @nums;
my @evens = grep !($_%2), @nums;

(Note the very important existance of the comma in the expression syntax,
and the equally important lack of comma in the block syntax).

Paul Lalli


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

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


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