[19580] in Perl-Users-Digest
Perl-Users Digest, Issue: 1775 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Sep 19 18:05:38 2001
Date: Wed, 19 Sep 2001 15:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1000937110-v10-i1775@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 19 Sep 2001 Volume: 10 Number: 1775
Today's topics:
DBI and Signals <mark.riehl@agilecommunications.com>
DBI/MySQL help needed (martinblack)
Re: DBI/MySQL help needed (John J. Trammell)
Re: Efficiency <Doug.King@abh.siemens.com>
Re: Error 405 using application/x-www-form-urlencoded <gnarinn@hotmail.com>
File Reading Problem <ychandra@cisco.com>
Re: File Reading Problem (John J. Trammell)
Re: File Reading Problem <jeff@vpservices.com>
Re: File Reading Problem <webmaster@kwakeb.net>
Re: File Reading Problem (John J. Trammell)
Re: File Reading Problem <webmaster@kwakeb.net>
Re: File Reading Problem <echang@netstorm.net>
Re: filter out short strings (Tad McClellan)
Re: HELP! Having Trouble concatenating or joining and (J.B. Moreno)
Re: How to htmlize an email, for eg lynx? (J.B. Moreno)
Re: How to htmlize an email, for eg lynx? <garyjohn@spk.agilent.com>
Re: how to replace several blank lines with 1 (Charles DeRykus)
Incorrect "Runaway format" error <person@company.com>
IRC.pm and non-local servers <zaz@mitre.org>
Re: Limiting floating point decimal places. (Mark Jason Dominus)
Login script <peter.cch@mailexcite.com>
Re: newbie question - why it gives filehandle error? <gnarinn@hotmail.com>
numerical then alpha sort of files <mdulrich@unity.ncsu.edu>
Re: numerical then alpha sort of files (Tad McClellan)
Re: numerical then alpha sort of files <bcaligari@fireforged.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 19 Sep 2001 20:28:14 GMT
From: "Mark Riehl" <mark.riehl@agilecommunications.com>
Subject: DBI and Signals
Message-Id: <yd7q7.11$Dy.2548@typhoon1.gnilink.net>
All - I'm running Perl 5.6.0 and DBI 1.14 under Win2k. I've got a problem
with signals. It seems as if I can't catch any signals (e.g., Ctrl-C) after
making a connection to my database (MySQL). I need to manually use the Task
Manager (Ctrl - Alt - Del) to stop the process.
I've deleted all unnecessary code, including the database query itself (yes,
the same problem occurs if a query is left in place). If I comment out the
connect and disconnect statements, I don't have any problems catching the
signal.
I need this set up inside the while loop because this code will eventually
be part of a server, accepting client connections from Perl and C++ clients.
Any suggestions?
Thanks,
Mark
*************************************************
Here's the code I'm running (it will run if you adjust $dbstring, user, and
password):
#!perl -w
use strict;
use diagnostics;
use DBI;
my $quit = 0;
$SIG{INT} = \&catch_int;
while (!$quit) {
print "in while()\n";
my $result = query_db();
print $result;
sleep(2);
}
sub query_db {
# Build the database connection string.
my $dbstring = "DBI:mysql:database01:127.0.0.1:3306";
# Connect to the database.
my $dbh = DBI->connect($dbstring,"user","password")
or die "Can't connect to mysql on 127.0.0.1: $DBI::errstr\n";
# Assume result from the db is named result.
my $result = "Test";
print "Disconnecting \$dbh\n";
$dbh->disconnect;
return ($result);
}
sub catch_int {
my $sig = shift;
print "Caught $sig\n";
$quit++;
}
--
Mark Riehl
Agile Communications, Inc.
Email: mark.riehl@agilecommunications.com
------------------------------
Date: 19 Sep 2001 12:16:09 -0700
From: martinblack26@yahoo.com (martinblack)
Subject: DBI/MySQL help needed
Message-Id: <c025943b.0109191116.3ce993f3@posting.google.com>
Hi, I have a problem with one of my scripts that supposedly creates
database tables. ? Okay, this ones probably quite easy, but I haven't
had very much DBI experience. The error message says:
"DBD::mysql::st execute failed: You have an error in your SQL syntax
near ')' at line 10 at dbstart.cgi line 56.
Can't execute: You have an error in your SQL syntax near ')' at line
10 at dbstart.cgi line 56."
The "Error" line in question is:
$sth->execute() || die "Can't execute: ", $dbh->errstr;
I've wrapped the above line into an eval, and nothing came up????
Could this be a problem with DBI?
Any help on this would be much appreciated, as I am at my wits end on
this.
Cheers,
martinblack
The snippet...
#!/usr/bin/perl
BEGIN {
open (STDERR, ">path/to/error.txt");
}
use DBI;
use DBD::mysql;
# here come the globals*
$max = 200;
$DBname= "DBI:mysql:blablabla";
$DBhost = "localhost";
$DBusername = "myuname";
$DBpassword = "mypassword";
$dbh = DBI->connect("$DBname:$DBhost", $DBusername, $DBpassword) ||
print "can't connect to the database";
#### here comes the bride...
eval {
$sth = $dbh->prepare(
$sql="CREATE TABLE product
(company_id VARCHAR (5) NOT NULL,
product_id INT NOT NULL,
title VARCHAR($max),
description VARCHAR($max),
spex tinyblob,
price Float not null,
sex char (2),
PRIMARY KEY (company_id, product_id),)
") || die "Can't prepare the sandwich: ", $dbh->errstr;
};
if($@) {
print "Content-type: text/html\n\n";
print "someting's wrong! $@\n";
exit;
} else {
$sth->execute() || die "Can't execute: ", $dbh->errstr;
}
... and so on...
------------------------------
Date: 19 Sep 2001 19:38:27 GMT
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: DBI/MySQL help needed
Message-Id: <slrn9qht1i.uaj.trammell@haqq.hypersloth.net>
On 19 Sep 2001 12:16:09 -0700, martinblack <martinblack26@yahoo.com> wrote:
[snip]
> Can't execute: You have an error in your SQL syntax near ')' at line
> 10 at dbstart.cgi line 56."
I'm guessing that this means there's an error in your SQL.
[snip]
> #!/usr/bin/perl
#!/usr/bin/perl -w
use strict;
>
> BEGIN {
> open (STDERR, ">path/to/error.txt");
open(...) or die $!;
> }
> use DBI;
> use DBD::mysql;
^^^^^^^^^^
Not needed.
> # here come the globals*
>
> $max = 200;
>
> $DBname= "DBI:mysql:blablabla";
> $DBhost = "localhost";
> $DBusername = "myuname";
> $DBpassword = "mypassword";
>
> $dbh = DBI->connect("$DBname:$DBhost", $DBusername, $DBpassword) ||
> print "can't connect to the database";
>
> #### here comes the bride...
>
> eval {
> $sth = $dbh->prepare(
> $sql="CREATE TABLE product
> (company_id VARCHAR (5) NOT NULL,
> product_id INT NOT NULL,
> title VARCHAR($max),
> description VARCHAR($max),
> spex tinyblob,
> price Float not null,
> sex char (2),
> PRIMARY KEY (company_id, product_id),)
^
^
> ") || die "Can't prepare the sandwich: ", $dbh->errstr;
> };
As far as I know, SQL doesn't handle trailing commas, unlike Perl.
------------------------------
Date: Wed, 19 Sep 2001 17:06:09 -0400
From: Doug King <Doug.King@abh.siemens.com>
Subject: Re: Efficiency
Message-Id: <3BA908C1.B3ACAE03@abh.siemens.com>
Bart Lateur wrote:
>
> TM wrote:
>
> >Can Perl instructions either from the core or from specific modules be
> >more efficient than system commands such as copy, xcopy, del, move etc
> >with their many switches and wildcards. Or maybe that's a nonsense. In
> >my case, I'm working on WIn2K with procedures that handle thousands of
> >files with such commands that's why I'm looking for improvement in
> >execution time of such actions.
>
> In my experience, File::Find is very slow on Win32. So no, if you want
> to process whole directory trees, I don't expect it to be blindinly
> fast.
>
> Of course, YMMV. It strongly depends on your hardware, and on your OS
> too, I presume.
>
> --
> Bart.
I use File::Find and File::Copy on a script in WinNT. It runs much
faster with those than it did with `copy ..` or system("copy ...");
Also, there is another reason to use the perl commands -- they are more
portable than using DOS commands
------------------------------
Date: Wed, 19 Sep 2001 17:58:00 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Error 405 using application/x-www-form-urlencoded
Message-Id: <1000922280.198696937412024.gnarinn@hotmail.com>
In article <61782897.0109182121.72bede40@posting.google.com>,
Todd Canedy <tcaxoxs@yahoo.com> wrote:
>Using the code directly out of the perl documentation for LWP:
>When using:
>$req->content_type('application/x-www-form-urlencoded');
>I get error 405.
do you get this error when this line is executed, or do you mean
that the error happens when you call the request method later?
is there no error unless you set the content-type?
why not show us a little more code?
>The req is not going to my server, but to a remote server for payment
>processing.
you should do your testing by creating a simple cgiscript locally
that only logs requests to a file, and returns a valid result, and
make your requests to that url.
this way, it is easier to debug.
when you have that working, then you can change to the external url
>Any and all help including links to read will be greatly appreciated.
i assume you have read
perldoc lwpcook
gnari
------------------------------
Date: Wed, 19 Sep 2001 12:04:36 -0700
From: Chandra Yemparala <ychandra@cisco.com>
Subject: File Reading Problem
Message-Id: <3BA8EC44.4042D03@cisco.com>
Hi,
I wrote an example program to read contents of a file. When I run this
it prints 0. Can you tell me what if I am doing anything wrong here.
#!/usr/local/bin/perl
open(FILE,"tmpfile")
or die "Couldn't open $!\n";
@content = <FILE>;
print "printing array" & @content &"\n";
close(FILE);
Thx
chandra
------------------------------
Date: 19 Sep 2001 19:13:25 GMT
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: File Reading Problem
Message-Id: <slrn9qhril.u7i.trammell@haqq.hypersloth.net>
On Wed, 19 Sep 2001 12:04:36 -0700, Chandra Yemparala wrote:
> Hi,
> I wrote an example program to read contents of a file. When I run this
> it prints 0. Can you tell me what if I am doing anything wrong here.
>
> #!/usr/local/bin/perl
#!/usr/local/bin/perl -w
use strict;
> open(FILE,"tmpfile")
> or die "Couldn't open $!\n";
> @content = <FILE>;
> print "printing array" & @content &"\n";
^ ^
^ ^
You probably want this to read:
print "printing array: @content\n";
> close(FILE);
--
Steve Balmer, CEO of Microsoft, recently referred to Linux as a Cancer.
Unsurprisingly, that's incorrect; Linux was released on August 25th, 1991
and is therefore a Virgo.
------------------------------
Date: Wed, 19 Sep 2001 12:13:56 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: File Reading Problem
Message-Id: <3BA8EE74.511CD0EC@vpservices.com>
Chandra Yemparala wrote:
>
> Hi,
> I wrote an example program to read contents of a file. When I run this
> it prints 0. Can you tell me what if I am doing anything wrong here.
>
> #!/usr/local/bin/perl
Better to use warnings and the strict pragma so:
#!/usr/local/bin/perl -w
use strict;
> print "printing array" & @content &"\n";
You are mistaking the use of the ampersand '&', it does not concatenate
strings. Also printing an array outside of quote marks does not do what
you probably expect. This will work:
print "printing array: @content\n";
But you are probably better off reading the file a line at a time and
printing those lines as they are read rather than putting the whole file
into an array first (watch out for Cardinal Slurphammer, he's
justifiably, grouchy).
--
Jeff
------------------------------
Date: Wed, 19 Sep 2001 22:15:37 +0300
From: "eDeveloper" <webmaster@kwakeb.net>
Subject: Re: File Reading Problem
Message-Id: <9oar51$k5r$1@ns1.isu.net.sa>
Hi
The first code :
-----------------------
> > print "printing array" & @content &"\n";
-----------------------
prints the size of the array
the second code
--------------------------
> print "printing array: @content\n";
--------------------------
prints the content of the array
this is a good way
but the common way to print an array is using foreach loop
for example
--------------------------
foreach (@content) {
print "$_\n";
}
---------------------------
Regards,
eDeveloper
"John J. Trammell" <trammell@haqq.hypersloth.invalid> wrote in message
news:slrn9qhril.u7i.trammell@haqq.hypersloth.net...
> On Wed, 19 Sep 2001 12:04:36 -0700, Chandra Yemparala wrote:
> > Hi,
> > I wrote an example program to read contents of a file. When I run this
> > it prints 0. Can you tell me what if I am doing anything wrong here.
> >
> > #!/usr/local/bin/perl
>
> #!/usr/local/bin/perl -w
> use strict;
>
> > open(FILE,"tmpfile")
> > or die "Couldn't open $!\n";
> > @content = <FILE>;
> > print "printing array" & @content &"\n";
> ^ ^
> ^ ^
>
> You probably want this to read:
>
> print "printing array: @content\n";
>
> > close(FILE);
>
> --
> Steve Balmer, CEO of Microsoft, recently referred to Linux as a Cancer.
> Unsurprisingly, that's incorrect; Linux was released on August 25th, 1991
> and is therefore a Virgo.
------------------------------
Date: 19 Sep 2001 19:49:35 GMT
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: File Reading Problem
Message-Id: <slrn9qhtme.uaj.trammell@haqq.hypersloth.net>
On Wed, 19 Sep 2001 22:15:37 +0300, eDeveloper <webmaster@kwakeb.net>
jeopary posted:
> Hi
>
> The first code :
> -----------------------
> > > print "printing array" & @content &"\n";
> -----------------------
> prints the size of the array
No, it doesn't. This is easy to test:
[ ~ ] perl -e '@x=qw[a b c]; print "foo" & @x & "\n"'
0[ ~ ]
perldoc perlop, and search for "Bitwise String".
------------------------------
Date: Wed, 19 Sep 2001 22:52:23 +0300
From: "eDeveloper" <webmaster@kwakeb.net>
Subject: Re: File Reading Problem
Message-Id: <9oat9v$mit$1@ns1.isu.net.sa>
-------------------------
perl -e '@x=qw[a b c]; print "foo" & @x & "\n"'
-------------------------
'&' is wrong ... you must use the dot '.' instead of it
if you used the comma ',' it will print the elements of the array
"John J. Trammell" <trammell@haqq.hypersloth.invalid> wrote in message
news:slrn9qhtme.uaj.trammell@haqq.hypersloth.net...
> On Wed, 19 Sep 2001 22:15:37 +0300, eDeveloper <webmaster@kwakeb.net>
> jeopary posted:
> > Hi
> >
> > The first code :
> > -----------------------
> > > > print "printing array" & @content &"\n";
> > -----------------------
> > prints the size of the array
>
> No, it doesn't. This is easy to test:
>
> [ ~ ] perl -e '@x=qw[a b c]; print "foo" & @x & "\n"'
> 0[ ~ ]
>
> perldoc perlop, and search for "Bitwise String".
>
------------------------------
Date: Wed, 19 Sep 2001 21:21:05 GMT
From: "E.Chang" <echang@netstorm.net>
Subject: Re: File Reading Problem
Message-Id: <Xns9121B15814285echangnetstormnet@207.106.93.86>
Chandra Yemparala <ychandra@cisco.com> wrote in
news:3BA8EC44.4042D03@cisco.com:
> Hi,
> I wrote an example program to read contents of a file. When I run
> this it prints 0. Can you tell me what if I am doing anything wrong
> here.
>
>#!/usr/local/bin/perl open(FILE,"tmpfile")
> or die "Couldn't open $!\n";
> @content = <FILE>;
> print "printing array" & @content &"\n";
> close(FILE);
If you had enabled warnings, you would have seen why the output wasn't
what you expected.
Argument "printing array" isn't numeric in bitwise and (&) at ...
Argument "\n" isn't numeric in bitwise and (&) at ...
The print function takes a list of arguments which should be separated
by a comma, not an &. All the values are printed 'as is'.* you may
have been thinking of concatenation - the operator is . - but that will
cause the array to be evaluated in scalar context and thus use its
length, again not what you want.
Scalar and array variables can be interpolated into strings. When
printed, the values of an interpolated array will be separated by a
space in the output.* The elements can also be printed out
individually using a loop. (All 3 ways are illustrated in example 1.)
However, unles you have some other reason for keeping all the lines of
a file in an array, your best approach is just to read and print them
one line at a time. (Example 2.)
Example 1:
#!/usr/bin/perl -w
@content = <DATA>;
print @content,
"=========================\n",
"@content",
"=========================:\n";
foreach (@content) {
print "$_\n";
}
__DATA__
First set is just the array
Second set interpolates using "" (notice extra space)
Third set uses a loop with extra \n. (notice double-spacing)
Produces the output
First set is just the array
Second set interpolates using "" (notice extra space)
Third set uses a loop with extra \n. (notice double-spacing)
=========================
First set is just the array
Second set interpolates using "" (notice extra space)
Third set uses a loop with extra \n. (notice double-spacing)
=========================:
First set is just the array
Second set interpolates using "" (notice extra space)
Third set uses a loop with extra \n. (notice double-spacing)
Example 2:
#!/usr/bin/perl -w
while (<DATA>) {
print $_;
}
__DATA__
First line
Second line
Third line
Produces the output
First line
Second line
Third line
--------------------
*Yes, if we're being picky, whatever the values of $, and $" are.
(Incidentally, $" is not be shown correctly in some forms of the
documentation because of the algorithms used to convert from the POD.)
--
EBC
------------------------------
Date: Wed, 19 Sep 2001 18:41:31 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: filter out short strings
Message-Id: <slrn9qhmrl.5cs.tadmc@tadmc26.august.net>
* Tong * <sun_tong@users.sourceforge.net> wrote:
>"Wyzelli" <wyzelli@yahoo.com> writes:
>
>> > How can I filter out strings that are too short from an array?
>> >
>> > @out = grep { (=~ tr/a-z//i) <3} @in;
>
>> @out = grep {(length $_ > 3)} @in;
>
>Thanks, I forgot to mention the reason that I want use tr instead of
>length:
>
>For a string 'Abc1234', I want it count as 3 instead of 7, i.e.,
>count characters in it only.
No, that string has 7 characters. Digit characters are characters too.
I guess you mean 3 "letter characters".
>Is it possible? thanks
my @out = grep tr/a-zA-Z// > 3, @in;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 19 Sep 2001 15:14:36 -0400
From: planb@newsreaders.com (J.B. Moreno)
Subject: Re: HELP! Having Trouble concatenating or joining and making or building a url with ActivePerl and the '.' operator.
Message-Id: <1ezzloe.14xy6mmjiaof1N%planb@newsreaders.com>
codeslayer <weedmonster_99@yahoo.com> wrote:
> Thanks to everyone who responded. I tried the code at home and it
> worked this time!
-snip-
> Here is a link to a post where my final code is:
>
> http://groups.google.com/groups?q=codeslayer&hl=en&rnum=4&selm=4b459565.01
> 09181000.19305984%40posting.google.com
Normally it is considered sufficient to provide just the message-id of
the article -- then those that can access it directly can, and those
that have to pass it off to google won't have any trouble.
So, in article <4b459565.0109181000.19305984@posting.google.com> you
wrote:
| print "\n\n";
| print $url_t1;
| print "\n\n";
| print "another version ...\n";
| print $url_t2;
| print "\n";
> If there is an easier way, please let me know.
print "\n\n" . $url_t1 . "\n\n";
print "another version ...\n" . $url_t2 . "\n";
or...
print "
$url_t1
another version ...
$url_t2
";
or
print "\n\n$url_t1\n\nanother version ...\n$url_t2\n";
all work. Which you'll want to use depends upon which you consider more
legible.
--
JBM
"Your depression will be added to my own" -- Marvin of Borg
------------------------------
Date: Wed, 19 Sep 2001 14:51:05 -0400
From: planb@newsreaders.com (J.B. Moreno)
Subject: Re: How to htmlize an email, for eg lynx?
Message-Id: <1ezzku0.5rjxay1my32scN%planb@newsreaders.com>
David Combs <dkcombs@panix.com> wrote:
> I get emails (from a listserv) that has
> lots of interesting links.
>
> Being as I do *not* use M$, and instead use
> (as email-reader) mutt, I need some way to
> convert an email like this:
>
> Building Debate: Should Twin Towers Go Up Again?
> http://www.dallasnews.com/national/472263_nycarchitect_1.html
Are you sure that mutt doesn't have the ability to recognize and launch
such links?
It's not only MS that makes such things easy...
--
JBM
"Your depression will be added to my own" -- Marvin of Borg
------------------------------
Date: Wed, 19 Sep 2001 21:08:41 +0000 (UTC)
From: Gary Johnson <garyjohn@spk.agilent.com>
Subject: Re: How to htmlize an email, for eg lynx?
Message-Id: <1000933721.261830@cswreg.cos.agilent.com>
In comp.mail.mutt J.B. Moreno <planb@newsreaders.com> wrote:
> David Combs <dkcombs@panix.com> wrote:
>
>> I get emails (from a listserv) that has
>> lots of interesting links.
>>
>> Being as I do *not* use M$, and instead use
>> (as email-reader) mutt, I need some way to
>> convert an email like this:
>>
>> Building Debate: Should Twin Towers Go Up Again?
>> http://www.dallasnews.com/national/472263_nycarchitect_1.html
>
> Are you sure that mutt doesn't have the ability to recognize and launch
> such links?
>
> It's not only MS that makes such things easy...
If your e-mail typically contains only a few links, try urlview. It's
bound in mutt to CTRL-B by default. It is also discussed in the mutt
manual. If your e-mail typically contains several links and you would
like to see them in the context of the message, pipe the message to w3m
and type ':' to see the links highlighted and so you can follow them.
I like to see the links in context, so I use w3m, but I think w3m does
require more keystrokes to launch a graphical browser than does urlview.
I have the following in my muttrc to make it easier to invoke w3m:
macro index \cB |w3m\n "call w3m to extract URLs out of a message"
macro pager \cB |w3m\n "call w3m to extract URLs out of a message"
I just read the top of your message again. For e-mail newsletters that
contain lots of links (such as the Slashdot Daily Headlines), I use
display-hooks to set my pager to w3m for just those newsletters:
display-hook ~A 'set pager="builtin"'
display-hook '~s "\\[ Slashdot Message \\] Daily Headlines"' 'set pager="w3m"'
HTH,
Gary
------------------------------
Date: Wed, 19 Sep 2001 21:20:38 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: how to replace several blank lines with 1
Message-Id: <GJxHyE.1H6@news.boeing.com>
In article <1geao9.81r.ln@mail.scotlegal.com>,
Tam McLaughlin <tamm@scotlegal.com> wrote:
>I cannot find how to replace or delete several successive blank lines
>from a text file.
>
>I have text file which is normally sent to the printer but now want to split
>the file up and email the different files to different people. I have
>created
>the different files but wish to get rid of the blank lines that are left
>over
>that are inserted for correct page length etc.
>I have looked at the /start pattern/ .. /end attern/ operator but cant work
>this out.
>
perl -ni.bak -e 'print if !/^$/' file1 file2 ...
--
Charles DeRykus
------------------------------
Date: Wed, 19 Sep 2001 12:07:46 -0700
From: The Small Kahuna <person@company.com>
Subject: Incorrect "Runaway format" error
Message-Id: <3BA8ED02.3EF57252@company.com>
I am using Damian Conway's Parse::RecDescent module (Yea! Damian!!) to
do some relatively sophistocated parsing of files. There is a debug
mode that allows you to watch the parser parse so you can figure out
what you did wrong. The message subroutines use formatted writes to
produce columnar output.
I am using a particular file to parse which contains relatively large
parse blocks in it that will be output by the parse diagnostics. By
sheer coincidence, near the end of these large blocks are several
identical lines.
Reading perldiag, it sez:
Runaway format
(F) Your format contained the ~~ repeat-until-blank sequence, but it
produced 200 lines at once, and the 200th line looked exactly like the
199th line. Apparently you didn't arrange for the arguments to exhaust
themselves, either by using ^ instead of @ (for scalar variables), or by
shifting or popping (for array variables). See the perlform manpage.
Damn if the 199th line isn't exactly the same as the 200th, BUT THIS IS
"NORMAL".
My question is "is there any way to either disable this or up the
count"? While the error check is helpful, it just turns out in this
case to be wrong. This causes the diagnostic output to fail, so I can
either not debug my broken parser or crash and burn before I get to the
problem. (Of course I can (and will) hack at the input file in the
hopes of avoiding this specific issue, but I'm asking if there is a
general solution.)
------------------------------
Date: Wed, 19 Sep 2001 15:34:25 -0400
From: Zachary Zebrowski <zaz@mitre.org>
Subject: IRC.pm and non-local servers
Message-Id: <3BA8F341.9134891E@mitre.org>
Hi.
For some reason, I cannot connect under red hat linux to servers other
than localhost using irc.pm Note this works prefectly fine on windows.
DNS resolves servers correctly, have no idea what is going on.
Error message:
Connecting to server 127.0.0.1 (SUCCESS)
Can't connect to [server].mitre.org:6667! at
/usr/lib/perl5/site_perl/5.6.0/Net/IRC.pm line 192
Can't call method "add_global_handler" on an undefined value at
script.pl line 55.
windows:
Connecting to server 127.0.0.1 (SUCCESS)
Connecting to server [server].mitre.org (SUCCESS)
**thanks**.
Zak
------------------------------
Date: Wed, 19 Sep 2001 18:18:04 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Limiting floating point decimal places.
Message-Id: <3ba8e15c.4a55$2ac@news.op.net>
In article <x766ahdrbj.fsf@home.sysarch.com>,
Uri Guttman <uri@sysarch.com> wrote:
> CF> Also look at $OFMT and $# in the perlvar manual page.
>
>$# is deprecated and not useful. i think it is also broken in some ways.
It's extremely broken. Try this:
$s = 1.23456789;
$# = '%.0f';
print $s, "\t$s\n";
I doubt anyone has ever successfully used $# for anything.
I'd really like to see an example of a program that uses it successfully.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: Thu, 20 Sep 2001 02:05:07 +0800
From: "Peter Chan" <peter.cch@mailexcite.com>
Subject: Login script
Message-Id: <3ba8df0b.0@news.tm.net.my>
i wish to make a login page in my website .... but i don't know how to do
it.
Can I know what is the algorithm for login script ?
Just like i'm using my email ... once I login, then every email that i
retrive or view is no need to enter my password already.
Is it the pasword and username is stored somewhere else so that every time
it will retrieve the password from there ?
Pls guide my on the algorithm and the need skill or syntax.
Thank you.
By Peter
------------------------------
Date: Wed, 19 Sep 2001 17:38:02 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: newbie question - why it gives filehandle error?
Message-Id: <1000921082.438051130622625.gnarinn@hotmail.com>
In article <9o7rq7$m082@imsp212.netvigator.com>,
hwchui <hwc33@hotmail.com> wrote:
>I don't no idea why it gives me an error message like
>
>"print() on closed filehandle main::FH2 at ./tb.pl line 16."
>
>What I understand is, FH2 in ta.pl should be closed before
>return back to tp.pl so what goes wrong?
that is what goes wrong. you are trying to print to FH2 after closing it
>#----------------------------------------
># ta.pl
>#-----------------------------------------
>#!/usr/bin/perl -w
note: the #! line should really be the first line
>
>sub doSomething {
>
> ($file1,$file2) = @_;
>
> print "file1 = $file1\n";
> print "file2 = $file2\n";
>
> local(*FH1, *FH2);
>
> open (FH1, "< $file1") || die "Can't Open file $file1: $!\n";
> open (FH2, "> $file2") || die "Can't Open file $file2: $!\n";
>
> select FH2;
this line is what is causing the problem. in this example, it does
not serve any purpose, so could be removed.
>
> while (<FH1>) {
> print FH2 $_;
> }
>
> close FH1;
> close FH2;
now you have closed FH2 , but it is still selected. either
remove the select line above, or select a valid filehandle
before you print. for example:
select STDOUT;
>}
>1;
>
>#----------------------------------------------------------------------
># tb.pl
>#----------------------------------------------------------------------
>#!/usr/bin/perl -w
>
>
>require "ta.pl";
>
>
>$myf1 = shift @ARGV;
>$myf2 = shift @ARGV;
>
>print $myf1, "\n";
>print $myf2, "\n";
>
>doSomething($myf1,$myf2);
>
>print "what happen?\n"; #It doesn't print to FH2 which should be closed
>in ta.pl
it *tries* to print to the closed FH2
gnari
------------------------------
Date: Wed, 19 Sep 2001 15:51:54 -0400
From: Marc Ulrich <mdulrich@unity.ncsu.edu>
Subject: numerical then alpha sort of files
Message-Id: <3BA8F75A.BEFD1F7E@unity.ncsu.edu>
Here's an interesting sort problem. I've got files like:
ag1, ag2, ag2a, ag2b, ag10, ag11, ag11b, ag20, ....
If I just tell perl to sort them, I get an alpha only sort:
ag1, ag10, ag11, ag11b, ag2, ag20, ag2a, ag2b, ....
I have created a routine that creates a hash where
key is the $filename =~ s/[a-z]//;
value = $filename;
Then I iterate through the hash and create another array which will be
the files sorted numerically since the hash keys are the filenames
stripped of anything but numbers. However, this routine fails for the
above because I need 3 files for the hash w/ key = 2 and the result is
something like
ag1, ag2b, ag10, ag11b, ag20 ....
Any ideas on how I can combine the two to get a numerical sort first,
then alpha sort second?
Thanks,
Marc
------------------------------
Date: Wed, 19 Sep 2001 20:21:26 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: numerical then alpha sort of files
Message-Id: <slrn9qhsso.5tt.tadmc@tadmc26.august.net>
Marc Ulrich <mdulrich@unity.ncsu.edu> wrote:
>Here's an interesting sort problem.
^^^^^^^^^^^^
^^^^^^^^^^^^
Then we can assume that you have already seen:
perldoc -q sort
"How do I sort an array by (anything)?"
??
So what part of the answer given there are you having trouble with?
>I've got files like:
^^^^^
>ag1, ag2, ag2a, ag2b, ag10, ag11, ag11b, ag20, ....
I assume you meant "array elements" there instead of "files".
>Any ideas on how I can combine the two to get a numerical sort first,
>then alpha sort second?
alpha on _what_? The first alpha string or the second one (if present)?
This sorts numerically first, then on the first alpha part:
my @sorted = map { $_->[0] }
sort { $a->[2] <=> $b->[2] or
$a->[1] cmp $b->[1]
}
map { [ $_, /^(\D+)(\d+)/ ] } @data;
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 19 Sep 2001 21:00:20 -0000
From: "B. Caligari" <bcaligari@fireforged.com>
Subject: Re: numerical then alpha sort of files
Message-Id: <9ob0i602hbj@enews1.newsguy.com>
"Marc Ulrich" <mdulrich@unity.ncsu.edu> wrote in message
news:3BA8F75A.BEFD1F7E@unity.ncsu.edu...
> Here's an interesting sort problem. I've got files like:
>
> ag1, ag2, ag2a, ag2b, ag10, ag11, ag11b, ag20, ....
>
> If I just tell perl to sort them, I get an alpha only sort:
>
> ag1, ag10, ag11, ag11b, ag2, ag20, ag2a, ag2b, ....
>
> I have created a routine that creates a hash where
>
> key is the $filename =~ s/[a-z]//;
> value = $filename;
>
> Then I iterate through the hash and create another array which will be
> the files sorted numerically since the hash keys are the filenames
> stripped of anything but numbers. However, this routine fails for the
> above because I need 3 files for the hash w/ key = 2 and the result is
> something like
>
> ag1, ag2b, ag10, ag11b, ag20 ....
>
> Any ideas on how I can combine the two to get a numerical sort first,
> then alpha sort second?
>
> Thanks,
> Marc
>
#!/usr/local/bin/perl
use warnings;
use strict;
my @arr = ('ag1', 'ag2', 'ag2a', 'ag2b', 'ag10', 'ag11', 'ag11b', 'ag20',);
print "$_\n" for (sort mySort @arr);
exit 0;
sub mySort
{
($a eq $b) && return 0;
my ($A) = $a =~ m/(\d+)/;
my ($B) = $b =~ m/(\d+)/;
print ("A = $A\n");
($A <=> $B) || ($a cmp $b);
}
B
------------------------------
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 1775
***************************************