[21992] in Perl-Users-Digest
Perl-Users Digest, Issue: 4214 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Dec 4 09:05:46 2002
Date: Wed, 4 Dec 2002 06:05: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 Wed, 4 Dec 2002 Volume: 10 Number: 4214
Today's topics:
Re: any cool script site??? (Tad McClellan)
Compile perl5.8 on sco5.05 <markr@NOTHANKYOUbluecap.co.uk>
forking server and autoflush? <astone@i.net>
Re: how to get it quoted? <nobull@mail.com>
Re: passing data between perl scripts and a module: pro (Ben Morrow)
Re: passing data between perl scripts and a module: pro (Tad McClellan)
Re: Perl Packages question (Kasp)
Posting Guidelines for comp.lang.perl.misc ($Revision: tadmc@augustmail.com
PWD detection without $ENV? (Vorxion)
Re: PWD detection without $ENV? <billy@arnis-bsl.com>
Re: PWD detection without $ENV? (Helgi Briem)
Redirect ls -l output <jon@rogers.tv>
Re: Redirect ls -l output <ian@WINDOZEdigiserv.net>
Re: Redirect ls -l output (Ben Morrow)
Re: Redirect ls -l output (Helgi Briem)
Re: Redirect ls -l output <jurgenex@hotmail.com>
Re: RegExp: Capturing parentheses in quantified sub-pat <julian@mehnle.net>
Re: RegExp: Capturing parentheses in quantified sub-pat <robertbu@hotmail.com>
RegExp: Capturing parentheses in quantified sub-pattern <julian@mehnle.net>
rolling my own perl-based content management system <nuba@dcc.ufmg.br>
Re: Warnings when creating an array of hashes <s.patterson@freeuk.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 4 Dec 2002 07:11:35 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: any cool script site???
Message-Id: <slrnaurvo7.32t.tadmc@magna.augustmail.com>
palladium@spinn.net <palladium@spinn.net> wrote:
> On 3 Dec 2002 04:32:01 -0800, keshavforever@rediffmail.com (keshav
> prasad) wrote:
>>if you know any cool network script site.. please tell me
> Yeah.. Matt's Script Archive.....Everyone uses it !
^^^^^^^^
The world is full of silly people, emulating them is risky.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 4 Dec 2002 12:45:05 -0000
From: "Mark R" <markr@NOTHANKYOUbluecap.co.uk>
Subject: Compile perl5.8 on sco5.05
Message-Id: <3dedf3ad$1@news.star.co.uk>
Hi,
I'm trying to compile perl5.8.0 on Sco OSR5.05 with gcc 2.95 but get this
error.
Can anyone help me out on this?
Many thanks
BEGIN failed--compilation aborted at lib/lib_pm.PL line 1.
make: *** [lib/lib.pm] Error 2
------------------------------
Date: Wed, 04 Dec 2002 12:30:44 GMT
From: astone <astone@i.net>
Subject: forking server and autoflush?
Message-Id: <MPG.18581391bc8ad463989725@news.pandora.be>
Hi all
As a fairly new perl programmer, i'm working on a small application
which includes a forking server. But i'm having a little problem.
When i log to the server with a single telnet session, all works
great, whatever i type gets echoed by the server after a carriage
return. However, when i log in with a second client at the same time,
that second client doesn't act like the first one did: at first, it
doesn't echo anything at all, but as soon i type something in the first
client, it echoes everything at once, and from then on the second client
behaves the same as the first one.
So it's some kind of buffer that empties itself. That made me think that
a simple autoflush would solve the issue, but it doesn't, the behavior
is still the same. Can anyone give me a hint on how to solve this
problem?
Another smaller problem with this same piece of code is that, again with
the second session only, the ip_address is only shown after the session
has ended.
Here's the code:
use IO::Socket;
use Socket;
$SIG{CHLD} = sub {wait ()};
$main_sock = new IO::Socket::INET (LocalHost => 'freestyle',
LocalPort => 1200,
Listen => 15,
Proto => 'tcp',
Reuse => 1,
);
die "socket could not be created: $!\n" unless ($main_sock);
$main_sock->autoflush(1);
while ($new_sock = $main_sock->accept())
{
$pid = fork();
die "Cannot fork: $!" unless defined($pid);
if ($pid == 0)
{
&serve;
exit(0);
}
}
close ($main_sock);
exit(0);
sub serve
{
$other_end = getpeername($new_sock)
or die "couldn't identify client: $!\n";
($port, $iaddr) = unpack_sockaddr_in($other_end);
$ip_address = inet_ntoa($iaddr);
print "$ip_address\n";
while (defined ($buf = <$new_sock>))
{
print $new_sock "you said: $buf\n";
}
}
Thanks in advance for any help.
Dk
------------------------------
Date: 04 Dec 2002 13:05:42 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: how to get it quoted?
Message-Id: <u9lm36c4t5.fsf@wcl-l.bham.ac.uk>
user <du_bing@hotmail.com> rudely vomits TOFU into Tad's face:
> I tried open(MAIL,"|mailx -s 'for test' 'c24b18d4bb4afdf052330678af9a601d+sent
> mail\@neo.tamu.edu'") as you suggested. No luck either.
>
> mailx still treat 'c24b18d4bb4afdf052330678af9a601d+sent mail\@neo.tamu.edu' as two separate
> email addresses even though it's quoted.
Your problem is now clearly not related to Perl. You have a question
about the mailx program and/or quoting spaces in RFC2822 addresses.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 4 Dec 2002 11:26:31 +0000 (UTC)
From: mauzo@ux-ma160-16.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: passing data between perl scripts and a module: probably a basic question
Message-Id: <askop7$qrq$1@wisteria.csv.warwick.ac.uk>
ben.rogers@escalate.com (benrog) wrote:
>Goal: write two scripts (one takes input and one prints processed
>input) and one module (which processes the input)
<snip: problem is valus not being passed correctly>
>FILE ONE -----------------------------------------------------------------
>#!perl -w
>#use strict;
You want strictures, really.
>#my $userid; # User data
>use Hits;
>
>&getInput;
This is better written
getInput();
or just
getInput;
if you explicitly import in from Hits.
>sub getInput {
>print "Enter your USER ID:"; chomp ($userid = <STDIN>); # Letters &
>not null
> $_ = $userid;
> if ( /[a-z]{8}/i && !/[0-9\W_]/ ) { print "Thank you for
>visiting!\n";}
> else { print "You must enter an ID of 8 letters!\n"; &getInput;}
> &makeDatabase();
This should be
makeDatabase($userid);
>}
>
>
>FILE TWO --------------------------------------------------------------------
>#!perl -w
<snip C<my> declarations>
>package Hits;
>use Exporter;
>@ISA = qw(Exporter);
This should be
our @ISA = qw(Exporter);
, then it'll work with strictures.
>@EXPORT = qw(&makeDatabase &printHits &dateReport &hitReport &Menu
Ditto should be our @EXPORT; also you don't need the &s. It makes no odds here,
but if you put them in @EXPORT_OK they will need importing with the &s, which
is a bad idea.
>%DATABASE $database);
Why are you exporting these? In general, export as little as possible; and put
even less in @EXPORT rather than in @EXPORT_OK. I tend to use @EXPORT_TAGS to
define a tag :all which imports everything in @EXPORT_OK; but that is just a
preference.
>
>sub makeDatabase() { ##### MAKE DATABASE
Either remove the () or make it ($). Preferably the former, unless you know
what the latter does (it probably isn't quite what you think).
Then add a line
my $userid = shift;
to get the first argument out of @_ and into $userid.
>
<much snippage>
>FILE THREE ---------------------------------------------------
>#!perl -w
>#use strict;
>use Hits;
You probably want to move most stuff out of @EXPORT into @EXPORT_OK, then
use Hits qw/Menu/;
. But that's just a matter of style, and personal preference.
>
>&Menu;
Ben
------------------------------
Date: Wed, 4 Dec 2002 06:55:48 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: passing data between perl scripts and a module: probably a basic question
Message-Id: <slrnauruqk.32t.tadmc@magna.augustmail.com>
benrog <ben.rogers@escalate.com> wrote:
> I started out by putting all the code in one file just to get the
> fundamentals in place. That was successful and all was ok. After
> breaking the code up into the requisite pieces, nothing works. I am
> thinking that my current vortex of ignorance centers around passing
> values between subroutines, modules, and scripts.
You do not appear to be "passing" (as in passing arguments) values
at all, you are communicating via global variables.
Global variables are generally "bad". You should avoid them
whenever possible.
> FILE ONE -----------------------------------------------------------------
> #!perl -w
> #use strict;
^
^
You should have strictures enabled.
> #my $userid; # User data
> use Hits;
>
> &getInput;
getInput();
You probably don't want the semantics that are associated
with using the ampersand on function calls. See perlsub.pod
for what the ampersand does.
> sub getInput {
> print "Enter your USER ID:"; chomp ($userid = <STDIN>); # Letters &
> not null
You should format your code so that it is easier to read and
understand. perlstyle.pod has many good style suggestions.
Indent code that is in blocks. One statement per line.
print "Enter your USER ID:";
chomp ($userid = <STDIN>);
> $_ = $userid;
Why copy it from one variable to another variable?
If any other code makes use of $_, you have just stomped on
whatever value was in there. You should local()ize $_ if you
use it in your subroutines:
local $_ = $userid;
> if ( /[a-z]{8}/i && !/[0-9\W_]/ ) { print "Thank you for
> visiting!\n";}
You can avoid using $_ altogether:
if ( $userid =~ /[a-z]{8}/i && $userid !~ /[0-9\W_]/ )
> else { print "You must enter an ID of 8 letters!\n"; &getInput;}
^^^
Misleading. You really require _at least_ 8 letters.
The usual idiom for validating data is:
1) anchor the beginning
2) anchor the end
3) write a pattern in between that accounts for everything
that you want to allow
You can redo your if() into:
if ( $userid =~ /^[a-z]{8,}$/i ) # 8 or more letters, nothing else
and avoid the 2nd pattern match altogether.
> &makeDatabase();
makeDatabase( $userid ); # pass args, avoid global variables
> FILE TWO --------------------------------------------------------------------
> my %DATABASE; # DB file filehandle
> my $database; # Var for db filename
> package Hits;
> @EXPORT = qw(&makeDatabase &printHits &dateReport &hitReport &Menu
> %DATABASE $database);
^^^^^^^^^^^^^^^^^^^
That will not work.
You cannot use lexical (my) variables across files, for that
you need package variables instead.
I expect that this is where your uninitialized messages are coming from.
See this FAQ:
"What's the difference between dynamic and lexical (static) scoping?
Between local() and my()?"
and this paper:
"Coping with Scoping":
http://perl.plover.com/FAQs/Namespaces.html
> sub makeDatabase() { ##### MAKE DATABASE
^^
^^
You should probably avoid using prototypes.
For more information on prototypes in Perl, see:
http://www.perl.com/pub/a/language/misc/fmproto.html
> $time = time; $hits = 1;
> @row = ($userid, $time, $hits);
> $row = join " ", @row;
You don't need all of those temporary variables. You can replace
all 4 statements (3 lines) with just this:
$row = join " ", $userid, scalar(time), 1;
> sub Menu { ### MENU SUBROUTINE: MENU WITH NAV OPTIONS
> print "\n\n-----------OPTIONS-------------\n\n";
> print " \"Control C\" to quit\;\n";
^
^ that backslash does nothing
> print " -?: Show menu\n -u: Show user hits, date, and time\n
> -d: Print report sorted by date\n -h: Print report sorted by
> hits\n\n";
> print "-------------------------------\n\n\n";
A "here-document" will be much easier to read and understand:
=========================================================
print <<ENDMENU;
-----------OPTIONS-------------
"Control C" to quit;
-?: Show menu
-u: Show user hits, date, and time
-d: Print report sorted by date
-h: Print report sorted by hits
-------------------------------
ENDMENU
=========================================================
> chomp ($menuitem = <STDIN>);
> if ($menuitem =~ /-\?/){ &Menu; }
> elsif ($menuitem =~ /-u/i){ &printHits; }
printHits() will be called if this menu selection is entered:
f-ubar
^^
^^
is that what you want?
Maybe you wanted /^-u$/i instead?
I prefer to use the equality operator to test for equality:
if ( lc $menuitem eq '-u' )
rather than disguising an equality test as a pattern match.
> elsif ($menuitem =~ /-d/i){ &dateReport; }
> elsif ($menuitem =~ /-h/i){ &hitReport; }
> else { print "Choose a menu option or press \"Control C\" to
> quit.\n"; &Menu;}
You might consider using a dispatch table instead:
my %funcs = (
'-?' => \&Menu,
'-u' => \&printHits,
'-d' => \&dateReport
'-h' => \&hitReport
);
...
if ( exists $funcs{ lc $menuitem } )
{ $funcs{ lc $menuitem }->() } # call appropriate function
else
{"Choose a menu option or press..."}
> @list = sort (@list); @list = reverse (@list);
Why not just sort it into descending order in the first place
rather than reversing the results of an ascending order sort?
@list = sort {$b cmp $a} @list;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 4 Dec 2002 05:22:12 -0800
From: kasp@epatra.com (Kasp)
Subject: Re: Perl Packages question
Message-Id: <3b04990d.0212040522.220c3151@posting.google.com>
Thanks for your replies guys.
I was able to do some fingering into modules and got them running too :-)
kasp@epatra.com (Kasp) wrote in message news:<3b04990d.0212030920.7cffa9cd@posting.google.com>...
> I am quite new to Perl and still am grasping the basics. I have seen
> many code use packages like IO::File and Mail::Mailer etc etc.
>
> The question I had:-
>
> 1. How and from where can I get Perl Packages like Mail::Mailer etc.
> From CPAN? But where exactly?
>
> 2. How do I install these packages and start using them? A small
> example would be greatly appreciated.
>
> Thanks
> Kasp.
------------------------------
Date: Wed, 04 Dec 2002 05:52:42 -0600
From: tadmc@augustmail.com
Subject: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.2 $)
Message-Id: <tPmdnewgzrQXcXCgXTWc2Q@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.2 $)
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.
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":
Please do not use the existence of these guidelines as a
"license to flame" or other meanness. It is possible that
a poster is not aware of the things discussed here. Let's
give them the benefit of the doubt, and just help them learn
how to post, rather than assume that they do know and are
being the "bad kind" of Lazy.
A note about technical terms used here:
In this document, we use words like "must" and "should" in the
very precise sense that they're used in technical conversation
(such as you're likely to 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 very unlikely that you're going to
get much benefit from using this group. We're not trying to boss
you around; we're just trying to convey the point without using
a lot 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 is expected regardless of what newsgroup
you are visiting. Lurking means to simply monitor a newsgroup for a
period of time until you become very familiar with local customs.
Think of a newsgroup as foreign culture. Each newsgroup has its own
specific customs and rituals. Get to know those customs and rituals
well before you participate. This will help you to 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.perl.com/CPAN-local/authors/Dean_Roehrich/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* the sections of quoted text
that your comments apply to. Failure to do this is called "Jeopardy"
posting because the answer comes before the question.
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://www.geocities.com/nnqweb/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: 4 Dec 2002 06:45:49 -0500
From: vorxion@fairlite.com (Vorxion)
Subject: PWD detection without $ENV?
Message-Id: <3dedeaed$1_1@news.iglou.com>
Okay, I'm currently using ${ENV{'PWD'}} to grab the present working
directory. This has some serious drawbacks in that you can have:
/home/vorxion/testdir/projects/pwds/testdir/another/more/newdir -> ../../..
...In which case if you cd to that path, and call $ENV, you will end up
with the full path, but your REAL path is three directories lower.
I have some code that depends on knowing the absolute PWD.
Short of doing a system call to `pwd`, which I don't want to do, is there a
way to do it internally without relying on the inaccurate $ENV contents?
--
Vorxion - Member of The Vortexa Elite
------------------------------
Date: Wed, 04 Dec 2002 14:29:42 +0200
From: Ilja Tabachnik <billy@arnis-bsl.com>
Subject: Re: PWD detection without $ENV?
Message-Id: <asksfe$s9g3e$1@ID-33095.news.dfncis.de>
Vorxion wrote:
> Okay, I'm currently using ${ENV{'PWD'}} to grab the present working
> directory. This has some serious drawbacks in that you can have:
>
> /home/vorxion/testdir/projects/pwds/testdir/another/more/newdir ->
> ../../..
>
> ...In which case if you cd to that path, and call $ENV, you will end up
> with the full path, but your REAL path is three directories lower.
>
> I have some code that depends on knowing the absolute PWD.
>
> Short of doing a system call to `pwd`, which I don't want to do, is there
> a way to do it internally without relying on the inaccurate $ENV contents?
>
Maybe 'perldoc Cwd' could help ?
HTH
Ilja.
------------------------------
Date: Wed, 04 Dec 2002 12:37:02 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: PWD detection without $ENV?
Message-Id: <3dedf6bf.4267764140@news.cis.dfn.de>
On 4 Dec 2002 06:45:49 -0500, vorxion@fairlite.com (Vorxion)
wrote:
>Okay, I'm currently using ${ENV{'PWD'}} to grab the present working
>directory. This has some serious drawbacks in that you can have:
>
>/home/vorxion/testdir/projects/pwds/testdir/another/more/newdir -> ../../..
>
>...In which case if you cd to that path, and call $ENV, you will end up
>with the full path, but your REAL path is three directories lower.
>
>I have some code that depends on knowing the absolute PWD.
>
>Short of doing a system call to `pwd`, which I don't want to do, is there a
>way to do it internally without relying on the inaccurate $ENV contents?
Yes, use the standard Cwd module, part of every Perl
distribution.
use Cwd;
my $pwd = cwd;
--
Regards, Helgi Briem
helgi AT decode DOT is
A: Top posting
Q: What is the most irritating thing on Usenet?
- "Gordon" on apihna
------------------------------
Date: Wed, 04 Dec 2002 12:36:27 +0100
From: Jon Rogers <jon@rogers.tv>
Subject: Redirect ls -l output
Message-Id: <3DEDE8B4.4495BDAB@rogers.tv>
Hello
In my script I make use of the external ls command to list a directory,
open (prog, "l$ls -l > file.txt") and then read the file to a matrix.
Is it possible to get direct access to the ls outdata without having to
make use of a file?
/ Jon
------------------------------
Date: Wed, 04 Dec 2002 11:35:43 GMT
From: "Ian.H [dS]" <ian@WINDOZEdigiserv.net>
Subject: Re: Redirect ls -l output
Message-Id: <86qruu019o81kcb10e228bsv6krv3anuic@4ax.com>
Keywords: Remove WINDOZE to reply
In a fit of excitement on Wed, 04 Dec 2002 12:36:27 +0100, Jon Rogers
<jon@rogers.tv> managed to scribble:
> Hello
>
> In my script I make use of the external ls command to list a directory,
> open (prog, "l$ls -l > file.txt") and then read the file to a matrix.
>
> Is it possible to get direct access to the ls outdata without having to
> make use of a file?
>
> / Jon
my $lst = `ls -l`;
might work.
Regards,
Ian
--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Scripting, Web design, development & hosting.
------------------------------
Date: Wed, 4 Dec 2002 11:35:55 +0000 (UTC)
From: mauzo@ux-ma160-16.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: Redirect ls -l output
Message-Id: <askpar$r3o$1@wisteria.csv.warwick.ac.uk>
Jon Rogers <jon@rogers.tv> wrote:
>Hello
>
>In my script I make use of the external ls command to list a directory,
>open (prog, "l$ls -l > file.txt") and then read the file to a matrix.
Errr, what exactly do you think this does?
What does $ls contain?
And what do you do with *prog?
>Is it possible to get direct access to the ls outdata without having to
>make use of a file?
Yes.
open my $LS, "ls -l |";
for (<$LS>) {
[do summat]
}
Read perldoc perlopentut.
Ben
------------------------------
Date: Wed, 04 Dec 2002 12:33:56 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Redirect ls -l output
Message-Id: <3dedf50b.4267328333@news.cis.dfn.de>
On Wed, 04 Dec 2002 12:36:27 +0100, Jon Rogers
<jon@rogers.tv> wrote:
>In my script I make use of the external ls command to list a directory,
>open (prog, "l$ls -l > file.txt") and then read the file to a matrix.
>
>Is it possible to get direct access to the ls outdata without having to
>make use of a file?
yes, by using backticks or qx.
my $outdata = `ls -l` or die "Cannot run ls:$!\n";
or in list context:
my @outdata = qx/ls -l/ or die "Cannot run ls:$!\n";
However, it is wrong to rely on external
programs for that sort of thing, when Perl has
all the built-in functions for determining file
attributes, sizes, permissions and so forth.
--
Regards, Helgi Briem
helgi AT decode DOT is
A: Top posting
Q: What is the most irritating thing on Usenet?
- "Gordon" on apihna
------------------------------
Date: Wed, 04 Dec 2002 12:35:59 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Redirect ls -l output
Message-Id: <PEmH9.33850$ic6.31379@nwrddc01.gnilink.net>
Jon Rogers wrote:
> In my script I make use of the external ls command to list a
> directory, open (prog, "l$ls -l > file.txt") and then read the file
> to a matrix.
>
> Is it possible to get direct access to the ls outdata without having
> to make use of a file?
Yes, please see "perldoc -f open".
But maybe 'opendir' and 'readdir' is a better choice?
jue
------------------------------
Date: Wed, 4 Dec 2002 13:26:54 +0100
From: "Julian Mehnle" <julian@mehnle.net>
Subject: Re: RegExp: Capturing parentheses in quantified sub-patterns -- how is it supposed to work? (ADDITION)
Message-Id: <asksaf$s48id$1@ID-65075.news.dfncis.de>
Julian Mehnle <julian@mehnle.net> wrote:
> From a string, I want to capture items separated by whitespace (parameter
> parsing).
>
> IMO, the pattern (\S+)(?:\s+(\S+))* should do the job fine and capture
the
> first as well as every following non-whitespace item (if any). But it does
> only capture the first and the last items.
And: no, I don't want to use split(), because the real code looks like this:
| gray:~> perl -MData::Dumper -e \
| '$PARAMETER = qr/\".*?\"|\S+/;
| $PARAMETERS = qr/($PARAMETER)(?:\s+($PARAMETER))+/;
| print(Dumper([$ARGV[0] =~ /^$PARAMETERS$/]));' \
| '"ab cd" ef gh'
|
| $VAR1 = [
| '"ab cd"',
| 'gh'
| ];
...so I can capture quoted parameters ("ab cd") as a whole.
Julian.
------------------------------
Date: Wed, 04 Dec 2002 13:51:53 GMT
From: "robertbu" <robertbu@hotmail.com>
Subject: Re: RegExp: Capturing parentheses in quantified sub-patterns -- how is it supposed to work? (ADDITION)
Message-Id: <ZLnH9.41331$%r6.17672@nwrddc02.gnilink.net>
Julian Mehnle <julian@mehnle.net> wrote:
>
> And: no, I don't want to use split(), because the real code looks like
this:
>
> | gray:~> perl -MData::Dumper -e \
> | '$PARAMETER = qr/\".*?\"|\S+/;
> | $PARAMETERS = qr/($PARAMETER)(?:\s+($PARAMETER))+/;
> | print(Dumper([$ARGV[0] =~ /^$PARAMETERS$/]));' \
> | '"ab cd" ef gh'
> |
> | $VAR1 = [
> | '"ab cd"',
> | 'gh'
> | ];
>
> ...so I can capture quoted parameters ("ab cd") as a whole.
>
Since you have nested delimiters, how about the Text::ParseWords module?
"The &nested_quotewords() and "ewords() functions accept a delimiter
(which can be a regular expression) and a list of lines and then breaks
those lines up into a list of words ignoring delimiters that appear inside
quotes."
== Rob ==
------------------------------
Date: Wed, 4 Dec 2002 13:17:50 +0100
From: "Julian Mehnle" <julian@mehnle.net>
Subject: RegExp: Capturing parentheses in quantified sub-patterns -- how is it supposed to work?
Message-Id: <askrpf$sah2l$1@ID-65075.news.dfncis.de>
Hi all!
First, the code:
| gray:~> perl -MData::Dumper -e \
| 'print(Dumper([$ARGV[0] =~ /^(\S+)(?:\s+(\S+))*$/]));' \
| 'ab cd ef gh'
|
| $VAR1 = [
| 'ab',
| 'gh'
| ];
From a string, I want to capture items separated by whitespace (parameter
parsing).
IMO, the pattern (\S+)(?:\s+(\S+))* should do the job fine and capture the
first as well as every following non-whitespace item (if any). But it does
only capture the first and the last items.
How are capturing parentheses in a quantified (?*+{x,y}) sub-pattern
supposed to work? I searched `perldoc perlre` and `perldoc perlop` but could
not find any definite statements. Obviously, it does NOT work in the way I'm
doing it above! Is this a bug? I doubt it, but then how to do it?
Thanks in advance,
Julian Mehnle.
------------------------------
Date: Wed, 4 Dec 2002 11:47:35 -0200
From: Nuba <nuba@dcc.ufmg.br>
Subject: rolling my own perl-based content management system
Message-Id: <Pine.GSO.4.21.0212041143310.3957-100000@turmalina.dcc.ufmg.br>
Hello you wise people out there ,
1. BRIEFLY
I've rolled my own perl-based content management system,
using 'template toolkit' and 'mysql'.
Would this be interesting for the community ?
Else, I'm just been another newbie reinventing the wheel ?
2. BACKGROUND
Around a year ago I decided to step towards Perl (as my language of
choice)
and into a perl-enabled web development (coming also from a webdesign
background).
When my CGIs started to grow up, I had to pass them thru the webdesigning
process, too. I wasn't willing to throw away the years spent with
Dreamweaver, so I decided for templating with TT (Template Toolkit),
instead of embedding HTML into my CGIs (the usual way) or perl code into
HTML files (like EmbPerl or Mason).
Also, I was already dealing with gathering content from a mysql database,
so it took no effort to centralize the management of these templates in
the database.
3. RESULTS
What I have archieved so far is, briefly :
. receive a request in the form
"script.pl?section=XXXXXX&etc=XX"
. do the site-wise work ( referer managmt, random images, etc.)
. based on the section specified, do this section-specific work
. get the template for this section from the database
. send the output to the client
. I DID it ALL IN VIM :-) Yes !!! VIM !
ok... let's get back serious...
4. THOUGHTS
This previous weeks I've been grinding and thinking out :
" Boy, this is getting cool... maybe with a little more effort this
could be GPL-ed as a nice content management system... "
But yesterday I thought also :
" Am I reinventing the wheel ? "
I know there is many content management systems flowing around, but I
haven't been able to find a serious, enterprise-oriented, perl based
one. Of course, these is slashcode, but it seems to be more community
than content driven.
5. HELP ! HELP !
Can someone shed some light on this ?
There's already a solution which I haven't heard of ?
Otherwise, does this sound interesting ?
Any thoughts ?
Big thanks in advance,
Nuba
---
,::::,
:: : Nuba Rodrigues Princigalli _____________
:. O-O: | '\\\\\\
: > Web Design and Development | ' ____|_
____\ - ._. Computational Mathematics | + '||::::::
/' \ -::' .' | '||_____|
/. ,- O < \ www.nuba.tk '________|_____|
(\ <' ' |\ / '-.___ nuba@dcc.ufmg.br ___/____|___\___
_.\__\________\_\___/), |\\____________________| _ ' <<<:|
|_________'___o_o|
------------------------------
Date: 4 Dec 2002 12:02:28 GMT
From: Stephen Patterson <s.patterson@freeuk.com>
Subject: Re: Warnings when creating an array of hashes
Message-Id: <slrnaurrmj.mjm.s.patterson@seagoon.localdomain>
On 4 Dec 2002 10:57:53 GMT, Tassilo v. Parseval wrote:
> Just realized that I forgot something to mention.
>
> Also sprach Stephen Patterson:
>
> It also makes use of the fact that the loop variable is actually an
> alias for the value of the array you are iterating over. So changing $i
> changes the corresponding array element.
>
> Hash-slices are so useful that everyone should read about them
> instantly. See 'perldoc perldata', the section "Slices".
Thanks! Think I'll stick with the first one you sent as its just more
readable to me if I have to rework this code in future.
--
Stephen Patterson http://www.lexx.uklinux.net http://patter.mine.nu
steve@SPAM.lexx.uklinux.net remove SPAM to reply
Linux Counter No: 142831 GPG Public key: 252B8B37
Last one down the pub's an MCSE
------------------------------
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 4214
***************************************