[22896] in Perl-Users-Digest
Perl-Users Digest, Issue: 5116 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 13 11:05:42 2003
Date: Fri, 13 Jun 2003 08:05:07 -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 Fri, 13 Jun 2003 Volume: 10 Number: 5116
Today's topics:
Re: `du -bs $dir` question (Math55)
Re: `du -bs $dir` question <bernard.el-hagin@DODGE_THISlido-tech.net>
calling functions from another perl script <vervoom@hotmail.com>
Re: calling functions from another perl script <bernard.el-hagin@DODGE_THISlido-tech.net>
Re: db file problem <paul.marquess@btinternet.com>
Re: exporting oracle query to excel using perl <r_reidy@comcast.net>
Permute List of Lists? (David)
Re: print operand file name (Tad McClellan)
Question about regular expression optimization nono547@hotmail.com
relocation error <vervoom@hotmail.com>
Re: script to do global search & replace (Tad McClellan)
Re: Sorting Algorithm: organize data into a tree <jeffrey@jhu.edu>
Re: Sorting Algorithm: organize data into a tree <jeffrey@jhu.edu>
Re: test (Tad McClellan)
Using a while loop to search/remove lines.. (Eric)
Re: Which value is tha largest(benchmarked) <glex_nospam@qwest.net>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 13 Jun 2003 03:12:57 -0700
From: magelord@t-online.de (Math55)
Subject: Re: `du -bs $dir` question
Message-Id: <a2b8188a.0306130212.559b8ebb@posting.google.com>
"Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net> wrote in message news:<Xns93989CEE07C94elhber1lidotechnet@62.89.127.66>...
> Math55 wrote:
>
> > hello, i wrote the following subroutine.
> >
> > sub getFolderSize{
> >
> > my $FolderPath = shift;
> >
> > my $du_parse = `du -bs $_`;
> ^^
>
>
> > $du_parse =~ /^(\d+)/;
> > $dirSizeTest = $1;
> > return $dirSizeTest;
> >
> > }
> >
> > i try to use it to geth the size of a directory with all its subdirs.
> > the method is called with a path like /home/test. it always gives me
> > 12980 bytes, for EVERY directory!! whats wrong?
>
>
> Your folder path is in $FolderPath but you're du()ing what's in $_.
>
>
> --
> Cheers,
> Bernard
yes right, when i use the $FolderPAth, nothing happens, the program
starts and it freezes. or is du that slow?
THANKS
------------------------------
Date: Fri, 13 Jun 2003 10:15:08 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: `du -bs $dir` question
Message-Id: <Xns93997C4337561elhber1lidotechnet@62.89.127.66>
Math55 wrote:
> "Bernard El-Hagin" wrote:
>
>> Math55 wrote:
>>
>> > hello, i wrote the following subroutine.
>> >
>> > sub getFolderSize{
>> >
>> > my $FolderPath = shift;
>> >
>> > my $du_parse = `du -bs $_`;
>> ^^
>>
>>
>> > $du_parse =~ /^(\d+)/;
>> > $dirSizeTest = $1;
>> > return $dirSizeTest;
>> >
>> > }
>> >
>> > i try to use it to geth the size of a directory with all its
>> > subdirs. the method is called with a path like /home/test. it
>> > always gives me 12980 bytes, for EVERY directory!! whats wrong?
>>
>>
>> Your folder path is in $FolderPath but you're du()ing what's in $_.
>
> yes right, when i use the $FolderPAth, nothing happens, the program
> starts and it freezes. or is du that slow?
How are you calling getFolderSize() ?
--
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: Fri, 13 Jun 2003 13:55:51 +0100
From: JS <vervoom@hotmail.com>
Subject: calling functions from another perl script
Message-Id: <bcchlq$jh6$1@cspc1n11.baplc.com>
Hi,
Is it possible to have 2 perl scripts e.g. script-A.pl and script-B.pl
and call a function e.g. getdata() in script-B.pl from script-A.pl that
returns an array? If so, how do you do that?
Thanks,
JS.
------------------------------
Date: Fri, 13 Jun 2003 13:20:18 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: calling functions from another perl script
Message-Id: <Xns93999BA7F39A3elhber1lidotechnet@62.89.127.66>
JS wrote:
> Hi,
>
> Is it possible to have 2 perl scripts e.g. script-A.pl and script-B.pl
> and call a function e.g. getdata() in script-B.pl from script-A.pl that
> returns an array? If so, how do you do that?
perldoc -f require
--
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: Fri, 13 Jun 2003 11:16:08 +0100
From: "Paul Marquess" <paul.marquess@btinternet.com>
Subject: Re: db file problem
Message-Id: <3ee9a469$0$10620$ed9e5944@reading.news.pipex.net>
That method of locking does not work.
The soultion is in the DB_File documentation.
Have a read at the sections "Locking: The Trouble with fd" to understand why
you should not use "fd" to lock a database, and the section "Safe ways to
lock a database" for a solution to your problem.
Paul
"Vassilis Tavoultsidis" <ixanthi@ixanthi.remove.gr> wrote in message
news:bcbs2l$1gt$1@nic.grnet.gr...
> You have a point and I made a mistate stating the problem. I use file
> locking with the following code
>
> local *DBM;
> my $db = tie %dbase, "DB_File",
"${temp_data}/".$params{"database"}.".db",
> O_CREAT | O_RDWR, 0755 or die "could not tie to db file: $!";
> my $fd = $db->fd;
> open DBM, "+<&=$fd" or die "Could not dub DBM for lock : $!";
> flock DBM, LOCK_EX;
> undef $db;
>
> I had corruption problems with the dbmopen and dbmclose because the script
i
> am writing is serving a portal where news are added at the same time from
> multiple users and viewers see them at the same time. I use the BerkeleyDB
> but have no idea what the DB_INIT_CDB mode is. Any reference?
>
> Thanks
>
> "Dan Wilga" <dwilga-MUNGE@mtholyoke.edu> wrote in message
> news:dwilga-MUNGE-B42A1B.16414111062003@nap.mtholyoke.edu...
> > In article <bc7jeq$icq$1@nic.grnet.gr>,
> > "Vassilis Tavoultsidis" <ixanthi@ixanthi.remove.gr> wrote:
> >
> > > I am working with the simple db files perl gives and I open and close
> the
> > > with the dbmopen and dbmclose files. Sometimes (i don't know the
> conditions)
> > > it seems that the file contains 2(!!) identical records in it. The
> records
> > > have the same key and the same content. If I erase one the other is
gone
> > > too. If i modify one the other is modified too. I have tried to figure
> out
> > > what may cause this but nothing.
> >
> > Are you doing updates to the DB in multiple instances of the same
> > program at the same time, for instance in a CGI program or something
> > that uses fork()?
> >
> > If so, that's probably your problem. The dbmXXX calls don't support any
> > sort of locking. For more robust flatfile database access, use something
> > like the DB_INIT_CDB mode of the BerkeleyDB module (available on CPAN).
> >
> > --
> > Dan Wilga dwilga-MUNGE@mtholyoke.edu
> > ** Remove the -MUNGE in my address to reply **
>
>
------------------------------
Date: Fri, 13 Jun 2003 05:38:25 -0600
From: Ron Reidy <r_reidy@comcast.net>
Subject: Re: exporting oracle query to excel using perl
Message-Id: <3EE9B7B1.1090106@comcast.net>
Yes,
use Spreadsheet::WriteExcel;
Jessica wrote:
> Has anyone ever used perl to query an oracle database and tried to
> export that to an excel file? I am new to perl and could use any good
> examples.
--
Ron Reidy
Oracle DBA
------------------------------
Date: 13 Jun 2003 07:38:15 -0700
From: david.evans@vir.gla.ac.uk (David)
Subject: Permute List of Lists?
Message-Id: <4097909c.0306130638.5523adb3@posting.google.com>
I have a list of lists, something like ([a,b],[i,j,k],[y,z]) and need
to permute every possible combination i.e. aiy aiz ajy ajz aky akz ..
bkz etc. Each internal list can have 1,2,3,4 or 6 scalar values
(often 4), the outer list may contain 10 or so inner lists. T
appreciate the scale of possible variation (up to 6x10e7 or so). I
can easily calculate the latter (e.g. 2 x 3 x 2), but actually need
the list of possible variation ([aiy aiz ajy ajz etc.]) for further
calculations. This is clearly - to my untutored eye anyway - an
exercise in recursion, never my strong point.
I've searched CPAN for modules - particularly Math:: and Algorithm::
- that may help, and c.l.p.m for 'permute list of lists' and the like,
and struggled with code 'til the early hours. All were fruitless
exercises.
Has anyone else tackled and solved this type of problem?
To put the problem in context, I'm interested in thermodynamic
prediction of nucleic acid structures that encode proteins - for any
particular peptide I want to calculate the possible range of sequences
that (taking account of codon degeneracy) could encode it.
Any advice would be greatly appreciated.
Many thanks
David
------------------------------
Date: Fri, 13 Jun 2003 07:13:22 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: print operand file name
Message-Id: <slrnbejfv2.4cc.tadmc@magna.augustmail.com>
mhearse <mhearse@hotmail.com> wrote:
> I've recently developed a script to validate simple macro commands. This
> script may be run on as many as 200 files at once (macro_valid.pl *).
> Currently it prints only the errors detected (no way to tell which errors go
> with which filename). I need a way to print the filename when an error is
> detected. Possibly some way to read the filename into input, and print it
> if an error is detected. Any suggestions?
There is an error on line 17.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 13 Jun 2003 15:21:08 +0200
From: nono547@hotmail.com
Subject: Question about regular expression optimization
Message-Id: <bccj3m$i60$1@news-reader14.wanadoo.fr>
Hi all
Does anyone know where I can find information about the optimizations the
perl interpreter performs on regular expressions while compiling them ?
For example, considering the following expression : "ab|ac", does the perl
compiler transform it into "a(?:b|c)", which is more effective ?
Thanks
Pascal
------------------------------
Date: Fri, 13 Jun 2003 14:49:39 +0100
From: JS <vervoom@hotmail.com>
Subject: relocation error
Message-Id: <bcckqm$jle$1@cspc1n11.baplc.com>
Can anyone help me with this problem please? I've built ImageMagick and
was trying to test out the script below but got the following error:
Thanks,
JS.
smpd9$ ./test.pl
Can't load
'/usr/local/lib/perl5/site_perl/5.005/sun4-solaris/auto/Image/Magick/Magick.so'
for module Image::Magick: ld.so.1: /usr/bin/perl: fatal: relocation
error: file
/usr/local/lib/perl5/site_perl/5.005/sun4-solaris/auto/Image/Magick/Magick.so:
symbol png_create_read_struct_2: referenced symbol not found at
/usr/local/lib/perl5/5.00503/sun4-solaris/DynaLoader.pm line 169.
at ./test.pl line 3
BEGIN failed--compilation aborted at ./test.pl line 3.
smpd9$ nm
/usr/local/lib/perl5/site_perl/5.005/sun4-solaris/auto/Image/Magick/Magick.so
| grep png_create_read_struct_2
[3252] | 0| 0|FUNC |GLOB |0 |UNDEF
|png_create_read_struct_2
smpd9$ echo $LD_LIBRARY_PATH
/opt/local/gnu/lib:/opt/local/lib:/opt/local/lib:/usr/openwin/lib:/usr/lib
smpd9$ ldd
/usr/local/lib/perl5/site_perl/5.005/sun4-solaris/auto/Image/Magick/Magick.so
libtiff.so => /opt/local/gnu/lib/libtiff.so
libfreetype.so.6 => /opt/local/lib/libfreetype.so.6
libpng10.so.0 => /opt/local/lib/libpng10.so.0
libdpstk.so.5 => /usr/openwin/lib/libdpstk.so.5
libdps.so.5 => /usr/openwin/lib/libdps.so.5
libXext.so.0 => /usr/openwin/lib/libXext.so.0
libSM.so.6 => /usr/openwin/lib/libSM.so.6
libICE.so.6 => /usr/openwin/lib/libICE.so.6
libX11.so.4 => /usr/openwin/lib/libX11.so.4
libsocket.so.1 => /usr/lib/libsocket.so.1
libnsl.so.1 => /usr/lib/libnsl.so.1
libxml2.so.2 => /opt/local/lib/libxml2.so.2
libz.so => /opt/local/lib/libz.so
libpthread.so.1 => /usr/lib/libpthread.so.1
libm.so.1 => /usr/lib/libm.so.1
libc.so.1 => /usr/lib/libc.so.1
libXt.so.4 => /usr/openwin/lib/libXt.so.4
libdl.so.1 => /usr/lib/libdl.so.1
libmp.so.2 => /usr/lib/libmp.so.2
libthread.so.1 => /usr/lib/libthread.so.1
/usr/platform/SUNW,Ultra-Enterprise-10000/lib/libc_psr.so.1
This is the script test.pl:
#! /usr/bin/perl
use Image::Magick;
my $image = Image::Magick->new;
my $text = 'Hello World!';
$image->Set( size => "100x100" );
$image->ReadImage( "xc:white" );
$image->Annotate(font=>'arial.ttf', text=>$text);
$image->Write("test.gif");
undef $image;
------------------------------
Date: Fri, 13 Jun 2003 07:10:29 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: script to do global search & replace
Message-Id: <slrnbejfpl.4cc.tadmc@magna.augustmail.com>
Ofuuzo <ofuuzo@ub.uit.no> wrote:
> I'm looking for a good perl script to do global search & replace
> does recursive search/find
(line-wrapped for posting)
perl -MFile::Find -pi.bak -e
'BEGIN{find sub {push @ARGV, $File::Find::name if -f }, "."}
s/Windows Bill/Open Linux/g'
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 13 Jun 2003 10:36:06 -0400
From: "Jeffrey Silverman" <jeffrey@jhu.edu>
Subject: Re: Sorting Algorithm: organize data into a tree
Message-Id: <pan.2003.06.13.14.36.03.614075@jhu.edu>
On Thu, 12 Jun 2003 21:11:43 +0000, Jay Tilton wrote:
> "Jeffrey Silverman" <jeffrey@jhu.edu> wrote:
>
> : I am cross-posting to PHP and Perl newsgroups, as the algorithm I am
> : seeking should be fairly language-agnostic, and I know both Perl and PHP.
> :
> : I need to organize a multi-dimensional array into a tree. The data
> : structure is roughly as follows:
<snip!>
> # show results
> use Data::Dumper;
> $Data::Dumper::Sortkeys = 1;
> print Dumper( \%tree );
Great! Now I must take a few moments to digest this...
Also, I have a wee problem:
I have to write this thing in PHP, and as such will not have access to
Data::Dumper. Does Data::Dumper do anything critical for the algorithm
here, or is it just for printing the result out at the end? (i.e. will
this thing work without it?)
Also, what is the ||= operator?
Actually, it occurs to me that I am going to look up the answers to these
questions for myself, but feel free to answer for posterity's sake and for the
interest of anyone else tuning in...
Also, also, is this sort of algorithm typically covered in CS classes?
(Just to put a not-completely-relevant question out there) I no take CS
classes cause me dumb. (Actually, 'cause I have a biology degree instead.)
Thanks for your help!
--
Jeffrey D. Silverman | jeffrey AT jhu DOT edu
Johns Hopkins University | Baltimore, MD
Website | http://www.wse.jhu.edu/newtnotes/
------------------------------
Date: Fri, 13 Jun 2003 10:44:09 -0400
From: "Jeffrey Silverman" <jeffrey@jhu.edu>
Subject: Re: Sorting Algorithm: organize data into a tree
Message-Id: <pan.2003.06.13.14.44.06.560116@jhu.edu>
On Thu, 12 Jun 2003 12:51:33 -0700, Nikolai Chuvakhin wrote:
> "Jeffrey Silverman" <jeffrey@jhu.edu> wrote in message
> news:<pan.2003.06.12.14.09.21.340715@jhu.edu>...
>>
>> I am cross-posting to PHP and Perl newsgroups, as the algorithm I am
>> seeking should be fairly language-agnostic, and I know both Perl and PHP.
>>
>> I need to organize a multi-dimensional array into a tree. The data
>> structure is roughly as follows:
<snip!>
>
> Let me ask a couple of clarifying questions:
>
> 1. What happens to the "data"? I can't see it anywhere in the
> structure of the target array? In the source array, element
> "B" has "data", in the target array, it doesn't.
Not important. Pretend it isn't there; I am going to do stuff with it
later.
>
> 2. What is the significance of the "self" field in the original
> array? If it only duplicates a higher-level key, it serves
> no purpose other than creating confusion. If it can be
> different from the higher-level key, it can screw up the
> conversion. For example, the array
<snip!>
Right. "self" will *never* be different from its index because of the way the
"self" field is created. that is, "self" is *always* equal
to its index. I know it's redundant. I suppose I should get rid of it,
though, huh? Might make everything less confusing for me...
> 3. How do you safeguard against circular references? How would
> you get out of something like this?
I haven't thought about this, but the data source is well structured and
resonably well protected from this problem. I've implemented safeguards
on the side of the data source rather than within the scope of this
script. (The data source is a database. I create the initial array from
selected database fields).
<snip!>
> Cheers,
> NC
--
Jeffrey D. Silverman | jeffrey AT jhu DOT edu
Johns Hopkins University | Baltimore, MD
Website | http://www.wse.jhu.edu/newtnotes/
------------------------------
Date: Fri, 13 Jun 2003 07:12:23 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: test
Message-Id: <slrnbejft7.4cc.tadmc@magna.augustmail.com>
Rohan Romanus Almeida <arc_of_descent@gmx.net> wrote:
> This is just a test
> It is my first post to this group.
It is your last post that I will be reading.
There are test newsgroups for posting test messages.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 13 Jun 2003 07:46:51 -0700
From: evia@excel.com (Eric)
Subject: Using a while loop to search/remove lines..
Message-Id: <9bdebd3.0306130646.5bf72e64@posting.google.com>
Perl friends,
I am doing something in a script that is WORKING - but it's a
bonehead way of doing it - and so it's bugging me - please glance at
the code below - what it does in a nutshell is open a file of hundreds
of thousands of lines, and search EACH line for a number - if FOUND -
it's removed.
But - look below - see the times I look for "tpn" in my big input
file? In reality I do 150 OTHER numbers - so my script is basically
silly - it just so happens I'm good with SED and VI and can easily
modify my Perl script to do so many lines of "if ($tpn != "nnnnn").
I'd RATHER do it a more professional way - that being to open my
huge input, THEN open the listing of 150 numbers - and loop through
them - but what happens when I tried it that way was that each time I
searched one line in my input for 150 different numbers, if the number
was NOT found I'd print it 150 times - so if I wanted to strip an
input file of 10 records of a possible 150 numbers - when it was all
said and done I'd end up with HUNDREDS of lines of output where it
didn't match my number (Sure I could sort it after-the-fact but that's
hokey too!) it was something about WHERE I was putting the "print
OUTPUT" line in the loop - and it confused me no end.
Here's what my code looks like - works fine - but again - must I
list EACH number to search for!?:
open(OUTPUT, ">MODIFIED_$file") || die "Can't open the output
file!\n";
open(INFO, $file) || die "WHERE IS IT ERIC!!? Fool!\n";
while(<INFO>){
$originalcount++;
$tpn = substr($_,196,5);
if ($tpn != "10638"
&& $tpn != "10638"
&& $tpn != "40843"
&& $tpn != "30808"
&& $tpn != "33548") {
print OUTPUT "$_";
$keep++
} else {
$removecount++
}
}
I hope I make sense and I thank you for your time!
Eric
------------------------------
Date: Fri, 13 Jun 2003 09:36:10 -0500
From: "J. Gleixner" <glex_nospam@qwest.net>
Subject: Re: Which value is tha largest(benchmarked)
Message-Id: <kjlGa.68$vb7.16544@news.uswest.net>
> Remember, the Universe favors disorder, so only sort when needed. :-)
I forgot to add that in this case sorting is needed, since you want to
impart some sort of order or results of an order. It doesn't make sense
to sort something then do a linear search looking for the max/min. Sort
it and use the results of the sort.
------------------------------
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 5116
***************************************