[10278] in Perl-Users-Digest
Perl-Users Digest, Issue: 3871 Volume: 8
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Oct 2 06:07:12 1998
Date: Fri, 2 Oct 98 03:00:23 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 2 Oct 1998 Volume: 8 Number: 3871
Today's topics:
byte in perl <johnvun@asiapac.net>
Can somebody comment? <erhmiru@erh.ericsson.se>
Re: Can somebody comment? (Sam Holden)
Re: Can somebody comment? <erhmiru@erh.ericsson.se>
connecting to a Mysql via command line ok FAILs with pe randy.paries@avex.com
Re: DBI/mysql <JoelNelson@Home.net>
eq on if statement causing problems with string <brettr@centuryinter.net>
Re: Excel + OLE: a disaster! (Hekon Alstadheim)
I have installed Linux. Now what? <dan.bialek@mindspring.com>
Is there one different way to order data ? <edv@dragenopharm.de>
Re: need a regular expressions expert... sir_roland@my-dejanews.com
Re: need a regular expressions expert... <dominique.cretel@cfwb.be>
Re: Need IP Address Sort Subroutine <erhmiru@erh.ericsson.se>
Omaha Perl Mongers - First Meeting ! (Patrick Timmins)
Problem with readdir <smith@avl.com>
Re: Problems Using a Compare Subroutine with Sort <erhmiru@erh.ericsson.se>
Re: Problems Using a Compare Subroutine with Sort <erhmiru@erh.ericsson.se>
Q: Speed Optimization tilmanglotzner@my-dejanews.com
Q: Speed Optimization tilman@spp.hpc.fujitsu.co.jp
Re: Q: Speed Optimization <uri@sysarch.com>
Re: Q: Speed Optimization (Larry Rosler)
Re: Q: Speed Optimization <erhmiru@erh.ericsson.se>
Re: send geroge reese (was Re: Call for Participation: (Larry Wall)
Re: Some kind of 'real' user interface? <erhmiru@erh.ericsson.se>
Re: Stock paging, anyone seen this script? <erhmiru@erh.ericsson.se>
Re: string from array (Bart Lateur)
Re: URL & strings searches <erhmiru@erh.ericsson.se>
Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 02 Oct 1998 17:30:36 +0800
From: johnvun <johnvun@asiapac.net>
Subject: byte in perl
Message-Id: <36149D3B.A65F817E@asiapac.net>
Hi,
i want to know more "Byte" concept in perl. Where i can find more
information ???
For example, i want to send four bytes information to another server
through socket on NT.
Below is my message format
Byte Name Value Data Type
0-1 ID 9000 Short
2-3 Length 4 Short
Value of 0 to 1 Byte is 9000, value of 2 to 3 byte is 4
so $send_value = "90004" is this right ?
or $send_value = "9000 4 "
or $send_value = "9000 4 "
if both values are empty, so is $send_value equal to 36 empty space ????
like this $send_value = " " ????
which one is right ???
Thanks !!!
johnvun
------------------------------
Date: 02 Oct 1998 10:53:44 +0200
From: Michal Rutka <erhmiru@erh.ericsson.se>
Subject: Can somebody comment?
Message-Id: <laww6jpco7.fsf@erh.ericsson.se>
Hello all,
I have the following code:
$a = 1;
$b = "";
$c = "";
$a ? $b = "AA" : $c = "AA";
print "b => \"$b\"\tc => \"$c\"\n";
$b = "";
$c = "";
$a ? $b .= "AA" : $c .= "AA";
print "b => \"$b\"\tc => \"$c\"\n";
$b = "";
$c = "";
($a ? $b : $c) .= "AA";
print "b => \"$b\"\tc => \"$c\"\n";
When I run it I get:
b => "AA" c => ""
b => "AAAA" c => ""
b => "AA" c => ""
which is not what I expected. Namely the second line is my opinion
wrong. Am I right? or is there something which I am missing?
Regards,
Michal
------------------------------
Date: 2 Oct 1998 09:12:45 GMT
From: sholden@pgrad.cs.usyd.edu.au (Sam Holden)
Subject: Re: Can somebody comment?
Message-Id: <slrn71968d.koo.sholden@pgrad.cs.usyd.edu.au>
On 02 Oct 1998 10:53:44 +0200, Michal Rutka <erhmiru@erh.ericsson.se> wrote:
>Hello all,
>
>I have the following code:
>
>$a = 1;
>$b = "";
>$c = "";
>$a ? $b = "AA" : $c = "AA";
>print "b => \"$b\"\tc => \"$c\"\n";
>
>$b = "";
>$c = "";
>$a ? $b .= "AA" : $c .= "AA";
>print "b => \"$b\"\tc => \"$c\"\n";
>
>$b = "";
>$c = "";
>($a ? $b : $c) .= "AA";
>print "b => \"$b\"\tc => \"$c\"\n";
>
>When I run it I get:
>
>b => "AA" c => ""
>b => "AAAA" c => ""
>b => "AA" c => ""
>
>which is not what I expected. Namely the second line is my opinion
>wrong. Am I right? or is there something which I am missing?
You are missing precedence rules...
($a ? $b : $c) .= "AA";
is the same as :
$a ? $b : $c .= "AA";
Which means that :
$a ? $b .= "AA" : $c .= "AA";
is the same as :
($a ? $b .= "AA" : $c) .= "AA";
--
Sam
There's no such thing as a simple cache bug.
--Rob Pike
------------------------------
Date: 02 Oct 1998 11:38:15 +0200
From: Michal Rutka <erhmiru@erh.ericsson.se>
Subject: Re: Can somebody comment?
Message-Id: <lavhm3pam0.fsf@erh.ericsson.se>
sholden@pgrad.cs.usyd.edu.au (Sam Holden) writes:
[...]
> You are missing precedence rules...
My Camel book is already open on a good page...
Michal
------------------------------
Date: Fri, 02 Oct 1998 06:09:55 GMT
From: randy.paries@avex.com
Subject: connecting to a Mysql via command line ok FAILs with perl
Message-Id: <6v1qnj$7cl$1@nnrp1.dejanews.com>
Hello,
Please help..
I can connect to my database via command line
/usr/local/mysql/bin/mysql --password=foo unitdb
this works ok.
I can not attatch via a very simple perl script(see error below code):
#!/usr/local/bin/perl
use Mysql;
$dbh = Mysql->connect("node.com","unitdb","foo","username");
if ( $dbh ){
print "Connected to DB\n";
}else{
print "Connect Failed [$dbh]\n";
}
$sth = $dbh->Query("SELECT * FROM users" ) or die $Mysql::db_errstr;
$ test.pl Connect Failed [] Can't call method "Query" without a package or
object reference at test.pl line 12.
Thanks for any help
Randy Paries
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Fri, 02 Oct 1998 05:48:19 GMT
From: Joel Nelson <JoelNelson@Home.net>
Subject: Re: DBI/mysql
Message-Id: <36146989.A8593360@Home.net>
The syntax for you prepare statement should be something like:
CREATE TABLE MyTable (var1 INT NOT NULL AUTO_INCREMENT, # Column
definition
var2
VARCHAR(10), # More column
definitions
PRIMARY
KEY(var1)); # Primary Key definition
Dustin Puryear wrote:
> How do I *create* a table in a database using DBI? I read the DBI
> info. and couldn't find it. I tried to create a program, taken from the
> documentation, but it doesn't work. ANY help would be appreciated since
> I can't find _any_ information on how to create a table rather than
> retrieve information from one. Please email a copy of your reply, if
> possible, because my access to a news server is only 1 to 2 days a week.
>
> Regards, Dustin
>
> P.S. I have include the create.pl program I was using to setup the
> table. Of course, I get an error that the table (the file really)
> doesn't exist.
>
> #!/usr/bin/perl -w
>
> # ---
> # Author: Dustin Puryear
> # Project: learning sql/dbi
> # File: create.pl
> # ----
>
> use DBI;
> use strict;
>
> # ###
> # main
> # ###
>
> print "I'm learning SQL/DBI, so hang on!\n";
> print "Create the name, phone table.\n\n";
>
> # ---
> # print out driver/database information
> # ---
>
> # $driver our DBI driver
> # @drivers array of DBI drivers available
> # @databases array of databases available from our server
> # $str
>
> my($driver) = "mysql";
> my(@drivers) = DBI->available_drivers;
> my(@databases) = DBI->data_sources($driver);
> my($str);
>
> print "Checking out our system...\n";
>
> $str = DBI::neat_list(\@drivers);
> print "Database drivers available: $str\n";
> $str = DBI::neat_list(\@databases);
> print "Databases available: $str\n";
> print "\n";
>
> # ---
> # connect to the database server
> # ---
>
> my($dbh) = DBI->connect('DBI:mysql:test:localhost', '', '', 'mysql',
> {RaiseError => 1});
> die "Database error: $DBI::errstr\n" if (!$dbh);
>
> # ---
> # insert the data
> # ---
>
> # $sth statement handle
> # IN our file handle (contains name, phone values)
>
> my($sth);
> my($IN);
>
> # prepare our SQL statement
> $sth = $dbh->prepare(q{INSERT INTO phonetbl (name, phone) VALUES (?,
> ?)});
>
> # open our (name, phone) list and load into the table
> open IN, "phone.lst" or die "Can't open phone.lst!\n";
> while (<IN>)
> {
> chop;
> my ($name, $phone) = split /,/;
> $sth->execute($name, $phone)
> }
> close IN;
>
> # ---
> # close our session and exit
> # ---
>
> $dbh->disconnect;
> exit;
------------------------------
Date: Fri, 2 Oct 1998 04:22:40 -0500
From: "brettr" <brettr@centuryinter.net>
Subject: eq on if statement causing problems with string
Message-Id: <6v267q$23e$1@newsread1-mx.centuryinter.net>
I'm using this line if ($password eq $user[1]) to compare the two
variables. I know both contain the same string, say "hi". If I replace the
$_ variables with "hi" on both sides of the eq, the if statement will run,
not the else part.
If I place either $password or $user[1] on both sides of the statement, the
if part will run and not the else.
However, like the statement is above, the else part runs. I've looked at
both strings and they are exactly alike. Would the eq be causing some kind
of problem. The full script is below.
if ($form{'pass'} eq "ok")
{
$passwd="Y";
}
else
{
open (PEOPLE, "$users");
while (<PEOPLE>)
{
$row=$_;
@user = split(/ /,$row);
if ($form{'user'} eq $user[0])
{
$password = crypt($form{'password'}, "MM");
//space inserted here so $password will be equal to $user[1]. For some
//reason, $user[1] has a space at the end of it.
$password = "$password ";
if ($password eq $user[1])
{$passwd="Y";}
else
{print "<br>password_else = ,$password, user1 = ,$user[1],";}
}
}
close (PEOPLE);
}
------------------------------
Date: 02 Oct 1998 11:28:15 +0200
From: haakon.alstadheim@sds.no (Hekon Alstadheim)
Subject: Re: Excel + OLE: a disaster!
Message-Id: <uvhm3e2j4.fsf@sds.no>
Domenico Viggiani <mimmo-nospam@nospam-diemme.it> writes:
> I'm trying to use Win32::OLE package provided with Standard Distribution
[...]
> $ex = new Win32::OLE 'Excel.Application' || die "Impossible initialize
[...]
> $ex->Workbooks->OpenText( {FileName => 'd:\\mimmo\\prove\\ole.csv'} )
[...]
> $ex->Workbooks(1)->SaveAs( 'd:\\mimmo\\prove\\ole.xls', 'xlNormal') ||
I believe this is an Excel question and not a perl question.
I believe simply changing the name dows not change the format, I've
been trying to read a csv file via OLE, and got nothing by just opening
the file and trying to get the cells.
I changed my spec to require the user to open the file and save as .xls.
Might not be an option for you, so you might need to look up ways
to fire off a Visual Basic Macro inside Excel to open the file as .csv
and save it as .xls.
------------------------------
Date: Fri, 02 Oct 1998 01:31:23 -0700
From: Dan Bialek <dan.bialek@mindspring.com>
Subject: I have installed Linux. Now what?
Message-Id: <36148F5B.7440D3CE@mindspring.com>
Dear Clever Linux People,
I have installed Red Hat onto my PC, and now I am unable to get it do
anything useful. How do I use
the various editors, so that I can write basic Perl programs from my new
example book and run them?
I am at complete loss. I fired up the emacs in X windows, but I really
have no idea what I am doing. I apologize for my ignorance, but if
anyone can shine flashlight of help this way, I would be ever thankful.
Please respond via email.
Thanks again,
Dan
--
** Insert clever signature here **
------------------------------
Date: Fri, 2 Oct 1998 07:42:27 +0200
From: "Manfred Henning" <edv@dragenopharm.de>
Subject: Is there one different way to order data ?
Message-Id: <3614677f.0@news.zeitung-online.net>
Hello !
i wanted to display one birthday list of our employes.
The database field is one date field (like 31.12.1998)
I split the date in day, month and year.
i create after the spliting one query, to show me the people, that had
birthday in the last 7 days.
Now, i wanted to order the raws. I want to have as the 1st position, the
person with the youngest day and month. (not year!)
Just to order the string in the SQL query, is not enough - if i do it like
this, i get the youngest people at the first line (because the order
criterium in the database, reads also the year...)
Every idea is welcome !
Thanks,
Manfred
------------------------------
Date: Fri, 02 Oct 1998 08:54:56 GMT
From: sir_roland@my-dejanews.com
To: adavis@tivoli.com
Subject: Re: need a regular expressions expert...
Message-Id: <6v24cv$ic1$1@nnrp1.dejanews.com>
Alan Davis wrote:
>
> I have a need to have a program spit back any string that DOESN'T start
> with "BAD", but I cannot use perl's inherent "!" syntax.
Folks, read more carefully, he is seeking help for regexps, but not for
*perl* regexps, clear? He is just using perl to figure out the RE and
then plug it into some other RE matcher.
Anyway, try this RE:
^([^B]|B[^A]|BA[^D])
which spells: "Match lines that don't start with `B' or lines
that start with `B' but don't have an `A' in the second place or
lines that start with `BA' but don't have `D' in the third place."
This should do it.
Roland
--
GS/CS/IT e*+++ d-(+) s++:++ C++$ USL*$++>+++ DI++(+++)>++++ w--->? P+++$
L>++ E+$>++ N+(++) W+$(-)>+++ PGP++>+++ G+ t++* 5? X+ D++(---) Y+ PS+ PE
b>++++ tv(++) r+++ h----(*) y++++-- a>?
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Fri, 02 Oct 1998 11:15:25 +0200
From: Dominique Critel <dominique.cretel@cfwb.be>
To: sir_roland@my-dejanews.com
Subject: Re: need a regular expressions expert...
Message-Id: <361499AD.73A7@cfwb.be>
Hello Roland,
> GS/CS/IT e*+++ d-(+) s++:++ C++$ USL*$++>+++ DI++(+++)>++++ w--->? P+++$
> L>++ E+$>++ N+(++) W+$(-)>+++ PGP++>+++ G+ t++* 5? X+ D++(---) Y+ PS+ PE
> b>++++ tv(++) r+++ h----(*) y++++-- a>?
I'm not a Perl Expert but I'd like to know what does it mean????
Dominique
------------------------------
Date: 02 Oct 1998 09:25:02 +0200
From: Michal Rutka <erhmiru@erh.ericsson.se>
Subject: Re: Need IP Address Sort Subroutine
Message-Id: <la3e97qvch.fsf@erh.ericsson.se>
droby@copyright.com writes:
> If Laplace and Fourier can have transforms named after them, why can't Randal?
OK. He can. Are you happy now?
Regards,
Michal
------------------------------
Date: Fri, 02 Oct 1998 06:58:46 GMT
From: ptimmins@netserv.unmc.edu (Patrick Timmins)
Subject: Omaha Perl Mongers - First Meeting !
Message-Id: <6v1tj6$a8i$1@nnrp1.dejanews.com>
The first meeting of the Omaha Perl Mongers will be next week:
Wednesday, October 7, 1998
6:00 pm-ish
The Dubliner Pub
1205 Harney (in the Old Market)
Omaha, NE
Show up, and you could win a free Perl Mongers T-shirt !
The first order of business will be to begin the ground
swell of grassroots support that will quickly spread
through out the world ... the cry of the people ...
the will of the masses ... for bringing the year 2000
4th annual Perl Conference to the big 'O', the River City,
the Gateway to the West, beautiful Omaha, Nebraska
... or we may table that, and just have a beer!
Questions? e-mail to ptimmins@netserv.unmc.edu, or http to the
Omaha Perl Mongers home page at: 137.197.214.91/perl_mongers.html
( follow the 'Omaha, the Beautiful' link to see the top 10 reasons
why Omaha should host the year 2000 Perl Conference! )
Patrick Timmins
$monger{Omaha}[0]
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: Fri, 2 Oct 1998 09:54:19 +0100
From: "Steven Primrose-Smith" <smith@avl.com>
Subject: Problem with readdir
Message-Id: <6v20sk$i3v@fstgal00.tu-graz.ac.at>
Hi,
Here's hoping someone can help. Is there some reason why readdir does
not work with a root directory (running on NT with administrator
permissions) ?
I tried this...
opendir (TEST, "u:\\test\\");
@files = readdir(TEST);
closedir(TEST);
foreach $file (@files)
{
print "$s\n";
}
...and I get a list of all files in the test directory, but this...
opendir (TEST, "u:\\");
@files = readdir(TEST);
closedir(TEST);
foreach $file (@files)
{
print "$s\n";
}
...gives me nothing.
Stupid mistake on my part or some restriction?
Thanks for your help.
Steven
smith@avl.com
------------------------------
Date: 02 Oct 1998 09:22:16 +0200
From: Michal Rutka <erhmiru@erh.ericsson.se>
Subject: Re: Problems Using a Compare Subroutine with Sort
Message-Id: <la4stnqvh3.fsf@erh.ericsson.se>
Uri Guttman <uri@camel.fastserv.com> writes:
> MR> Hymm, just tell what results you are getting and why do you think
> MR> they are wrong. Then I tell you why John's clever routine is not
> MR> so clever.
>
> yes, tell us what is so unclever.
Dear Uri
not so clever != unclever
Therefore, please dont put words to my mounth which I did not say.
What is not so unclever: trusting that 4 byte integer will not
overflow.
> you don't understand the schwartian
> transform so it must not be good. well,
I already said that I understand it, and I did not say that it is not
good but 'Horror' (read UGLY). But it is only my taste and you do not
need to agree or disagree. Moreover, I dont think that we should discuss
about it anymore.
> benchmark against it in a real
> world situation.
John did. I think that results showed something opposite to what are
you trying to proof here.
> MR> Hint - you are loohing for bug in a wrong place. After you spot a
> MR> bug, you can tell John how much time did it cost you. He should be
> MR> proud.
>
> and you should feel shame for spouting such nonsense. you have never
> tried his fixed code or anything to do with the ST.
Hymm, do you know something more than ST?
> you don't even
> understand what it is trying to do and how it saves both development and
> cpu time.
I think you are going a little bit too far, dear friend. Therefore I stop
discussion with you here...
[rest of the not friendly text deleted]
------------------------------
Date: 02 Oct 1998 09:32:14 +0200
From: Michal Rutka <erhmiru@erh.ericsson.se>
Subject: Re: Problems Using a Compare Subroutine with Sort
Message-Id: <la1zorqv0h.fsf@erh.ericsson.se>
John Porter <jdporter@min.net> writes:
> But I'll tell you this: my dotted_to_int() subroutine is more
> correct -- although a lot slower -- than your pack/split method.
More correct?? Do you dont understand that it overflows? Thats mean it
gives different result on your Spark than on mine. Does this not worry
you? At least it worries me.
[...]
> You've got a monstrous chip on your shoulder, droog.
>
?-|
You guys are so ... eh, probably you understand something diffrent to
what I mean.
Regards,
Michal
------------------------------
Date: Fri, 02 Oct 1998 05:04:33 GMT
From: tilmanglotzner@my-dejanews.com
Subject: Q: Speed Optimization
Message-Id: <6v1mt0$24m$1@nnrp1.dejanews.com>
Hello everybody,
I have a little perl script which needs some improvement in terms of speed.
Right now it runs just to slow.
The script scans for an expression of a spezified portion of an
ASCII-File and if the expression matches it dumps an referencing url.
The file's form is:
<add>
.
<url>http.....<\url>
.
<body>
text text scan here text text
<\body>
<\add>
<add>
.
.
<url>http.....<\url>
.
.
<body>
text text scan here text text
<\body>
<\add>
.
and so on.
Here comes the script:
#arg1 = SearchExpression
#arg2 = Negation (0 = off, 1 = on)
#arg3 = result file name
$start = (times)[0];
print "$ARGV[0]\n";
open(RAW_DATA, "@ARGV[0]") or die "Can't open file: $!\n";
$Search = $ARGV[1];
$Negation = $ARGV[2];
open(RESULT,">>@ARGV[3]") or die "Can't open file: $!\n";
$FoundFlag = 0;
while ($line = <RAW_DATA>) {
if ($line =~ /<add>/) {
$Doc = 1;
}
if ($line =~ /<body>/) {
$Zone = 1;
}
if ($line =~ /(<url>)(.+)(<\/url>)/) {
$url = "$2";
}
if ($Zone==1 && $line =~ /$Search/i) {
$FoundFlag = 1;
}
if ($line =~ /<\/body>/) {
$Zone = 0;
}
if ($line =~ /<\/add>/) {
if ($FoundFlag == 0 && Negation == 1) {
print RESULT "$url\n";
}
if ($FoundFlag == 1 && Negation == 0) {
print RESULT "$url\n";
$FoundFlag = 0;
}
$Doc = 0;
}
}
close (RAW_DATA);
close (RESULT);
$end = (times)[0];
printf "Elapsed CPU time: %.2f\n",$end - $start;
Thanks Tilman
-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp Create Your Own Free Member Forum
------------------------------
Date: Fri, 02 Oct 1998 05:19:57 GMT
From: tilman@spp.hpc.fujitsu.co.jp
Subject: Q: Speed Optimization
Message-Id: <6v1npt$3fn$1@nnrp1.dejanews.com>
Hello everybody,
I have a little perl script which needs some speed improvement. Right now it
is just too slow.
The script scans a spezific portion of an ASCII file for an expression and
dumps a referencing URL if found.
The format of the ASCII file:
<add>
.
<url>referencing url<\url>
.
<body>
text text scan here text text
<\body>
.
<\add>
<add>
.
<url>referencing url<\url>
.
<body>
text text scan here text text
<\body>
.
<\add>
.
.and so on.
Here comes the script:
#!/usr/bin/perl
#arg0 = index
#arg1 = SearchExpression
#arg2 = Negation (0 = off, 1 = on)
#arg3 = result file name
$start = (times)[0];
print "$ARGV[0]\n";
open(RAW_DATA, "@ARGV[0]") or die "Can't open file: $!\n";
$Search = $ARGV[1];
$Negation = $ARGV[2];
open(RESULT,">>@ARGV[3]") or die "Can't open file: $!\n";
$FoundFlag = 0;
while ($line = <RAW_DATA>) {
if ($line =~ /<add>/) {
$Doc = 1;
}
if ($line =~ /<body>/) {
$Zone = 1;
}
if ($line =~ /(<url>)(.+)(<\/url>)/) {
$url = "$2";
}
if ($Zone==1 && $line =~ /$Search/i) {
$FoundFlag = 1;
}
if ($line =~ /<\/body>/) {
$Zone = 0;
}
if ($line =~ /<\/add>/) {
if ($FoundFlag == 0 && Negation == 1) {
print RESULT "$url\n";
}
if ($FoundFlag == 1 && Negation == 0) {
print RESULT "$url\n";
$FoundFlag = 0;
}
$Doc = 0;
}
}
close (RAW_DATA);
close (RESULT);
$end = (times)[0];
printf "Elapsed CPU time: %.2f\n",$end - $start;
Thanks in anticipation
Tilman
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
------------------------------
Date: 02 Oct 1998 01:47:56 -0400
From: Uri Guttman <uri@sysarch.com>
To: tilmanglotzner@my-dejanews.com
Subject: Re: Q: Speed Optimization
Message-Id: <x7yaqztsz7.fsf@sysarch.com>
>>>>> "t" == tilmanglotzner <tilmanglotzner@my-dejanews.com> writes:
t> <add>
t> .
t> <url>http.....<\url>
t> .
t> <body>
t> text text scan here text text
t> <\body>
t> <\add>
t> <add>
t> Here comes the script:
and here comes my comments:
t> #arg1 = SearchExpression
t> #arg2 = Negation (0 = off, 1 = on)
t> #arg3 = result file name
t> $start = (times)[0];
t> print "$ARGV[0]\n";
t> open(RAW_DATA, "@ARGV[0]") or die "Can't open file: $!\n";
that should be $ARGV[0], the @ is wrong. and you don't need "" since it
is a plain variable. but at least you check the result of open.
t> $Search = $ARGV[1];
t> $Negation = $ARGV[2];
t> open(RESULT,">>@ARGV[3]") or die "Can't open file: $!\n";
same problem with @, but you need the quotes here.
t> $FoundFlag = 0;
in general flag bases code is poor. control flow based is better. i will
try to show you how to fix this but it is untested.
t> while ($line = <RAW_DATA>) {
t> if ($line =~ /<add>/) {
t> $Doc = 1;
t> }
since each tag seems to be on a line by itself you can just do a next
and skip the rest of the tests. this applies for all of you tests and
that will speed it up a great deal.
t> if ($line =~ /<body>/) {
t> $Zone = 1;
next ;
t> }
t> if ($line =~ /(<url>)(.+)(<\/url>)/) {
use different delimiters if you want to match /. makes it much more
readable.
no need for the () around the <url> since you don't grab it.
if ( $line =~ m|<url>(.+)</url>| ) {
$url = $1;
no need for "" here.
next ;
t> }
t> if ($Zone==1 && $line =~ /$Search/i) {
t> $FoundFlag = 1;
next ;
t> }
t> if ($line =~ /<\/body>/) {
use different delimiters if you want to match /. makes it much more readable.
t> $Zone = 0;
next ;
t> }
t> if ($line =~ /<\/add>/) {
use different delimiters if you want to match /. makes it much more readable.
if ($line =~ m|</add>|) {
move to front of if block since we exit with next.
$Doc = 0;
t> if ($FoundFlag == 0 && Negation == 1) {
t> print RESULT "$url\n";
next ;
t> }
t> if ($FoundFlag == 1 && Negation == 0) {
t> print RESULT "$url\n";
t> $FoundFlag = 0;
next ;
t> }
t> }
t> }
as an advanced exercise check out the scalar range operator .. it let
you know when you are in the middle the <add> </add> section (also the
body section) so you can simplify the code like this:
if ( $line =~ m|<add>| .. $line =~ |</add>| ) {
if ($line =~ m|<url>(.+?)</url>| ) {
$url = $1;
next ;
}
if ( $line =~ m|<body>| .. $line =~ |</body>| ) {
if ( $line =~ /$Search/i ) {
$FoundFlag = 1;
next ;
}
}
........
}
you can even simplify further by using the -n option loop and just using
the shell to control which files are read and appended to.
there are other ways to speed it up but they are beyond the scope of
this letter and left as an exercise to other readers.
hth,
uri
--
Uri Guttman ----------------- SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire ---------------------- Perl, Internet, UNIX Consulting
uri@sysarch.com ------------------------------------ http://www.sysarch.com
The Best Search Engine on the Net ------------- http://www.northernlight.com
------------------------------
Date: Thu, 1 Oct 1998 23:00:22 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Q: Speed Optimization
Message-Id: <MPG.107e0bccefc5422b989893@nntp.hpl.hp.com>
[Posted to comp.lang.perl.misc and copy mailed.]
In article <6v1mt0$24m$1@nnrp1.dejanews.com> on Fri, 02 Oct 1998 05:04:33
GMT, tilmanglotzner@my-dejanews.com <tilmanglotzner@my-dejanews.com>
says...
!> I have a little perl script which needs some improvement in terms of
speed.
!> Right now it runs just to slow.
!> The script scans for an expression of a spezified portion of an
!> ASCII-File and if the expression matches it dumps an referencing url.
!> The file's form is:
!>
!> <add>
!> .
!> <url>http.....<\url>
!> .
!> <body>
!> text text scan here text text
!> <\body>
!> <\add>
!> <add>
!> .
!> .
!> <url>http.....<\url>
!> .
!> .
!> <body>
!> text text scan here text text
!> <\body>
!> <\add>
!> .
!> and so on.
I presume you mean forward slashes for all those. That's what the code
looks for.
!> #arg1 = SearchExpression
!> #arg2 = Negation (0 = off, 1 = on)
!> #arg3 = result file name
!>
!> $start = (times)[0];
!> print "$ARGV[0]\n";
!>
!> open(RAW_DATA, "@ARGV[0]") or die "Can't open file: $!\n";
$ARGV[0] # Use the -w flag!
!> $Search = $ARGV[1];
!> $Negation = $ARGV[2];
!>
!> open(RESULT,">>@ARGV[3]") or die "Can't open file: $!\n";
">>$ARGV[3]" # Use the -w flag!
...
!> if ($Zone==1 && $line =~ /$Search/i) {
I think this is the only place that can be speeded up much, but it will
probably be by a lot. As the pattern doesn't change, add the /o
modifier. Also, unless there are letters in the pattern and you *really*
need case-independent matching, drop the /i modifier, which slows things
down.
BTW, why did you post this twice, with different 'From:' addresses???
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: 02 Oct 1998 10:19:35 +0200
From: Michal Rutka <erhmiru@erh.ericsson.se>
Subject: Re: Q: Speed Optimization
Message-Id: <layaqzpe94.fsf@erh.ericsson.se>
Hi,
just two fast things.
tilmanglotzner@my-dejanews.com writes:
> Hello everybody,
>
> I have a little perl script which needs some improvement in terms of speed.
> Right now it runs just to slow.
[...]
Change above line to:
if ($Zone==1 && $line =~ /$Search/io){
you do not change $Search? am I right?
> if ($line =~ /<\/add>/) {
> if ($FoundFlag == 0 && Negation == 1) {
> print RESULT "$url\n";
> }
> if ($FoundFlag == 1 && Negation == 0) {
> print RESULT "$url\n";
> $FoundFlag = 0;
> }
> $Doc = 0;
> }
> }
I dont know whether this improve speed but you cab give it a try:
if ($line =~ /<\/add>/) {
print RESULT "$url\n" if ($FoundFlag != $Negation);
$FoundFlag = 0;
$Doc = 0;
}
Hope this helps.
Michal
------------------------------
Date: 2 Oct 1998 01:05:12 -0700
From: larry@kiev.wall.org (Larry Wall)
Subject: Re: send geroge reese (was Re: Call for Participation: Python Conference)
Message-Id: <6v21fo$l6@kiev.wall.org>
In article <361435F6.702C6EDD@floorboard.com>,
Jonathan Biggar <jon@floorboard.com> wrote:
>Zenin wrote:
>> Of course they could, after all, where do you think Perl came
>> up with its original object design? None other then Python.
>
>Actually, not, or at least mostly not. I was sitting back to back with
>Larry in the same office while he was designing Perl 5, and he borrowed
>liberally from many languages, including C++ and Ada, although Python
>was part of the mix.
I primarily borrowed Python's notions of how simple OO can be. (And
where Python's notions of OO aren't so simple, I didn't borrow them.)
But the -> for method calls definitely came from C++. And packages
definitely came from Ada (via Perl 3).
>Not to brag :-), but I am partly to blame for Perl 5, by pushing Larry
>to add the OO stuff.
Yeah, for OO I added all of half an operator. :->
Seriously, I am deeply indebted to both my brothers-in-law, who for
some reason are always hanging around when I need to bounce ideas off
of them, or more likely, when they want to bounce ideas off of me (with
the hope that occasionally one of them will stick to my teflon brain.)
Perl wouldn't be what it is without Jon and Mark.
Larry
------------------------------
Date: 02 Oct 1998 09:35:44 +0200
From: Michal Rutka <erhmiru@erh.ericsson.se>
Subject: Re: Some kind of 'real' user interface?
Message-Id: <lazpbfpga7.fsf@erh.ericsson.se>
John Porter <jdporter@min.net> writes:
> Michal Rutka wrote:
> >
> > You can try tcl/tk. It works cool under Windows.
>
> Even better, try Perl/Tk.
This is what I meant. Thanks for correction.
Regards,
Michal
------------------------------
Date: 02 Oct 1998 09:10:09 +0200
From: Michal Rutka <erhmiru@erh.ericsson.se>
To: uri@camel.fastserv.com
Subject: Re: Stock paging, anyone seen this script?
Message-Id: <la90izqw1a.fsf@erh.ericsson.se>
Uri Guttman <uri@camel.fastserv.com> writes:
[...]
> i wouldn't correct him if i were you randal. he thinks the ST is not
> portable and doesn't work.
You should reffer to my previous post and find that what is most not
portable is trusting that an integer will not overflow. This is my
statement.
About ST -> I personally find it ugly, but it is case of taste and about
tastes gentelmen dont discuss.
> he must know much more perl than you and all
> of c.l.p.m put together. so let him type all he wants.
You must know more about me that myself. A discussion with you will be
very interesting. I can learn something about me.
Regards,
Michal
------------------------------
Date: Fri, 02 Oct 1998 08:40:10 GMT
From: bart.mediamind@ping.be (Bart Lateur)
Subject: Re: string from array
Message-Id: <36148dba.2841929@news.ping.be>
Jerrad Pierce wrote:
>Is there a way to dump the contents of an array of unknown length into a
>string?
>Other than iterating over each element? eg;
>
>for($i = 0; $i < $#ary+`; $i++){
> $string .= $ary[$i];
>}
Apart from
$string = join ('',@ary);
there's also
undef $"; $string = "@ary";
Bart.
------------------------------
Date: 02 Oct 1998 11:47:47 +0200
From: Michal Rutka <erhmiru@erh.ericsson.se>
Subject: Re: URL & strings searches
Message-Id: <lau31npa64.fsf@erh.ericsson.se>
droby@copyright.com writes:
[...]
> > I can write this script for you for a appriotiate fee, i.e. I am taking $150
> > per hour. Mimimum fee is for one hour. Writing of this script
> > will not exceed one hour.
> >
>
> Don't forget "payment in advance". ;-)
Yeach, and time include coffe ;-)
Michal
------------------------------
Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>
Administrivia:
Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.
If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu.
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.misc (and this Digest), send your
article to perl-users@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.
The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.
The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.
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 V8 Issue 3871
**************************************