[24110] in Perl-Users-Digest
Perl-Users Digest, Issue: 6304 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 26 06:05:37 2004
Date: Fri, 26 Mar 2004 03:05:08 -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 Fri, 26 Mar 2004 Volume: 10 Number: 6304
Today's topics:
Re: Declaring variables outside subroutines <Joe.Smith@inwap.com>
Re: Declaring variables outside subroutines <vetro@online.no>
Re: demystifying UTF-8 and quotelike <kuujinbo@hotmail.com>
Re: demystifying UTF-8 and quotelike <Joe.Smith@inwap.com>
Re: directory properties (Andy)
Re: How to interpolate string containing a variable (Anno Siegel)
Re: How to interpolate string containing a variable <mark.gaber@obs.unige.ch>
How to store multiple value in a Hash for cookies <nvidiawt3@dart.net.au>
Re: How to store multiple value in a Hash for cookies <noreply@gunnar.cc>
Re: How to store multiple value in a Hash for cookies <Joe.Smith@inwap.com>
Re: I want to scanf, dammit! <mitia.nospam@northwestern.edu.invalid>
Re: I want to scanf, dammit! <mitia.nospam@northwestern.edu.invalid>
Re: I want to scanf, dammit! <mitia.nospam@northwestern.edu.invalid>
Re: I want to scanf, dammit! (Anno Siegel)
Re: I want to scanf, dammit! <vetro@online.no>
Re: I want to scanf, dammit! <Joe.Smith@inwap.com>
Re: Parsing from file <Joe.Smith@inwap.com>
Re: Perl DB: how2 silence "redefined" warnings? <Joe.Smith@inwap.com>
Posting Guidelines for comp.lang.perl.misc ($Revision: tadmc@augustmail.com
Re: problem with index not matching string exactly <uri.guttman@fmr.com>
scalar or array? (mike)
Re: scalar or array? <noreply@gunnar.cc>
Re: Signal handling in objects. Good idea? Best pract (Anno Siegel)
Re: The "value" of a block in 'map' (Anno Siegel)
Re: Unix sokets and signal handling <online-toglimi@carpani-toglimi.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 26 Mar 2004 09:47:18 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Declaring variables outside subroutines
Message-Id: <G_S8c.97639$_w.1295666@attbi_s53>
Appoooh wrote:
> I'm no guru, and I haven't been programming professionally for long, but I
> can't help finding it disturbing that in the code below, $var is in scope
> within the subroutine foo. This is a bit eccentric compared to C++ or Java
It's standard procedure for creating static variables in C.
-Joe
------------------------------
Date: Fri, 26 Mar 2004 11:04:58 +0100
From: Vetle Roeim <vetro@online.no>
Subject: Re: Declaring variables outside subroutines
Message-Id: <m33c7v3ovp.fsf@quimby.dirtyhack.org>
* anon@ics.mq.edu.au
> I'm no guru, and I haven't been programming professionally for long, but I
> can't help finding it disturbing that in the code below, $var is in scope
> within the subroutine foo.
It's not unique for Perl. Other languages have it too. Python, for
instance:
var = "fnord"
def printvar():
print var
> This is a bit eccentric compared to C++ or Java ... do perl hackers
> just accept this?
You wouldn't find it disturbing if you knew more about different
languages and scope rules. Learning Perl is a step in the right
direction. :)
(...)
--
#!/usr/bin/vr
------------------------------
Date: Fri, 26 Mar 2004 18:00:08 +0900
From: ko <kuujinbo@hotmail.com>
Subject: Re: demystifying UTF-8 and quotelike
Message-Id: <c40rf1$2e845m$1@ID-227975.news.uni-berlin.de>
valued customer wrote:
> ### PROBLEM
>
> As you already know, the perl 'quotelike' operator is a useful and
> quite unique feature of perl for specifying arbitrary strings in
> your code. It helps you to avoid the need to add a lot of cumbersome
> 'escape' characters.
>
> The problem is this, Unicode messes up the operation of the
> 'quotelike' operator! If you have a text editor that allows
> you to save a file as UTF-8 instead of ASCII, the following
=========^^^^^^^^^^^^^^^^^^^^========
Try adding the following statement:
use utf8;
> demonstration code illustrates this point:
>
> print q^"Jump!" said Jack^; ### <-- works as expected
> print ("\n-----------------------------------\n");
>
> print q@"Jump!" said Jack@; ### <-- works as expected
> print ("\n-----------------------------------\n");
>
> print q§"Jump!" said Jack§; ## <-- FAILS in utf-8, works in ASCII
> print ("\n-----------------------------------\n");
>
> ### QUESTIONS
> Why does this not work as expected? Is this a bug, feature, or
> misuse of the quotelike operator? Is there a non-baffling
> explaination of what UTF-8 does to mess things up?
Reading the following documentation should help clarify things for you:
perldoc perluniintro
perldoc utf8
HTH - keith
------------------------------
Date: Fri, 26 Mar 2004 09:23:28 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: demystifying UTF-8 and quotelike
Message-Id: <kES8c.95768$1p.1448406@attbi_s54>
valued customer wrote:
> The problem is this, Unicode messes up the operation of the
> 'quotelike' operator! If you have a text editor that allows
> you to save a file as UTF-8 instead of ASCII, ...
Unless told otherwise, perl assumes that the scripts is ASCII
or ISO-latin1. If you feed it a UTF-8 file instead, you will
need to inform perl that you are doing so. Some versions of
perl require a valid BOM at the beginning of the file. Others
want to see "use utf8;" before the first high-bit byte.
-Joe
------------------------------
Date: 26 Mar 2004 01:16:24 -0800
From: andreasmaier@nurfuerspam.de (Andy)
Subject: Re: directory properties
Message-Id: <ee11c0d9.0403260116.788c6a1b@posting.google.com>
Thanks, Win32::FileSecurity works fine.
------------------------------
Date: 26 Mar 2004 09:12:56 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: How to interpolate string containing a variable
Message-Id: <c40s6o$8c8$1@mamenchi.zrz.TU-Berlin.DE>
Matt Garrish <matthew.garrish@sympatico.ca> wrote in comp.lang.perl.misc:
>
> "Mark Gaber" <mark.gaber@obs.unige.ch> wrote in message
> news:40635605.C81F56B4@obs.unige.ch...
> > Hello,
> >
> > I have a string variable which contains a command to be executed using
> > backticks ``. The command involves variables and so has to be
> > interpolated. For example, the following does a touch of /tmp/zzTest:
> >
> > #!/usr/bin/perl
> >
> > $filename = "/tmp/zzTest";
> > $strCmd = "`touch \$filename`";
> >
>
> You aren't interpolating the variable into the string. You're escaping the
> dollar sign, so you wind up with `touch $filename` as your string. If you
> want string interpolation, don't use a slash:
>
> $strCmd = "`touch $filename`";
>
> >
> > eval ${\ $strCmd };
> >
>
> What on earth is this eval? Is the following what you are after?
>
> eval "$strCmd";
Why the quotes?
Anno
------------------------------
Date: Fri, 26 Mar 2004 11:14:55 +0100
From: Mark Gaber <mark.gaber@obs.unige.ch>
Subject: Re: How to interpolate string containing a variable
Message-Id: <4064029F.AE5CED2@obs.unige.ch>
Anno Siegel wrote:
>
> Matt Garrish <matthew.garrish@sympatico.ca> wrote in comp.lang.perl.misc:
> >
> > "Mark Gaber" <mark.gaber@obs.unige.ch> wrote in message
> > news:40635605.C81F56B4@obs.unige.ch...
> > > Hello,
> > >
> > > I have a string variable which contains a command to be executed using
> > > backticks ``. The command involves variables and so has to be
> > > interpolated. For example, the following does a touch of /tmp/zzTest:
> > >
> > > #!/usr/bin/perl
> > >
> > > $filename = "/tmp/zzTest";
> > > $strCmd = "`touch \$filename`";
> > >
> >
> > You aren't interpolating the variable into the string. You're escaping the
> > dollar sign, so you wind up with `touch $filename` as your string. If you
> > want string interpolation, don't use a slash:
> >
> > $strCmd = "`touch $filename`";
> >
> > >
> > > eval ${\ $strCmd };
> > >
> >
> > What on earth is this eval? Is the following what you are after?
> >
> > eval "$strCmd";
>
> Why the quotes?
>
> Anno
Great, the eval is understandable now (works indeed without the quotes).
I started from the Perl cookbook without really understanding their
context. Thanks for that.
I realize that I am escaping the dollar sign; this is on purpose just to
be able to to have a simple example. The actual case is one in which we
have a perl script that will launch a series of executables and save the
results. This perl script will be used for testing the executables
using different inputs, to the launch commands are long and have
variables to avoid hardcoding values that repeat. There are different
ways to pass the information to the perl script, and the one chosen led
to the above situation.
I am almost sure that there is a way in Perl to make it evaluate the
string so that the logging is more informative. Answering your mails
led me to consider different approaches which might have been better,
but still, for knowledge sake, I would like to know how to do this
evaluation.
Thanks for your help.
Mark
------------------------------
Date: Fri, 26 Mar 2004 18:23:48 +1000
From: Nvidia <nvidiawt3@dart.net.au>
Subject: How to store multiple value in a Hash for cookies
Message-Id: <c40paj$cv5$1@gnamma.connect.com.au>
Hello
I have just started learning PERL and I have written a simple CGI script.
Inside this script, I have a group of checkboxes:
1. name: "tools"
values: "hammer", "nails", "screwdriver"
2. name: "cars"
values: "sedan", "hatch", "sports"
and also a submit button. The user can choose any number of tools or
cars from the checkboxes. After submit button is clicked, the perl
scripts will put the data into a hash.
BUT I'm having problem storing multiple values into a hash. Even when
user click more than 1 value in each group of checkboxes, my hash only
have one item in each group.
I need to use hash because I want to store the number of checkboxes the
user "checked" in the cookies.
Can anyone HELP???
Regards
------------------------------
Date: Fri, 26 Mar 2004 10:14:35 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: How to store multiple value in a Hash for cookies
Message-Id: <c40s88$2cfr0j$1@ID-184292.news.uni-berlin.de>
Nvidia wrote:
> Can anyone HELP???
Not without code. Please post a small but complete program that people
can copy and run and that illustrates the problem.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Fri, 26 Mar 2004 09:27:58 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: How to store multiple value in a Hash for cookies
Message-Id: <yIS8c.95803$1p.1448301@attbi_s54>
Nvidia wrote:
> BUT I'm having problem storing multiple values into a hash. Even when
> user click more than 1 value in each group of checkboxes, my hash only
> have one item in each group.
There's all sorts of things you can store in a hash.
A simple string (like you are currently doing),
a multi-value space-delimited string,
a multi-value "\0"-delimited string, or
a reference to an anonymous array of strings.
The latter is called a hash of arrays.
From the command line,
perldoc perlreftut
will get you started.
-Joe
------------------------------
Date: 26 Mar 2004 08:41:24 GMT
From: Dmitry Epstein <mitia.nospam@northwestern.edu.invalid>
Subject: Re: I want to scanf, dammit!
Message-Id: <Xns94B81CD9BB8A7mitianorthwesternedu@63.218.45.21>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in
news:c3vc0e$a0d$1@mamenchi.zrz.TU-Berlin.DE:
> Dmitry Epstein <mitia.nospam@northwestern.edu.invalid> wrote
> in comp.lang.perl.misc:
>> anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in
>> news:c3u5gn$elj$1@mamenchi.zrz.TU-Berlin.DE:
>> > Dmitry Epstein <mitia.nospam@northwestern.edu.invalid>
>> > wrote in comp.lang.perl.misc:
>
> [find the nth number in a file]
>
>> > my $n = 500;
>> > my @line;
>> > while ( <DATA> ) { last if ( $n -= @line = split) < 0 }
>> > print "$line[ $n]\n";
>> >
>>
>> I think your $n is negative by the time you get to the last
>> statement, no?
>
> Yes, it is, in exactly the right way :) Look for "negative"
> in perldata.
Well, you live and learn:
"Normal arrays are ordered lists of scalars indexed by number,
starting with 0 and with negative subscripts counting from the
end."
------------------------------
Date: 26 Mar 2004 08:44:59 GMT
From: Dmitry Epstein <mitia.nospam@northwestern.edu.invalid>
Subject: Re: I want to scanf, dammit!
Message-Id: <Xns94B81D756C8E9mitianorthwesternedu@63.218.45.21>
"Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote in
news:c3vj6k$5c$1@nets3.rz.RWTH-Aachen.DE:
>>> If it doesnt, just use Inline::C.
>>
>> Er.. what's that?
>
> Inline::C allows you to embed C code into your Perl script.
> Here's a super-simplistic scanner on top of fscanf() available
> from Perl:
>
> #! /usr/bin/perl -w
>
> use strict;
> use Inline Config => BUILD_NOISY => 1;
> use Inline 'C';
[snip]
I am sorry, I can't find any mention of Inline in my Perl docs...
------------------------------
Date: 26 Mar 2004 08:56:57 GMT
From: Dmitry Epstein <mitia.nospam@northwestern.edu.invalid>
Subject: Re: I want to scanf, dammit!
Message-Id: <Xns94B81F7CF7D8Dmitianorthwesternedu@63.218.45.21>
Paul Lalli <ittyspam@yahoo.com> wrote in
news:20040325145317.G21521@dishwasher.cs.rpi.edu:
> On Thu, 25 Mar 2004, Paul Lalli wrote:
>
>> On Thu, 25 Mar 2004, Dmitry Epstein wrote:
>>
>> > I have a file with floats separated by spaces and newlines.
>> > There can be several numbers per line, but I don't know
>> > and don't care about exactly how they are written because
>> > that has no relation to the logic of the problem. Suppose
>> > the file contains 2500 numbers and I need to read the first
>> > 500, or better yet, read just the number #500. This number
>> > can be in the middle of a line, for all I know.
>> >
>>
>> use strict;
>> use warnings;
>> use File::Stream;
>>
>> open my $fh, $ARGV[0] or die "Cannot open $ARGV[0]: $!";
>> my $fs = File::Stream->new($fh);
>> local $/ = qr/\s+/;
[snip]
Thanks! Din't know about that Stream module. Will download.
--
Dmitry Epstein
Northwestern University, Evanston, IL. USA
mitia(at)northwestern(dot)edu
------------------------------
Date: 26 Mar 2004 09:22:30 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: I want to scanf, dammit!
Message-Id: <c40som$8c8$2@mamenchi.zrz.TU-Berlin.DE>
Dmitry Epstein <mitia.nospam@northwestern.edu.invalid> wrote in comp.lang.perl.misc:
> "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de> wrote in
> news:c3vj6k$5c$1@nets3.rz.RWTH-Aachen.DE:
> >>> If it doesnt, just use Inline::C.
> >>
> >> Er.. what's that?
> >
> > Inline::C allows you to embed C code into your Perl script.
> > Here's a super-simplistic scanner on top of fscanf() available
> > from Perl:
> >
> > #! /usr/bin/perl -w
> >
> > use strict;
> > use Inline Config => BUILD_NOISY => 1;
> > use Inline 'C';
> [snip]
>
> I am sorry, I can't find any mention of Inline in my Perl docs...
It's a standard module, "perldoc Inline" should show it. If not,
http://cpan.uwinnipeg.ca/htdocs/Inline/, but you should check your
installation.
Anno
------------------------------
Date: Fri, 26 Mar 2004 10:29:29 +0100
From: Vetle Roeim <vetro@online.no>
Subject: Re: I want to scanf, dammit!
Message-Id: <m38yho2bye.fsf@quimby.dirtyhack.org>
* Dmitry Epstein
(...)
> I am sorry, I can't find any mention of Inline in my Perl docs...
<URL:http://search.cpan.org>. Search for Inline and Inline::C.
--
#!/usr/bin/vr
------------------------------
Date: Fri, 26 Mar 2004 09:42:20 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: I want to scanf, dammit!
Message-Id: <0WS8c.97602$_w.1296756@attbi_s53>
Dmitry Epstein wrote:
>>>>If it doesnt, just use Inline::C.
>>>
>>>Er.. what's that?
> I am sorry, I can't find any mention of Inline in my Perl docs...
The double colons indicate it is a perl module.
If you download the perl sources, you will get a bunch of core modules
with docs. If you download a distribution (like ActiveState's), you
will get more modules with docs. But that doesn't cover all possible
modules.
If it's not in your docs, and not on your disk, the thing to do is
go fetch it from CPAN. http://search.cpan.org/
-Joe
------------------------------
Date: Fri, 26 Mar 2004 09:14:11 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Parsing from file
Message-Id: <DvS8c.97433$_w.1296403@attbi_s53>
Toni wrote:
> So, in $array I get a string "Par1 Val1 Par2 Val2 ...".
> And now I want to have this.
>
> my $var1 =
> [
> { name => 'Par1', value => 'Val1' },
> { name => 'Par2', value => 'Val2' },
> ...
> ];
>
> my $var2 =
> [
> { name => 'Par3', value => 'Val3' },
> { name => 'Par4', value => 'Val4' },
> { name => 'Par5', value => 'Val5' },
> ...
> ];
No, you don't want that. You want a hash of hashes.
my %vars = (
Option1 => { Par1 => 'Val1',
Par2 => 'Val2' },
Option2 => { Par3 => 'Val3',
Par4 => 'Val4',
Par5 => 'Val5'}
);
foreach my $opt (sort keys %vars) {
foreach my $parm (sort keys %{$vars{$opt}}) {
print "$opt:$parm = $vars{$opt}{$parm}\n";
}
}
See how easy it is to iterate over all the options?
-Joe
--
I love my TiVo - http://www.inwap.com/u/joe/tivo/
------------------------------
Date: Fri, 26 Mar 2004 09:52:15 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Perl DB: how2 silence "redefined" warnings?
Message-Id: <j3T8c.97687$_w.1297229@attbi_s53>
kj wrote:
> Thanks. As it turns out, the problem vanished mysteriously. I
> don't know what's different now, but the warning messages no longer
> appear when I repeatedly re-invoke "do 'some_perl_file.pl'", even
> though I can confirm that subs *are* being redefined. Perl is one
> mysterious universe...
Sounds similar to the difference between
#!/usr/bin/perl -w
...
and
#!/usr/bin/perl
use warnings;
...
------------------------------
Date: Fri, 26 Mar 2004 02:22:40 -0600
From: tadmc@augustmail.com
Subject: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.5 $)
Message-Id: <NZudnX_Cm4_Ndf7dRVn-sA@august.net>
Outline
Before posting to comp.lang.perl.misc
Must
- Check the Perl Frequently Asked Questions (FAQ)
- Check the other standard Perl docs (*.pod)
Really Really Should
- Lurk for a while before posting
- Search a Usenet archive
If You Like
- Check Other Resources
Posting to comp.lang.perl.misc
Is there a better place to ask your question?
- Question should be about Perl, not about the application area
How to participate (post) in the clpmisc community
- Carefully choose the contents of your Subject header
- Use an effective followup style
- Speak Perl rather than English, when possible
- Ask perl to help you
- Do not re-type Perl code
- Provide enough information
- Do not provide too much information
- Do not post binaries, HTML, or MIME
Social faux pas to avoid
- Asking a Frequently Asked Question
- Asking a question easily answered by a cursory doc search
- Asking for emailed answers
- Beware of saying "doesn't work"
- Sending a "stealth" Cc copy
Be extra cautious when you get upset
- Count to ten before composing a followup when you are upset
- Count to ten after composing and before posting when you are upset
-----------------------------------------------------------------
Posting Guidelines for comp.lang.perl.misc ($Revision: 1.5 $)
This newsgroup, commonly called clpmisc, is a technical newsgroup
intended to be used for discussion of Perl related issues (except job
postings), whether it be comments or questions.
As you would expect, clpmisc discussions are usually very technical in
nature and there are conventions for conduct in technical newsgroups
going somewhat beyond those in non-technical newsgroups.
The article at:
http://www.catb.org/~esr/faqs/smart-questions.html
describes how to get answers from technical people in general.
This article describes things that you should, and should not, do to
increase your chances of getting an answer to your Perl question. It is
available in POD, HTML and plain text formats at:
http://mail.augustmail.com/~tadmc/clpmisc.shtml
For more information about netiquette in general, see the "Netiquette
Guidelines" at:
http://andrew2.andrew.cmu.edu/rfc/rfc1855.html
A note to newsgroup "regulars":
Do not use these guidelines as a "license to flame" or other
meanness. It is possible that a poster is unaware of things
discussed here. Give them the benefit of the doubt, and just
help them learn how to post, rather than assume
A note about technical terms used here:
In this document, we use words like "must" and "should" as
they're used in technical conversation (such as you will
encounter in this newsgroup). When we say that you *must* do
something, we mean that if you don't do that something, then
it's unlikely that you will benefit much from this group.
We're not bossing you around; we're making the point without
lots of words.
Do *NOT* send email to the maintainer of these guidelines. It will be
discarded unread. The guidelines belong to the newsgroup so all
discussion should appear in the newsgroup. I am just the secretary that
writes down the consensus of the group.
Before posting to comp.lang.perl.misc
Must
This section describes things that you *must* do before posting to
clpmisc, in order to maximize your chances of getting meaningful replies
to your inquiry and to avoid getting flamed for being lazy and trying to
have others do your work.
The perl distribution includes documentation that is copied to your hard
drive when you install perl. Also installed is a program for looking
things up in that (and other) documentation named 'perldoc'.
You should either find out where the docs got installed on your system,
or use perldoc to find them for you. Type "perldoc perldoc" to learn how
to use perldoc itself. Type "perldoc perl" to start reading Perl's
standard documentation.
Check the Perl Frequently Asked Questions (FAQ)
Checking the FAQ before posting is required in Big 8 newsgroups in
general, there is nothing clpmisc-specific about this requirement.
You are expected to do this in nearly all newsgroups.
You can use the "-q" switch with perldoc to do a word search of the
questions in the Perl FAQs.
Check the other standard Perl docs (*.pod)
The perl distribution comes with much more documentation than is
available for most other newsgroups, so in clpmisc you should also
see if you can find an answer in the other (non-FAQ) standard docs
before posting.
It is *not* required, or even expected, that you actually *read* all of
Perl's standard docs, only that you spend a few minutes searching them
before posting.
Try doing a word-search in the standard docs for some words/phrases
taken from your problem statement or from your very carefully worded
"Subject:" header.
Really Really Should
This section describes things that you *really should* do before posting
to clpmisc.
Lurk for a while before posting
This is very important and expected in all newsgroups. Lurking means
to monitor a newsgroup for a period to become familiar with local
customs. Each newsgroup has specific customs and rituals. Knowing
these before you participate will help avoid embarrassing social
situations. Consider yourself to be a foreigner at first!
Search a Usenet archive
There are tens of thousands of Perl programmers. It is very likely
that your question has already been asked (and answered). See if you
can find where it has already been answered.
One such searchable archive is:
http://groups.google.com/advanced_group_search
If You Like
This section describes things that you *can* do before posting to
clpmisc.
Check Other Resources
You may want to check in books or on web sites to see if you can
find the answer to your question.
But you need to consider the source of such information: there are a
lot of very poor Perl books and web sites, and several good ones
too, of course.
Posting to comp.lang.perl.misc
There can be 200 messages in clpmisc in a single day. Nobody is going to
read every article. They must decide somehow which articles they are
going to read, and which they will skip.
Your post is in competition with 199 other posts. You need to "win"
before a person who can help you will even read your question.
These sections describe how you can help keep your article from being
one of the "skipped" ones.
Is there a better place to ask your question?
Question should be about Perl, not about the application area
It can be difficult to separate out where your problem really is,
but you should make a conscious effort to post to the most
applicable newsgroup. That is, after all, where you are the most
likely to find the people who know how to answer your question.
Being able to "partition" a problem is an essential skill for
effectively troubleshooting programming problems. If you don't get
that right, you end up looking for answers in the wrong places.
It should be understood that you may not know that the root of your
problem is not Perl-related (the two most frequent ones are CGI and
Operating System related), so off-topic postings will happen from
time to time. Be gracious when someone helps you find a better place
to ask your question by pointing you to a more applicable newsgroup.
How to participate (post) in the clpmisc community
Carefully choose the contents of your Subject header
You have 40 precious characters of Subject to win out and be one of
the posts that gets read. Don't waste them. Take care while
composing them, they are the key that opens the door to getting an
answer.
Spend them indicating what aspect of Perl others will find if they
should decide to read your article.
Do not spend them indicating "experience level" (guru, newbie...).
Do not spend them pleading (please read, urgent, help!...).
Do not spend them on non-Subjects (Perl question, one-word
Subject...)
For more information on choosing a Subject see "Choosing Good
Subject Lines":
http://www.cpan.org/authors/id/D/DM/DMR/subjects.post
Part of the beauty of newsgroup dynamics, is that you can contribute
to the community with your very first post! If your choice of
Subject leads a fellow Perler to find the thread you are starting,
then even asking a question helps us all.
Use an effective followup style
When composing a followup, quote only enough text to establish the
context for the comments that you will add. Always indicate who
wrote the quoted material. Never quote an entire article. Never
quote a .signature (unless that is what you are commenting on).
Intersperse your comments *following* each section of quoted text to
which they relate. Unappreciated followup styles are referred to as
"top-posting", "Jeopardy" (because the answer comes before the
question), or "TOFU" (Text Over, Fullquote Under).
Reversing the chronology of the dialog makes it much harder to
understand (some folks won't even read it if written in that style).
For more information on quoting style, see:
http://web.presby.edu/~nnqadmin/nnq/nquote.html
Speak Perl rather than English, when possible
Perl is much more precise than natural language. Saying it in Perl
instead will avoid misunderstanding your question or problem.
Do not say: I have variable with "foo\tbar" in it.
Instead say: I have $var = "foo\tbar", or I have $var = 'foo\tbar',
or I have $var = <DATA> (and show the data line).
Ask perl to help you
You can ask perl itself to help you find common programming mistakes
by doing two things: enable warnings (perldoc warnings) and enable
"strict"ures (perldoc strict).
You should not bother the hundreds/thousands of readers of the
newsgroup without first seeing if a machine can help you find your
problem. It is demeaning to be asked to do the work of a machine. It
will annoy the readers of your article.
You can look up any of the messages that perl might issue to find
out what the message means and how to resolve the potential mistake
(perldoc perldiag). If you would like perl to look them up for you,
you can put "use diagnostics;" near the top of your program.
Do not re-type Perl code
Use copy/paste or your editor's "import" function rather than
attempting to type in your code. If you make a typo you will get
followups about your typos instead of about the question you are
trying to get answered.
Provide enough information
If you do the things in this item, you will have an Extremely Good
chance of getting people to try and help you with your problem!
These features are a really big bonus toward your question winning
out over all of the other posts that you are competing with.
First make a short (less than 20-30 lines) and *complete* program
that illustrates the problem you are having. People should be able
to run your program by copy/pasting the code from your article. (You
will find that doing this step very often reveals your problem
directly. Leading to an answer much more quickly and reliably than
posting to Usenet.)
Describe *precisely* the input to your program. Also provide example
input data for your program. If you need to show file input, use the
__DATA__ token (perldata.pod) to provide the file contents inside of
your Perl program.
Show the output (including the verbatim text of any messages) of
your program.
Describe how you want the output to be different from what you are
getting.
If you have no idea at all of how to code up your situation, be sure
to at least describe the 2 things that you *do* know: input and
desired output.
Do not provide too much information
Do not just post your entire program for debugging. Most especially
do not post someone *else's* entire program.
Do not post binaries, HTML, or MIME
clpmisc is a text only newsgroup. If you have images or binaries
that explain your question, put them in a publically accessible
place (like a Web server) and provide a pointer to that location. If
you include code, cut and paste it directly in the message body.
Don't attach anything to the message. Don't post vcards or HTML.
Many people (and even some Usenet servers) will automatically filter
out such messages. Many people will not be able to easily read your
post. Plain text is something everyone can read.
Social faux pas to avoid
The first two below are symptoms of lots of FAQ asking here in clpmisc.
It happens so often that folks will assume that it is happening yet
again. If you have looked but not found, or found but didn't understand
the docs, say so in your article.
Asking a Frequently Asked Question
It should be understood that you may have missed the applicable FAQ
when you checked, which is not a big deal. But if the Frequently
Asked Question is worded similar to your question, folks will assume
that you did not look at all. Don't become indignant at pointers to
the FAQ, particularly if it solves your problem.
Asking a question easily answered by a cursory doc search
If folks think you have not even tried the obvious step of reading
the docs applicable to your problem, they are likely to become
annoyed.
If you are flamed for not checking when you *did* check, then just
shrug it off (and take the answer that you got).
Asking for emailed answers
Emailed answers benefit one person. Posted answers benefit the
entire community. If folks can take the time to answer your
question, then you can take the time to go get the answer in the
same place where you asked the question.
It is OK to ask for a *copy* of the answer to be emailed, but many
will ignore such requests anyway. If you munge your address, you
should never expect (or ask) to get email in response to a Usenet
post.
Ask the question here, get the answer here (maybe).
Beware of saying "doesn't work"
This is a "red flag" phrase. If you find yourself writing that,
pause and see if you can't describe what is not working without
saying "doesn't work". That is, describe how it is not what you
want.
Sending a "stealth" Cc copy
A "stealth Cc" is when you both email and post a reply without
indicating *in the body* that you are doing so.
Be extra cautious when you get upset
Count to ten before composing a followup when you are upset
This is recommended in all Usenet newsgroups. Here in clpmisc, most
flaming sub-threads are not about any feature of Perl at all! They
are most often for what was seen as a breach of netiquette. If you
have lurked for a bit, then you will know what is expected and won't
make such posts in the first place.
But if you get upset, wait a while before writing your followup. I
recommend waiting at least 30 minutes.
Count to ten after composing and before posting when you are upset
After you have written your followup, wait *another* 30 minutes
before committing yourself by posting it. You cannot take it back
once it has been said.
AUTHOR
Tad McClellan <tadmc@augustmail.com> and many others on the
comp.lang.perl.misc newsgroup.
------------------------------
Date: 25 Mar 2004 14:44:21 -0500
From: Uri Guttman <uri.guttman@fmr.com>
Subject: Re: problem with index not matching string exactly
Message-Id: <sisc65csiuei.fsf@tripoli.fmr.com>
>>>>> "G" == G <bay_dar@yahoo.com> writes:
G> - Also note we have entires of m423, m423a and m423b. The problem with
G> my code, is that it matches the $entered_code of m423 to m423, m423a,
G> and m423b but I want it to only match up to m423. Of course 423 should
G> only match up to 423 and so on. Anyone have a suggestion to fix this?
G> my @code = split /,/, $exits;
G> if (index($code, $entered_code) != -1) {
why are you using index there? index only tells where the string is if
found. a simple eq is all you need there.
uri
------------------------------
Date: 26 Mar 2004 00:51:08 -0800
From: s99999999s2003@yahoo.com (mike)
Subject: scalar or array?
Message-Id: <dfd17ef4.0403260051.7d8b3ea@posting.google.com>
hi
sometimes i see code like "@$results".
what does that mean? Does it mean converting a scalar to an array??
thanks
------------------------------
Date: Fri, 26 Mar 2004 10:20:57 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: scalar or array?
Message-Id: <c40sk6$2c0iqb$1@ID-184292.news.uni-berlin.de>
mike wrote:
> sometimes i see code like "@$results".
> what does that mean? Does it mean converting a scalar to an array??
It means "converting" (or dereferencing) an *array reference* to an
array. This in an intro to references in Perl:
http://www.perldoc.com/perl5.8.0/pod/perlreftut.html
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: 26 Mar 2004 10:24:56 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Signal handling in objects. Good idea? Best practices?
Message-Id: <c410do$ad1$1@mamenchi.zrz.TU-Berlin.DE>
A. Sinan Unur <1usa@llenroc.ude> wrote in comp.lang.perl.misc:
> carltonbrown@hotmail.com (Carlton Brown) wrote in
> news:aa611a32.0403251545.2c484b80@posting.google.com:
>
> > Is it "right" to try to define signal handlers in a class, or should
> > this be handled elsewhere such as the implementation code? How should
> > I be thinking about this problem?
[...]
> > sub new($) {
> > my $classname = shift;
> > my $self = {};
> > bless($self, $classname);
> > warn "Created object of type $classname";
> > $SIG{'INT'} = $self->gripe();
>
> Here you assign to $SIG{'INT'} the return value of the $self->gripe()
> method call. That is why you see the statement printed once at object
> creation time.
>
> > return $self;
> > }
> >
> > sub gripe($) {
> > my $self = shift;
> > print "What do you want?\n";
> > }
> > return 1;
>
> I am not going to be able to speak to design issues except to note that I
> would find it odd to have 10 different signal handlers for the same
> signal.
>
> I also do not know the correct syntax for obtaining to references to
> methods of on object and too lazy right now to look it up.
my $coderef = $self->can( 'gripe');
However, the automatic calls to $SIG{INT} aren't method calls, so putting
that in $SIG{INT} won't work right with "real" methods (as opposed to
ones that ignore their first argument). It also freezes method resolution
to the moment when $SIG{INT} is set, so dynamic changes in inheritance
wouldn't be honored.
The new() method could do this:
$SIG{'INT'} = sub { $self->gripe };
That would call ->gripe correctly and do method dispatch each time.
To OP: The prototypes ($) in method definitions are ignored. They
shouldn't be there.
Anno
------------------------------
Date: 26 Mar 2004 08:09:41 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: The "value" of a block in 'map'
Message-Id: <c40og5$5bn$2@mamenchi.zrz.TU-Berlin.DE>
Bernie Cosell <bernie@fantasyfarm.com> wrote in comp.lang.perl.misc:
> Tad McClellan <tadmc@augustmail.com> wrote:
>
> } Bernie Cosell <bernie@fantasyfarm.com> wrote:
>
> } >>>> open(FOO) ? 'hi mom' : die "Can't open $FOO: $!";
> } >>>> # a bit exotic, that last one
> } >>>>
> } >
> } > Isn't "that last one" not only exotic, but incorrect???
> }
> }
> } No.
> }
> } > [in fact, won't it
> } > *always* 'die' regardless of whether the open works or not?]
>
> [...]
>
> } Do you know how the ?: operator works?
>
> Yes, in fact I do: but as it turns out, of all of the languages [and there
> are several] that have this ternary operator, *ONLY*PERL* short-circuits
> it.
Not true.
Afaik, "?:" appeared first in C, which *does* short-circuit.
1 ? printf( "hi\n") : printf( "ho\n");
prints only "hi".
Anno
------------------------------
Date: Fri, 26 Mar 2004 10:48:06 +0100
From: ".a.c." <online-toglimi@carpani-toglimi.net>
Subject: Re: Unix sokets and signal handling
Message-Id: <pan.2004.03.26.09.48.06.939122@carpani-toglimi.net>
Il Thu, 25 Mar 2004 18:01:03 +0000, Brian McCauley ha scritto:
> Check $! when accept() returns false. If it's Errno::EINTR then don't
> exit the loop.
Thanks
---
.a.c.
------------------------------
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 6304
***************************************