[23763] in Perl-Users-Digest
Perl-Users Digest, Issue: 5967 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Dec 21 18:05:42 2003
Date: Sun, 21 Dec 2003 15:05:10 -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 Sun, 21 Dec 2003 Volume: 10 Number: 5967
Today's topics:
${'Q::' . $var} and use strict (webwzrd)
Re: ${'Q::' . $var} and use strict <noreply@gunnar.cc>
Re: ${'Q::' . $var} and use strict <no_spam_for_jkeen@verizon.net>
Re: ${'Q::' . $var} and use strict <noreply@gunnar.cc>
A proposal about logical connectives in conjunction wit <bik.mido@tiscalinet.it>
Re: A proposal about logical connectives in conjunction (Tad McClellan)
Re: A proposal about logical connectives in conjunction <qumsieh@cim.mcgill.ca>
Re: Announcing File::Finder 0.01 <tore@aursand.no>
Re: Horrendous memory leak with TCP/IP Socket client, n <slaven@rezic.de>
Re: how to detect broken pipe ? <usenet@morrow.me.uk>
Re: HTTP_CONNECTION = Keep-Alive or 180 seconds <jwillmore@remove.adelphia.net>
Re: Is mysql.pm part of DBI? (Tad McClellan)
Re: Parsing File <tore@aursand.no>
Re: Parsing File (BrokenSaint)
perl golf <troy@resophonic.com>
Re: perl golf <uri@stemsystems.com>
Re: replacing two EOL chars by one <shoot@the.moon>
Re: replacing two EOL chars by one <gnari@simnet.is>
Re: replacing two EOL chars by one <jurgenex@hotmail.com>
Re: replacing two EOL chars by one <matthew.garrish@sympatico.ca>
Re: replacing two EOL chars by one <spam@thalassa.informatimago.com>
Re: replacing two EOL chars by one (Tad McClellan)
Re: sort <bik.mido@tiscalinet.it>
sprintf - problems <psmith6@SparnBlock.bigpond.net.au>
Re: sprintf - problems <uri@stemsystems.com>
Re: sprintf - problems <matthew.garrish@sympatico.ca>
Re: sprintf - problems (Rasto Levrinc)
Re: sprintf - problems <flavell@ph.gla.ac.uk>
strange problem with perl/tk and detaching threads <Wolfgang_.fischer@lycos.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 21 Dec 2003 11:14:48 -0800
From: ccolumbu@hotmail.com (webwzrd)
Subject: ${'Q::' . $var} and use strict
Message-Id: <b5c2407f.0312211114.46ed9bcd@posting.google.com>
Hello Perl experts,
I am new to use strict and in general the idea of name spaces,
symbolic, lexical and global variables in the way you all understand
them.
Here is what I am trying to do basically.
For each dow (day of the week) I want to capture a person's start time
of day.
So I print to the screen like so (snippet):
--------------------------------------------------
#!/usr/bin/perl -w
use strict;
$|=1;
print "Content-type: text/html\n\n";
my %dow;
my $key;
my $junk;
my $show_dow;
my $i;
$dow{'0:sun'} = "Sunday";
$dow{'1:mon'} = "Monday";
$dow{'2:tue'} = "Tuesday";
$dow{'3:wed'} = "Wednesday";
$dow{'4:thr'} = "Thursday";
$dow{'5:fri'} = "Friday";
$dow{'6:sat'} = "Saturday";
print "<form method=\"post\">";
foreach $key (sort keys %dow){
($junk, $show_dow) = split(":", $key);
print "When do you start working on $dow{$key}? <select
name=\"${show_dow}_start\">";
for $i(0..23){
print "<option value=\"$i\">$i</option>\n";
}
print "</select><br>\n";
}
print "<input type=\"submit\"></form>";
--------------------------------------------------
Now when they submit the form, I capture the data and print it back to
them in the same form so they can review it. I do so like this
(snippet):
--------------------------------------------------
#!/usr/bin/perl -w
use strict;
use CGI;
$|=1;
my $query = new CGI;
$query->import_names('Q');
print "Content-type: text/html\n\n";
my %dow;
my $key;
my $junk;
my $show_dow;
my $selected;
my $i;
$dow{'0:sun'} = "Sunday";
$dow{'1:mon'} = "Monday";
$dow{'2:tue'} = "Tuesday";
$dow{'3:wed'} = "Wednesday";
$dow{'4:thr'} = "Thursday";
$dow{'5:fri'} = "Friday";
$dow{'6:sat'} = "Saturday";
print "<form method=\"post\">";
foreach $key (sort keys %dow){
($junk, $show_dow) = split(":", $key);
print "When do you start working on $dow{$key}? <select
name=\"${show_dow}_start\">";
for $i(0..23){
if (defined ${'Q::' . $show_dow . '_start'} && ${'Q::' . $show_dow .
'_start'} == $i){
$selected = "selected";
} else {
$selected = "";
}
print "<option value=\"$i\" $selected>$i</option>\n";
}
print "</select><br>\n";
}
print "<input type=\"submit\"></form>";
--------------------------------------------------
I get an error:
Can't use string ("Q::sun_start") as a SCALAR ref while "strict refs"
in use at dow_time.pl line . . .
It works if you do not use "use strict;".
I want to use strict and do this correctly so please tell me what the
best way to do this is?
------------------------------
Date: Sun, 21 Dec 2003 21:04:21 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: ${'Q::' . $var} and use strict
Message-Id: <bs4v30$9hm2m$1@ID-184292.news.uni-berlin.de>
webwzrd wrote:
> I get an error:
> Can't use string ("Q::sun_start") as a SCALAR ref while "strict
> refs" in use at dow_time.pl line . . .
>
> It works if you do not use "use strict;".
It's because you are using symbolic references.
http://www.perldoc.com/perl5.8.0/pod/perlref.html#Symbolic-references
You _might_ fix it by adding this as the first line within the foreach
loop:
no strict 'refs';
> I want to use strict and do this correctly so please tell me what
> the best way to do this is?
Symbolic references are considered something that should be avoided
when there are other methods available. There is nothing in your app
that would make symbolic references necessary. Accordingly, the _best_
way is to switch to some other approach.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Sun, 21 Dec 2003 20:28:21 GMT
From: "Jim Keenan" <no_spam_for_jkeen@verizon.net>
Subject: Re: ${'Q::' . $var} and use strict
Message-Id: <FnnFb.7459$xh2.5806@nwrdny02.gnilink.net>
"webwzrd" <ccolumbu@hotmail.com> wrote in message
news:b5c2407f.0312211114.46ed9bcd@posting.google.com...
> Hello Perl experts,
> I am new to use strict and in general the idea of name spaces,
> symbolic, lexical and global variables in the way you all understand
> them.
> [rearranging OP]
> I want to use strict and do this correctly so please tell me what the
> best way to do this is?
It's good that you're learning/writing Perl with 'use strict' in place.
> Here is what I am trying to do basically.
> For each dow (day of the week) I want to capture a person's start time
> of day.
>
> So I print to the screen like so (snippet):
> --------------------------------------------------
>
> #!/usr/bin/perl -w
> use strict;
> $|=1;
>
> print "Content-type: text/html\n\n";
>
> my %dow;
> my $key;
> my $junk;
> my $show_dow;
> my $i;
> $dow{'0:sun'} = "Sunday";
> $dow{'1:mon'} = "Monday";
> $dow{'2:tue'} = "Tuesday";
> $dow{'3:wed'} = "Wednesday";
> $dow{'4:thr'} = "Thursday";
> $dow{'5:fri'} = "Friday";
> $dow{'6:sat'} = "Saturday";
> print "<form method=\"post\">";
> foreach $key (sort keys %dow){
> ($junk, $show_dow) = split(":", $key);
My hunch is that the way you've set your script up is unnecessarily
complicated and error prone -- and that 'use strict' happened to catch an
error that you could have avoided.
Why are you defining %dow in a way such that you are splitting the keys. If
you are classifying data on the basis of the day of the week, you could
either use an array:
@start_times = ( # start times for each of 7 days, where you simply
remember that $start_times[0] holds Sunday's start time );
or a hash:
%start_times = (
Sun => '10:01',
Mon => '8:37',
### etc.
);
Try simplifying the data structure. Also, when posting a question that
involves CGI to a newsgroup or mailing list, try to isolate the problem. Is
it a CGI-problem? If so, post to a CGI newsgroup (see c.l.p.m. Posting
Guidelines for suggestions). Is it a Perl question (as I suspect it is in
this instance)? If so, then strip out all CGI-related code before you post.
You may find that that clarifies your understanding of the code and
contributes to solving the problem.
------------------------------
Date: Sun, 21 Dec 2003 22:09:06 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: ${'Q::' . $var} and use strict
Message-Id: <bs52tf$92qh8$1@ID-184292.news.uni-berlin.de>
Gunnar Hjalmarsson wrote:
> There is nothing in your app that would make symbolic references
> necessary. Accordingly, the _best_ way is to switch to some other
> approach.
This is an example with a minimum of changes:
Replace
$query->import_names('Q');
with
my %in;
$in{$_} = $query->param($_) for $query->param;
and replace
if (defined ${'Q::' . $show_dow . '_start'} &&
${'Q::' . $show_dow . '_start'} == $i){
with
if (defined $in{$show_dow.'_start'} &&
$in{$show_dow.'_start'} == $i){
That would replace the symbolic references. But you'd better consider
Jim's suggestions as well.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 22 Dec 2003 12:34:02 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: A proposal about logical connectives in conjunction with comma
Message-Id: <3clduvgbufeesnolf1n6g7mked8kjea9vp@4ax.com>
[Caveat: please do not think I am a crank! So don't suggest to RTFM, I
don't have an actual problem, just want to discuss a feature I would
like to see in (future releases of) Perl]
In a follow-up to another article I included the following snippet of
code:
@ARGV = grep {
warn "`$_' is not a directory!\n" unless -d;
-d _;
} @ARGV;
OK, I know there are tons of WTDI. But first I had thought of using
@ARGV = grep { -d or warn "`$_' is not a directory!\n" };
of course this won't work beacuse warn() will always return 1. So I
wonder if there could be "room for" a comma+or/and/||/&& combination
so that
@ARGV = grep { -d , or warn "`$_' is not a directory!\n" };
should be equivalent to the first solution. The mnemonics would be
that since the comma "comes *first*", then this "combined operator"
would short circuit just like 'or' does, but it would return its
*first* argument in any case.
For consistency (IMHO) one should allow 'or ,' even if that would just
behave like a regular 'or' would.
For semi-consistency (IMHO) one should also allow a "double-comma"
operator to behave just like the comma operator, but returning the
value of its first argument and discarding that of the second one. (so
that the first comma is somehow "dominant"!)
As of now ', or' is perfectly legal (but the comma silently
evaporates), whereas ' or,' is not:
# perl -wMstrict -MO=Deparse,-p -e '/foo/ or /bar/'
BEGIN { $^W = 1; }
use strict 'refs';
(/foo/ or /bar/);
-e syntax OK
# perl -wMstrict -MO=Deparse,-p -e '/foo/ , or /bar/'
BEGIN { $^W = 1; }
use strict 'refs';
(/foo/ or /bar/);
-e syntax OK
# perl -wMstrict -MO=Deparse,-p -e '/foo/ or , /bar/'
syntax error at -e line 1, near "or ,"
-e had compilation errors.
BEGIN { $^W = 1; }
Use of uninitialized value in split at
/usr/lib/perl5/5.8.2/linux/B/Deparse.pm line 795.
use strict 'refs';
Hmmm, thinking of it better, provided that the whole thing is
meaningful (it is for me!), rather than allowing composed operators to
be generated by the "marriage" of comma and logical connectives, it
would be better to just introduce brand new ones:
qw/,|| ,or/ ,&& ,and ,,/
Any thoughts/ideas/comments?
Michele
--
# This prints: Just another Perl hacker,
seek DATA,15,0 and print q... <DATA>;
__END__
------------------------------
Date: Sun, 21 Dec 2003 08:46:46 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: A proposal about logical connectives in conjunction with comma
Message-Id: <slrnbubcim.uh.tadmc@magna.augustmail.com>
Michele Dondi <bik.mido@tiscalinet.it> wrote:
> just want to discuss a feature I would
> like to see in (future releases of) Perl]
Step 1 should be enumerating some of the "better" ways that it
can be done with Today's Perl, so that you can then argue the
value of your Future Perl versus the cost of implementing it and
the cost of adding yet another off-beat nook-and-cranny for Perl
programmers to remember.
> In a follow-up to another article I included the following snippet of
> code:
>
> @ARGV = grep {
> warn "`$_' is not a directory!\n" unless -d;
> -d _;
> } @ARGV;
>
> OK, I know there are tons of WTDI.
We should examine them to see if there isn't already one that
is "good enough"...
> But first I had thought of using
>
> @ARGV = grep { -d or warn "`$_' is not a directory!\n" };
>
> of course this won't work beacuse warn() will always return 1.
You can fix that in Today's Perl by adding 4 characters:
@ARGV = grep { -d or warn "`$_' is not a directory!\n" and 0 } @ARGV;
^^^ ^
^^^ ^
or
@ARGV = grep { -d or warn("`$_' is not a directory!\n"), 0 } @ARGV;
^ ^^ ^
^ ^^ ^
They both seem understandable by Today's Programmers, particularly
that first one.
> So I
> wonder if there could be "room for" a comma+or/and/||/&& combination
> so that
>
> @ARGV = grep { -d , or warn "`$_' is not a directory!\n" };
>
> should be equivalent to the first solution.
Your solution does it with 1 added character.
Cost:
p5p has to get it to parse in all the places where a binop can occur.
Perl programmers have yet another strangeosity to hold in their head.
Benefit:
type 3 less characters
I don't find that very compelling. :-)
> For consistency (IMHO) one should allow 'or ,' even if that would just
> behave like a regular 'or' would.
Symmetry is overrated. Overrated is symmetry. -- Larry Wall
:-)
> Any thoughts/ideas/comments?
It fails _my_ cost-benefit analysis...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 21 Dec 2003 16:06:20 GMT
From: Ala Qumsieh <qumsieh@cim.mcgill.ca>
Subject: Re: A proposal about logical connectives in conjunction with comma
Message-Id: <0yjFb.630$Wk7.207@newssvr27.news.prodigy.com>
Michele Dondi wrote:
> @ARGV = grep { -d or warn "`$_' is not a directory!\n" };
>
> of course this won't work beacuse warn() will always return 1. So I
How about:
@ARGV = grep { -d or !warn "'$_' is not a directory!\n" } ...;
--Ala
------------------------------
Date: Sun, 21 Dec 2003 14:19:49 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: Announcing File::Finder 0.01
Message-Id: <pan.2003.12.21.09.37.26.689760@aursand.no>
On Fri, 19 Dec 2003 09:55:25 -0600, Tad McClellan wrote:
>> I've always thought comp.lang.perl.announce was the group for posts like
>> this.
> Did you notice the Newsgroups header on the original post?
Yes. Does crossposting to _one_ correct newsgroup imply that it's ok to
post to wrong groups?
--
Tore Aursand <tore@aursand.no>
"Omit needless words. Vigorous writing is concise. A sentence should
contain no unnecessary words, a paragraph no unnecessary sentences,
for the same reason that a drawing should have no unnecessary lines
and a machine no unnecessary parts." -- William Strunk Jr.
------------------------------
Date: 21 Dec 2003 16:42:48 +0100
From: Slaven Rezic <slaven@rezic.de>
Subject: Re: Horrendous memory leak with TCP/IP Socket client, new to 5.8.0?
Message-Id: <87hdzu5g93.fsf@vran.herceg.de>
Sisyphus <kalinaubears@iinet.net.au> writes:
> Tim Shoppa wrote:
>
> > #!/usr/bin/perl
> > use strict;
> > use Socket;
> > my $internet_addr = inet_aton('localhost') or die "Failed to aton:
> > $!";
> > my $paddr = sockaddr_in(7001, $internet_addr) or die "failed to get
> > paddr: $!";
> > while(1) {
> > socket(Server,PF_INET, SOCK_STREAM, getprotobyname('tcp')) or die
> > "Socket failed: $!";
> > connect (Server,$paddr) or die "Couldn't connect to remote port:
> > $!";
> > undef $/; #Slurp all the data
> > my $bigline = <Server>;
> > close(Server);
> > }
> > The server is ridiculously simplistic: connect to it and it sends you
> > some data, then hangs up. The server works fine without a memory leak
> > so I'm not showing it here.
> >
>
> Can't replicate the problem on Win2k. Your code seems fine.
> Is the server script also doing a close() ? (Didn't seem to matter on
> Win2k.)
>
> I also have linux, but didn't try your script on that platform as I
> don't know how to check for memory leaks on linux .... I couldn't find
> its "Task Manager" :-)
>
> How do you know that it's the client and not the server that's leaking
> memory ?
>
Use "top".
Regards,
Slaven
--
Slaven Rezic - slaven@rezic.de
tknotes - A knotes clone, written in Perl/Tk.
http://ptktools.sourceforge.net/#tknotes
------------------------------
Date: Sun, 21 Dec 2003 16:08:50 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: how to detect broken pipe ?
Message-Id: <bs4gii$krh$1@wisteria.csv.warwick.ac.uk>
a_gilotra@yahoo.com (funtoosh) wrote:
> generate | perl myPerl.pl # pipe output from "generate" to the perl
> script.
>
> And in myPerl.pl, I wrote this :
>
> sub whatSignal { print "caught ",shift, "\n" };
> $SIG($_}=\ &whatSignal for keys %SIG
You only get sent SIGPIPE when you write to a broken pipe. Reading
will simply return EOF.
This Is Not A Perl Question.
Ben
--
. | .
\ / The clueometer is reading zero.
. .
__ <-----@ __ ben@morrow.me.uk
------------------------------
Date: Sun, 21 Dec 2003 11:32:44 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: HTTP_CONNECTION = Keep-Alive or 180 seconds
Message-Id: <20031221063243.2149be2f.jwillmore@remove.adelphia.net>
On Sun, 21 Dec 2003 07:31:58 GMT
"I Report, You Decide" <test@test.com> wrote:
> Need to run a client side script to call something on a web server
> Want to know if the http header
> HTTP_CONNECTION = Keep-Alive
> is sent from the client or set by the server
> I have heard if the transfer of data is not finished in 180 seconds,
> the server will stop sending data, then I guess download will never
> be completed.
post this to
comp.infosystems.www.authoring.cgi
-or-
post what *Perl* code you have put together thus far and we can aid
you where you're stuck.
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
"I cannot and will not cut my conscience to fit this year's
fashions." -- Lillian Hellman
------------------------------
Date: Sun, 21 Dec 2003 07:54:08 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Is mysql.pm part of DBI?
Message-Id: <slrnbub9g0.uh.tadmc@magna.augustmail.com>
I Report, You Decide <test@test.com> wrote:
> I don't have root access, so I can not install it.
Your conclusion is easily disproved.
perldoc -q module
How do I keep my own module/library directory?
You should check all of the Perl FAQs about modules *before*
you ask a question about modules.
Are you using clp.misc as a read-the-docs-to-me service? Please don't.
Asking for clarification of what the docs say is OK.
Not even reading the docs is not OK.
perldoc DBI
If you have questions about DBI, you can get help from
...
Also worth a visit is the DBI home page at:
...
Before asking any questions, reread this document, consult
the archives and read the DBI FAQ.
Good advice. Follow it please.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Sun, 21 Dec 2003 14:19:44 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: Parsing File
Message-Id: <pan.2003.12.21.09.42.11.727893@aursand.no>
On Sat, 20 Dec 2003 19:21:35 -0800, BrokenSaint wrote:
> i have a file with the following data:
> ...
> Record created on 24-Jun-2003.
> Database last updated on 27-Nov-2003 17:14:03 EST.
>
> Domain servers in listed order:
>
> ns00.nameserver.com 123.456.789.012
> ns00.nameserver.com 123.456.789.012
> =====================================================
> What i would like to do is parse thru the file and find and retain
> "NS99.WORLDNIC.COM" to a variable. The data i desire almost always is
> available after the words "Domain servers...:"
What have you tried so far? What doesn't work?
--
Tore Aursand <tore@aursand.no>
"Omit needless words. Vigorous writing is concise. A sentence should
contain no unnecessary words, a paragraph no unnecessary sentences,
for the same reason that a drawing should have no unnecessary lines
and a machine no unnecessary parts." -- William Strunk Jr.
------------------------------
Date: 21 Dec 2003 13:26:25 -0800
From: tartemp@epix.net (BrokenSaint)
Subject: Re: Parsing File
Message-Id: <24813030.0312211326.7594a90b@posting.google.com>
Tore Aursand <tore@aursand.no> wrote in message news:<pan.2003.12.21.09.42.11.727893@aursand.no>...
> On Sat, 20 Dec 2003 19:21:35 -0800, BrokenSaint wrote:
> > i have a file with the following data:
> > ...
> > Record created on 24-Jun-2003.
> > Database last updated on 27-Nov-2003 17:14:03 EST.
> >
> > Domain servers in listed order:
> >
> > ns00.nameserver.com 123.456.789.012
> > ns00.nameserver.com 123.456.789.012
> > =====================================================
> > What i would like to do is parse thru the file and find and retain
> > "ns00.nameserver.com" to a variable. The data i desire almost always is
> > available after the words "Domain servers...:"
>
> What have you tried so far? What doesn't work?
I can open the file and read it, but not sure how to go about parsing
thru it to find "ns00.nameserver.com "
i've tried grep to find the line using: grep "Domain servers"
filename, but would rather use an if or while statement to find the
line and then get the ns00....but am clueless to getting it
accomplished
------------------------------
Date: Sun, 21 Dec 2003 19:26:26 +0100
From: "Troy D. Straszheim" <troy@resophonic.com>
Subject: perl golf
Message-Id: <3FE5E5D2.90607@resophonic.com>
there is something really disturbing about this. I thought the
obfuscated C contest was bad...
http://www.sysarch.com/perl/golf/
-t
------------------------------
Date: Sun, 21 Dec 2003 22:31:04 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: perl golf
Message-Id: <x7r7yxvm54.fsf@mail.sysarch.com>
>>>>> "TDS" == Troy D Straszheim <troy@resophonic.com> writes:
> there is something really disturbing about this. I thought the
> obfuscated C contest was bad...
> http://www.sysarch.com/perl/golf/
then shut your eyes when playing. and why complain about it as well?
better to go to golf.perl.com or sign up on the golf mailing list.
and if you don't have fun when hacking perl, then use python instead. i
think they have a bowling contest where you try to bloat the code as
much as possible but they stopped the game as all entries were tied with
all the code that was in production.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Sun, 21 Dec 2003 13:28:32 +0000
From: Steve Horsley <shoot@the.moon>
Subject: Re: replacing two EOL chars by one
Message-Id: <bs46uj$u9m$1@news.freedom2surf.net>
The boy's an idiot!
------------------------------
Date: Sun, 21 Dec 2003 14:02:04 -0000
From: "Ragnar Hafstað" <gnari@simnet.is>
Subject: Re: replacing two EOL chars by one
Message-Id: <bs495e$fnf$1@news.simnet.is>
"Xah Lee" <xah@xahlee.org> wrote in message
news:7fe97cc4.0312210106.5a72c199@posting.google.com...
> Ragnar Hafsta? (gnari@simnet.is) wrote:
>
> > you are forgetting what -p does
> > ...
> > perl -0 -pi'*~' -e 's@\n\n@\n@g' *.java
>
> Thank you kindly.
>
> --
>
> Now there are a slew of perl driviling morons who
> has also participated in answering to no avail. Die!
(snipped rather much more)
I apologise
gnari
------------------------------
Date: Sun, 21 Dec 2003 15:32:58 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: replacing two EOL chars by one
Message-Id: <K2jFb.23141$jG4.357@nwrddc02.gnilink.net>
Xah Lee wrote:
[...]
> --
[246 lines of signature snipped]
That even beats any spammer I know of.
If your foul language wasn't reason enough yet, this really does it:
*PLONK*
jue
------------------------------
Date: Sun, 21 Dec 2003 11:27:28 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: replacing two EOL chars by one
Message-Id: <LRjFb.439$d%1.193083@news20.bellglobal.com>
"Xah Lee" <xah@xahlee.org> wrote in message
news:7fe97cc4.0312210106.5a72c199@posting.google.com...
>
> Now there are a slew of perl driviling morons who
> has also participated in answering to no avail. Die!
>
> PS pasted below my sig is some meat about unix. Unix morons please
> slurp and spruce it up and place it on wikipedia.org or something.
>
Since you're obviously in need of an expanded vocabulary, I think you'll
find you can use the following to describe yourself nicely:
http://en.wikipedia.org/wiki/Script_kiddie
Matt
------------------------------
Date: 21 Dec 2003 19:16:30 +0100
From: Pascal Bourguignon <spam@thalassa.informatimago.com>
Subject: Re: replacing two EOL chars by one
Message-Id: <87vfoaf341.fsf@thalassa.informatimago.com>
xah@xahlee.org (Xah Lee) writes:
> maybe some other day when i'm pissed, i'll write a better exposition
> on this issue. I've been wanting to write a final-say essay on this
> for long. Don't feel like it now.
Perhaps instead of losing you time with this, you would better use one
of the other strengths of unix: it's modularity, and implement your
own shell, or try scsh (scheme shell). There, you don't have to mess
with sh idiosyncratic syntax: you just write pure lisp to combine your
commands. There is also an easy way to replace to EOL chars by one in
scsh.
--
__Pascal_Bourguignon__ . * * . * .* .
http://www.informatimago.com/ . * . .*
There is no worse tyranny than to force * . . /\ ( . *
a man to pay for what he does not . . / .\ . * .
want merely because you think it .*. / * \ . .
would be good for him. -- Robert Heinlein . /* o \ .
http://www.theadvocates.org/ * '''||''' .
SCO Spam-magnet: postmaster@sco.com ******************
------------------------------
Date: Sun, 21 Dec 2003 14:02:23 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: replacing two EOL chars by one
Message-Id: <slrnbubv2f.25c.tadmc@magna.augustmail.com>
Jürgen Exner <jurgenex@hotmail.com> wrote:
> Xah Lee wrote:
> [...]
>> --
> [246 lines of signature snipped]
>
> That even beats any spammer I know of.
> If your foul language wasn't reason enough yet, this really does it:
>
> *PLONK*
I did that 2 years ago when I identified him as a troll from his .sig
Message-ID: <7fe97cc4.0111080051.71a0c6f3@posting.google.com>
The heuristics work correctly yet again!
(except I went "slumming" and got pulled in again anyway :-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 22 Dec 2003 12:34:01 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: sort
Message-Id: <78lduv8bn87qsadhje7k5dfj684hdq8lve@4ax.com>
Original post slightly edited for clarity. Please do not top-post!
On Sat, 20 Dec 2003 18:33:25 +0100, "Martin" <martin@gmx.de> wrote:
>> I want to walk through a directory path and get the sorted filepaths of
^^^^^^^^^
This may be a good reason (even though not stringent!) to use
'no_chdir => 1': see below...
>since I am unclear, here is the whole script, what i get is an unsorted
>List.
Others have explained your main error(s) and suggested ways to get the
desired result following your approach. However this implies that the
directory tree is first scanned and then the results are sorted and
printed.
A more natural approach that for *some reason* I've seldom (if ever!)
seen advised here (but by me, of course ;-) is to use the 'preprocess'
"method", with which you can obtain a sorted output as the directory
tree is scanned.
Before the actual code, just a few side-note observations:
>my $start_verzeichnis = "../";
>
>unless (-d $start_verzeichnis) {
> die "Startverzeichnis '$start_verzeichnis' ist kein Verzeichnis.\n";
>}
Probably more clear:
die "Something: $!\n" unless -d $start_verzeichnis;
But... huh?!? Can ../ fail to be a directory? (I'm not saying it
can't, I'm truly *asking* to more knowledgeable readers!)
Well, I guess something may "go wrong" at most in the/a root dir.
Let's try it (I guess you're under Win*): actually
C:\>dir ..
[snip]
Directory non valida
But!
C:\>perl -le "print -d '..'"
1
And on Linux no pb, either:
# ls ..
System.map cdrom0 dev-state home mnt root usr
bin cdrom1 etc lib opt sbin var
boot dev floppy map proc tmp vmlinuz
# perl -le 'print -d ".."'
1
However I will give you a slightly more flexible solution below!
> return unless /\.html$/ || /\.shtml$/ ;
I'm not a regex wizard, by any means, but /\.s?html$/!
>exit 0;
redundant!
Now, here's OWTDI:
#!/usr/bin/perl -l
use strict;
use warnings;
use File::Find;
@ARGV = grep {
warn "`$_' is not a directory!\n" unless -d;
-d _;
} @ARGV;
die "Usage: $0 <dir> [<dirs>]\n" unless @ARGV;
find { no_chdir => 1,
preprocess => sub { sort @_ },
wanted => sub {
return unless /\.s?html$/;
print;
} }, @ARGV;
__END__
HTH,
Michele
--
# This prints: Just another Perl hacker,
seek DATA,15,0 and print q... <DATA>;
__END__
------------------------------
Date: Sun, 21 Dec 2003 16:00:36 GMT
From: "Peter Smith" <psmith6@SparnBlock.bigpond.net.au>
Subject: sprintf - problems
Message-Id: <EsjFb.60748$aT.1892@news-server.bigpond.net.au>
$max4="0123"
$FORM{'R2'}="0"
$max4= sprintf("%04d", $max); #max to 4 digits
foreach $key ('R2') {
$rep2= $FORM{$key};
}
$rep4= sprintf("%04d", $rep2);
print("$max4.$rep2");
The above script is giving $max4="0123"
but giving $rep2="0"
Is there a trick to getting "0000" to print?
- Peter
------------------------------
Date: Sun, 21 Dec 2003 16:11:40 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: sprintf - problems
Message-Id: <x7brq2w3pg.fsf@mail.sysarch.com>
>>>>> "PS" == Peter Smith <psmith6@SparnBlock.bigpond.net.au> writes:
> $max4="0123"
> $FORM{'R2'}="0"
> $max4= sprintf("%04d", $max); #max to 4 digits
> foreach $key ('R2') {
> $rep2= $FORM{$key};
> }
> $rep4= sprintf("%04d", $rep2);
> print("$max4.$rep2");
> but giving $rep2="0"
well, you zero pad $rep2 into $rep4, so you should be printing $rep4
> Is there a trick to getting "0000" to print?
yes, print the correct variable
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Sun, 21 Dec 2003 11:18:17 -0500
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: sprintf - problems
Message-Id: <8JjFb.422$d%1.188630@news20.bellglobal.com>
"Peter Smith" <psmith6@SparnBlock.bigpond.net.au> wrote in message
news:EsjFb.60748$aT.1892@news-server.bigpond.net.au...
>
> $max4="0123"
> $FORM{'R2'}="0"
>
> $max4= sprintf("%04d", $max); #max to 4 digits
> foreach $key ('R2') {
> $rep2= $FORM{$key};
> }
> $rep4= sprintf("%04d", $rep2);
> print("$max4.$rep2");
>
>
> The above script is giving $max4="0123"
>
> but giving $rep2="0"
>
> Is there a trick to getting "0000" to print?
Yes, it's called using strictures and warnings in your scripts. It's not a
trick, however, but a habit you should form. If you had, and had pasted your
real working code, you probably would have noticed what you were doing
wrong:
1) you're missing semi-colons at the end of the first two lines;
2) you're assigning the value from the first sprintf to some new variable
called $max (instead of back to $max4);
3) you then assign the value from your second sprintf to another new
variable called $rep4; and
4) you then try and print the $max4, which is set to '0000' after using
sprintf on an undefined value, and $rep2, which is still set to '0' because
you assigned '0000' to $rep4.
Matt
------------------------------
Date: 21 Dec 2003 10:28:38 -0800
From: e9526925@stud3.tuwien.ac.at (Rasto Levrinc)
Subject: Re: sprintf - problems
Message-Id: <e4807da1.0312211028.52e37b5@posting.google.com>
"Peter Smith" <psmith6@SparnBlock.bigpond.net.au> wrote in message news:<EsjFb.60748$aT.1892@news-server.bigpond.net.au>...
> $max4="0123"
> $FORM{'R2'}="0"
>
> $max4= sprintf("%04d", $max); #max to 4 digits
> foreach $key ('R2') {
> $rep2= $FORM{$key};
> }
> $rep4= sprintf("%04d", $rep2);
> print("$max4.$rep2");
>
>
> The above script is giving $max4="0123"
>
> but giving $rep2="0"
>
> Is there a trick to getting "0000" to print?
>
The trick is to replace $rep2 with $rep4 in your print statement.
print("$max4.$rep4");
Rasto Levrinc
------------------------------
Date: Sun, 21 Dec 2003 19:46:42 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: sprintf - problems
Message-Id: <Pine.LNX.4.53.0312211940100.27743@ppepc56.ph.gla.ac.uk>
On Sun, 21 Dec 2003, Rasto Levrinc wrote:
> > Is there a trick to getting "0000" to print?
>
> The trick is to replace $rep2 with $rep4 in your print statement.
No tricks would be required, if the original poster had been following
this newsgroup's posting guidelines.
http://mail.augustmail.com/~tadmc/clpmisc.shtml , posted here
on the group at regular intervals.
Please, use Perl's own self-help tools -before- appealing for
assistance from the newsgroup. In so many cases, the appeal will then
no longer be needed, and the time and patience of the newsgroup
members won't be squandered.
------------------------------
Date: Sun, 21 Dec 2003 20:00:28 +0100
From: Wolfgang Fischer <Wolfgang_.fischer@lycos.de>
Subject: strange problem with perl/tk and detaching threads
Message-Id: <pan.2003.12.21.19.00.24.808133@lycos.de>
Hello,
in normal programs (without Tk) this both statements behave equally:
my $t=thread->new(sub{sleep 3})->detach();
and
my $t=thread->new(sub{sleep 3}); $t->detach;
However, when I use the first one in a Tk program, the program crashes and
prints this error messages when the thread returns.
Attempt to free non-existent shared string '.' at /usr/lib/perl5/Tk/Widget.pm line 96 during global destruction.
Attempt to free non-existent shared string 'tclAfter' at /usr/lib/perl5/Tk/Widget.pm line 96 during global destruction.
Attempt to free non-existent shared string 'after' at /usr/lib/perl5/Tk/Widget.pm line 96 during global destruction.
Attempt to free non-existent shared string '_CmdInfo_' at /usr/lib/perl5/Tk/Widget.pm line 96 during global destruction.
Attempt to free non-existent shared string '_When_Deleted_' at /usr/lib/perl5/Tk/Widget.pm line 96 during global destruction.
Attempt to free non-existent shared string '_AssocData_' at /usr/lib/perl5/Tk/Widget.pm line 96 during global destruction.
Scalars leaked: -26
When I use the second example, it works fine. See below for a short
example script.
What's the reason why this two statements behave different? Why do they
behave equally in programs without Tk? Is this a bug?
This crashes:
#! /usr/bin/perl
use threads;
use Tk;
Tk::MainWindow->new();
my $t=scalar(threads->new(sub{sleep 3}))->detach;
MainLoop;
This works:
#! /usr/bin/perl
use threads;
use Tk;
Tk::MainWindow->new();
my $t=scalar(threads->new(sub{sleep 3}));
$t->detach;
MainLoop;
PS: I'm using Debian GNU/Linux.
--
Regards/Gruesse
Wolfgang
------------------------------
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 5967
***************************************