[22387] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4608 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Feb 22 18:10:38 2003

Date: Sat, 22 Feb 2003 15:10:11 -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           Sat, 22 Feb 2003     Volume: 10 Number: 4608

Today's topics:
    Re: Problems comparing strings (Anno Siegel)
    Re: Problems comparing strings (Anno Siegel)
        Q: about opening many processes in parallel as filehand <bik.mido@tiscalinet.it>
    Re: Questions about perl. <spam@thecouch.homeip.net>
    Re: Reading tab delimited files into a hash. <goldbb2@earthlink.net>
    Re: Religious question: commenting (Anno Siegel)
    Re: Religious question: commenting <bik.mido@tiscalinet.it>
    Re: Returning the field list from DBI ctcgag@hotmail.com
    Re: setting permissions on my server for cgi <jeff@vpservices.com>
    Re: setting permissions on my server for cgi <bwalton@rochester.rr.com>
    Re: Suppress DBD MySQL info messages at terminal ctcgag@hotmail.com
    Re: Use or not to use modules [was: How do I ...] <spamtrap@nowhere.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 22 Feb 2003 21:41:28 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Problems comparing strings
Message-Id: <b38qq8$a2a$1@mamenchi.zrz.TU-Berlin.DE>

Mikey <PleaseDontThrowSpam@Me.com> wrote in comp.lang.perl.misc:
> Hi,
> 
> I'm storing names into variables and then trying to compare them. Some
> example names are:
> 
> Mikey Jones
> Jimmy Beef
> Donald H Samuel
> Sarah A Girl
> 
> Unfortunately, the following code does not work:
> 
>     if ($name1 == $name2) {
                 ^^

One point for jue and his FAQ proposal.

>         print "Names are the same\n";
>     }
> 
> It gives the error:
> 
> "Argument "Donald H Samuel" isn't numeric in numeric eq (==)"

This is supposed to be a hint.  "==" is for numeric comparison, so it
tries to treat your names as numbers.  See an article (or thread)
currently on clpm, titled "FAQ proposal", I think.

> For your information: these names are read in from a dat file.

Did you remember to chomp() them?  See "perldoc -f chomp() in case
you didn't.  This doesn't have to do with your problem, however.

> How can I compare these names?

Use "eq".

Anno
-- 
perl -e'$_=shift().".pm";s|::|/|g;require;exec"view",$INC{ $_}' File::Find


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

Date: 22 Feb 2003 21:46:34 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Problems comparing strings
Message-Id: <b38r3q$a2a$2@mamenchi.zrz.TU-Berlin.DE>

Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote in comp.lang.perl.misc:
> Mikey <PleaseDontThrowSpam@Me.com> wrote in comp.lang.perl.misc:
> > Hi,
> > 
> > I'm storing names into variables and then trying to compare them. Some
> > example names are:
> > 
> > Mikey Jones
> > Jimmy Beef
> > Donald H Samuel
> > Sarah A Girl
> > 
> > Unfortunately, the following code does not work:
> > 
> >     if ($name1 == $name2) {
>                  ^^
> 
> One point for jue and his FAQ proposal.

Oops.  I posted this before realizing that this post had set off the
FAQ proposal. [1]

Anno

[1] Note to self: When reading a newsgroup in reverse date order, remember
    you're doing so.
-- 
perl -e'$_=shift().".pm";s|::|/|g;require;exec"view",$INC{ $_}' File::Find


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

Date: Sat, 22 Feb 2003 23:57:12 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Q: about opening many processes in parallel as filehandles and win* OSes
Message-Id: <rrof5vos9l2gnar09unvra4sh6j21okuvq@4ax.com>

"Inspired" by a post on this ng (by Mr. Goldberg, I think), I wrote
and tried the following simple script on a linux box:

#!/usr/bin/perl -w
use strict;

die "Usage: $0 <net>\n" unless @ARGV == 1;
# Rudimentary check on the argument
(my $net=shift) =~ s/\.0+$/./ 
  or die "Supply an IP of the form <#.#.#.0>\n";

print "Begun pings at ".localtime()."\n";
my @p;
open $p[$_], "-|", "ping $net$_ -c 10"
  or die "Couldn't start ping for $net$_: $!\n" for 1..255;
shift @p;
undef $/;
print map <$_>, @p;
__END__
  

Then I tried it on my Win98 system (AS 5.6.1 FWIM) as well (modulo a
minor modification on the invocation of ping), but it failed with
(e.g.) 127.0.0.65 dying with the error message "Bad file descriptor".

After some experimenting I discovered that I can have at most 64 FHs
opened as pipes. Is this limitation perl-implementation-dependent or
OS-dependent? Ah, and where is it documented?


Michele
-- 
>It's because the universe was programmed in C++.
No, no, it was programmed in Forth.  See Genesis 1:12:
"And the earth brought Forth ..."
- Robert Israel on sci.math, thread "Why numbers?"


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

Date: Sat, 22 Feb 2003 15:45:30 -0500
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: Questions about perl.
Message-Id: <NjR5a.2309$Bf1.55109@weber.videotron.net>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

Joe Creaney wrote:
> I picked up a book on c++.  It is very intersting but seems like it is 
> rather cumbersome to program next to perl.

C and C++ sacrifice ease of use (from the programmer's prespective) for 
speed and precise control.

>  C++ has objects and classes? 

Yes it does.

> Does perl have simmilar functions?

You can do object-oriented programming in perl, yes.  That's where the 
similaries end though.

See http://www.perldoc.com/perl5.8.0/pod/perl.html , specifically 
perboot, perltoot, perltooc and perlbot.

Best of luck.


-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE+V+FveS99pGMif6wRAqKtAKDnAGI019mcywgUwq50drCj85lNvACZATpN
DrbNEtrPHH57RDqYb+QR9O0=
=DfEi
-----END PGP SIGNATURE-----



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

Date: Sat, 22 Feb 2003 16:43:51 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Reading tab delimited files into a hash.
Message-Id: <3E57EF17.90FA6BB3@earthlink.net>

"Charles R. Thompson" wrote:
> 
> I constantly find myself reading tab delimited files into a hash in a
> method similar to below. I'm realizing now that it's probably not the
> best way to do it but reading through the docs I haven't come across
> anything new:
[snip]
> Surely there is a more efficient way to deal with the tabs and
> whatnot.

   #!perl.exe -w
   use strict;   # always use strict!
   use warnings; # always use warnings!
   my %hosts;
   # always check whether your open() succeeds!
   open( my($hosts), "<", 'D:/WEB_LOG_PROCESSING/HOSTS.TXT' )
      # always include $! in the error message if open() fails!
      or die "Error opening hosts.txt: $!";
   # These are the field names.
   my @fields = qw(host username password serverfile 
      clientfile logdirectory firstname lastname email
      clientcode sysimg logo hostfilter);
   while( <$hosts> ) {
      # remove leading CLIENT: and trailing \n.
      # If they aren't there, skip this line of data.
      s/^CLIENT:// and chomp or next;
      # split on tabs.  Don't omit trailing empty fields.
      my ($name, @vals) = split /\t/, $_, -1;
      # Must be same number of values as field names.
      next unless @vals == @fields;
      # Store the data in %hosts.
      @{$hosts{$name}}{@fields} = @vals;
   }
   use Data::Dumper;
   print Dumper(\%hash);
   __END__
[untested]

-- 
$;=qq qJ,krleahciPhueerarsintoitq;sub __{0 &&
my$__;s ee substr$;,$,&&++$__%$,--,1,qq;;;ee;
$__>2&&&__}$,=22+$;=~y yiy y;__ while$;;print


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

Date: 22 Feb 2003 19:14:17 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Religious question: commenting
Message-Id: <b38i69$681$1@mamenchi.zrz.TU-Berlin.DE>

Charlton Wilbur  <cwilbur@mithril.chromatico.net> wrote in comp.lang.perl.misc:
> >>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:

[...]

>     AS> In any case comments are only one tool in making code
>     AS> understandable.  Asking people to restrict the discussion to
>     AS> only one aspect is silly. 
> 
> I agree with the former, but not the latter.  Profitable discussions
> can be had of all aspects of programming.

Definitely, in the right setting, which would be that of a seminary
or classroom.  A Usenet discussion cannot be focussed that sharply,
and insisting that it be was silly.  But never mind that now...

>     AS> One reason why comment-writing is unpopular among programmers
>     AS> is that it is hard to do right.  It requires you to put
>     AS> yourself in the place of someone who doesn't know what you're
>     AS> up to and to forget "for the moment" all the intricacies of
>     AS> the code you're struggling with.  The mental effort of viewing
>     AS> your work from outside is disruptive, but if it isn't made,
>     AS> the resulting comment is likely to be unhelpful.  It is far
>     AS> easier to just write down what goes through your head at the
>     AS> moment, so this happens a lot, but (like in Usenet subject
>     AS> lines), the result is mostly unsatisfactory.  We have all
>     AS> puzzled over comments that look like radio messages from Mars.
> 
> But this is an argument against *bad* commenting, not against
> commenting in general.  I don't find the mental effort of viewing my
> work from outside at all disruptive; it's roughly the same as writing
> a paper in which you know all the other sources and the audience does
> not.  Instead of just writing the code for the computer and the
> maintainer, you're writing the comments for the maintainer as well.

My argument is that the effort spent on comment-writing isn't negligible
and may be better spent in improving the readability of the program by
other means.  Your comparison with writing a paper is quite apt.  Usually,
when you write the paper, the necessary research (the problem-solving) is
done.  Commenting is supposed to be done while programming, which is
the problem-solving phase.  If at all, I'd prefer to write a paper
about my program another time.

Also note that, like code, comments must be maintained.  Making them
maintainable adds another complexity level to good commenting.
Mentioning a variable by name is risky, because it may be renamed.
Relating to data and their ordering is worse, but often comes naturally:
"# Countries from 'BE' to 'FR' ...".  Avoiding these is cumbersome and
leads to convoluted prose.  But maintaining comments is particularly
hard because there are no tools that help.  You must understand the
code and the comment and see if they still fit.  This burden is not
only on the programmer, but also on the later maintainer, who may
find it a particularly heavy load, or neglect it altogether.

There are more things I dislike about heavy commenting, but I guess
my main point is that it is harder than it may appear.  The amount
of well-meaning but useless commentary we get to see proves this.
In fact, when I see comment-heavy code, my reaction is not "Oh, this
is going to be a snap", but more like "Oh dear...".

> A similar argument could be made for sensible variable names and
> coding conventions as well; they require other considerations beyond
> simply telling the computer what to do, forgetting the code you're
> struggling with and considering the maintainer and yourself.  We've
> all puzzled over variable names that are opaque and unhelpful; does
> this mean we should give up on trying to create clear variable names?

Not at all.  I'm not quite sure what you're saying with the last sentence,
but choosing a reasonable variable name is certainly a good thing.  It
improves the overall quality of the program and has no future cost, so
the effort is well spent.

Adding a comment may improve the code or not, and can entail future
maintenance costs.  Comments are overrated.

Anno
-- 
perl -e'$_=shift().".pm";s|::|/|g;require;exec"view",$INC{ $_}' File::Find


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

Date: Sat, 22 Feb 2003 23:57:11 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Religious question: commenting
Message-Id: <0ulf5v8i2rtmao46eoddgvoi32cr7u32qd@4ax.com>

On Fri, 21 Feb 2003 23:16:00 +0100, Sandman <mr@sandman.net> wrote:

>You are free to post whatever you feel like. My intentions was to discuss 
>comments, and I felt I should try to direct the discussion back to that when I 

You asked how people make comments. They do it like these:
"... # ..."!

But then this is not exactly what you wanted to know and evidence
seems to indicate you were aimed at exploring how people comment their
code reliably and efficiently (in their opinions), aren't you?

Well, a discussion on these matters cannot be detached from a
discussion on code itself. After all comments *are* a part (or a
feature) of the code - they're not "something else"...

>noticed that some people were more interested in talking about coding only.
              ^^^^

You should have noticed *all* people were interested in talking about
comments wrt the context they "live" in, that is CODE.

They gave advices on how to write code that (a) doesn't even need
comments or (b) can be commented more *fruitfully* (than badly written
code). [Case (a) can be considered as a particular instance of case
(b).]

If you want to know a general rule for "code-independent comments",
then you probably have to devise it yourself, as it seems that for
people here such a beast just doesn't exist (and I agree with them,
for what the humble opinion of newbie like me is worth)...


Michele
-- 
>It's because the universe was programmed in C++.
No, no, it was programmed in Forth.  See Genesis 1:12:
"And the earth brought Forth ..."
- Robert Israel on sci.math, thread "Why numbers?"


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

Date: 22 Feb 2003 21:32:08 GMT
From: ctcgag@hotmail.com
Subject: Re: Returning the field list from DBI
Message-Id: <20030222163208.769$Yq@newsreader.com>

jsn@microlib.co.uk (Jason Singleton) wrote:

> Also how do I change the read position in the returned data? I don't
> want to return all records to the user at once I want it to display
> the returned data in pages like a search engine.

My prefered way for accomplishing paging in web applications is to
explain the proper use of the "page down" key and the scroll bars
to the end user.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service              New Rate! $9.95/Month 50GB


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

Date: Sat, 22 Feb 2003 11:53:13 -0800
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: setting permissions on my server for cgi
Message-Id: <3E57D529.9090608@vpservices.com>

Gunnar Hjalmarsson wrote:

> chris wrote:
> 
>> i am having a few problems getting cgi scripts to work on my server.
> 
> Bob Walton wrote:
> 
>> BTW, conspicuously absent from your CGI script is the statement:
>>
>>     use CGI;
> 
> 
> Load CGI.pm in order to print "HELLO"? ;-)

Yes, definitely, since the only purpose of printing "HELLO" is to test 
how perl CGI scripts work, and especially so for someone like the OP who 
is extremely unlikely to be aware of the issues that CGI.pm would 
protect them from.

-- 
Jeff



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

Date: Sat, 22 Feb 2003 22:36:37 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: setting permissions on my server for cgi
Message-Id: <3E57FB52.9080000@rochester.rr.com>

chris wrote:

 ...

 > i do my best to read the documentation, but it's very frustrating 
with > the amount of reading required. it requires time, and patience 
that i > do not often have to devote to this.

Then hire a programmer to do your programming for you.

> i tried doing use cgi; that didn't work. thanks anyway.what newsgroup should
> i try posting this to?
 ...

 > "Bob Walton" <bwalton@rochester.rr.com> wrote

>>Have you followed everything in the FAQ?  (that's perldoc -q 500).  Oh,
>>guess not -- it says there to submit requests like yours to a different
>>newsgroup.  Where they talk about server configuration and file
 ...


What newsgroup did it suggest when you took the two seconds it takes to 
type:

    perldoc -q 500

?  BTW, posting to a newsgroup, including 
comp.infosystems.www.authoring.cgi, should come *after* having read all 
the documentation and FAQ's and making a serious attempt at solving the 
problem yourself.  Not only is reading the docs etc faster and more 
reliable, it also avoids sending millions of copies of the same old 
question to newsservers all over the world and wasting the time of 
thousands of people who, believe it or not, are eager to help with 
questions that aren't FAQ's.  Harsh?  Not really.  What is harsh is when 
you get "plonked" (put on newsreader autorejection lists) by the people 
who could have helped you.

Also, the more information you can supply, the better.  Statements like 
"that didn't work" (above) are not helpful at all.  What did it do that 
was different from what the documentation says?  Or you expected?  Did 
it generate any error messages?  If so, what *exactly* did they say?  Etc.
-- 
Bob Walton



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

Date: 22 Feb 2003 21:36:19 GMT
From: ctcgag@hotmail.com
Subject: Re: Suppress DBD MySQL info messages at terminal
Message-Id: <20030222163619.531$GO@newsreader.com>

"Jane_Dunnie" <jane_dunnie@hotmail.cmo> wrote:
> Hi,
>
> I have a small Perl script, which connects to a MySql database. Works
> fine, except that when a duplicate record is attempted to be added, the
> error message is wriiten to the terminal, thus:
>
> DBD::mysql::db do failed: Duplicate entry .......etc
>
> How can I get rid of that, and just have it return nothing....?

add the "ignore" keyword to the insert statement.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service              New Rate! $9.95/Month 50GB


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

Date: Sat, 22 Feb 2003 20:42:01 GMT
From: Andrew Lee <spamtrap@nowhere.com>
Subject: Re: Use or not to use modules [was: How do I ...]
Message-Id: <pinf5vgeg9r27fjcd5m8p63gt8c67lvufj@4ax.com>

On 21 Feb 2003 15:32:41 -0800, noreply@gunnar.cc (Gunnar Hjalmarsson)
wrote:

>"Steffen Beyer" <Steffen.Beyer@de.bosch.com> wrote in message news:<b34itt$hn8$1@ns2.fe.internet.bosch.com>...
>> But in general, it is of course a good idea not to re-invent
>> the wheel and to use modules wherever possible.
>> 
>> I'm the last to object because I'm a module author myself. :-)
>
>I don't agree on "wherever possible".
>
>I started to write my first Perl/CGI program about three years ago
>with (almost) no programming experience. I applied the "learning by
>doing" approach. Don't we all, btw? ;-)
>
>Anyway, personally I like to really understand what I'm doing. I
>believe that most often, when people use modules, they don't care to
>learn how they really work. Another aspect is that some modules are
>very large, and require quite some effort before you can use them and
>still feel reasonably comfortable.
>
>Consequently, in order to be in control and more rapidly increase my
>own Perl/CGI knowledge, I prefer to "re-invent the wheel", before
>using modules, for tasks that I consider to be *simple enough*.
>Nevertheless, I often study modules without using them, and sometimes
>I copy methods from them.
>
>Recently I uploaded my first CPAN module, CGI::ContactForm
>(http://search.cpan.org/author/GUNNAR/), and, believe it or not, even
>if it's a pure CGI module, I'm not using CGI.pm.
>
>I Guess I'm expressing a slightly provocative view here. But am I
>really that wrong?


I see your point.  However, I would not want to program C without
libraries.  If I need more specific functionality than one of the core
module provides I'd rather subclass it than redo the entire thing.  Then
again, I have been on projects where I read RFC's till I was blind only
to learn that there was a solution on CPAN (I was getting paid by the
hour -- so maybe this was not a bad thing ...)


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

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.  

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


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