[22622] in Perl-Users-Digest
Perl-Users Digest, Issue: 4843 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Apr 14 18:06:04 2003
Date: Mon, 14 Apr 2003 15:05:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 14 Apr 2003 Volume: 10 Number: 4843
Today's topics:
Re: Consistent ithreads limit on Win32... ? (Dave Byrd)
Re: Consistent ithreads limit on Win32... ? <goldbb2@earthlink.net>
Re: DBI and binding [attempt 2] <nobull@mail.com>
embeded perl <peter@nospam.calweb.com>
Re: embeded perl <tassilo.parseval@rwth-aachen.de>
Re: embeded perl <peter@nospam.calweb.com>
error when reading file what is wrong (julio)
Re: executing perl script (Bryan Castillo)
Re: help with using Net-Telnet module.. (Bryan Castillo)
How does Perl auto increase hash size? (James Thornton)
Re: How does Perl auto increase hash size? <abigail@abigail.nl>
How to do a regexp to find #'s? <Jeff@aetherweb.co.uk>
Re: How to do a regexp to find #'s? <abigail@abigail.nl>
Re: How to do a regexp to find #'s? <michael.p.broida@boeing.com>
Re: How to do a regexp to find #'s? <abigail@abigail.nl>
Re: How to do a regexp to find #'s? (Tad McClellan)
LISA 2003 Submission Deadline is Approaching <alex@usenix.org>
Re: match identical lines of file. <tzz@lifelogs.com>
Re: Method inheritance? <mbudash@sonic.net>
Re: Method inheritance? <uri@stemsystems.com>
Re: Method inheritance? <rm@no-mail.com>
Re: Method inheritance? <goldbb2@earthlink.net>
Re: Method inheritance? <mpapec@yahoo.com>
Re: My 1st japh!! <goldbb2@earthlink.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 14 Apr 2003 08:31:33 -0700
From: digitalarcana@charter.net (Dave Byrd)
Subject: Re: Consistent ithreads limit on Win32... ?
Message-Id: <392a1d54.0304140731.38f29aeb@posting.google.com>
Benjamin Goldberg <goldbb2@earthlink.net> wrote in message news:<3E9736EF.68C57206@earthlink.net>...
> Ilya Zakharevich wrote:
> > Dave Byrd wrote:
> > > Here's the problem. No matter how I structure the creation of these
> > > threads: have the main thread create all subthreads, or have some
> > > worker threads spawn other worker threads in a "pyramid", I run into
> > > weird behavior when I try to spawn the 111th thread (threadid 110).
> > >
> > > I get no error from the create().
> [snip]
> > But keep in mind that your *actual* problem is most probably
> > orthogonal to this one. You are trying to run 111 threads
> > simultaneously?
>
> If he's trying to do IO on multiple thingys which don't like IO::Select,
> (as I infer from the "Poll" in \&PollManager) he probably has to.
>
> > Perl REx engine is (was?) very stack hungry; if you want to use RExes,
> > you better have megabytes of stack. Even with 1M of stack (pretty low
> > - one can match circa 4000 (groups)'s in /(COMPLICATED_REX)*/) you get
> > 111M of virtual memory allocated for the stacks. In short: at some
> > moment you will run off the virtual memory.
>
> Well, hopefully he's designing his program so that each io thread passes
> it's data back to the main thread, and all regex matching is done there;
> this would decrease the amount of memory needed.
That's right. The reason I'm trying to run a highly-multithreaded
application is that I'm doing very rapid data gathering from a lot of
sources (thousands of machines). Each thread is basically just a
telnet session to a different machine. These machines are old
telephone switches, so they are quite limited in their communication
capabilities.
In terms of processor usage, I'm absolutely fine, because each thread
spends 99% of its time blocking for I/O from the remote machine. The
problem seems to be that perl has a very "heavy" thread model in terms
of memory usage.
I think what you're both telling me is that perl is not a suitable
choice for this task right now, because I need a lightweight thread
model where each thread uses few resources when it isn't doing
anything, and perl's current thread model is the opposite of that.
Was the old 5.005 thread model any better in that regard?
Thanks for the assistance!
--Dave
------------------------------
Date: Mon, 14 Apr 2003 12:19:05 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Consistent ithreads limit on Win32... ?
Message-Id: <3E9ADF79.494787DE@earthlink.net>
Dave Byrd wrote:
>
> Benjamin Goldberg wrote:
>> Ilya Zakharevich wrote:
>>> Dave Byrd wrote:
>>>> Here's the problem. No matter how I structure the creation of
>>>> these threads: have the main thread create all subthreads, or have
>>>> some worker threads spawn other worker threads in a "pyramid", I run
>>>> into weird behavior when I try to spawn the 111th thread (threadid
>>>> 110).
>>>>
>>>> I get no error from the create().
>> [snip]
>>> But keep in mind that your *actual* problem is most probably
>>> orthogonal to this one. You are trying to run 111 threads
>>> simultaneously?
>>
>> If he's trying to do IO on multiple thingys which don't like
>> IO::Select, (as I infer from the "Poll" in \&PollManager) he probably
>> has to.
[snip]
> That's right. The reason I'm trying to run a highly-multithreaded
> application is that I'm doing very rapid data gathering from a lot of
> sources (thousands of machines). Each thread is basically just a
> telnet session to a different machine.
Telnet? select/IO::Select works perfectly fine with sockets. I think
I'm in agreement with Ilya on this one -- threads are not the way to go
for your problem -- instead, multiplex your data in a single thread.
> These machines are old telephone switches, so they are quite limited in
> their communication capabilities.
So long as you connect to those machines using sockets, there should be
no problem multiplexing. If you're on *nix instead of windows, then you
could even spawn a seperate telnet process, and you could multiplex ok
with it.
> In terms of processor usage, I'm absolutely fine, because each thread
> spends 99% of its time blocking for I/O from the remote machine. The
> problem seems to be that perl has a very "heavy" thread model in terms
> of memory usage.
>
> I think what you're both telling me is that perl is not a suitable
> choice for this task right now, because I need a lightweight thread
> model where each thread uses few resources when it isn't doing
> anything, and perl's current thread model is the opposite of that.
Perl's a perfectly suitable choice for your problem -- just not the way
you're doing it.
Now, if you really needed thousands of threads, then no, perl wouldn't
be a suitable choice.
> Was the old 5.005 thread model any better in that regard?
Well, you could create more threads, but since every global variable was
shared by default, you were highly prone to crashes.
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: 14 Apr 2003 17:40:52 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: DBI and binding [attempt 2]
Message-Id: <u9adetav6z.fsf@wcl-l.bham.ac.uk>
"Bigus" <bigus NO @ SPAM creationfactor .net> writes:
> $sth = $db->prepare("SELECT * FROM thetable WHERE refs LIKE '%$display%'
> OR messageid = '$display' ORDER BY article DESC");}
> So, I've tried substituting $display for a ? and then doing
> "$sth->execute($display)" but it didn't pick up any records
Please do not _descibe_ what you did. Please show us.
If you put ? inside a literal string then it will be interpreted as
just a literal '?'. If you want it treated as a placeholder you have
to put it in a context where an SQL variable could be used.
$sth = $db->prepare("SELECT * FROM thetable WHERE refs LIKE ?
OR messageid = ? ORDER BY article DESC");}
> (plus [...] it wants 2 bind parameters).
That is correct if you put two placeholders in prepare() you need two
arguments in execute().
> I guess I must be using the bind thingies incorrectly,
Probably, but you haven't shown us what you've done so it's kinda hard
to comment.
It should also be pointed out that if $display contains SQL LIKE
metacharacters and you don't want these to be treated as
metacharacters then you need to escape them according to the rules of
SQL LIKE patterns (which are off-topic here).
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Mon, 14 Apr 2003 10:14:03 -0700
From: Penguinista <peter@nospam.calweb.com>
Subject: embeded perl
Message-Id: <3e9af9e9$0$4691$d368eab@news.newshosting.com>
working to embed perl in a project, I discovered gcc griping about the
perl header files. tracing macros back from the messages, I came to the
following from EXTERN.h (just the part relivant to my system)
# define EXT extern
# define dEXT
# define EXTCONST extern const
# define dEXTCONST const
the space in the #define strikes me as odd.
Characteristics of this binary (from libperl):
Compile-time options:
Built under linux
Compiled at Aug 9 2001 22:48:52
@INC:
/usr/lib/perl5/5.6.0/i386-linux
/usr/lib/perl5/5.6.0
/usr/lib/perl5/site_perl/5.6.0/i386-linux
/usr/lib/perl5/site_perl/5.6.0
/usr/lib/perl5/site_perl
.
Is my diagnosis reasonable? Any suggested fix?
------------------------------
Date: 14 Apr 2003 19:07:42 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: embeded perl
Message-Id: <b7f0tu$la9$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Penguinista:
> working to embed perl in a project, I discovered gcc griping about the
> perl header files. tracing macros back from the messages, I came to the
> following from EXTERN.h (just the part relivant to my system)
> # define EXT extern
> # define dEXT
> # define EXTCONST extern const
> # define dEXTCONST const
>
> the space in the #define strikes me as odd.
It shouldn't since it's perfectly legal. Your gcc must be griping about
something else.
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
------------------------------
Date: Mon, 14 Apr 2003 12:45:35 -0700
From: Penguinista <peter@nospam.calweb.com>
Subject: Re: embeded perl
Message-Id: <3e9b1d6c$0$4692$d368eab@news.newshosting.com>
Tassilo v. Parseval wrote:
> Also sprach Penguinista:
>
>
>>working to embed perl in a project, I discovered gcc griping about the
>>perl header files. tracing macros back from the messages, I came to the
>>following from EXTERN.h (just the part relivant to my system)
>># define EXT extern
>># define dEXT
>># define EXTCONST extern const
>># define dEXTCONST const
>>
>>the space in the #define strikes me as odd.
>
>
> It shouldn't since it's perfectly legal. Your gcc must be griping about
> something else.
>
> Tassilo
finaly got it to compile by placing an #include <EXTERN.h> before the
#include <perl.h>. strangely, perl.h was using #defines from Extern.h
before including it.
------------------------------
Date: 14 Apr 2003 17:04:13 -0500
From: julio@hot.com (julio)
Subject: error when reading file what is wrong
Message-Id: <3e9b2fb0$0$3121$45beb828@newscene.com>
running on Sun unix on Sun server
i have following code
#!/usr/local/bin/perl -w
#
#---------------------------------------------------------------#
# A program to read an #
#---------------------------------------------------------------#
$logFile = "tag.txt";
open (LOGFILE,"$logFile") || die " Error opening log file $logFile.\n";
while() {
#----------------------------------------------#
# condense one or more whitespace character #
# to one single space #
#----------------------------------------------#
s/FORD/xxxx/g
}
close (LOGFILE);
tag.txt line looks like
13 CRAWFORD 38TR82 MW
13 CRAWFORD 38TR82 45 MW
13 CRAWFORD 38TR82 CT MW
13 CRAWFORD 38TR83 MW
13 CRAWFORD 38TR83 45 MW
13 CRAWFORD 38TR83 CT MW
13 CRAWFORD 38TR84 MW
13 CRAWFORD 38TR84 45 MW
i get error
Use of uninitialized value in substitution (s///) at p.sh line 19.
what is wrong
------------------------------
Date: 14 Apr 2003 13:15:44 -0700
From: rook_5150@yahoo.com (Bryan Castillo)
Subject: Re: executing perl script
Message-Id: <1bff1830.0304141215.5c442aff@posting.google.com>
rnbhat89@yahoo.com (bhat) wrote in message news:<4f49dc09.0304120109.2bcb01da@posting.google.com>...
> Hello,
> I am able to execute the below script from the command prompt.
> However when i try to run through internet explorer the script doesn't
> work as intended. The variable $folder in the script below now has
> null value. Seems like it doesn't execute any command after the
> statement my $msg = $folder->message(0);. I don't see any error
> messages. Any clues to solve this problem would be appriciated.
> Regards,
> Roopa
>
Have you tried?
use CGI;
use CGI::Carp qw{fatalsToBrowser};
Make sure you put these before the use Mail::X
That should catch the case where the modules aren't installed
properly for the web server.
>
>
> #!/usr/bin/perl --
>
> use Mail::Box;
> use Mail::Box::POP3;
> use Mail::Box::Manager;
> use Mail::Message::Body;
> use Mail::Message;
>
> print "Content-type: text/html\n\n";
If you print something here, will it show up on your browser?
> my $mgr = new Mail::Box::Manager;
> my $folder = $mgr->open(type => "pop3", username => "roopa", password
> => "bhat", server_name => "mail.xxxx.net");
> #---i am getting null value in the folder dirctory.
If you print something here, will it show up on your browser?
How do you know the values are null, unless you are able to print something?
> my $msg = $folder->message(0);
> my $head = $msg->head;
> my $body = $msg->body;
> #--all the values remain null and even the print statemnt doesn't
> print anything the below statement.
> print "the header is $head\n";
> #--for the above diagonistic print statement i am expecting to see on
> the screen "the header is " but i don't even see "the header is "-
>
This is probably because your script died, failed to compile, etc......
> $folder->close;
------------------------------
Date: 14 Apr 2003 12:15:39 -0700
From: rook_5150@yahoo.com (Bryan Castillo)
Subject: Re: help with using Net-Telnet module..
Message-Id: <1bff1830.0304141115.483bc47d@posting.google.com>
"Shay Hugi" <shayh@mpthrill.com> wrote in message news:<3e992a42@news.012.net.il>...
> Hi,
> I would like to use net-telnet to collect information on some of our network
> equipments,
> right now i'm working with a vb script that starts a telnet session (run a
> few commands) and saves the session as a text file.
> i want to replace this vb script with a perl script that does the same, all
> i need is a few lines of example on how to do it...
> including the part of saving the telnet session as a text file (it should
> overwrite the file if exist and not append it)
>
> currently i work as script per network equipment, instead of writing an
> external array that reads the network nodes information and post them in one
> script.
> i would like to stay in this way for some reasons that are related to the
> data collection and the types of network nodes i monitor.
> i'm looking for a script where i could have simple arguments such as
> "collect.pl 127.0.0.1 log.txt" and it will take the data according to the
> commands written in the script and write them into log.txt...
>
You need many more parameters than that, you will need a file
containing commands, the host, (perhaps the port?), the log file, the
username, the password and the prompt, maybey others?
I thought the docs for Net::Telnet had an example basic enough,
anyway....
Here is something to start you off. You just have to change it so
some of the variables are taken as parameters from a config file or
@ARGV. I would be in favor of a config file for the username and
password (where you might set the file permissions more strict than
the script itself.)
use strict;
use warnings;
use Net::Telnet;
use IO::File;
$|=1;
# Any of these are variables are parameters you
# might want to change. (@ARGV? config file?)
my $host = 'jabba';
my $timeout = 10;
my $prompt = '/\$ $/';
my $user = 'bryanc';
my $pass = 'blahblahblah';
my $log = $host.".log";
my $cmds = "cmds.txt"; # file containing command to send 1 per
line
my $in = IO::File->new($cmds, "r") || die "can't open $cmds - $!";
my $out = IO::File->new($log, "w") || die "can't open $log - $!";
select $out; # send output to file (im lazy)
my $t = Net::Telnet->new(Timeout=>$timeout, Prompt=>$prompt);
$t->open($host);
$t->login($user, $pass);
while (my $cmd = <$in>) {
chomp($cmd);
my @lines = $t->cmd($cmd);
print "Command = $cmd\n";
print "Response--------------------------\n";
print @lines;
print "End Response--------------------------\n";
}
select STDOUT;
$t->close;
$in->close;
$out->close;
> if someone already wrote something similar i'll be happy to get it (it's not
> a problem for me to change the script, it's just i need the basic beginning)
>
> Thanks in advance everybody!
>
> Shay Hugi
> Golden-Channles
------------------------------
Date: 14 Apr 2003 10:48:10 -0700
From: james@unifiedmind.com (James Thornton)
Subject: How does Perl auto increase hash size?
Message-Id: <cabf0e7b.0304140948.19188a00@posting.google.com>
If a hash wasn't pre-sized large enough so that Perl has to
automatically increase its max size, what algo does Perl implement for
this? -- double the size and redistribute elements? What's the default
initial max size? Thanks.
------------------------------
Date: 14 Apr 2003 18:12:23 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: How does Perl auto increase hash size?
Message-Id: <slrnb9lug7.jcl.abigail@alexandra.abigail.nl>
James Thornton (james@unifiedmind.com) wrote on MMMDXIII September
MCMXCIII in <URL:news:cabf0e7b.0304140948.19188a00@posting.google.com>:
-- If a hash wasn't pre-sized large enough so that Perl has to
-- automatically increase its max size, what algo does Perl implement for
-- this? -- double the size and redistribute elements? What's the default
-- initial max size? Thanks.
What the initial size is, and how it's incremented may change from
version to version. It's not specified. But you can do some experimenting
yourself, if you don't want to look it up in the source code. Remember
that a hash in scalar context returns (if the hash is non-empty), a string
of the form "DD/DD", with the first number the number of used buckets,
and the second number the number of allocated buckets.
Abigail
--
sub _'_{$_'_=~s/$a/$_/}map{$$_=$Z++}Y,a..z,A..X;*{($_::_=sprintf+q=%X==>"$A$Y".
"$b$r$T$u")=~s~0~O~g;map+_::_,U=>T=>L=>$Z;$_::_}=*_;sub _{print+/.*::(.*)/s};;;
*_'_=*{chr($b*$e)};*__=*{chr(1<<$e)}; # Perl 5.6.0 broke this...
_::_(r(e(k(c(a(H(__(l(r(e(P(__(r(e(h(t(o(n(a(__(t(us(J())))))))))))))))))))))))
------------------------------
Date: Mon, 14 Apr 2003 19:13:33 +0100
From: "Jeff Snoxell" <Jeff@aetherweb.co.uk>
Subject: How to do a regexp to find #'s?
Message-Id: <b7etn8$vk6$1@newsg3.svr.pol.co.uk>
Hi,
I want to parse lines of text and remove any comments from them. Can't seem
to get my regexp to work. I'm currently trying to work with this:
$value =~ s/#+.*$//;
But its not working, I assume because the interperter thinks #+.*$//; is a
comment itself... so I tried:
$value =~ s/\#+.*$//;
And it doesn't like that either.
Thanks,
Jeff Snoxell
Aetherweb Ltd - http://www.bespoke-web-design-uk.co.uk
------------------------------
Date: 14 Apr 2003 18:48:29 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: How to do a regexp to find #'s?
Message-Id: <slrnb9m0jt.jcl.abigail@alexandra.abigail.nl>
Jeff Snoxell (Jeff@aetherweb.co.uk) wrote on MMMDXIII September MCMXCIII
in <URL:news:b7etn8$vk6$1@newsg3.svr.pol.co.uk>:
:) Hi,
:)
:) I want to parse lines of text and remove any comments from them. Can't seem
:) to get my regexp to work. I'm currently trying to work with this:
:)
:) $value =~ s/#+.*$//;
:)
:) But its not working, I assume because the interperter thinks #+.*$//; is a
:) comment itself... so I tried:
:)
:) $value =~ s/\#+.*$//;
:)
:) And it doesn't like that either.
Ah, the great "It doesn't work". And now we all know what's the problem.
I think you should pay more, and turn off the TV. Then it might start
to work.
Abigail
--
Djees, man. Tell us what happens. What do you think should happen?
What's in $value? What's in $value afterwards?
------------------------------
Date: Mon, 14 Apr 2003 19:09:16 GMT
From: "Michael P. Broida" <michael.p.broida@boeing.com>
Subject: Re: How to do a regexp to find #'s?
Message-Id: <3E9B075C.C57117AB@boeing.com>
Jeff Snoxell wrote:
>
> Hi,
>
> I want to parse lines of text and remove any comments from them. Can't seem
> to get my regexp to work. I'm currently trying to work with this:
>
> $value =~ s/#+.*$//;
>
> But its not working, I assume because the interperter thinks #+.*$//; is a
> comment itself... so I tried:
>
> $value =~ s/\#+.*$//;
>
> And it doesn't like that either.
That second one works for me, BUT... You have to worry
about HOW you got the # into the $value variable in the
first place. If you did it via an assign like:
$value = "abc#def";
I don't think that will work; the # ends the line. (I think.)
I set $value from user input like this:
$value = <STDIN>;
Then did the substitution and printed it out. Worked perfectly.
Mike
------------------------------
Date: 14 Apr 2003 20:30:41 GMT
From: Abigail <abigail@abigail.nl>
Subject: Re: How to do a regexp to find #'s?
Message-Id: <slrnb9m6jh.u5s.abigail@alexandra.abigail.nl>
Michael P. Broida (michael.p.broida@boeing.com) wrote on MMMDXIII
September MCMXCIII in <URL:news:3E9B075C.C57117AB@boeing.com>:
|| Jeff Snoxell wrote:
|| >
|| > Hi,
|| >
|| > I want to parse lines of text and remove any comments from them. Can't seem
|| > to get my regexp to work. I'm currently trying to work with this:
|| >
|| > $value =~ s/#+.*$//;
|| >
|| > But its not working, I assume because the interperter thinks #+.*$//; is a
|| > comment itself... so I tried:
|| >
|| > $value =~ s/\#+.*$//;
|| >
|| > And it doesn't like that either.
||
|| That second one works for me, BUT... You have to worry
|| about HOW you got the # into the $value variable in the
|| first place. If you did it via an assign like:
||
|| $value = "abc#def";
||
|| I don't think that will work; the # ends the line. (I think.)
You think. How much trouble would it have taken to actually try it?
Abigail
--
You thought wrong.
------------------------------
Date: Mon, 14 Apr 2003 16:21:49 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: How to do a regexp to find #'s?
Message-Id: <slrnb9m9jd.ivq.tadmc@magna.augustmail.com>
Jeff Snoxell <Jeff@aetherweb.co.uk> wrote:
> I'm currently trying to work with this:
>
> $value =~ s/#+.*$//;
>
> But its not working,
Show us a short and complete Perl program that we can run,
that duplicates your problem, and we will help you fix it.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 14 Apr 2003 14:58:23 -0700
From: Alex Walker <alex@usenix.org>
Subject: LISA 2003 Submission Deadline is Approaching
Message-Id: <3E9B2EFF.9060109@usenix.org>
There is still time to submit your ideas, proposals, and papers for
invited talks, refereed papers, panels, work-in-progress reports, and
Guru-in-in sessions at LISA 2003!
Submissions are due Monday, April 21, 2003
17th Systems Administration Conference (LISA ‘03)
October 26-31, 2003 San Diego, California
http://www.usenix.org/events/lisa03
GET INVOLVED!
We welcome submissions that address all facets of the practice and
theory of system and network administration.
The Call for Papers with submission guidelines and topics is available
on the USENIX Web site at http://www.usenix.org/events/lisa03/cfp/
We look forward to hearing from you!
AEleen Frisch, Exponential Consulting
LISA 2003 Program Chair
aeleen@usenix.org
=============================================================
LISA 2003 is sponsored by USENIX, the Advanced Computing Systems
Association, and SAGE, the System Administrators Guild.
=============================================================
------------------------------
Date: Mon, 14 Apr 2003 13:16:56 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: match identical lines of file.
Message-Id: <4nof39roc7.fsf@lockgroove.bwh.harvard.edu>
On 12 Apr 2003, molivier@caregroup.harvard.edu wrote:
> i need to search for an account number and then after the match is
> made read down the file, until i find the next match (/^0764/) but I
> need the search to end after the first occurnece of a line not
> matching /^0764/. I tried using until, but am having no luck. Just
> pointing me in the right direction would be great. Thanks in
> adavance.
This can be optimized, but I've made it as legible as possible so you
can understand the logic. Either replace 'DEFAULT' or give the
account number to the program as a command-line argument. Note that
this uses standard input, so you would run "program ACCOUNT < file.txt"
if the input was in file.txt.
Ted
#!/usr/bin/perl -w
use strict;
my $string = shift @ARGV || 'DEFAULT';
while (<>)
{
if (m/$string/)
{
print;
while (<>)
{
exit unless m/$string/;
print;
}
}
}
------------------------------
Date: Mon, 14 Apr 2003 15:11:15 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Method inheritance?
Message-Id: <mbudash-CA2FDD.08111414042003@typhoon.sonic.net>
In article <20030415000039.7297b652.rm@no-mail.com>,
Roy Marteen <rm@no-mail.com> wrote:
> Hi,
>
> I tried to wrap DBI.pm with my own module. This is my script:
> ---[DB.pm]---
> package DB;
> use strict;
> use DBI;
>
> sub connect {
> my $class = shift();
> my $self = {};
> $self->{dbh} = DBI::->connect("DBI:mysql:dummy", "root", "mysql", {
> RaiseError => 1 });
> bless($self, $class);
> return $self;
> }
>
> Now I can use it using:
> ---[test.pl]---
> use DB;
> my $db = DB::->connect();
> my $dbh = $db->{dbh};
>
> I don't want it this way. I want to wrap it in such a way that I can
> access it using:
> ---[test.pl]---
> use DB;
> my $dbh = DB::->connect();
>
> How can I do this?
you need (at least) to have this at the top of your script:
package DB;
use strict;
use DBI;
@ISA = ("DBI");
hth-
--
Michael Budash
------------------------------
Date: Mon, 14 Apr 2003 15:33:55 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Method inheritance?
Message-Id: <x7y92d9jq5.fsf@mail.sysarch.com>
>>>>> "MB" == Michael Budash <mbudash@sonic.net> writes:
MB> you need (at least) to have this at the top of your script:
MB> package DB;
MB> use strict;
MB> use DBI;
MB> @ISA = ("DBI");
and that will fail under strict since you didn't declare @ISA.
either do:
our @ISA = qw( DBI ) ;
or IMO better:
use base DBI ;
which replaces both the use DBI and @ISA lines.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
------------------------------
Date: Tue, 15 Apr 2003 00:36:20 +0900
From: Roy Marteen <rm@no-mail.com>
Subject: Re: Method inheritance?
Message-Id: <20030415003620.7f003404.rm@no-mail.com>
Hi Michael,
> you need (at least) to have this at the top of your script:
>
> package DB;
> use strict;
> use DBI;
> @ISA = ("DBI");
Thanks for your reply. I tried this but seems like it didn't work. My
scripts:
---[DB.pm]---
package DB;
use strict;
use DBI;
@ISA = ("DBI");
sub connect {
my $class = shift();
my $self = {};
$self = DBI::->connect("DBI:mysql:dummy", "root", "mysql", {
RaiseError => 1 });
bless($self, $class);
return $self;
}
1;
Then to use it:
---[test.pl]---
#!/usr/bin/perl
use strict;
use DB;
my $dbh = DB::->connect();
## Try to access the database
my $sth = $dbh->$prepare("SHOW TABLES");
This produces error:
Can't locate auto/DB/prepare.al in @INC (@INC contains:
/usr/lib/perl5/5.8.0/i386-linux-thread-multi /usr/lib/perl5/5.8.0
/usr/lib/perl5/site_perl/5.8.0/i386-linux-thread-multi
/usr/lib/perl5/site_perl/5.8.0 /usr/lib/perl5/site_perl
/usr/lib/perl5/vendor_perl/5.8.0/i386-linux-thread-multi
/usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl .) at
./test.pl line 8
I just try to wrap the DBI module in my own module, so I don't need to put
host name, user name and password everytime I call it.
------------------------------
Date: Mon, 14 Apr 2003 12:34:55 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Method inheritance?
Message-Id: <3E9AE32F.ACA69EAE@earthlink.net>
Roy Marteen wrote:
>
> Hi,
>
> I tried to wrap DBI.pm with my own module. This is my script:
[snip]
> I don't want it this way. I want to wrap it in such a way that I can
> access it using:
> ---[test.pl]---
> use DB;
> my $dbh = DB::->connect();
>
> How can I do this?
First, I would suggest you use a name other than 'DB', since that's
special -- it's purpose is for hooking into the perl debugger.
Second, you need to subclass DBI, not merely create a container for it.
Well, not unless you want to use AUTOLOAD to delegate all database
method calls to the database handle object.
DBI is slightly picky about who it allows to subclass from it -- you
need to also provide subclasses for two other classes; DBI::st and
DBI::dr.
Try this:
package myDB;
use base 'DBI';
# you don't need anything here.
package myDB::st;
use base 'DBI::st';
# nor here.
package myDB::dr;
use base 'DBI::dr';
# DBI->connect returns a DBI::dr object.
# myDB->connect will return a myDB::dr object.
# so, for $dbh->foo, add a method here:
sub foo { ... }
1;
__END__
use myDB;
my $dbh = myDB->connect(...); # a myDB::dr object.
my $sth = $dbh->prepare(...); # a myDB::st object.
$dbh->foo;
[untested]
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
Date: Mon, 14 Apr 2003 21:35:10 +0200
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: Method inheritance?
Message-Id: <n13m9v8pt3nd192t3294m57pvcamk9csuk@4ax.com>
X-Ftn-To: Benjamin Goldberg
Benjamin Goldberg <goldbb2@earthlink.net> wrote:
>> ---[test.pl]---
>> use DB;
>> my $dbh = DB::->connect();
>>
>> How can I do this?
>
>First, I would suggest you use a name other than 'DB', since that's
>special -- it's purpose is for hooking into the perl debugger.
>
>Second, you need to subclass DBI, not merely create a container for it.
>Well, not unless you want to use AUTOLOAD to delegate all database
>method calls to the database handle object.
What should be done when inheriting a class and wanting to be sure that my
attribute didn't overwrite some of inherited class?
--
Matija
------------------------------
Date: Mon, 14 Apr 2003 12:05:04 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: My 1st japh!!
Message-Id: <3E9ADC30.4ED8ACF@earthlink.net>
Michele Dondi wrote:
>
> On Fri, 11 Apr 2003 16:10:58 -0400, Benjamin Goldberg
> <goldbb2@earthlink.net> wrote:
[snip]
> >I prefer my own japh from a while back.
> >
> > tr/`/ /, s/.//, print "@{[map --$| ? ucfirst lc : lc, split]},\n"
> > for pack 'u',pack 'H*','ab5cf4021bafd28972030972b00a218eb9720000'
>
> I do prefer it too... and it would be great if I could (fully)
> understand it!!
Ok.
pack 'H*','ab5cf4021bafd28972030972b00a218eb9720000'
That's a hexidcimal string, which pack() converts into a much binary
string (about half that length). I won't show that string, since it
looks like a mess.
pack 'u', ...
This does uuencoding, which converts binary data into 7-bit ascii clean
data. It also expands the data slightly. It produces the string:
"4JUST`ANOTHER`PERL`HACKER````"
The "for" aliases that string to $_.
The tr/`/ / converts all those backticks into spaces.
The s/.// removes the first character.
Skipping around slightly to the contents of the @{[ ... ]} :
map --$| ? ucfirst lc : lc, split
The 'split' splits on whitespace, discarding trailing empty fields.
This produces a list:
"JUST", "ANOTHER", "PERL", "HACKER"
Every other evaluation of --$| produces a true value, and every other
evaluation produces a false value. Thus, every other of these list
elements get ucfirst(lc())'d, and ever other element gets lc()'d. Thus,
you've got the list:
"Just", "another", "Perl", "hacker"
When stringifying an array in double-quotish context, the elements are
joined together on $", which is a space.
Then ",\n" is added, just before printing.
Tada! :)
--
$a=24;split//,240513;s/\B/ => /for@@=qw(ac ab bc ba cb ca
);{push(@b,$a),($a-=6)^=1 for 2..$a/6x--$|;print "$@[$a%6
]\n";((6<=($a-=6))?$a+=$_[$a%6]-$a%6:($a=pop @b))&&redo;}
------------------------------
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 4843
***************************************