[23905] in Perl-Users-Digest
Perl-Users Digest, Issue: 6107 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Feb 10 11:05:53 2004
Date: Tue, 10 Feb 2004 08:05:06 -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, 10 Feb 2004 Volume: 10 Number: 6107
Today's topics:
Re: (quickie) print in place? <bmb@ginger.libs.uga.edu>
A non-loop block early exit? (Sara)
Re: A non-loop block early exit? <jwillmore@remove.adelphia.net>
Re: A non-loop block early exit? <noreply@gunnar.cc>
Re: Anyone using Berkley XML DB w/Perl (of course)...? <usenet@morrow.me.uk>
Re: Array size <remorse@partners.org>
Re: build_dir/perl uses /usr/lib/perl !? <usenet@morrow.me.uk>
Comparing a string to filenames in a directory (nj_perl_newbie)
Re: Comparing a string to filenames in a directory <jurgenex@hotmail.com>
Re: How to execute a command line in Perlscript <ceo@nospan.on.net>
How2 prevent perl's searching "std directories"? <nomail@please.com>
Re: How2 prevent perl's searching "std directories"? <usenet@morrow.me.uk>
Re: How2 prevent perl's searching "std directories"? <nomail@please.com>
Re: How2 prevent perl's searching "std directories"? <nomail@please.com>
Re: How2 prevent perl's searching "std directories"? <nomail@please.com>
Re: Matching strings with index – getting extra m (G)
Re: Matching strings with index – getting extra m <usenet@morrow.me.uk>
Re: memory profiling <j.g.karssenberg@student.utwente.nl>
Re: memory profiling <usenet@morrow.me.uk>
Re: script working like daemon <jwillmore@remove.adelphia.net>
Re: Why references?? <usenet@morrow.me.uk>
Re: Why references?? <jurgenex@hotmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 10 Feb 2004 09:58:39 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: (quickie) print in place?
Message-Id: <Pine.A41.4.58.0402100954410.27212@ginger.libs.uga.edu>
On Mon, 9 Feb 2004, Damian wrote:
> was wondering how exactly do you print(...) in place? Like the percent
> counter for installers like linux's rpm. In other words so the output
> keeps going to the same spot in stead of advancing the cursor.
>
> If this is something only on Linux/Unix thats fine, as thats the only
> place I really need to do this. Though portability never hurts.
>
You've gotten answers that are surely more correct and more portable, but
I typically use this technique for "quickie" progress reporting:
perl -e '$|++;for(1..10){printf "%6d%s", $_, "\b"x6; sleep 1}'
Yes, it suffers from the same problems you mentioned re \r.
Regards,
Brad
------------------------------
Date: 10 Feb 2004 06:30:48 -0800
From: genericax@hotmail.com (Sara)
Subject: A non-loop block early exit?
Message-Id: <776e0325.0402100630.7c92a444@posting.google.com>
Can I exit a block early, as "last" operator does in a loop? Such as:
unless ($catsHaveWings)
{..do stuff
"escape" if $dogsHaveFins;
.. do more stuff
}
# I want "escape" to reenter HERE
.
.
.
I tried next and last operators and predictably they jump out of the
whole sub, not just the block or bareblock.
Thank-You for assistance.
------------------------------
Date: Tue, 10 Feb 2004 10:12:14 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: A non-loop block early exit?
Message-Id: <pan.2004.02.10.15.12.12.877187@remove.adelphia.net>
On Tue, 10 Feb 2004 06:30:48 -0800, Sara wrote:
> Can I exit a block early, as "last" operator does in a loop? Such as:
>
>
> unless ($catsHaveWings)
> {..do stuff
> "escape" if $dogsHaveFins;
> .. do more stuff
> }
> # I want "escape" to reenter HERE
> .
> .
> .
>
> I tried next and last operators and predictably they jump out of the
> whole sub, not just the block or bareblock.
One option is to put the block into a subroutine and use 'return'.
sub check_animal{
unless ($catsHaveWings)
{..do stuff
return undef if $dogsHaveFins;
.. do more stuff
}
return 1;
}
This allows you to also evaluate the 'return' value and then do something
else in your main script.
For eaxmple
....
print "Cats do have wings\n" if check_animal();
...
-or-
...
if(defined check_animal()){
print "Animals\n";
}else{
print "Zoo is empty\n";
}
...
That's just one way to do it.
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
Make it myself? But I'm a physical organic chemist!
------------------------------
Date: Tue, 10 Feb 2004 16:13:51 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: A non-loop block early exit?
Message-Id: <c0asie$14m068$1@ID-184292.news.uni-berlin.de>
Sara wrote:
> Can I exit a block early, as "last" operator does in a loop?
> Such as:
>
> unless ($catsHaveWings)
> {..do stuff
> "escape" if $dogsHaveFins;
> .. do more stuff
> }
> # I want "escape" to reenter HERE
You can do:
unless ($catsHaveWings) {
MYBLOCK: {
..do stuff
last MYBLOCK if $dogsHaveFins;
.. do more stuff
}
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Tue, 10 Feb 2004 14:17:17 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Anyone using Berkley XML DB w/Perl (of course)...?
Message-Id: <c0ap5d$95u$1@wisteria.csv.warwick.ac.uk>
"Paul Marquess" <paul.marquess@btinternet.com> wrote:
> "Ben Morrow" <usenet@morrow.me.uk> wrote in message
> news:c097lg$ajg$2@wisteria.csv.warwick.ac.uk...
> >
> > Vetle Roeim <vetro@online.no> wrote:
> > > * ceo@nospan.on.net
> > > You're not going to find it on CPAN, unfortunately. To install it, I
> > > downloaded the source code, compiled it, and then installed the Perl
> > > module from dbxml-1.2.0/src/perl.
> >
> > Having taken a look at that: bleech.
>
> Thanks for the constructive feedback Ben. :-)
Sorry, that was a little rude... :(.
> Seriously though, I'd be interested to hear in a bit more detail what you,
> and anoyone else in this thread, think about the current interface, both
> good and bad. To date, this is the first negative feedback I've received.
>
> > Is it *quite* necessary to
> > trample on that many different (including top-level and pragmatic)
> > namespaces?
>
> Yes. There are quite a few objects exposed by the dbxml interface. If you
> want those C++ objects to map to Perl objects, you need a namespace for
> each.
Yes, but you don't need to give them the same names as the C++ classes
had. What happens if someone's using another XML module as well (not
at all unlikely), and that happened to also define the package
XmlDocument?
Indeed, the C++ classes are all in the namespace DbXml, which will
keep them from conflicting with any other XmlDocument class people
might be using. I would have given the classes names like
DB::XML::Container, and kept all the names below DB::XML, or
something.
> I didn't think I was reusing any pragmatic namespaces - which are you
> thinking of?
std::exception. All lower-case top-level namespaces are reserved for
pragmata. The whole exception-handling logic seems unnecessarily
complex: what's wrong with
package DB::XML::Exception;
our @EXPORT = qw/catch/;
sub catch {
my $type = shift;
UNIVERSAL::isa($@, __PACKAGE__) and $@->{type} eq $type
and return $@;
return;
}
package main;
eval {
...
}
if (my $e = catch 'DbException') {
...
}
or
if (ref $@ and $a->isa(DB::XML::X::DbDeadlock)) {
or even
if ($@ and $!{EDEADLK}) {
, which I at least find much more Perlish? The mapping seems pretty
clear:
DbDeadlockException EDEADLK
DbException is never thrown
DbLockNotGrantedException EWOULDBLOCK
DbRunRecoveryException EINVAL
etc. XmlException could probably just throw a string.
I realise this means you can't just get the typemap to do all the work
:).
> > And is it really necessary to have the interface be so C++ish?
>
> Well it is an interface to a C++ library after all :-)
True... your BerkeleyDB module, though, provides a much more Perl-ish
interface to the C db libraries.
> > You may be better off writing your own wrapper: it shouldn't be *that*
> > hard...
>
> Absolutely, TMTOWTDI.
Well, yes :).
Ben
--
Musica Dei donum optimi, trahit homines, trahit deos. |
Musica truces molit animos, tristesque mentes erigit. | ben@morrow.me.uk
Musica vel ipsas arbores et horridas movet feras. |
------------------------------
Date: Tue, 10 Feb 2004 09:29:34 -0500
From: Richard Morse <remorse@partners.org>
Subject: Re: Array size
Message-Id: <remorse-AE8FA9.09293410022004@plato.harvard.edu>
In article <m2r7x3ao7a.fsf@gw.dd-b.net>,
David Dyer-Bennet <dd-b@dd-b.net> wrote:
> "gnari" <gnari@simnet.is> writes:
> > did you try $#$f ?
>
> No, but I'm quite sure it's not in the man pages anywhere, because I
> looked at all the $# hits, and didn't find it.
$ perldoc perlintro
...
/array
/
> An array represents a list of values:
>
> my @animals = ("camel", "llama", "owl");
> my @numbers = (23, 42, 69);
> my @mixed = ("camel", 42, 1.23);
>
> Arrays are zero-indexed. Here's how you get at elements in an
> array:
>
> print $animals[0]; # prints "camel"
> print $animals[1]; # prints "llama"
>
> The special variable $#array tells you the index of the last ele-
> ment of an array:
>
> print $mixed[$#mixed]; # last element, prints 1.23
>
> You might be tempted to use "$#array + 1" to tell you how many
> items there are in an array. Don't bother. As it happens, using
> @array where Perl expects to find a scalar value ("in scalar con-
> text") will give you the number of elements in the array:
I'm assuming you're using less as your pager.
Also, page 76 in the Camel book (3rd ed).
HTH,
Ricky
------------------------------
Date: Tue, 10 Feb 2004 14:39:11 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: build_dir/perl uses /usr/lib/perl !?
Message-Id: <c0aqef$9u4$1@wisteria.csv.warwick.ac.uk>
bill <bill_knight2@yahoo.com> wrote:
> I'm doing a re-installation of Perl 5.8.2-2, because the currently
> installed version has threads enabled, which I don't want. When
> I do make test, 2 tests fail. Not surprisingly, these tests also
> fail when I run them individually using:
>
> bash-2.05b$ LD_LIBRARY_PATH=`pwd`:$LD_LIBRARY_PATH; export
> LD_LIBRARY_PATH; cd t; ./perl harness <test_file>
>
> The first failing test (run/fresh_perl.t) fails with the error:
>
> /home/knight/build/perl-5.8.2/perl: relocation error:
> /usr/lib/perl/5.8.2/auto/NDBM_File/NDBM_File.so: undefined symbol:
> Perl_Gthr_key_pt
Whomever installed your previous version of perl should be shot
:). Shared objects (indeed, anything arch-specific) should go in
/usr/lib/perl/5.8.2/arch-os-thread-multi/auto/whatever
which would stop the new perl from finding the old modules that are
not compatible (as it would be looking for them in
/usr/lib/perl/5.8.2/arch-os/auto/whatever
, because it wasn't build with threads). I'd suggest moving the whole
auto directory into an arch-specific subdirectory (perl -v will tell
you the right name, eg. mine says
This is perl, v5.8.2 built for i686-linux-thread-multi
), or, alternatively, removing the whole installation.
> The second failing test (../lib/ExtUtils/t/Embed.t) fails with
>
> /usr/bin/ld: cannot find -lperl
> collect2: ld returned 1 exit status
>
> Again, another library related failure, but here I'm clueless as
> to what may be going on.
Looking at lib/ExtUtils/t/Embed.t, it is expecting to be run from t
and find libperl in ..: is that where it is?
Ben
--
If you put all the prophets, | You'd have so much more reason
Mystics and saints | Than ever was born
In one room together, | Out of all of the conflicts of time.
ben@morrow.me.uk |----------------+---------------| The Levellers, 'Believers'
------------------------------
Date: 10 Feb 2004 07:23:35 -0800
From: aotoole@optonline.net (nj_perl_newbie)
Subject: Comparing a string to filenames in a directory
Message-Id: <d7fb9254.0402100723.6963e89e@posting.google.com>
I apologize for posting such a basic question...I have spent a
substantial ammount of time reading thick books trying to figure out
how to do this.
The goal is to read the second field in a text file and compare that
string to a list of filenames in a directory.
So use submits a file with "foo, test.txt" the script will look for
"test.txt" in the directory, if it exists it will copy test.txt to a
different directory.
Here's what I have:
opendir(DIR, $limbodir);
&log_entry($logfh,"Opening Limbo Directory"); if $debug;
@files = grep { /\.csv$/ } readdir(DIR);
&log_entry($logfh, "Files in limbodir read") if $debug;
closedir(DIR);
open (FILE, "$cnfrm_file") || die();
($line)= <FILE>; #Read only the first line into the input file.
while (<FILE>) { #not sure if the while is needed
my @line = split /\,/, $_;
my($firstfield, $filename, $junk) = @line;
unless ( $firstline ) {
#attempts to match the filename submitted in the confirm file with
an already existing input file in the limbo directory
if ( $filename) {
( $filename =~ m/^@files/i ) {
&log_entry($logfh, "Confirm submitted by $username for input
file $path/$basename ");
move ("$_", "$transdir/$basename") || die "move failed: $!";
&log_entry($logfh, "$_ moved to $transdir");
chown 23456,23458, "$transdir/$_" || warn $!;
}
Thanks
------------------------------
Date: Tue, 10 Feb 2004 15:41:12 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Comparing a string to filenames in a directory
Message-Id: <sY6Wb.5552$dp5.2135@nwrddc02.gnilink.net>
nj_perl_newbie wrote:
> I apologize for posting such a basic question...I have spent a
> substantial ammount of time reading thick books trying to figure out
> how to do this.
>
> The goal is to read the second field in a text file and compare that
> string to a list of filenames in a directory.
>
> So use submits a file with "foo, test.txt" the script will look for
> "test.txt" in the directory, if it exists it will copy test.txt to a
> different directory.
>
>
> Here's what I have:
>
You are missing
use strict;
use warnings;
> opendir(DIR, $limbodir);
> &log_entry($logfh,"Opening Limbo Directory"); if $debug;
What's the ampersand doing there? Or are you still programming Perl4?
What is the semicolon doing in the middle of the line?
> @files = grep { /\.csv$/ } readdir(DIR);
> &log_entry($logfh, "Files in limbodir read") if $debug;
> closedir(DIR);
From the program logic this whole readdir section above is not needed.
It is much easier to use "-e" later.
> open (FILE, "$cnfrm_file") || die();
You may want to get into the habit of using the lower-priority "or" operator
instead of "||".
Also, you will get much better error messages if you include some text, the
error code, and the file name with your die() statement:
open (FILE, "$cnfrm_file") or die("Cannot open file $dnfrm_file because
$!\n");
> ($line)= <FILE>; #Read only the first line into the input file.
Well, I would have made the comment
# skipping first line
because that is what you are doing.
However, do you really want to skip the first line?
> while (<FILE>) { #not sure if the while is needed
Do you want to read the whole file line by line?
> my @line = split /\,/, $_;
No need to escape the comma. It is not a special character in a RE.
> my($firstfield, $filename, $junk) = @line;
Clearer in my opinion would be
my (undef, $filename, undef) = split /,/;
Then there is no missunderstanding about if you ever use $firstfield and
$junk.
> unless ( $firstline ) {
I don't understand what you are trying to do here? Why are you testing if
$firstline evaluates to true?
> #attempts to match the filename submitted in the confirm file with
> an already existing input file in the limbo directory
> if ( $filename) {
I don't understand what you are trying to do here, either? Why are you
testing if $filename evaluates to true?
> ( $filename =~ m/^@files/i ) {
If you just want to test if a file with the name $filename exists then just
use a simple
if (-e $filename) {
> &log_entry($logfh, "Confirm submitted by $username for input
> file $path/$basename ");
> move ("$_", "$transdir/$basename") || die "move failed: $!";
> &log_entry($logfh, "$_ moved to $transdir");
> chown 23456,23458, "$transdir/$_" || warn $!;
> }
HTH
jue
------------------------------
Date: Tue, 10 Feb 2004 15:49:20 GMT
From: Chris <ceo@nospan.on.net>
Subject: Re: How to execute a command line in Perlscript
Message-Id: <447Wb.8351$L96.2404@newssvr31.news.prodigy.com>
Eric SALGON wrote:
> In article <A4bVb.19477$2x6.1543@newssvr16.news.prodigy.com>,
> ceo@nospan.on.net says...
>
>>Chris wrote:
>>
>>>Eric SALGON wrote:
>>>
>>>
>>>>In article <elvUb.19067$Fp6.2360@newssvr16.news.prodigy.com>,
>>>>ceo@nospan.on.net says...
>>>>
>>>>
>>>>>Eric SALGON wrote:
>>>>>
>>>>>
>>>>>>Hi,
>>>>>>
>>>>>>Is there someone who knows how to execute a command line (such a simple
>>>>
>>>>
>>>>echo
>>>>
>>>>
>>>>>>cmd) in PerlScript.
>>>>>>
>>>>>>I hve tryed '' or system() but the result is the same: no result but no
>>>>
>>>>
>>>>error
>>>>
>>>>
>>>>>>!
>>>>>>
>>>>>>This syntax works fine in a perl program but not in PerlScript
>>>>>>
>>>>>>An idea ?
>>>>>>
>>>>>
>>>>>I just realized I didn't answer your question in my last response.
>>>>>
>>>>>First of all, as a general rule, and one that is outlined in the FAQ
>>>>>(and asked about a lot here is) system() does NOT provide output.
>>>>>But most especially in the Windows world where Microsoft writes their
>>>>>own rules, this is also not the case in either ASP or WSH (still
>>>>>assuming you are talking about "PerlScript" and not "Perl script.")
>>>>>
>>>>>Using output wrappers in the ASP and WSH worlds for outputing a
>>>>>string, the following code will work in both worlds for outputing a
>>>>>"system" command:
>>>>>
>>>>>sub shell {
>>>>>
>>>>> my @output;
>>>>> for (@_) { push( @output, `$_` ) }
>>>>> chomp( @output );
>>>>> return wantarray ? @output : \@output;
>>>>>
>>>>>}
>>>>>
>>>>>puts( shell( 'dir /l/on/' ) );
>>>>>
>>>>>or you can:
>>>>>
>>>>>puts( shell(
>>>>> 'dir',
>>>>> 'type c:\\autoexec.bat',
>>>>> 'dir c:\\winnt\\system32',
>>>>> 'command4',
>>>>> 'command5',
>>>>>));
>>>>>
>>>>>If:
>>>>>
>>>>>ASP: sub puts { for (@_) { $Response->Write( "$_\n" ) } }
>>>>>WSH: sub puts { for (@_) { $WScript->Echo( "$_\n" ) } }
>>>>>
>>>>>Incidentially using PerlScript in Windows allows you this
>>>>>convenience. The "official" Microsoft "interface" (read "complicated
>>>>>and convolluted") for executing a command in a scripting environment
>>>>>(both ASP and WSH) is WshShell.Exec() (which takes two calls to set
>>>>>up.) You can do this in PerlScript if you want, but the regular Perl
>>>>>way of executing a system command works much smoother.
>>>>>
>>>
>>> > [Top Posting Fixed]
>>> >
>>>
>>>>Unfortunatly, I have implemented "shell" and "puts" functions in my
>>>>ASP code but `$_` return no result in @output array with a simple
>>>>'dir' command.
>>>>
>>>>I'm afraid it's a problem of right on my IIS server.
>>>>
>>>
>>>If your tick marks above are an accurate portrayal of what you used in
>>>your shell() code, then, no you will not get output. (You would only
>>>get an echo back of the command(s) you wanted to run that way.) The
>>>single tick marks in my shell() routine above are backward ticks. Use
>>>qx() if this is confusing:
>>>
>>>sub shell {
>>>
>>> my @output;
>>> for (@_) { push( @output, qx($_) } }
>>> chomp( @output );
>>> return wantarray ? @output : \@output;
>>>
>>>}
>>>
>>
>>The extra "}" at the end of the line "for (@_) { push..." in the shell()
>>routine should be removed. Should have been:
>>
>>for (@_) { push( @output, qx($_) ) }
>>
> Chris,
>
> It was not a problem of backward ticks, no chance.
> The result is unfortunatly the same ...
>
> another idea ?
>
Really weird. I suppose the "on topic" question is, what is in the
array that is returned by 'shell()' when you call it? Nothing? If you
are trying to do a directory listing or something like that, redirect
errors to the CONsole so you can see what the issue is:
puts( shell( 'dir 2>&1' ) );
Another thing to try would be to issue a command that leaves results
that can be otherwise inspected after the command is done. Try to
delete some file you know you should be able to delete and after the
script runs, go see if it's still there. Something like that. Perhaps
it *is* a permissions issue. Sounds like IIS might be setup in some
weird way after all.
Redirect all output to the CONsole no matter what as a trouble-shooting
measure (you may have already thought of that). If it's a permissions
issue, you should get SOMETHING back in the return array of 'shell()'.
Chris
-----
Chris Olive
chris -at- --spammers-are-__________-- technologEase -dot- com
http://www.technologEase.com
(pronounced "technologies")
------------------------------
Date: Tue, 10 Feb 2004 14:38:32 +0000 (UTC)
From: kj <nomail@please.com>
Subject: How2 prevent perl's searching "std directories"?
Message-Id: <c0aqd8$p16$1@reader2.panix.com>
Is there a way to prevent perl from searching "standard" directories
when looking for library files? Is there a way to set (as opposed
to append to) @INC on the command line when invoking perl?
Thanks!
kj
------------------------------
Date: Tue, 10 Feb 2004 14:44:55 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: How2 prevent perl's searching "std directories"?
Message-Id: <c0aqp7$9u4$2@wisteria.csv.warwick.ac.uk>
kj <nomail@please.com> wrote:
>
> Is there a way to prevent perl from searching "standard" directories
> when looking for library files? Is there a way to set (as opposed
> to append to) @INC on the command line when invoking perl?
perl -e'BEGIN { @INC = "/my/inc" }'
If you need to do this when invoking a script, it'd probably be easier
to write a little lib::only module
package lib::only;
sub import {
@INC = @_;
}
1;
and use
perl -Mlib::only=/my/inc,/my/other/inc script
rather than
perl -e'BEGIN { @INC = qw|/my/inc /my/other/inc| }' -e'do "script"'
Ben
--
Joy and Woe are woven fine,
A Clothing for the Soul divine William Blake
Under every grief and pine 'Auguries of Innocence'
Runs a joy with silken twine. ben@morrow.me.uk
------------------------------
Date: Tue, 10 Feb 2004 14:48:53 +0000 (UTC)
From: kj <nomail@please.com>
Subject: Re: How2 prevent perl's searching "std directories"?
Message-Id: <c0ar0l$p94$1@reader2.panix.com>
>> Is there a way to prevent perl from searching "standard" directories
>> when looking for library files? Is there a way to set (as opposed
>> to append to) @INC on the command line when invoking perl?
I neglectd to mention that I want to control the searchpath for
the perl debugger. I'm trying to debug a perl installation, but
the debugger is crashing on me because it is reading the previously
installed (and incompatible) site libraries.
Thanks,
kj
------------------------------
Date: Tue, 10 Feb 2004 14:53:14 +0000 (UTC)
From: kj <nomail@please.com>
Subject: Re: How2 prevent perl's searching "std directories"?
Message-Id: <c0ar8q$p94$2@reader2.panix.com>
In <c0aqp7$9u4$2@wisteria.csv.warwick.ac.uk> Ben Morrow <usenet@morrow.me.uk> writes:
> perl -Mlib::only=/my/inc,/my/other/inc script
I tried
~/build/perl-5.8.2$ ./perl -Mlib::only=lib -d misctmp003
./perl: relocation error: /usr/lib/perl/5.8.2/auto/IO/IO.so: undefined symbol: Perl_Tstack_sp_ptr
...so perl is still looking at the standard directories.
kj
------------------------------
Date: Tue, 10 Feb 2004 15:00:48 +0000 (UTC)
From: kj <nomail@please.com>
Subject: Re: How2 prevent perl's searching "std directories"?
Message-Id: <c0arn0$ph8$1@reader2.panix.com>
In <c0ar8q$p94$2@reader2.panix.com> kj <nomail@please.com> writes:
>In <c0aqp7$9u4$2@wisteria.csv.warwick.ac.uk> Ben Morrow <usenet@morrow.me.uk> writes:
>> perl -Mlib::only=/my/inc,/my/other/inc script
>I tried
>~/build/perl-5.8.2$ ./perl -Mlib::only=lib -d misctmp003
>./perl: relocation error: /usr/lib/perl/5.8.2/auto/IO/IO.so: undefined symbol: Perl_Tstack_sp_ptr
>...so perl is still looking at the standard directories.
OK, it worked. I needed to add -Ilib to the command line.
Cool! Thanks.
kj
------------------------------
Date: 10 Feb 2004 06:22:57 -0800
From: bay_dar@yahoo.com (G)
Subject: Re: Matching strings with index – getting extra matches.
Message-Id: <cad04083.0402100622.347402b3@posting.google.com>
"gnari" <gnari@simnet.is> wrote in message news:<c08oh6$3b9$1@news.simnet.is>...
> "G" <bay_dar@yahoo.com> wrote in message
> news:cad04083.0402090825.2eba95a5@posting.google.com...
>
> [problem with index not matching string exactly]
>
> > sales item aaa | m423a
> > sales item bbb | m423
> > sales item ccc | m423b
> > sales item ddd | 423
>
> if there is allways space around the '|' you should
> have them in your split
>
> > ...
> > ($sales_item, $code) = split /\|/;
> ($sales_item, $code) = split / \| /;
>
> > if (index($code, $entered_code) != -1) {
>
>
> if there is no trailing space after the code then
> if ($code eq $entered_code) {
>
> if on the other hand, your data is dirty with
> whilespace, you are better off with a
> regexp match as someone else suggested
> or even replace the split with a match:
>
> ($sales_item, $code) = /^\s*(.+?)\s*\|\s*(.+?)\s*/;
> if ($code eq $entered_code) {
>
> gnari
Thanks for the suggestions so far, but I now realize I the sample text
file was flawed. For one there is Never white space around the '|'.
Secondly a line could have multiple codes but no duplicates(on that
line only). The sample file should have looked as follows:
sales item aaa|543,m423a
sales item bbb|m423,543 'Note how code 543 is on the 1st 2nd
line.
sales item ccc|m423b
sales item ddd|423,423b,m523,652
Given that the above has changed how could I get a match. e.g. a code
of 423 should return the description in line 4 "sales item ddd" Where
m423 only matches the 3rd line. etc.
Thanks,
C
------------------------------
Date: Tue, 10 Feb 2004 15:02:55 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Matching strings with index – getting extra matches.
Message-Id: <c0arqv$9u4$4@wisteria.csv.warwick.ac.uk>
bay_dar@yahoo.com (G) wrote:
> Thanks for the suggestions so far, but I now realize I the sample text
> file was flawed. For one there is Never white space around the '|'.
> Secondly a line could have multiple codes but no duplicates(on that
> line only). The sample file should have looked as follows:
>
> sales item aaa|543,m423a
> sales item bbb|m423,543 'Note how code 543 is on the 1st 2nd
> line.
> sales item ccc|m423b
> sales item ddd|423,423b,m523,652
>
> Given that the above has changed how could I get a match. e.g. a code
> of 423 should return the description in line 4 "sales item ddd" Where
> m423 only matches the 3rd line. etc.
my $code = 'm423';
while (<>) {
my ($item, $codes) = split /\|/;
my @codes = split /,/, $codes;
print $item if grep { $_ eq $code } @codes;
}
alternatively:
/(.*) \| (?:.*,|) \Q$code\E (?:,|$)/x and print $1 while <>;
Ben
--
$.=1;*g=sub{print@_};sub r($$\$){my($w,$x,$y)=@_;for(keys%$x){/main/&&next;*p=$
$x{$_};/(\w)::$/&&(r($w.$1,$x.$_,$y),next);$y eq\$p&&&g("$w$_")}};sub t{for(@_)
{$f&&($_||&g(" "));$f=1;r"","::",$_;$_&&&g(chr(0012))}};t # ben@morrow.me.uk
$J::u::s::t, $a::n::o::t::h::e::r, $P::e::r::l, $h::a::c::k::e::r, $.
------------------------------
Date: Tue, 10 Feb 2004 15:38:32 +0100
From: Jaap Karssenberg <j.g.karssenberg@student.utwente.nl>
Subject: Re: memory profiling
Message-Id: <20040210153832.0b3f3c41@Captain>
On 10 Feb 2004 01:18:10 GMT ctcgag@hotmail.com wrote:
: Jaap Karssenberg <j.g.karssenberg@student.utwente.nl> wrote:
: > Does anyone know of a simple way to see where the memory goes in a
: > large perl application ?
:
: Depends on how modular the application is.
It's kinda modular, if can figure out the memory usage per module that
would make a good start for further analysis. So what do you suggest ?
--
) ( Jaap Karssenberg || Pardus [Larus] | |0| |
: : http://pardus-larus.student.utwente.nl/~pardus | | |0|
) \ / ( |0|0|0|
",.*'*.," Proud owner of "Perl6 Essentials" 1st edition :) wannabe
------------------------------
Date: Tue, 10 Feb 2004 14:51:30 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: memory profiling
Message-Id: <c0ar5i$9u4$3@wisteria.csv.warwick.ac.uk>
Jaap Karssenberg <j.g.karssenberg@student.utwente.nl> wrote:
> Does anyone know of a simple way to see where the memory goes in a large
> perl application ?
Devel::Leak may help.
Ben
--
Joy and Woe are woven fine,
A Clothing for the Soul divine William Blake
Under every grief and pine 'Auguries of Innocence'
Runs a joy with silken twine. ben@morrow.me.uk
------------------------------
Date: Tue, 10 Feb 2004 09:44:58 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: script working like daemon
Message-Id: <pan.2004.02.10.14.44.56.77587@remove.adelphia.net>
On Tue, 10 Feb 2004 02:25:46 -0800, murph wrote:
> James Willmore <jwillmore@remove.adelphia.net> wrote in message news:<pan.2004.02.09.16.56.35.23637@remove.adelphia.net>...
>> On Mon, 09 Feb 2004 04:52:21 -0800, murph wrote:
<snip>
>>
>> Another option is to put together a script to read from a FIFO, alter
>> your syslog.conf file to include sending messages to the FIFO, and then do
>> something when a specified line is encountered.
<snip>
> I understand how to configure the syslogd.conf to put the logs direct
> to a named pipe . Now i want to write my perl script , but i have
> really problems using named pipes .
> I created named pipe manually (mkfifo pipe ) , change it permissions
> so that the script can read and write from it ( 0777 )
To make it really secure, make the owner 'root' and make the permissions
600 (-rw-------).
You don't what *anyone* to have the ability to read/write to the FIFO -
because that would open a potential "hole" in your system and
you don't wwant that :-)
> #!/usr/bin/perl
> $fifo_name = "./fifo" ;
> while(1){
> open(FIFO ,"> $fifo_name");
> $error = <FIFO> ;
> if($error){
> chomp($error);
> print "Error: $error\n";
> }
> }
This is what I have used. I used IO::File versus 'open'.
--read script --
#!/usr/bin/perl -w
use strict;
use IO::File;
$SIG{__WARN__} = $SIG{__DIE__} = sub { print "Opps\n$_[0]\n$!\n"; exit; };
$SIG{ALRM} = $SIG{INT} =
sub { undef $fh; print "Caught a signal - Terminating\n"; exit; };
my $fh = new IO::File "/tmp/myfifo";
while (1) {
while ( my $line = $fh->getline ) {
print "FIFO: $line";
}
}
exit;
-----------------
--write script --
#!/usr/bin/perl -w
$SIG{__DIE__} = $SIG{__WARN__} =
sub { print "Dying\n$!\n$@\n ... exiting\n"; exit; };
$SIG{INT} = $SIG{TERM} = sub { print "Caught a signal ... exiting\n"; exit; };
$SIG{ALRM} = sub { print "Timed out\n"; exit; };
alarm 5;
for ( 1 .. 100 ) {
system("echo $_ > /tmp/myfifo");
}
alarm 0;
exit;
-----------------
Some things to consider that are not included in the scripts above -
* autoflush may need to be turned on. With syslogd, I don't think it
matters that much, since, from my understanding, it doesn't buffer it's
output. But, it is something to consider.
* it works only on a *NIX type platform (Linux, SunOS, FreeBSD (maybe -
FreeBSD has tighter security, so it may not work as expected)).
* you may need to alter your signal handlers to suit your needs.
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
Wiker's Law: Government expands to absorb revenue and then some.
------------------------------
Date: Tue, 10 Feb 2004 14:18:21 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Why references??
Message-Id: <c0ap7d$95u$2@wisteria.csv.warwick.ac.uk>
Tore Aursand <tore@aursand.no> wrote:
> On Mon, 09 Feb 2004 17:41:02 +0100, Thomas Deschepper wrote:
> > But why would someone use a reference if they can use a normal variable?
>
> I've read a lot of the other answers in this group, but none of them seem
> to relate to why I prefer references: performance.
>
> Copying the reference to a huge array is always faster than copying the
> array itself. It also uses less memory.
But the semantics are different. If one is correct, the other is
wrong.
Ben
--
"If a book is worth reading when you are six, * ben@morrow.me.uk
it is worth reading when you are sixty." - C.S.Lewis
------------------------------
Date: Tue, 10 Feb 2004 15:01:02 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Why references??
Message-Id: <Om6Wb.5400$dp5.154@nwrddc02.gnilink.net>
"Tore Aursand" <tore@aursand.no> wrote in message
news:pan.2004.02.10.12.06.53.594714@aursand.no...
> On Mon, 09 Feb 2004 17:41:02 +0100, Thomas Deschepper wrote:
> > But why would someone use a reference if they can use a normal variable?
>
> I've read a lot of the other answers in this group, but none of them seem
> to relate to why I prefer references: performance.
>
> Copying the reference to a huge array is always faster than copying the
> array itself. It also uses less memory.
True. But the effect is totally different. You can't replace one with the
other.
> And - I think references are
> easier to "read" (syntax wise) than "ordinary variables".
That on the other hand is probably a rather unique opinion ;-)
jue
------------------------------
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.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
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 6107
***************************************