[21865] in Perl-Users-Digest
Perl-Users Digest, Issue: 4069 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Nov 5 21:06:45 2002
Date: Tue, 5 Nov 2002 18: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 Tue, 5 Nov 2002 Volume: 10 Number: 4069
Today's topics:
Re: A vision for Parrot <goldbb2@earthlink.net>
Any Experience with Embedded Perl/HTML? (darryl)
Re: Complex search/replace <krahnj@acm.org>
Re: DBI <bobx@linuxmail.org>
Re: DBI <trammell+usenet@hypersloth.invalid>
Re: DBI <bobx@linuxmail.org>
grep question (KTyson9426)
Re: grep question <bwalton@rochester.rr.com>
Re: grep question (Jay Tilton)
Re: Help Simplifying (Jay Tilton)
Re: Help Simplifying <krahnj@acm.org>
Re: How to copy some sections of a file that varies eve <mgjv@tradingpost.com.au>
Re: Is it wrong to store method definitions in a databa <goldbb2@earthlink.net>
Re: param($var); (Jay Tilton)
Problem with Opening files and die <craig-and-linda@the-mcniels.com>
Re: Problem with Opening files and die <kevin@vaildc.net>
Re: Problem with Opening files and die <ak@freeshell.org.REMOVE>
Q: Reading process memory on Win32? miketemp3@techinxs.com
special characters in command-line (Stuart Kendrick)
Re: special characters in command-line (Walter Roberson)
Re: special characters in command-line <krahnj@acm.org>
Re: split() results limited to 32k length? (Mark Jason Dominus)
Re: split() results limited to 32k length? <spam@thecouch.homeip.net>
Re: Tie'd filehandle and the system() function <goldbb2@earthlink.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 05 Nov 2002 19:28:43 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: A vision for Parrot
Message-Id: <3DC8623B.88753C16@earthlink.net>
Frodo Morris wrote:
>
> Daniel Pfeiffer wrote:
> > Hi,
> > Apache would essentially have a mod_parrot. Maybe, if this can be
> > tested very hard, we'd even have a Parrot kernel module for all
> > Unices supporting that. Then exec() could perform compiled scripts
> > right away, like machine code :-)
>
> I would have thought that a more platform-independent version of
> this would be, say, a parrotd, which sits on top of the kernel,
> intercepts calls to exec() bytecode and spawns the relevant processes.
What advantage would this have over putting a #! line in the bytecode?
Most existing *nix kernels (except some very old ones) will look at the
#!, parse out the path to an executable program, and the run it.
> I may be wrong. This parrotd system would also help in projects like
> Beowulfs (although why you'd be using byte-compiled languages in
> parallel computing is beyond me), because you could use inetd or
> similar to spawn a parrot when data was received on a certain port.
I don't really see the point of having a parrotd, except if you want to
create something vaguely like PersistantPerl.
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: 5 Nov 2002 16:05:18 -0800
From: dfdyck@yahoo.com (darryl)
Subject: Any Experience with Embedded Perl/HTML?
Message-Id: <da6cdb12.0211051605.6cb146be@posting.google.com>
I'm currently using HERE documents for dynamic perl web pages and it's
getting messy. I want to shift over to using an embedded perl solution
but I can't decide which to use...does anybody have experience
(positive or neg.) with the following:
HTML::Template
Template
HTML::Mason
HTML::Embperl
Apache::ASP
Thanks!!
Darryl
------------------------------
Date: Wed, 06 Nov 2002 00:17:23 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Complex search/replace
Message-Id: <3DC85F6F.F6EC9474@acm.org>
"H.Wiersema" wrote:
>
> I've a sql script to create lots of objects in a database. The format
> of the script looks like this:
>
> ...
> create table ABC
> column1 varchar2(10),
> column2 varchar2(10),
> ..
> columnN varchar2(20)
> tablespace UNKNOWN
> /
>
> create table DEF
> column1 varchar2(20),
> column2 varchar2(20),
> ..
> columnN varchar2(30)
> tablespace UNKNOWN
> /
>
> create table GHI
> column1 varchar2(20),
> column2 varchar2(10),
> ..
> columnN varchar2(20)
> tablespace UNKNOWN
> /
> ...
>
> etc etc!
>
> I want to make a (sed|awk|perl) script that is able to grep (for
> example) the 'DEF' object create clause, then catch the
> 'tablespace'occurence of that clause. Then replace the tablespacename
> after 'tablespace' by another tablespacename. The name of the
> tablespace is the script above is not known, so I cant search for the
> name. Too make it, perhaps, more clear:
>
> create table DEF <1> Grep on this object
> column1 varchar2(20),
> column2 varchar2(20),
> ..
> columnN varchar2(30)
> tablespace NEWNAME <2> Something like
> /^tablespace/s/$2/$NEW_NAME/
> /
>
> Does anyone can give me a hint how to programm this in sed|awk|perl ?
perl -i~ -00pe'/\Acreate table DEF/&&s/(?<=\ntablespace )\S+/NEW_NAME/'
yourfile
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 05 Nov 2002 23:38:58 GMT
From: "Bob X" <bobx@linuxmail.org>
Subject: Re: DBI
Message-Id: <mEYx9.44266$Lg2.11984679@news2.news.adelphia.net>
"John Joseph Trammell" <trammell+usenet@hypersloth.invalid> wrote in message
news:slrnasgg00.328.trammell+usenet@bayazid.el-swifto.com...
<snip>
> Only if the book includes the source code now. :-)
>
> Seriously though, the O'Reilly DBI book is good. It does not
> have everything I have needed to know though. You may need
> to know less, though.
>
Well I am interested in DBI in general as I want to use DBD::SQLite in a
project. If there was a tutorial just for that then I would have what I
need. I guess I could get the DBI book and then write a How-To or something.
: \
Bob
------------------------------
Date: Tue, 5 Nov 2002 23:57:11 +0000 (UTC)
From: John Joseph Trammell <trammell+usenet@hypersloth.invalid>
Subject: Re: DBI
Message-Id: <slrnasgmmn.5lc.trammell+usenet@bayazid.el-swifto.com>
On Tue, 05 Nov 2002 23:38:58 GMT, Bob X <bobx@linuxmail.org> wrote:
[snip]
> Well I am interested in DBI in general as I want to use DBD::SQLite in a
> project. If there was a tutorial just for that then I would have what I
> need. I guess I could get the DBI book and then write a How-To or something.
>
You could always start with the free documentation in the DBI and
DBD::SQLite packages. Just download them from CPAN, install them,
and do 'perldoc DBI' and 'perldoc DBD::SQLite'.
------------------------------
Date: Wed, 06 Nov 2002 01:26:36 GMT
From: "Bob X" <bobx@linuxmail.org>
Subject: Re: DBI
Message-Id: <gd_x9.44295$Lg2.12003797@news2.news.adelphia.net>
"John Joseph Trammell" <trammell+usenet@hypersloth.invalid> wrote in message
news:slrnasgmmn.5lc.trammell+usenet@bayazid.el-swifto.com...
<snip>
> You could always start with the free documentation in the DBI and
> DBD::SQLite packages. Just download them from CPAN, install them,
> and do 'perldoc DBI' and 'perldoc DBD::SQLite'.
>
I did the DBD::SQLite docs are sparse...and I am a beginner. I will take a
look at the DBI ones and start doing it.
------------------------------
Date: 05 Nov 2002 23:12:57 GMT
From: ktyson9426@aol.com (KTyson9426)
Subject: grep question
Message-Id: <20021105181257.25044.00002165@mb-dh.aol.com>
Much thanks thanks in advance for any light anyone can shed on my problem.
I'm new to Perl, but I'm trying to write a program that will open 2 different
files, then read the invoice number of the first file, 'grep' the second file
as it reads it and compare the invoice numbers. If the 'grep' matches the
invoice numbers, then the 'print' writes out specific info from the 2 seperate
files into 1 file.
This is what I have written but it's not working (obviously or I wouldn't be
posting). When it runs, it matches 1 record and then stops. If I simply put a
print "$Invoice_Number,$Invoice\n"; I can see it reading threw all of the
Invoice numbers. I'm sort of confused why the 'grep' would only see 1 record.
Once again..... Thanks in advance for any help someone can offer.
$x = 'z:\data\invprw.txt';
$z = 'z:\data\routprw.txt';
$Complete_info = 'z:\data\complete_info.txt';
#
#
# open file handles
#
#
open ( Invoice, $x ) || die "Reading Bottom-Line route export failed. Please
run again!\n";
open ( Complete_info,">$Complete_info" ) || die "Can not open file\n";
#
#
# Create master file
#
#
while (<Invoice>)
{
($Invoice_Number,$Customer_Name,$Job_Name,$Order_Number,$Order_Date,$Prom
ised_Date,$Promised_Time,$Completed_Date,$Truck,$Entry_Person,$Job_Zone,$J
ob_Priority,$Payment,$Special,$Price_Level,$Sales_Person,$Job_Status,$Depa
rtment,$Mechanic,$Mechanic_Hours,$Mechanic_Rate,$Helper,$Helper_Hours,$Hel
per_Rate,$Part_Sales,$Labor_Sales,$Discount_Amount,$Sales_Tax,$Total_Sales
,$Paid_Amount_1,$Paid_Date_1,$Paid_Amount_2,$Paid_Date_2,$Balance_Due,$Par
t_Cost,$Labor_Cost,$Miles_Cost,$Sales_Tax,$Sales_Tax_Type,$Flat_Rate_Invoi
ce,$Discount_Type) = split (/;/,$_);
open (Route, $z) || die "Reading Bottom-Line route export failed. Please run
again!\n";
while (<Route>)
{
($Zone,$Truck,$Promised_Date,$Promised_Time,$Promised_Time_AM_PM,$Priority
,$Invoice,$Customer_Name,$Customer_Address1,$Customer_Address2,$Customer_A
ddress3,$Customer_Address4,$Job_Name,$Job_Address1,$Job_Address2,$Job_Addr
ess3,$Job_Address4,$Phone1,$Special,$Dispatch_Status,$Phone2,$Customer_Gro
up,$Method_of_Payment,$Work_Description1,$Work_Description2,$Work_Descript
ion3,$Work_Description4,$Estimated_Time,$Service_Type,$Effective_Date,$Exp
iration_Date,$Last_Service_Date,$Next_Service_Date) = split (/;/,$_);
($city, $state_zip) = split (/,/, $Customer_Address2);
($state, $zip) = split (/ /, $state_zip);
chop ($zip);
if (grep(/$Invoice/,$Invoice_Number)) {
print Complete_info
"$Invoice_Number,$Completed_Date,$Customer_Name,$Customer_Address1,$city,$
state, $zip,$Mechanic,$Total_Sales\n"
};
}
close (Route);
}
close (Invoice);
------------------------------
Date: Wed, 06 Nov 2002 01:27:59 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: grep question
Message-Id: <3DC87003.8080105@rochester.rr.com>
KTyson9426 wrote:
...
> I'm new to Perl, but I'm trying to write a program that will open 2 different
> files, then read the invoice number of the first file, 'grep' the second file
> as it reads it and compare the invoice numbers. If the 'grep' matches the
> invoice numbers, then the 'print' writes out specific info from the 2 seperate
> files into 1 file.
>
> This is what I have written but it's not working (obviously or I wouldn't be
> posting). When it runs, it matches 1 record and then stops. If I simply put a
> print "$Invoice_Number,$Invoice\n"; I can see it reading threw all of the
> Invoice numbers. I'm sort of confused why the 'grep' would only see 1 record.
> Once again..... Thanks in advance for any help someone can offer.
>
Please see commentary below. Also, it would be very helpful if you
could whittle your program down to the very simplest subset (fewest
variable names, etc) which still exhibit the problem. Also, proper
indenting of your source code would help greatly. If you did these
things, you might find the problem yourself.
>
>
>
> $x = 'z:\data\invprw.txt';
I assume you are working on Windoze. If you want \'s in a '-delimited
string, you should escape them, like:
$x = 'z:\\data\\invprw.txt';
since a backslash is an escape character, even in an '-string. Even
though it will give the results you want as long as it does not preceed
a ' or a \ character.
Or better yet, just use / -- Perl is smart, and does what you mean, even
on Windoze!
> $z = 'z:\data\routprw.txt';
> $Complete_info = 'z:\data\complete_info.txt';
>
>
>
>
>
> #
> #
> # open file handles
> #
> #
>
>
>
>
> open ( Invoice, $x ) || die "Reading Bottom-Line route export failed. Please
> run again!\n";
Include the $! variable in your die text so you can tell why it failed.
> open ( Complete_info,">$Complete_info" ) || die "Can not open file\n";
>
>
>
> #
> #
> # Create master file
> #
> #
>
> while (<Invoice>)
> {
>
>
>
>
> ($Invoice_Number,$Customer_Name,$Job_Name,$Order_Number,$Order_Date,$Prom
> ised_Date,$Promised_Time,$Completed_Date,$Truck,$Entry_Person,$Job_Zone,$J
> ob_Priority,$Payment,$Special,$Price_Level,$Sales_Person,$Job_Status,$Depa
> rtment,$Mechanic,$Mechanic_Hours,$Mechanic_Rate,$Helper,$Helper_Hours,$Hel
> per_Rate,$Part_Sales,$Labor_Sales,$Discount_Amount,$Sales_Tax,$Total_Sales
> ,$Paid_Amount_1,$Paid_Date_1,$Paid_Amount_2,$Paid_Date_2,$Balance_Due,$Par
> t_Cost,$Labor_Cost,$Miles_Cost,$Sales_Tax,$Sales_Tax_Type,$Flat_Rate_Invoi
> ce,$Discount_Type) = split (/;/,$_);
>
>
>
>
>
> open (Route, $z) || die "Reading Bottom-Line route export failed. Please run
> again!\n";
>
> while (<Route>)
This while loop is inside the outer while loop above. It is using the
same default variable $_ . AS Perl build 633 is happy with this -- but
I don't know about older Perls. It generally doesn't seem like good
programming practice, but this doesn't look like it is your problem.
> {
>
> ($Zone,$Truck,$Promised_Date,$Promised_Time,$Promised_Time_AM_PM,$Priority
> ,$Invoice,$Customer_Name,$Customer_Address1,$Customer_Address2,$Customer_A
> ddress3,$Customer_Address4,$Job_Name,$Job_Address1,$Job_Address2,$Job_Addr
> ess3,$Job_Address4,$Phone1,$Special,$Dispatch_Status,$Phone2,$Customer_Gro
> up,$Method_of_Payment,$Work_Description1,$Work_Description2,$Work_Descript
> ion3,$Work_Description4,$Estimated_Time,$Service_Type,$Effective_Date,$Exp
> iration_Date,$Last_Service_Date,$Next_Service_Date) = split (/;/,$_);
> ($city, $state_zip) = split (/,/, $Customer_Address2);
> ($state, $zip) = split (/ /, $state_zip);
> chop ($zip);
>
>
> if (grep(/$Invoice/,$Invoice_Number)) {
grep might not be the function you are looking for here. The docs on
grep state that grep applies a pattern (first arg) to a list (second
arg). Your second arg is a scalar. Also, depending upon what is in
variable $Invoice, you might get results you don't expect -- for
example, if $Invoice is '.......', it would match any $Invoice_Number
which is seven characters or more long. Also, if $Invoice_Number is,
for example, 12345666789, and $Invoice is 666, you would also match. Is
that what you want? I think you probably just want:
if ($Invoice eq $Invoice_Number) {
> print Complete_info
> "$Invoice_Number,$Completed_Date,$Customer_Name,$Customer_Address1,$city,$
> state, $zip,$Mechanic,$Total_Sales\n"
> };
>
> }
> close (Route);
>
>
>
> }
> close (Invoice);
>
I don't see why your program would fail to match all the invoices
containing the given invoice numbers, given the comments above.
If you can't figure out what is going on, I suggest the Perl debugger.
Just add the -d switch to your command line:
perl -d program.pl
HTH.
--
Bob Walton
------------------------------
Date: Wed, 06 Nov 2002 01:59:37 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: grep question
Message-Id: <3dc85ab9.192655546@news.erols.com>
ktyson9426@aol.com (KTyson9426) wrote:
: I'm trying to write a program that will open 2 different
: files, then read the invoice number of the first file, 'grep' the second file
: as it reads it and compare the invoice numbers. If the 'grep' matches the
: invoice numbers, then the 'print' writes out specific info from the 2 seperate
: files into 1 file.
:
: This is what I have written but it's not working (obviously or I wouldn't be
: posting). When it runs, it matches 1 record and then stops. If I simply put a
: print "$Invoice_Number,$Invoice\n"; I can see it reading threw all of the
: Invoice numbers. I'm sort of confused why the 'grep' would only see 1 record.
It is impossible for anybody not in possession of the data to know.
Could there be leading/trailing blanks that are not easily seen in the
print() statement? Make them show up clearly with a couple
delimiters.
print " '$Invoice_Number' '$Invoice'\n";
Could $Invoice contain any regex metacharacters that would mess up the
grep()?
: $x = 'z:\data\invprw.txt';
: $z = 'z:\data\routprw.txt';
: $Complete_info = 'z:\data\complete_info.txt';
: open ( Invoice, $x ) || die "Reading Bottom-Line route export failed. Please run
: again!\n";
: open ( Complete_info,">$Complete_info" ) || die "Can not open file\n";
: while (<Invoice>) {
: ($Invoice_Number,$Customer_Name,$Job_Name,$Order_Number,$Order_Date,
[oodles and oodles more elided]
: ) = split (/;/,$_);
That's perfectly dreadful. 40 scalars are created, (41 if you want to
count the duplicated $Sales_Tax), but only five of them ever get used.
It's a good time to learn about list slices. See perldata for
details.
my( $Invoice_Number, $Customer_Name,
$Completed_Date, $Mechanic,
$Total_Sales
) = (split /;/)[0, 1, 7, 18, 28];
It's also a decent time to learn about my() and variable scoping.
The names of six of those original scalars are duplicated in the next
split(), so their values get clobbered. Not that they ever get used
for anything in this program, though.
: open (Route, $z) || die "Reading Bottom-Line route export failed. Please run
: again!\n";
:
: while (<Route>) {
: ($Zone,$Truck,$Promised_Date,$Promised_Time,$Promised_Time_AM_PM,$Priority
[snip another 27 scalars]
: ) = split (/;/,$_);
More list slicing.
my( $Invoice,
$Customer_Address1,
$Customer_Address2,
) = (split /;/)[6, 8, 9];
: ($city, $state_zip) = split (/,/, $Customer_Address2);
: ($state, $zip) = split (/ /, $state_zip);
: chop ($zip);
: if (grep(/$Invoice/,$Invoice_Number)) {
grep() has to be the worst choice of tool for a true/false test of
whether one scalar is a substring of another. A plain m// or index()
should be preferred.
if( index($Invoice_Number, $Invoice) != -1 ) {
# do stuff
}
Or, if $Invoice_Number and $Invoice will match completely,
if( $Invoice_Number eq $Invoice ) {
# do stuff
}
: print Complete_info
: "$Invoice_Number,$Completed_Date,$Customer_Name,$Customer_Address1,$city,$
: state, $zip,$Mechanic,$Total_Sales\n"
: };
: }
: close (Route);
: }
: close (Invoice);
During development, always start your program with
use warnings;
use strict;
Read up on perlstyle. The use of capital letters in names can carry
strong visual clues to their meanings and purposes.
Be aware of how your newsreader will word-wrap long lines in a
posting.
It looks like two files may have been exported from a database or
spreadsheet. The DBI module and a splash of SQL could do all the work
from the original source data.
------------------------------
Date: Tue, 05 Nov 2002 23:53:29 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Help Simplifying
Message-Id: <3dc8595a.192304566@news.erols.com>
"TBN" <ihave@noemail.com> wrote:
: Can someone give me some hints on how I can simplify the code below?
Simplify in what way? Make it easier to read? Eliminate redundant
operations? Make one statement do the work of many?
: I'm thinking there has got to be a more efficient way, but maybe not.
Define your metric for efficiency. Fewer lines? Faster execution?
Ease of maintenance?
: s/status=\"0\"/status=\"3\"/;
: s/info=\".*?\"/info=\"\"/;
: s/var=\".*?\"/var=\"\"/;
: s/change=\".*?\"/change=\"\"/;
: s/<graph>.*<\/graph>//;
: s/datafile=\".*?\"/datafile=\"\"/;
The double quote character does not need escaping. It has no special
significance in either part of the s/// operator.
------------------------------
Date: Wed, 06 Nov 2002 00:31:46 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Help Simplifying
Message-Id: <3DC862D0.6F98D0B3@acm.org>
TBN wrote:
>
> Can someone give me some hints on how I can simplify the code below? I'm
> thinking there has got to be a more efficient way, but maybe not.
>
> while (<CODE>) {
> s/status=\"0\"/status=\"3\"/;
> s/info=\".*?\"/info=\"\"/;
> s/var=\".*?\"/var=\"\"/;
> s/change=\".*?\"/change=\"\"/;
> s/<graph>.*<\/graph>//;
> s/datafile=\".*?\"/datafile=\"\"/;
> }
> }
while (<CODE>) {
s{(?<=status=")0"} {3"};
s{(?<=info=")[^"]*} {};
s{(?<=var=")[^"]*} {};
s{(?<=change=")[^"]*} {};
s{<graph>.*</graph>} {};
s{(?<=datafile=")[^"]*} {};
}
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 05 Nov 2002 23:16:49 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: How to copy some sections of a file that varies every month?
Message-Id: <slrnasgkem.3cr.mgjv@verbruggen.comdyn.com.au>
On 5 Nov 2002 14:10:20 -0800,
Karen <kjbarahona@hotmail.com> wrote:
> Hi Martien,
>
> Martien Verbruggen <mgjv@tradingpost.com.au> wrote in message news:<slrnase71m.2c3.mgjv@verbruggen.comdyn.com.au>...
>> On 4 Nov 2002 15:31:02 -0800,
>> Karen <kjbarahona@hotmail.com> wrote:
>> > Hi everybody,
>> >
>> > I'm trying to modify a file with a perl script. I get a report once a
>> > month (the report has 11 sections), I need to be able to run a script
>> > that will make the report have only 5 sections. (It must be done
>> > automatically, that's why I don't do it manually)
>> >
>> > This is part of the file I get originally (the one that needs to be
>> > modified by the script):
>> >
>> > ################################################################
>> > ### Section 1
>> ><h3>The last Months Daily Availability</h3>
>> ><p>Daily Average of svcs monitored and availability of svcs divided by
>>
>> [SNIP]
>>
>> Your file looks like HTML. You should probably have a look at the
>> various HTML:: modules on CPAN. Maybe HTML::Tree would be useful.
>> If your HTML is very clean, and is valid XML, maybe one of the
>> XML::DOM modules could be of use.
>
> Ok, I used HTML::Tree, but I run into another problem, I don't know
> why my code doesn't work:
>
> my $root = HTML::TreeBuilder->new;
> $file=/opt/OpenNMS/share/reports/AVAIL-HTML-File-Servers20020729.html
You should use quotes here. make sure to run perl with warnings and
strict enabled.
> $root->parse_file($file);
> $h=HTML::Element->new("table");
> $h->delete();
You should probably read the HTML::Tree::Scanning article that comes
with the HTML::Tree distribution. It explains quite well how to do
what you want to do.
> I have 11 tables in the report, how do I declare each table as
> different one: ex, table1, table2, table3....table11 so I can say
> $table6->delete()
I'd probably iterate over the tree, until I found a table. I would
then remove that table, and insert the contents of the table in
another one, which I'd have ready. Once finished, I'd re-insert the
tables back into the original document and export it. It's hard to
tell without knowing exactly what you're doing.
Martien
--
|
Martien Verbruggen | Think of the average person. Half of the
Trading Post Australia | people out there are dumber.
|
------------------------------
Date: Tue, 05 Nov 2002 20:41:44 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Is it wrong to store method definitions in a database?
Message-Id: <3DC87358.82E4CFA7@earthlink.net>
Phil Brodd wrote:
>
> I feel I'm about to perpetrate a miscarriage of OO Perl, so I thought
> I'd ask some advice first. I'm kind of an OO newbie.
>
> My project is a system that downloads and parses the contents of
> various web pages, each on its own collection schedule. A Perl cron
> job checks a DB table to see if any pages are to be collected at that
> time, creating a Collector object for each one.
First possible re-think: If you can add cron jobs any time you want,
how about you specifically schedule the cron job to run at the time of
the first scheduled collection (as a kind of once-only cron job).
That is, have your Perl cron job only run when there *is* a job
scheduled, rather than frequently running, checking for jobs, and then
exiting due to not finding any to run.
Each time your Perl cron job is run, it removes that one job (or those
few jobs) from the DB table, then finds when the next scheduled job is
from the DB file, and edits the crontab file to run perl again at the
desired time.
In other words, avoid polling.
> For each Collector object, methods are invoked to download the page,
> parse its contents, and insert the results in another DB table.
>
> Here's where I'm not sure how to proceed. The Collector objects will
> differ in the URLs they access and the parsing routines they use.
How many different parsing routines will there be? A small number? A
large, but finite number? Or even every Collector unique?
> I can think of two approaches:
>
> 1) Store the URLs and the parsing routines in the database and
> instantiate Collectors from there. I'm not sure how I would go about
> defining a class whose methods are taken from a db, though.
*Collector::parse = \&{ $method_from_db };
This should work regardless of whether $method_from_db is the name of a
subroutine, or an anonymous subroutine (created by evaling a string of
the form 'sub { .... }' ... which in turn might have been created with
B::Deparse).
> 2) Use inheritance. Create an abstract Collector class, and subclass
> it for each page to be collected. This seems more natural, but if I
> do it this way, how will my script know what kind of object to create?
eval qq[require $classname_from_db] or die $@;
my $collector = $classname_from_db->new;
> In the first scenario, it's easy because there's only one class. I
> can just say 'use Collector;' at the top of my script. With scenario
> two, wouldn't I have to put a 'use' statement for every subclass,
> whether or not an object of that class is actually created?
You can use or require the class at runtime, whichever you prefer.
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
Date: Tue, 05 Nov 2002 23:50:47 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: param($var);
Message-Id: <3dc85782.191832031@news.erols.com>
Todd Anderson <todd@mrnoitall.com> wrote:
: The code below replaces \n with <br> for param($var). I need to do the
: same thing with variable handles ie: $text = "This is the text"; After
: the param($var); has been assigned a handle. ie: $text = param(text);
What is a "handle?"
If you need to do the same thing, go ahead and do it.
$text =~ s/\r\n/<br>/g;
A little too obvious, though. Surely that's not what you really want.
The problem statement is not adequately describing what you want.
Try restating it with actual code that you believe should accomplish
what you want but fails.
Something about that peculiar term "variable handles" brings to mind
symbolic references, but we won't go there if we don't have to.
------------------------------
Date: Tue, 5 Nov 2002 19:35:30 -0600
From: "Craig McNiel" <craig-and-linda@the-mcniels.com>
Subject: Problem with Opening files and die
Message-Id: <aq9ri0$lsd$1@ins22.netins.net>
I have just compiled Perl 5.8 on an AIX 4.3.3 box with gcc 3.02. Now the
following code will no longer die if the file open actually does fail for
some reason.
open MYHANDLE, "filethatdoesntexist" || die $! ;
however
open (MYHANDLE, "filethatdoesntexist") || die $! ;
does produce the desired error message and termination of the script. I
have a lot of scripts that use the preceding syntax and will no longer catch
a bad file open operation. I don't get any warnings or errors using either
syntax so I'm at a loss as to if this is a bug or how to fix the perl
compiler. Any suggestions are welcome.
Thanks,
Craig
------------------------------
Date: Tue, 05 Nov 2002 20:50:42 -0500
From: Kevin Michael Vail <kevin@vaildc.net>
Subject: Re: Problem with Opening files and die
Message-Id: <kevin-551615.20504105112002@vienna7.his.com>
In article <aq9ri0$lsd$1@ins22.netins.net>,
"Craig McNiel" <craig-and-linda@the-mcniels.com> wrote:
> I have just compiled Perl 5.8 on an AIX 4.3.3 box with gcc 3.02. Now the
> following code will no longer die if the file open actually does fail for
> some reason.
>
> open MYHANDLE, "filethatdoesntexist" || die $! ;
This one is treated as:
open MYHANDLE, ("filethatdoesntexist" || die $!);
The || takes precedence over the comma. To get around this, use the
"or" operator instead of ||. This has lower priority than the comma:
open MYHANDLE, "filethatdoesntexist" or die $!;
> however
>
> open (MYHANDLE, "filethatdoesntexist") || die $! ;
>
> does produce the desired error message and termination of the script. I
> have a lot of scripts that use the preceding syntax and will no longer catch
> a bad file open operation. I don't get any warnings or errors using either
> syntax so I'm at a loss as to if this is a bug or how to fix the perl
> compiler. Any suggestions are welcome.
It's not a bug, it's the way things work.
--
Kevin Michael Vail | Dogbert: That's circular reasoning.
kevin@vaildc.net | Dilbert: I prefer to think of it as no loose ends.
http://www.vaildc.net/kevin/
------------------------------
Date: Wed, 06 Nov 2002 01:51:06 -0000
From: Andreas =?iso-8859-1?Q?K=E4h=E4ri?= <ak@freeshell.org.REMOVE>
Subject: Re: Problem with Opening files and die
Message-Id: <slrnasgtba.ku2.ak@otaku.freeshell.org>
Submitted by "Craig McNiel" to comp.lang.perl.misc:
> I have just compiled Perl 5.8 on an AIX 4.3.3 box with gcc 3.02. Now the
> following code will no longer die if the file open actually does fail for
> some reason.
>
> open MYHANDLE, "filethatdoesntexist" || die $! ;
>
> however
>
> open (MYHANDLE, "filethatdoesntexist") || die $! ;
>
> does produce the desired error message and termination of the script. I
> have a lot of scripts that use the preceding syntax and will no longer catch
> a bad file open operation. I don't get any warnings or errors using either
> syntax so I'm at a loss as to if this is a bug or how to fix the perl
> compiler. Any suggestions are welcome.
>
> Thanks,
> Craig
>
>
From the perlop manual:
The precedence of "and" and "or" is much lower, however,
so that you can safely use them after a list operator
without the need for parentheses:
unlink "alpha", "beta", "gamma" or gripe(), next LINE;
With the C-style operators that would have been written like
this:
unlink("alpha", "beta", "gamma") || (gripe(), next LINE);
--
Andreas Kähäri --==::{ Have a Unix: netbsd.org
--==::{ This post ends with :wq
------------------------------
Date: Tue, 05 Nov 2002 23:49:24 GMT
From: miketemp3@techinxs.com
Subject: Q: Reading process memory on Win32?
Message-Id: <8OYx9.6136$sP2.1214@sccrnsc02>
Hi,
I have a strange problem that I hope can be solved with Perl...
I have a program that I run which needs to snoop packets off my
network and decode them (some of you will know what I am talking
about, and why I don't say -- it's not illegal, though!) The
packets travel from my Win32 machine out to the Net with the
sniffer sitting in-between (Linux, but that does not matter here).
Well, the particular datastream that this program is trying to
decode has become encrypted. The solution is to read the decryption
key from the official client program (win32) memory and then send
the key to the Linux machine which is doing the sniffing.
Currently, this problem has been addressed by several people with
a C/C++ program to read an offset location in the client thread
and display the decryption key/XXX number of bytes at that
location.
I am hoping to do the same thing via Perl as it would be much
easier to maintain and not require that a certain compiler be
used to generate the executable.
So, to summarize, I want to be able to run a program on my
Win32 (XP) machine that will read XX number of bytes from offset
XXXX in thread ABC.
I did some Googleing and did not find any specific examples of
this, so I don't even know if Perl has the facilities to allow
one process to read another's memory, even if run by the
Administrator (man, I hate that name -- why not something easy
to type like "root"? But I digress...)
Can someone here tell me if this is indeed possible using Win32
Perl and/or modules and if so, maybe a snippet of code or perhaps
a link to some existing code/documention?
Thanks!
Mike
------------------------------
Date: 5 Nov 2002 15:13:02 -0800
From: skendric@fhcrc.org (Stuart Kendrick)
Subject: special characters in command-line
Message-Id: <62dbf7f1.0211051513.265bdbcc@posting.google.com>
Hi,
My program receives input from another process ("swatch"); the input
is a line from syslog.
Basically, swatch performs a
"system ("/wherever/myprog Nov 5 13:53:12 process-name: here is the
line from syslog");
where 'myprog' is my Perl program.
'myprog' looks something like this:
#!/usr/bin/perl -w
@line = @ARGV;
#parse @line and do things
...
Sometimes, lines from syslog contain special characters, like $ ^ & *
( ) +
When that happens, myprog doesn't behave quite as I would like it to.
In fact, @line doesn't contain anything after the first special
character, which limits 'myprogs' ability to do what I would like it
to do.
As far as I can see, I'm stuck in the short-term. I can't control
what arrives in syslog ... "swatch" doesn't have any processing
capabilities ... it can send me the line from syslog, but it can't
pre-mangle it for me. And so 'myprog' is stuck with special
characters hitting it ... which it can't handle.
Longer-term, I could mess with "swatch", so that it escaped special
characters in text before it sends it to me.
What other options might be available, for solving this issue?
--sk
Stuart Kendrick
FHCRC
------------------------------
Date: 6 Nov 2002 00:30:39 GMT
From: roberson@ibd.nrc.ca (Walter Roberson)
Subject: Re: special characters in command-line
Message-Id: <aq9nrf$cs8$1@canopus.cc.umanitoba.ca>
In article <62dbf7f1.0211051513.265bdbcc@posting.google.com>,
Stuart Kendrick <skendric@fhcrc.org> wrote:
:My program receives input from another process ("swatch"); the input
:is a line from syslog.
:Basically, swatch performs a
:"system ("/wherever/myprog Nov 5 13:53:12 process-name: here is the
:line from syslog");
:where 'myprog' is my Perl program.
If that's what swatch is doing, without doing an escaping, and if
it's using system(), then swatch has a bug that needs to be fixed.
swatch should be using exec( programlocation, dataline )
which would avoid any quoting problems.
--
Positrons can be described as electrons traveling backwards in time.
Certainly many Usenet arguments about the past become clearer when they
are re-interpreted as uncertainty about the future.
-- Walter Roberson
------------------------------
Date: Wed, 06 Nov 2002 01:18:04 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: special characters in command-line
Message-Id: <3DC86DA5.BC357296@acm.org>
Stuart Kendrick wrote:
>
> My program receives input from another process ("swatch"); the input
> is a line from syslog.
>
> Basically, swatch performs a
> "system ("/wherever/myprog Nov 5 13:53:12 process-name: here is the
> line from syslog");
>
> where 'myprog' is my Perl program.
>
> 'myprog' looks something like this:
>
> #!/usr/bin/perl -w
> @line = @ARGV;
> #parse @line and do things
> ...
>
> Sometimes, lines from syslog contain special characters, like $ ^ & *
> ( ) +
>
> When that happens, myprog doesn't behave quite as I would like it to.
> In fact, @line doesn't contain anything after the first special
> character, which limits 'myprogs' ability to do what I would like it
> to do.
>
> As far as I can see, I'm stuck in the short-term. I can't control
> what arrives in syslog ... "swatch" doesn't have any processing
> capabilities ... it can send me the line from syslog, but it can't
> pre-mangle it for me. And so 'myprog' is stuck with special
> characters hitting it ... which it can't handle.
>
> Longer-term, I could mess with "swatch", so that it escaped special
> characters in text before it sends it to me.
>
> What other options might be available, for solving this issue?
Instead of using
exec command
in the swatch config file use
pipe command
and read from STDIN so that characters aren't interpolated by the shell.
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 5 Nov 2002 23:52:32 +0000 (UTC)
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: split() results limited to 32k length?
Message-Id: <aq9lk0$929$1@plover.com>
[Mailed and posted]
In article <8435e2fa.0211051335.7a9c8c49@posting.google.com>,
Noam Stopak <noam@orionsci.com> wrote:
>It seems that split limits the length of the results to 32k.
It seems that you are mistaken.
>My testing indicates that the result string is truncated if it is
>longer than this.
A pity that you didn't display your test code so that either (a) a bug
report could be submitted, or (b) someone could explain what you are
doing wrong.
>This behavior seems to violate the spirit (if not
>the letter) of the comment in Programming Perl that "Strings of any
>length can be split" (top of page 795 in the 3rd edition).
I would say it would violate the letter, if it were true. I don't
believe it is true, but without a more specific report, it's
impossible to say for sure.
------------------------------
Date: Tue, 05 Nov 2002 20:57:24 -0500
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: split() results limited to 32k length?
Message-Id: <3DC87704.1080208@thecouch.homeip.net>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Noam Stopak wrote:
| It seems that split limits the length of the results to 32k. My
| testing indicates that the result string is truncated if it is longer
| than this. This behavior seems to violate the spirit (if not the
| letter) of the comment in Programming Perl that "Strings of any length
| can be split" (top of page 795 in the 3rd edition). Have others
| encountered this? Is it a bug? Is it a known bug?
|
| Running v5.6.1 built for sun4-solaris.
|
| Thanks,
|
| Noam
|
| p.s. please excuse previous erroneous posting to non-existant
comp.lang.perl
Here's my code:
- - - - cut here - - -
$chunk = " " x (37 * 1024);
for (1..37) {
~ $data .= $chunk . "x";
~ }
print "Data is ", length($data), " bytes long\n";
print "Data has ", scalar split(/x/, $data), " chunks of ",
length((split(/x/, $data))[0]), " bytes each\n";
- - - - cut here - - -
Now show me yours.
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQE9yHcDeS99pGMif6wRAkRpAKDDu/7tAuJfi6j3Vlxi/IvvZ8Og8gCghGFo
Y+6qxWVc5dkylBfGt4dFch8=
=Qvmy
-----END PGP SIGNATURE-----
------------------------------
Date: Tue, 05 Nov 2002 20:07:51 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Tie'd filehandle and the system() function
Message-Id: <3DC86B67.29CBE495@earthlink.net>
Tim wrote:
>
> Hi:
>
> I've tied STDOUT and STDERR to be able to manipulate the input data
> before it's put into a file. This works well with functions like
> print. However, due (I'm sure) to my limited understanding of tie and
> object-oriented perl (I've learned just enough to be dangerous), I
> can't get output from the system() function to behave.
Although I've given you one answer already, I'd like to suggest the
following, non-tie solution:
open( LOG_FILE_DIRECT, ">>", "script.log" )
or die "Couldn't open script.log: $!";
my $old_select = select LOG_FILE_DIRECT;
$| = 1;
for my $fh (\*LOG_OUT, \*LOG_ERR) {
defined( my $pid = open( $fh, "|-" ) )
or die "Couldn't fork: $!";
select($fh), ($| = 1), next if $pid;
my $info = join("|", hostname(), $0, __FILE__, getppid());
print scalar(localtime), "|", $info, "|", $_ while <STDIN>;
exit;
}
select($old_select);
open( STDOUT, ">&LOG_OUT" )
or die "Couldn't dup LOG_OUT over STDOUT: $!";
open( STDERR, ">&LOG_ERR" ) or
or die "Couldn't dup LOG_ERR over STDERR: $!";
print "Beginning script\n";
print "This script was executed with \@ARGV == [@ARGV]\n";
system("external_process");
exit;
[untested]
--
my $n = 2; print +(split //, 'e,4c3H r ktulrnsJ2tPaeh'
."\n1oa! er")[map $n = ($n * 24 + 30) % 31, (42) x 26]
------------------------------
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 4069
***************************************