[19081] in Perl-Users-Digest
Perl-Users Digest, Issue: 1276 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 11 03:31:52 2001
Date: Wed, 11 Jul 2001 00:31:37 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <994836696-v10-i1276@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 11 Jul 2001 Volume: 10 Number: 1276
Today's topics:
help on arrays (bob)
Re: help on arrays <krahnj@acm.org>
Re: help on arrays <dbe@wgn.net>
Re: help on arrays (Tad McClellan)
Re: Help with Rewriting Application in OO Perl <goldbb2@earthlink.net>
help: How do you call a PL/SQL in a perl script? u518615722@spawnkill.ip-mobilphone.net
Re: How do I spawn an xterm executing another program a (Keith)
Re: How do I spawn an xterm executing another program a <goldbb2@earthlink.net>
Re: How I came to love Perl... (Dave Hoover)
Re: How I came to love Perl... (Tim Hammerquist)
Re: How I came to love Perl... <lmoran@wtsg.com>
Re: How I came to love Perl... (Damian James)
Re: I know this must be in the manpages... number forma <hafner-usenet@ze.tu-muenchen.de>
I'm starting to think our 5.6 install is braindead <ns@cfl.rr.com>
Re: I'm starting to think our 5.6 install is braindead <pne-news-20010711@newton.digitalspace.net>
lexical ordering of hash keys with $DB_BTREE not workin <m.grimshaw@salford.ac.uk>
Re: lexical ordering of hash keys with $DB_BTREE not wo <m.grimshaw@salford.ac.uk>
Re: list program fails depending on directory? <goldbb2@earthlink.net>
Name Space Question <wessner@hps.fzk.de>
Re: Name Space Question <ron@savage.net.au>
Re: Name Space Question <ubl@schaffhausen.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 10 Jul 2001 15:26:48 -0700
From: hirizedude@netscape.net (bob)
Subject: help on arrays
Message-Id: <44e5c763.0107101426.4138c6ef@posting.google.com>
Hello list, I need some help on this little perl script I put
together. My script parses the /etc/passwd file and emails the
manager of each user in the file. My script works fine but now I need
to refine it to where it sends 1 mail to the manager with all of the
users identified as his. I am at a dead end.
this assumes the passwd file is formatted like this..
where big.cheese=manager
bob:x:1001:10:bob.bohica,big.cheese,4449999:/export/home/bob:/bin/ksh
here is the code...
#!/usr/bin/perl
#
############################################################################
open(OUTPUT, "hostname|") || die "Can't stat hostname";
$hostname=<OUTPUT>;
close(OUTPUT);
############################################################################
# setup array of excluded system users
############################################################################
@exuser= ("root", "daemon", "bin", "sys", "adm", "lp", "uucp",
"nuucp", "listen", "nobody", "noaccess", "nobody4");
############################################################################
# read passwd file into array so weez can chunkonit
############################################################################
open (F, "/etc/passwd") || die "Could not open passwd file: $:";
@password=<F>;
################################################################################
# perform the magic filtering necessary to pick out the names from the
comment
# field and email the managers requesting status of the user.
################################################################################
foreach $line (@password)
{
( $login, $pass, $uid, $gid, $Comm, $dir, $shell ) = split
(/:/, $line);
@User = split (/,/, $Comm);
if (1 == scalar ( @User ))
{
next;
}
if ( $Comm eq "" )
{
next;
}
print "login=$login User=@User\n";
if ( 1 != grep ( /$login/, @exuser ) )
{
chomp ( $hostname );
open( MAIL, "| /bin/mailx -s \"User Access\" -U $User[1]\@hotmail.com"
);
print MAIL <<"_END_OF_FILE_";
Does $User[0] still require access to server $hostname?
Please respond to my Team.
_END_OF_FILE_
}
}
Any help would be appreciated...
thanks,
bob
------------------------------
Date: Wed, 11 Jul 2001 00:03:17 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: help on arrays
Message-Id: <3B4B980E.C1E7D41C@acm.org>
bob wrote:
>
> Hello list, I need some help on this little perl script I put
> together. My script parses the /etc/passwd file and emails the
> manager of each user in the file. My script works fine but now I need
> to refine it to where it sends 1 mail to the manager with all of the
> users identified as his. I am at a dead end.
>
> this assumes the passwd file is formatted like this..
> where big.cheese=manager
>
> bob:x:1001:10:bob.bohica,big.cheese,4449999:/export/home/bob:/bin/ksh
^^^^^^
Are you by chance in the military or ex-military?
> here is the code...
> #!/usr/bin/perl
#!/usr/bin/perl -w
use strict;
> #
> ############################################################################
> open(OUTPUT, "hostname|") || die "Can't stat hostname";
> $hostname=<OUTPUT>;
> close(OUTPUT);
You can simplify that to (and you won't need the chomp later on):
chomp( my $hostname = `hostname` );
> ############################################################################
> # setup array of excluded system users
> ############################################################################
> @exuser= ("root", "daemon", "bin", "sys", "adm", "lp", "uucp",
> "nuucp", "listen", "nobody", "noaccess", "nobody4");
There is a different quoting mechanism that looks better in this case:
my @exuser = qw(root daemon bin sys adm lp uucp nuucp listen nobody
noaccess nobody4);
> ############################################################################
> # read passwd file into array so weez can chunkonit
> ############################################################################
> open (F, "/etc/passwd") || die "Could not open passwd file: $:";
> @password=<F>;
my @password = <F>;
> ################################################################################
> # perform the magic filtering necessary to pick out the names from the
> comment
> # field and email the managers requesting status of the user.
> ################################################################################
>
> foreach $line (@password)
> {
> ( $login, $pass, $uid, $gid, $Comm, $dir, $shell ) = split
> (/:/, $line);
> @User = split (/,/, $Comm);
>
> if (1 == scalar ( @User ))
> {
> next;
> }
> if ( $Comm eq "" )
> {
> next;
> }
> print "login=$login User=@User\n";
>
> if ( 1 != grep ( /$login/, @exuser ) )
> {
> chomp ( $hostname );
> open( MAIL, "| /bin/mailx -s \"User Access\" -U $User[1]\@hotmail.com"
> );
> print MAIL <<"_END_OF_FILE_";
> Does $User[0] still require access to server $hostname?
> Please respond to my Team.
> _END_OF_FILE_
> }
> }
my $exuser_lookup = '(' . join( '|', @exuser ) . ')';
my @all_users;
foreach ( @password ) {
my ( $login, $Comm ) = (split /:/)[0,4];
next if $login =~ /^$exuser_lookup$/;
next unless length $Comm and $Comm =~ /\bbig\.cheese\b/;
my @User = split /,/, $Comm;
print "login=$login User=@User\n";
push @all_users, $User[0];
}
open MAIL, '| /bin/mailx -s "User Access" -U big.cheese\@hotmail.com" or
die "Cannot open a pipe to mailx: $!";
print MAIL <<"_END_OF_FILE_";
Do the following users still require access to server $hostname?
@all_users
Please respond to my Team.
_END_OF_FILE_
close MAIL or die "Cannot close pipe to mailx: $!";
John
--
use Perl;
program
fulfillment
------------------------------
Date: Tue, 10 Jul 2001 18:03:46 -0700
From: "$Bill Luebkert" <dbe@wgn.net>
Subject: Re: help on arrays
Message-Id: <3B4BA5F2.51C37F29@wgn.net>
bob wrote:
>
> Hello list, I need some help on this little perl script I put
> together. My script parses the /etc/passwd file and emails the
> manager of each user in the file. My script works fine but now I need
> to refine it to where it sends 1 mail to the manager with all of the
> users identified as his. I am at a dead end.
>
> this assumes the passwd file is formatted like this..
> where big.cheese=manager
>
> bob:x:1001:10:bob.bohica,big.cheese,4449999:/export/home/bob:/bin/ksh
>
> here is the code...
> #!/usr/bin/perl
> #
> ############################################################################
> open(OUTPUT, "hostname|") || die "Can't stat hostname";
> $hostname=<OUTPUT>;
> close(OUTPUT);
> ############################################################################
> # setup array of excluded system users
> ############################################################################
> @exuser= ("root", "daemon", "bin", "sys", "adm", "lp", "uucp",
> "nuucp", "listen", "nobody", "noaccess", "nobody4");
> ############################################################################
> # read passwd file into array so weez can chunkonit
> ############################################################################
> open (F, "/etc/passwd") || die "Could not open passwd file: $:";
> @password=<F>;
> ################################################################################
> # perform the magic filtering necessary to pick out the names from the
> comment
> # field and email the managers requesting status of the user.
> ################################################################################
my %cheeses;
> foreach $line (@password)
> {
> ( $login, $pass, $uid, $gid, $Comm, $dir, $shell ) = split
> (/:/, $line);
> @User = split (/,/, $Comm);
>
> if (1 == scalar ( @User ))
> {
>
> next;
>
> }
>
> if ( $Comm eq "" )
> {
> next;
> }
>
> print "login=$login User=@User\n";
>
> if ( 1 != grep ( /$login/, @exuser ) )
> {
push @{$cheeses{$User[1]}}, $User[0];
}
> chomp ( $hostname );
foreach (keys %cheeses) {
foreach (@{$cheeses{$_}}) {
open MAIL, "| /bin/mailx -s \"User Access\" -U $_\@hotmail.com";
print MAIL <<"_END_OF_FILE_";
Do @{$cheeses{$_}} still require access to server $hostname?
Please respond to my Team.
_END_OF_FILE_
}
I think everything is near where it should be.
--
,-/- __ _ _ $Bill Luebkert ICQ=14439852
(_/ / ) // // DBE Collectibles Mailto:dbe@todbe.com
/ ) /--< o // // http://dbecoll.webjump.com/ (Free Perl site)
-/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/
------------------------------
Date: Tue, 10 Jul 2001 22:07:56 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: help on arrays
Message-Id: <slrn9knd7s.c8f.tadmc@tadmc26.august.net>
John W. Krahn <krahnj@acm.org> wrote:
>bob wrote:
>>
>> My script works fine but now I need
>> to refine it to where it sends 1 mail to the manager with all of the
>> users identified as his. I am at a dead end.
>>
>> this assumes the passwd file is formatted like this..
>> where big.cheese=manager
>>
>> bob:x:1001:10:bob.bohica,big.cheese,4449999:/export/home/bob:/bin/ksh
> ^^^^^^
>Are you by chance in the military or ex-military?
Yuck yuck. I was going to ask the same thing.
There is a Long, Grey and Underway in my past.
>> here is the code...
>> #!/usr/bin/perl
>
>#!/usr/bin/perl -w
>use strict;
"Don't forget to enable warnings and strictures even when you're not
writing in Perl. It's *that* important."
:-)
>> ############################################################################
>> open(OUTPUT, "hostname|") || die "Can't stat hostname";
>> $hostname=<OUTPUT>;
>> close(OUTPUT);
>
>You can simplify that to (and you won't need the chomp later on):
>chomp( my $hostname = `hostname` );
Or at least check the return value from close():
close(OUTPUT) or die "problem running hostname $!";
and don't mislead with that earlier diagnostic message:
open(OUTPUT, "hostname|") || die "Can't fork for hostname";
and see the Perl FAQ, part 8:
"Why doesn't open() return an error when a pipe open fails?"
Hmmm. Maybe backticks was better after all...
>> ############################################################################
>> # read passwd file into array so weez can chunkonit
>> ############################################################################
>> open (F, "/etc/passwd") || die "Could not open passwd file: $:";
>> @password=<F>;
>my @password = <F>;
You should close() the filehandle now that you are done with it.
Depending on autoclose cost me 6 hours of troubleshooting once...
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 10 Jul 2001 19:46:24 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: Help with Rewriting Application in OO Perl
Message-Id: <3B4B93D0.D2E8B189@earthlink.net>
Chris Fedde wrote:
>
> In article <3B306059.923F27DF@earthlink.net>,
> Benjamin Goldberg <goldbb2@earthlink.net> wrote:
> >Chris Fedde wrote:
[snip]
> >Is there a reason to use (?xo) instead of /x? There certainly isn't
> >any reason to be using the /o modifyer here, as there's no
> >interpolation going on.
>
> I use /o much as I might put in the trailing comma in a list.
> or a trailing semicolon in a block. It does no harm and prevents
> problems with some kinds of future modifications.
And what happens if you *want* to do a match with interpolation of a
changing variable? The /o would it keep matching the first value the
variable had. Also, I'd like to know why you use (?modifiyer) rather
than /modifyer.
[snip]
> >> my ($sec, $min, $hr, $day) = reverse (split (/[+:]/, $delay));
> >
> >What's wrong with:
> > my ($day, $hr, $min, $sec) = split /[+:]/, $delay, 4;
> >
>
> Perhaps you did not notice that day is sometimes absent from the
> sendmail ?delay= equates. Your form would put $hour into $day and
> leave $sec empty in most cases.
Ouch, I didn't know that. Maybe your code should have a comment
mentioning that fact, to show why you do it with the reverse?
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Tue, 10 Jul 2001 13:08:51 GMT
From: u518615722@spawnkill.ip-mobilphone.net
Subject: help: How do you call a PL/SQL in a perl script?
Message-Id: <l.994770531.1319854736@[198.138.198.252]>
I need to call a PL/SQL in my perl scripts.
For instance,
--------------------------------------------------------
#!/usr/local/bin/perl
use strict;
use DBI;
my $dbh = DBI->connect ( 'dbi:Oracle:test',
'user1',
'passwd1',
{
PrintError => 0,
RaiseError => 0
}
) || die "Database Connection not made $DBI::errstr" ;
# create tables A
my $sql = qq{ drop table A};
$dbh->do ( $sql );
my $sql = qq{ create table A(
col1 varchar2(10) tablespace users};
$dbh->do ( $sql );
NEED TO KNOW HOW TO CALL THE FOLLOWING PL/SQL.
$dbh->disconnect();
-----------------------------------------------------------------
The next step is to use a loop to insert values into table A, which we
use a PL/SQL.
DECLARE
sensor_rec sensor%ROWTYPE;
loop_counter NUMBER(12) := 0;
max_archive_id NUMBER(12);
min_prod_id NUMBER(12);
CURSOR PROD2 is
select * from B;
BEGIN
FOR sensor_rec IN PROD2 LOOP
loop_counter := loop_counter + 1;
insert into A
values (prod2.col1);
if loop_counter > 200 then
loop_counter := 0;
commit;
end if;
END LOOP;
END;
could somebody tell me how I can combine those two together?
Thanks for your help.
--
Sent by dbadba62 from hotmail subdomain of com
This is a spam protected message. Please answer with reference header.
Posted via http://www.usenet-replayer.com/cgi/content/new
------------------------------
Date: 10 Jul 2001 15:49:41 -0700
From: keith@aztek-eng.com (Keith)
Subject: Re: How do I spawn an xterm executing another program and then interact with the executed program with Expect.pm
Message-Id: <8683bf68.0107101449.5aaa4628@posting.google.com>
keith@aztek-eng.com (Keith) wrote in message news:<8683bf68.0106151259.f0fac1c@posting.google.com>...
> This is what I want to do:
> Run a perl script from one xterm that execs another xterm and then automates
> the program running in the new xterm using Expect.pm module.
>
> Expect normally works with programs that read from standard input or
> /dev/tty and xterms don't read their input in this manner; therefore , I
> believe something fancy has to be done with the IO::Pty module and the xterm
> '-S' option to get the Perl program with Expect.pm and the external xterm
> application communicating.
>
> I am relatively proficient in perl with Expect.pm, but my understanding of pseudo
> terminals, pty, tty, ... is limited. Can anyone help?
>
> Thanks,
> Keith
I need to spawn and interface multiple program at once. These
programs will be interfacing with each other via sockets. I need
something to drive the otherwise manual interfacing, to the multiple
programs running in multiple xterms.
Example:
I want to use Expect.pm to exec an xterm and then exec a rtos
simulation shell in the xterm. I will then need to load a protocol
stack and run it within the rtos simulation enviroment. I would like
to run scripted tests via a perl test harness against the protocol
stack ( currently running in its own xterm and interface via sockets
to the protocol stack ). I also need to simulate a management system
via input API calls controlled currently with by a C program running
in a 3rd xterm. I wanted to use Expect to controll all of this
functionality from a central driving terminal.
Anyone have any ideas?
------------------------------
Date: Tue, 10 Jul 2001 20:16:14 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: How do I spawn an xterm executing another program and then interact with the executed program with Expect.pm
Message-Id: <3B4B9ACE.5DDBA744@earthlink.net>
Keith wrote:
[snip]
> I need to spawn and interface multiple program at once. These
> programs will be interfacing with each other via sockets. I need
> something to drive the otherwise manual interfacing, to the multiple
> programs running in multiple xterms.
> Example:
> I want to use Expect.pm to exec an xterm and then exec a rtos
> simulation shell in the xterm. I will then need to load a protocol
> stack and run it within the rtos simulation enviroment. I would like
> to run scripted tests via a perl test harness against the protocol
> stack ( currently running in its own xterm and interface via sockets
> to the protocol stack ). I also need to simulate a management system
> via input API calls controlled currently with by a C program running
> in a 3rd xterm. I wanted to use Expect to controll all of this
> functionality from a central driving terminal.
>
> Anyone have any ideas?
Xterm will take a commandline argument for a program for it to execute.
So spawn the xterm and have *it* start rtos, or rather a seperate perl
program which uses expect to run rtos.
for my $extra_params (@rtos_params) {
next if fork;
exit if fork;
close $_ for *STDIN, *STDOUT, *STDERR;
exec "xterm", @xterm_params, "-e",
"perl", "runs_rtos_with_expect.pl",
@$extra_params;
}
The program which runs this should have an AF_UNIX listen socket which
each of the runs_rtos_with_expect scripts connect to; these connections
are then what the spawned scripts use to chat with the central script.
The reason I suggest unix sockets is it allows IPC without needing to to
establish pipes beforehand (which xterm would probably close when it
execs perl) and without allowing other machines than the one you're on
to interact [read: interfere] with the simulations.
Of course, if you *want*, you certainly can use AF_INET sockets... doing
so will allow you to distribute the load by replacing the exec of
"xterm", ... with an exec of "rsh", "user@host", "xterm", ...
Either way, you will need to pass the listen address, whether it's a
filename (as in the unix socket) or a host:port (as in the inet socket).
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: 9 Jul 2001 13:43:44 -0700
From: redsquirreldesign@yahoo.com (Dave Hoover)
Subject: Re: How I came to love Perl...
Message-Id: <812589bb.0107091243.500b9ac7@posting.google.com>
Lou wrote:
> --I get an Apple IIe in 1985, and A500 in 1987.
Wasn't the Apple IIe the greatest!? That was my first computer. I
tried to learn BASIC, but it was too hard to make all the cool games I
dreamed about making.
> --After 2 years of working I go to college fully prepared to leave an
> English teacher. While there I join the school newspaper and end up
> "fixing" the computers constantly. I graduate with an English Degree,
> a History degree a Linguistics minor and a Communications BS (it's a
> long story.)
I have a BA in Psychology and a MS in Marriage & Family Therapy (a
_very_ long story).
> --I end up finding out that I am making A LOT more at Coctco than I
> can as a first year teacher. I am still fixing computers. I decide
> "This Java sounds like a good idea." I buy two Java books. They
> still look like new. I am too stupid to learn Java.
I have two jobs, full-time therapist & part-time About.com Guide. I
grow to enjoy working with the WWW. I bought 'Java for Dummies.' After
three attempts, I gave up.
> --I get a job (after some time in the field) as a Network Guy (really
> was my title.) I find I need scripting to keep my sanity. I am
> running NT I use NT Shell Scripting and KiXart. I hear about this
> Perl a lot.
After teaching myself HTML, I get a job with a tech company.
Eventually they ask me to learn Perl.
> --I start learning Perl. It's great. I love everything about it.
Perl was love at first site...head over heels.
> --I still want to learn Java. I "decide" that if I get up to speed
> with "C" I can then move onto Java. (At this point I have to admit I
> don't even know why I want to learn Java anymore, but that's not
> important now... here comes the epiphany.)
I still want to learn Java (just for the challenge).
> --So inconclusion I fell in love with Perl b/c _for me_ it's all about
> words, text and data with which I am particularly comfortable.
I think I fell in love with Perl because it has a shallow learning
curve, which is very important when it's your first language and
you're teaching yourself! What keeps me hooked on Perl is its culture
and the many experts I greatly admire (Larry, Randal, Lincoln, to
name a few).
It's fun to hear about how other people come to love Perl...especially
when the paths that brought us to it have some similarities!
--
Dave Hoover
"Twice blessed is help unlooked for." --Tolkien
http://www.redsquirreldesign.com/dave
------------------------------
Date: Mon, 09 Jul 2001 22:00:42 GMT
From: tim@vegeta.ath.cx (Tim Hammerquist)
Subject: Re: How I came to love Perl...
Message-Id: <slrn9kkb2o.4io.tim@vegeta.ath.cx>
[ Majority of article snipped. ]
Dave Hoover <redsquirreldesign@yahoo.com> wrote:
> I still want to learn Java (just for the challenge).
The biggest challenge Java ever provided me (having been through the C++
gauntlet) was having the _time_ to satisfy all the pragmas.
--
-Tim Hammerquist <timmy@cpan.org>
Perl gives you enough rope to hang yourself and your neighbor.
-- Randal L. Schwartz
------------------------------
Date: Tue, 10 Jul 2001 13:25:02 -0400
From: Lou Moran <lmoran@wtsg.com>
Subject: Re: How I came to love Perl...
Message-Id: <tiemkt0lvgrq2ssrru86f30h6ukvajehe3@4ax.com>
On Wed, 4 Jul 2001 12:16:27 +0930, "Wyzelli" <wyzelli@yahoo.com> wrote
wonderful things about sparkplugs:
>Once I acquired 'Elements of Programming with Perl' by Andrew Johnson a
>whole lot of stuff suddenly clicked, and now I can write programs to save my
>life. There is still a lot of stuff I don't get (hardly ever use map and
>grep or dbi) but I am now understanding OOP (Damian Conway's book is really
>good).
>
>I read programming manuals like novels, which makes people look at me rather
>strangely, but that whole text vs maths things was the big epiphany for me
>too.
>
>Anyway, I still consider myself a 'hardware tech' but can look at programs
>without being put off now.
>
>Oh, and I LOVE Perl
ACK! You're living my life!
------------------------------
Date: 10 Jul 2001 22:56:42 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: How I came to love Perl...
Message-Id: <slrn9kn21p.g6k.damian@puma.qimr.edu.au>
Lou Moran chose Tue, 03 Jul 2001 09:53:12 -0400 to say this:
>--Quick background...
>
>--I get an Apple IIe in 1985, and A500 in 1987.
I got an Atari 800 in about 1984 -- with BASIC on a ROM cartridge. Gave up
in disgust after the tape drive packed it in a year or so later.
>--After 2 years of working I go to college fully prepared to leave an
>English teacher. While there I join the school newspaper and end up
>"fixing" the computers constantly. I graduate with an English Degree,
>a History degree a Linguistics minor and a Communications BS (it's a
>long story.)
Dude, you ARE me. I majored in english and cultural anthropology, with a
number of extra units in stuff like linguistics, philosophy, geology and
even first-year maths. I NEVER studied CS, though these days I often think
about going back and doing that. I started working at Uni as a Mac support
guy after doing the student newspaper thing. Since it was a big Sun site, I
quickly got into first SunOS then Solaris sysadmin, and have never looked
back. For years, I would say I was either a sysadmin or an IT support guy,
but NOT a programmer. I picked up Perl in bits and pieces over the years
(along with shell stuff), but eventually sat down with the Camel book and
basically taught myself to program from that. These days my job title
actually has 'developer' in it :-).
Yes, and I love Perl, too. I keep meaning to have a go at picking up C,
Java, Python, Lisp and even Haskell (yes, I have Lisp and Python interpreters
on my Palm -- one day I'd like to see perl there too), but never seem to
find the time.
Cheers,
Damian
------------------------------
Date: 09 Jul 2001 17:57:23 +0200
From: Walter Hafner <hafner-usenet@ze.tu-muenchen.de>
Subject: Re: I know this must be in the manpages... number formatting
Message-Id: <srjsng6m6xo.fsf@w3proj1.ze.tu-muenchen.de>
elwood@news.agouros.de (Konstantinos Agouros) writes:
> In <3B462B4A.F13B9FC@home.com> Michael Carman <mjcarman@home.com> writes:
>
> >Konstantinos Agouros wrote:
> >>
> >> I might be blind, but what I am looking for is some way to print
> >> larger integer numbers with digits (german way)
> >> [...]
> >> I played around with printf but couldn't find the trick...
>
> >It's not a printf() option. Look at perlfaq5 "How can I output my
> >numbers with commas added?" and adapt it to use dots instead of commas.
> >Or, use it as is and whack it with tr/.,/,./ afterwards.
> But it really has to be done by regexps... ?
> The C-Printf with localesupport seems to be able to do this... But ok
> I go with approach...
Try
s/(\d)(?=(\d{3})+$)/$1\./g;
-Walter
------------------------------
Date: Tue, 10 Jul 2001 22:07:34 GMT
From: tuxy <ns@cfl.rr.com>
Subject: I'm starting to think our 5.6 install is braindead
Message-Id: <3B4B7D76.4DE96B45@cfl.rr.com>
OK, I'm in the debugger (perl -wd) and I'm examining a scalar. Watch and
be amused:
91: $c += 2;
DB<55> x $c
0 106
DB<56> x $c+2
0 108
DB<57> s
doctorLine(x.pm:93):
93: s/^(\s*TEST\s+)\S+$/$1$c/;
DB<57> x $c
0 0
Wow. So line 91 is add 2 to $c. Prior to stepping thru that line, $c is
106, and I can do arithmetic on it. I step thru line 91 and voila', $c
is now 0. It doesn't matter what arithmetic I do- any math on C seems to
make it 0.
I could not duplicate this in a small testcase so I can't give you code
to try. Its only in this program. But HOW could this happen? Is my
install braindead? $c is assigned in a sub something like this:
.
.
my $c=ax();
.
.
sub ax
{my @l=<F>;
my $x=@l-1;
return $x;
}
Which doesn't look too exotic to me but perhaps I'm missing something?
Maybe @l is getting clobbered by garbage collection and somehow I'm
loosing the return value? I thought as long as I ref'ed it it would stay
alive..
------------------------------
Date: Wed, 11 Jul 2001 06:57:38 +0200
From: Philip Newton <pne-news-20010711@newton.digitalspace.net>
Subject: Re: I'm starting to think our 5.6 install is braindead
Message-Id: <pgmnktomrnq81skiigbg4lpjsqmp4nhih7@4ax.com>
On Tue, 10 Jul 2001 22:07:34 GMT, tuxy <ns@cfl.rr.com> wrote:
> OK, I'm in the debugger (perl -wd) and I'm examining a scalar. Watch and
> be amused:
>
>
> 91: $c += 2;
> DB<55> x $c
> 0 106
> DB<56> x $c+2
> 0 108
> DB<57> s
> doctorLine(x.pm:93):
> 93: s/^(\s*TEST\s+)\S+$/$1$c/;
> DB<57> x $c
> 0 0
>
> Wow. So line 91 is add 2 to $c. Prior to stepping thru that line, $c is
> 106, and I can do arithmetic on it. I step thru line 91 and voila', $c
> is now 0. It doesn't matter what arithmetic I do- any math on C seems to
> make it 0.
WAG: $c is block scoped and the block ends on line 92. Can you post,
say, lines 80-95 of that program?
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Tue, 10 Jul 2001 13:40:09 +0100
From: Mark Grimshaw <m.grimshaw@salford.ac.uk>
Subject: lexical ordering of hash keys with $DB_BTREE not working
Message-Id: <3B4AF7A9.30AC8EE9@salford.ac.uk>
Hi all,
Anyone got ideas why I don't get a lexical ordering of the hash keys
when using this code?:
#!/usr/local/bin/perl
use strict;
use diagnostics;
use DB_File;
use Fcntl qw(:flock);
my (%hash, $key, $value);
tie(%hash, 'DB_File', undef, O_RDWR|O_CREAT, $DB_BTREE) or die "cannot
create hash: $!";
foreach $key(keys %ENV)
{
$hash{$key} = $ENV{$key}
}
while (($key, $value) = each %hash)
{
print "$key: $value\n"
}
print "\n";
untie %hash;
undef %hash;
exit;
------------------------------
Date: Tue, 10 Jul 2001 13:48:44 +0100
From: Mark Grimshaw <m.grimshaw@salford.ac.uk>
Subject: Re: lexical ordering of hash keys with $DB_BTREE not working
Message-Id: <3B4AF9AC.22F803B3@salford.ac.uk>
Mark Grimshaw wrote:
>
> Hi all,
>
> Anyone got ideas why I don't get a lexical ordering of the hash keys
> when using this code?:
>
> #!/usr/local/bin/perl
> use strict;
> use diagnostics;
> use DB_File;
> use Fcntl qw(:flock);
> my (%hash, $key, $value);
>
> tie(%hash, 'DB_File', undef, O_RDWR|O_CREAT, $DB_BTREE) or die "cannot
> create hash: $!";
> foreach $key(keys %ENV)
> {
> $hash{$key} = $ENV{$key}
> }
> while (($key, $value) = each %hash)
> {
> print "$key: $value\n"
> }
> print "\n";
> untie %hash;
> undef %hash;
> exit;
Never mind - sorted. I'd missed out a flag in the tie() - should've
been:
tie(%hash, 'DB_File', undef, O_RDWR|O_CREAT, 0, $DB_BTREE) or....;
------------------------------
Date: Mon, 09 Jul 2001 12:23:10 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: list program fails depending on directory?
Message-Id: <3B49DA6E.C3B78AE2@earthlink.net>
Mark Stellaard wrote:
>
> Smeh Larat wrote in message ...
> >I have rewritten it with the error fixed it works a treat in the
> >e:/perl directory. It also works great on my c:/program files
> >directory.
> >
> >However when I tried e: it choked totally. When I tried c: I got the
> >temp directory and command .com, is the root of a drive a speacial
> >case?
> >
> >
>
> I also found the folllowing piece of code in the
> comp.lang.perl.modules:
> Maybe it's interesting for you ; - )
>
> sub process_directory {
> my ($path) = @_;
>
> # get all of the names from the directory, excluding "." and ".."
> local (*DIR);
> opendir (DIR, $path) || die "can't open directory $path: $!";
> my @names = grep (!/^\.\.?$/, readdir DIR);
> closedir DIR;
Note that DIR is still this local one through the end of the scope. So
if process_file wants to use the DIR which was defined before this block
was entered, it won't be able to.
>
> # the sort is optional
> for (sort @names) {
> my $temp = "$path/$_";
> if (-d $temp) {
> &process_directory ($temp);
> } else {
> &process_file ($temp);
> }
> }
> }
Using & for sub calls is deprecated unless you really intend to use the
special meaning it provides.
>
> sub process_file {
> my ($path) = @_;
>
> # whatever ...
>
> }
I would write it as:
sub deep_process_dir {
my ($code, $dir) = @_;
for ( sort grep !/^\.\.?$/, do {
opendir my $dirh, $dir
or die "Couldn't opendir $dir: $!\n";
readdir $dirh;
} ) {
substr($_,0,0,$dir."/");
local $_[1] = $_;
-d ? &process_directory : &$code;
}
}
deep_process_dir sub {
(undef, my ($path, @stuff)) = @_; local $" = ", ";
print "Processing file $path with args @stuff\n" }, "c:";
NB this code is untested.
--
The longer a man is wrong, the surer he is that he's right.
------------------------------
Date: Tue, 10 Jul 2001 11:19:08 -0700
From: Dirk Wessner <wessner@hps.fzk.de>
Subject: Name Space Question
Message-Id: <3B4B471C.3801C848@hps.fzk.de>
Hello to all.
I would like to call a subroutine in a Perl-Module
used by my main Script. But this subroutine shall
call a subroutine defined within the main script.
How do I do that?
e.g.:
#!/usr/bin/perl
use MyModul;
sub main_sub
{...}
MyModul::modul_sub();
------------------------------------------------
package MyModul;
...
sub modul_sub
{
call main_sub somehow...
}
Thanks in advance,
Dirk Wessner
------------------------------
Date: Tue, 10 Jul 2001 18:33:36 +1000
From: "Ron Savage" <ron@savage.net.au>
Subject: Re: Name Space Question
Message-Id: <18z27.89560$Rr4.126670@ozemail.com.au>
Dirk
See below.
--
Cheers
Ron Savage
ron@savage.net.au
http://savage.net.au/index.html
Dirk Wessner <wessner@hps.fzk.de> wrote in message news:3B4B471C.3801C848@hps.fzk.de...
> Hello to all.
>
> I would like to call a subroutine in a Perl-Module
> used by my main Script. But this subroutine shall
> call a subroutine defined within the main script.
>
> How do I do that?
Try (tested code):
-----><8-----
#!/usr/bin/perl
use integer;
use strict;
use warnings;
sub s1
{
print "main::s1 called via P::s2. \n";
}
package P;
sub s2
{
my($sub_ref) = @_;
&$sub_ref();
}
package main;
P::s2(\&s1);
-----><8-----
------------------------------
Date: Tue, 10 Jul 2001 11:35:10 +0100
From: Malte Ubl <ubl@schaffhausen.de>
Subject: Re: Name Space Question
Message-Id: <3B4ADA5E.BFBD9FB2@schaffhausen.de>
Dirk Wessner schrieb:
>
> Hello to all.
>
> I would like to call a subroutine in a Perl-Module
> used by my main Script. But this subroutine shall
> call a subroutine defined within the main script.
the sub resides in the default package main so you can call
it via main::my_sub(). This will work unless you are playing
with mod_perl where your scipt is executed in a special name
space.
->malte
------------------------------
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 1276
***************************************