[22691] in Perl-Users-Digest
Perl-Users Digest, Issue: 4912 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 29 21:06:21 2003
Date: Tue, 29 Apr 2003 18: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 Tue, 29 Apr 2003 Volume: 10 Number: 4912
Today's topics:
[ANNOUNCE] wxPerl 0.14 <mbarbon@delete_me.dsi.unive.it>
Re: AUTOLOAD runs repetitively on destruction <goldbb2@earthlink.net>
Re: books from beginner to guru - reading order <spamtrap@nowhere.com>
Re: Difference Flat Text & DBM Database <spamtrap@nowhere.com>
Re: errors passing values to sub from other sub with "u <anthony@movielink.net.au>
Re: errors passing values to sub from other sub with "u <anthony@movielink.net.au>
Re: file search logic <laocoon@eudoramail.com>
FW: How to determine width of text strings as displayed <russ.johnson@earthlink.net>
Re: FW: How to determine width of text strings as displ <goedicke@goedsole.com>
Lingua::EN::NameParse name parsing problem <bing-du@tamu.edu>
Re: Newbie cannot compile :( <spamtrap@nowhere.com>
NEWBIE: using zip::archive to extract files that only e (jdlail)
Problem building perl with DB support <ddunham@redwood.taos.com>
Re: problems finding an RPM - what is PLD? <goedicke@goedsole.com>
Re: problems finding an RPM - what is PLD? (Tad McClellan)
Reference Question (Michael Spertus)
Re: Reference Question <goedicke@goedsole.com>
Re: Reference Question <uri@stemsystems.com>
Re: Reference Question <w.koenig@acm.org>
Rounding the figures..... (Sara)
Re: Rounding the figures..... <noreply@gunnar.cc>
Re: Rounding the figures..... <kalinabears@hdc.com.au>
Re: Rounding the figures..... <TruthXayer@yahoo.com>
Re: search, replace and insert. <goldbb2@earthlink.net>
Re: setting a variable from a line in a file (Tad McClellan)
Re: Sybperl DBlib <spamtrap@nowhere.com>
Re: WTB: Programming PERL DBI <jboes@nexcerpt.com>
Re: WTB: Programming PERL DBI <goedicke@goedsole.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 29 Apr 2003 21:12:37 GMT
From: Mattia Barbon <mbarbon@delete_me.dsi.unive.it>
Subject: [ANNOUNCE] wxPerl 0.14
Message-Id: <Xns936CC1DD1145Bmbarbondsiuniveit@192.168.9.1>
A new version of wxPerl, the Perl bindings to wxWindows, is out!
wxWindows is a free and cross platform (Windows/Motif/GTK/Mac) C++ GUI
toolkit with native look and feel. (visit http://www.wxwindows.org/
for details).
You can download wxPerl sources from
$CPAN/authors/id/M/MB/MBARBON/Wx-0.14.tar.gz;
Binary packages for ActivePerl/Win32 6xx and 8xx builds, and Red Hat
Linux are available along with documentation in HTML and MS HTML Help
format from http://wxperl.sourceforge.net/
The project home page is http://wxperl.sourceforge.net/. There is also
a mailing list dedicated to wxPerl users:
wxperl-users@lists.sourceforge.net
Changes since the last version:
- new DEPRECATIONS section in README.txt, please read it
- Added Wx::DateTime (not the full interface).
- Restored compatibility with perl 5.005.
- Internal changes: objects returned by various constructors
will not have an additional _WXTHIS key anymore.
Regards
Mattia
------------------------------
Date: Tue, 29 Apr 2003 12:59:58 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: AUTOLOAD runs repetitively on destruction
Message-Id: <3EAEAF8E.DDB804CD@earthlink.net>
JS Bangs wrote:
>
> Tassilo v. Parseval sikyal:
>
> I've changed the subject line, because I've got a new problem.
>
> > Is there a way to turn the above into proper methods that you can
> > compile on the fly? Right now, AUTOLOAD is triggered for each call to
> > the same feature. Something like
> >
> > if ($self->feature($feature)) {
> > *$AUTOLOAD = eval qq!
> > sub $feature {
> > my (\$self, \$idx) = \@_;
> > ...
> > }
> > !;
> > goto &$AUTOLOAD;
> > }
That doesn't look quite right. It should either be:
*$AUTOLOAD = sub { .... };
Or
*$AUTOLOAD = eval qq!sub { .... }!;
Or:
eval qq!sub $AUTOLOAD { ... };
But not:
*$AUTOLOAD = eval qq!sub $AUTOLOAD { .... }!;
> This looked like a great idea, and as far as the feature-name methods
> are concerned, it works perfectly. But now there's a new problem: when
> the program ends, DESTROY() is trapped by AUTOLOAD and recurses through
> the subroutine infinitely.
>
> The old code, which looked broken, didn't have this problem. And I'm
> stumped--the best I can think of is to define a local DESTROY, but
> that's an inelegant way to hack out of this.
Actually, creating a "sub DESTROY {}" is probably the most optimal fix,
since you *know* that it's going to eventually get called, and you don't
need it to do anything.
[snip]
Your AUTOLOAD sub could be significantly simplified:
sub AUTOLOAD {
(my $feature = $AUTOLOAD) =~ s/.*:://;
die unless $_[0]->feature($feature);
my $coderef = sub {
my $self = shift;
$self->value( $feature, shift ) if @_;
$self->feature_index( $feature, shift ) if @_;
$self->value( $feature );
};
{
no strict 'refs';
*$feature = $coderef;
}
goto &$coderef;
}
[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: Tue, 29 Apr 2003 18:48:57 GMT
From: Andrew Lee <spamtrap@nowhere.com>
Subject: Re: books from beginner to guru - reading order
Message-Id: <sjhtav86cmv5mffihdn1hctdig2eodk1f7@4ax.com>
On 28 Apr 2003 08:23:43 -0700, fumail@freeuk.com (qanda) wrote:
>Hi all
>
>Would you be able to give me a list of books and the reading order
>that a programmer would need to learn Perl, from the basics through to
>advanced topcs.
ALso, don't forget to look at the online tutorials
perlretut, perlreftut, perldebtut, perlopentut, perlpacktut, perlboot,
perltoot, perbot, perldsc
Books are not meant as a replacement for online documentation. Online
documentation is not a replacement for books. They work hand in hand.
Using perdoc is a good habit to learn at the outset.
I wish someone had told me this earlier! :-)
HTH
------------------------------
Date: Tue, 29 Apr 2003 18:25:20 GMT
From: Andrew Lee <spamtrap@nowhere.com>
Subject: Re: Difference Flat Text & DBM Database
Message-Id: <r8ftavcjnuf7li666b350tee4jt0ft5mk0@4ax.com>
On 28 Apr 2003 21:34:12 -0700, csdude@hotmail.com (Mike) wrote:
>Is there an advantage to the DBM database that I'm not seeing?
>
>TIA,
>
>Mike
Speed, ease of use.
SBDM uses a technique called Dynamic Hashing. Briefly, the SDBM file
uses binary hash trees internally to point to data. A retrieval can
often be done with a single disk access. Using a text file requires
that you scan the file from the top until you find the key (not even a
binary search on ordered keys -- yech!).
For a small amount of data, the difference is not dramatic. If you
create 10,000 key value pairs and try each method you will notice a
difference ... That is the power of random versus sequential access. In
fact that may be a worthwhile exercise.
As for ease of uses, it is a LOT easier to say
print $tied_hash{$key}
than to fetch the data via scanning the file and pulling that data into
a hash then printing.
There are other less obvious advantages. Suppose you are reading in a
flat file of strings, like stock symbols. You don't want to store the
same stock symbol twice. With a tied hash you can say :
while (<SYMBOLS>) {
if ($tied_hash{$_}) { next}
else {$tied_hash{$_} = 1;}
}
Then you can say :
print sort keys %tied_hash;
To get a sorted list of all symbols with no repetitions. Doing that
with a flat file can be tedious and slow.
HTH
------------------------------
Date: Wed, 30 Apr 2003 09:57:21 +1000
From: "Tony" <anthony@movielink.net.au>
Subject: Re: errors passing values to sub from other sub with "use strict"
Message-Id: <pan.2003.04.29.23.57.19.861577@movielink.net.au>
To the guys that replied,
Thanks for trying - I did post a followup to my own post
when I realised some bobo had been made but it never came through :-(
Anyway lets put it right...
I posted a reduced program snippet as some of the stuff
going on in my code would just take up a lot of room for nothing
(Trying to do the right thing (TM)).
On Tue, 29 Apr 2003 12:55:37 +0200, Gunnar Hjalmarsson wrote:
> Tony wrote:
>> During the course of some perl programming I have come accross
>> a specific problem that has got me stumped.
>>
>> I have a small program (Simplified) with 2 sub's:
With corrections...
#!/usr/bin/perl
use warnings;
use strict;
@list = ("/this/path/file_1.txt 1", "this/path/file_2.txt 3");
process_list(@list)
sub process_list
{
foreach $item(@LIST);
my $var1 = "perl"; # Fixed string...
my $var2 = $item; # Copy so orig preserved
chop($var2) # Get rid of trailing digit - crude I know
my $var3 = $item;
my $var3 = chop($var3); # Leave trailing digit, loose the rest
do_something($var1,$var2,$var3) # Pass to sub do_something
}
### I know the above can be done better but this is only a test
### (And I am a newbie...give me time)
sub do_something
{
my $var_1 = "Good";
my $var_2 = "morning";
my $var_3 = $var1;
my $var_4 = $var2;
my $var_5 = $var3;
print "$var_1 $var_2 $var_3 $var_4 $var_5\n"
}
Should print:
Good morning perl /this/path/file_1.txt 1
Good morning perl /this/path/file_2.txt 3
Well it does not - I have just read up again on passing
variables to a sub. It would seem that my aproach
is flawed:-(
Is this more correct?:
sub do_something
{
my $var_1 = "Good";
my $var_2 = "morning";
my $var_3 = @_[1];
my $var_4 = @_[2];
my $var_5 = @_[3];
print "$var_1 $var_2 $var_3 $var_4 $var_5\n"
}
> <snip>
>
>> foreach $item(@LIST);
> ------------------^^^^^
> Where did that variable come from?
>
> Arguments passed to a subroutine can be found in the array @_ .
>
>> This works when switching off "use strict" but with "use strict"
>> all saundry errors like
>
> What you say "works" is calling _global_ variables from within a
> subroutine. You seem not to know how to grab arguments passed to a
> subroutine.
>
>> What am I doing wrong - reading "Learning perl" and the Camel book
>> 3rd ed. does not shed any light over it.
>
> Sounds odd. Try to read a little more. Or try
> http://www.perldoc.com/perl5.8.0/pod/perlsub.html
>
> / Gunnar
--
--------------------------------------------------------------
To reply directly send to: anthony AT movielink DOT net DOT au
Replace AT and DOT with @ and . and mail will get through.
Any spammers will be persued until they get booted off the net
------------------------------
Date: Wed, 30 Apr 2003 10:10:08 +1000
From: "Tony" <anthony@movielink.net.au>
Subject: Re: errors passing values to sub from other sub with "use strict"
Message-Id: <pan.2003.04.30.00.10.07.752027@movielink.net.au>
On Tue, 29 Apr 2003 12:55:37 +0200, Gunnar Hjalmarsson wrote:
> Tony wrote:
>> During the course of some perl programming I have come accross
>> a specific problem that has got me stumped.
>>
>> I have a small program (Simplified) with 2 sub's:
>
> <snip>
Hi again,
I have a further correction:
sub do_something
{
my $var_1 = "Good";
my $var_2 = "morning";
my $var_3 = @_[1];
my $var_4 = @_[2];
my $var_5 = @_[3];
print "$var_1 $var_2 $var_3 $var_4 $var_5\n"
}
was wrong, should be
sub do_something
{
my $var_1 = "Good";
my $var_2 = "morning";
my $var_3 = $_[0];
my $var_4 = $_[1];
my $var_5 = $_[2];
print "$var_1 $var_2 $var_3 $var_4 $var_5\n"
}
However switching on "use strict" still splutters....
A little more fiddling turned out that I was not defining
all $var's as local (my $something) - all works fine now.
Thank you guys.
Tony
>
>> What am I doing wrong - reading "Learning perl" and the Camel book
>> 3rd ed. does not shed any light over it.
>
> Sounds odd. Try to read a little more. Or try
> http://www.perldoc.com/perl5.8.0/pod/perlsub.html
>
> / Gunnar
--
--------------------------------------------------------------
To reply directly send to: anthony AT movielink DOT net DOT au
Replace AT and DOT with @ and . and mail will get through.
Any spammers will be persued until they get booted off the net
------------------------------
Date: Tue, 29 Apr 2003 21:09:30 +0200
From: Lao Coon <laocoon@eudoramail.com>
Subject: Re: file search logic
Message-Id: <pan.2003.04.29.19.09.30.319444.191@eudoramail.com>
On Tue, 29 Apr 2003 19:19:35 +0200, P S Mahesh wrote:
> Hi Folks,
>
> I have a file which contains a certain pattern "get_clear_data" and some
> lines in between them.
>
> get_clear_data 0 0 0
> -------
> --
> get_clear_data 0 1 0
> --
>
> I need to search in between this two occurences and find if a
> string"XXX" is present and if it is present. I need to print the
> previous get_clear_data pattern. I tried a couple of logics, could not
> get a head start. Can anyone suggest a proper logic.
$/ = "get_clear_data";
while(<INPUT>) {
if(/(.+?)\n.*SEARCH_STRING.*/ms) {
my $pattern = $1;
# ...
}
}
HTH
Lao
> thanks,
> mahesh.
------------------------------
Date: Tue, 29 Apr 2003 21:03:31 GMT
From: "Russ Johnson" <russ.johnson@earthlink.net>
Subject: FW: How to determine width of text strings as displayed in a given font?
Message-Id: <DMBra.47430$4P1.4431276@newsread2.prod.itd.earthlink.net>
I need to determine the widths of specified text strings as displayed in a
given variable-width (proportional) font (such as Times New Roman).
I have created 31102 (one for each verse in the Bible) "tables" like the one
below, using a fixed-width (non-proportional) font (Courier) and aligning
the "columns" with blank (" ") characters where needed. [If the "table"
below does NOT show proper column alignment, you're probably viewing it in a
variable width (proportional) font.]
1:1 ¶ In the beginning God created the
[Re22:19.42] [Re22:21.1] [Re22:13.7] [Re22:19.17] [Re10:6.12] 1:1.2
1:6.9 1:1.6 10:10.3 1:2.22 1:21.3 1:1.9
heaven and the earth.
[Re21:10.27] [Re22:19.35] 1:1.6 [Re21:24.21]
1:8.6 1:2.1 1:2.2 1:2.3
What I need to do, instead, is to create 31102 corresponding RTF tables,
using a variable-width (proportional) font (Times New Roman?) and sizing
each column by the maximum width of its contents. Does PERL have (or
support) a function to determine the widths (in inches, cm, points, TWIPS,
etc.) of specified text strings as displayed in a given non-proportional
font?
Or, is there a better way of accomplishing the same thing? [My real need is
to create something which is well formatted for printing, not something for
online display or editing, so I don't necessarily need to use RTF.]
Thanks for any information you can provide.
- Russ Johnson
JohnsonRuss@NetZero.com
Terre Hill, PA USA
------------------------------
Date: Tue, 29 Apr 2003 21:10:28 GMT
From: William Goedicke <goedicke@goedsole.com>
Subject: Re: FW: How to determine width of text strings as displayed in a given font?
Message-Id: <m3llxtdn7r.fsf@mail.goedsole.com>
Dear Russ -
"Russ Johnson" <russ.johnson@earthlink.net> writes:
> What I need to do, instead, is to create 31102 corresponding RTF
> tables, using a variable-width (proportional) font (Times New
> Roman?) and sizing each column by the maximum width of its
> contents. [...] Or, is there a better way of accomplishing the same
> thing? [My real need is to create something which is well formatted
> for printing
You need TeX.
Yours - Billy
============================================================
William Goedicke goedicke@goedsole.com
http://www.goedsole.com:8080
============================================================
Lest we forget:
Genomes act as the initial sequence for Wolframish "basic
rules" implemented by the amino acids.
- William Goedicke
------------------------------
Date: Tue, 29 Apr 2003 14:18:57 -0500
From: Bing Du Test <bing-du@tamu.edu>
Subject: Lingua::EN::NameParse name parsing problem
Message-Id: <3EAED021.84959A9E@tamu.edu>
This is perl, v5.6.1 built for sun4-solaris.
============
#!/usr/local/bin/perl
use locale;
use Lingua::EN::NameParse qw(clean case_surname);
$::RD_HINT = 1;
my %args =
(
salutation => 'Dear',
sal_default => 'Friend',
auto_clean => 1,
force_case => 1,
lc_prefix => 1,
initials => 3,
allow_reversed => 1
);
my $name = new Lingua::EN::NameParse(%args);
open(TESTS, "tests.txt") || die "Could not open input file: $!\n";
while (<TESTS>) {
chop;
$TestName = $_;
# Call the parser
$error = $name->parse($_);
if ( $error ) {
print "\nName parse failed for $_\n\n";
}
}
close TESTS;
=========
File tests.txt only has one name 'foo bar'.
Running the script returns the following results:
=======
ERROR: Internal error in generated parser code!
(Hint: Can't localize lexical variable $tracelevel at
(eval
91) line 25. )
Assembling with: <foo bar >
Name = <Lingua::EN::NameParse=HASH(0x61214)>, input_string = <foo bar >
Can't call method "full_name" on an undefined value at
/usr/local/perl/5.6.1/lib
/site_perl/5.6.1/Lingua/EN/NameParse.pm line 1006, <TESTS> line 1.
=======
What is the problem and how should I get it fixed?
Thanks in advance for any help,
Bing
------------------------------
Date: Tue, 29 Apr 2003 18:57:30 GMT
From: Andrew Lee <spamtrap@nowhere.com>
Subject: Re: Newbie cannot compile :(
Message-Id: <pkitav475uiflmv4krbfg3de5d9h1vg4r9@4ax.com>
On Mon, 28 Apr 2003 13:46:48 -0500, Jeff D Gleixner
<glex_nospam@qwest.net> wrote:
>ibits wrote:
>> I had some questions about my program. I can't compile/run the program
>> because of some errors. Can anyone please take a look at my program
>> and direct me to make the appropriate corrections.
>
>The error points you right to the line in question.
>
>Look at perldoc CGI a bit more, you don't need all those CGI objects. Also,
>be sure to
>
>use warnings;
>use strict;
>
Toss in use diagnostics too
------------------------------
Date: 29 Apr 2003 11:40:08 -0700
From: jdlail@hotmail.com (jdlail)
Subject: NEWBIE: using zip::archive to extract files that only end in 1p.eps
Message-Id: <e32bb269.0304291040.463e6f9d@posting.google.com>
I need a little help in figuring out how to extract from a zip file
only those files that end in 1p.eps using zip::archive.
Can anybody give me some example code for that?
-- jack lail
------------------------------
Date: Tue, 29 Apr 2003 18:36:38 GMT
From: Darren Dunham <ddunham@redwood.taos.com>
Subject: Problem building perl with DB support
Message-Id: <WCzra.82$Be1.17578250@newssvr21.news.prodigy.com>
I'm trying to build perl-5.8.0 with berkeley db-4.1.25. I see the
notice in INSTALL about building with db-3, so I'm assuming the same
steps go for db-4.
I've built the db libraries straight, with --enable-compat185, and with
the extra links in the library directory. Each time, I get failures
during the perl build.
gcc -c -fno-strict-aliasing -I/usr/site/db/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O -DVERSION=\"1.804\" -DXS_VERSION=\"1.804\" -fPIC "-I../.." DB_File.c
DB_File.xs: In function `ParseOpenInfo':
DB_File.xs:1370: warning: passing arg 2 of pointer to function from incompatible pointer type
DB_File.xs:1370: incompatible type for argument 4 of indirect function call
DB_File.xs:1370: too few arguments to function
*** Error code 1
make: Fatal error: Command failed for target `DB_File.o'
Current working directory /server2/home/add/src/perl-5.8.0/ext/DB_File
*** Error code 1
make: Fatal error: Command failed for target `lib/auto/DB_File/DB_File.so'
Is there something else that I'm missing?
Solaris 8, x86, gcc 2.95.3
Thanks!
--
Darren Dunham ddunham@taos.com
Unix System Administrator Taos - The SysAdmin Company
Got some Dr Pepper? San Francisco, CA bay area
< This line left intentionally blank to confuse you. >
------------------------------
Date: Tue, 29 Apr 2003 20:33:38 GMT
From: William Goedicke <goedicke@goedsole.com>
Subject: Re: problems finding an RPM - what is PLD?
Message-Id: <m3u1chdox6.fsf@mail.goedsole.com>
Dear Mark -
Mark Seger <mark.seger@hp.com> writes:
> it did tell me it couldn't find lynx but it never told me it was
> required.
Indeed, I was more suspicious of the ncftp stuff. lynx can come in
quite handy.
> I'm running redhat 7.2
If you're using the redhat delivered perl I'd do a reinstall from
scratch (and yes I remember your original point was to acquire the
convenience of RPMs). I've found the atypical redhat delivered
installation of perl to be nothing but heartache. (I was responsible
for several hundred redhat boxes at a web-hosting firm in a previous
job.) After trying to make things smooth with perl RPMs for about 6
months I switched to standard perl and things got much smoother.
Otherwise (with the exception of apache) I agree wholeheartedly that
RPMs are your friend.
Once that one-time install from tarball is done I'll bet everything
goes smoothly using the interactive CPAN.
Yours - Billy
============================================================
William Goedicke goedicke@goedsole.com
http://www.goedsole.com:8080
============================================================
Lest we forget:
For Heaven's sake McClusky close your valve.
- Evelyn Spillane (aka Nana)
------------------------------
Date: Tue, 29 Apr 2003 16:43:09 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: problems finding an RPM - what is PLD?
Message-Id: <slrnbatsfd.23h.tadmc@magna.augustmail.com>
William Goedicke <goedicke@goedsole.com> wrote:
> Yes, you change the default @INC value for perl. I don't know how,
> but it's in some startup script.
No it isn't.
It is compiled into the perl binary when it is built.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 29 Apr 2003 13:56:58 -0700
From: mps@geodesic.com (Michael Spertus)
Subject: Reference Question
Message-Id: <97be4c1e.0304291256.6e59b3c@posting.google.com>
How do I create a reference to a list returned by subroutine. In other
words, I have a subroutine "foo" that I want to invoke in list context
and store a reference to the returned list. None of the obvious things
seem to work.
Mike
------------------------------
Date: Tue, 29 Apr 2003 21:00:52 GMT
From: William Goedicke <goedicke@goedsole.com>
Subject: Re: Reference Question
Message-Id: <m3ptn5dnnr.fsf@mail.goedsole.com>
Dear Mike -
mps@geodesic.com (Michael Spertus) writes:
> How do I create a reference to a list returned by subroutine. In other
> words, I have a subroutine "foo" that I want to invoke in list context
> and store a reference to the returned list. None of the obvious things
> seem to work.
I don't think I understand what you want. Can you try saying it in perl?
Yours - Billy
============================================================
William Goedicke goedicke@goedsole.com
http://www.goedsole.com:8080
============================================================
Lest we forget:
When you think something nice about someone you're with, tell them
about it.
- William Goedicke
------------------------------
Date: Tue, 29 Apr 2003 21:06:35 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Reference Question
Message-Id: <x7he8h109w.fsf@mail.sysarch.com>
>>>>> "MS" == Michael Spertus <mps@geodesic.com> writes:
MS> How do I create a reference to a list returned by subroutine. In other
MS> words, I have a subroutine "foo" that I want to invoke in list context
MS> and store a reference to the returned list. None of the obvious things
MS> seem to work.
you can't get a reference to a list. you either return a list ref from
the sub (if you coded that sub) or copy the list to a new anon array and
use that:
@array = [ sub_returning_list() ] ;
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: Wed, 30 Apr 2003 02:10:29 +0200
From: Winfried Koenig <w.koenig@acm.org>
Subject: Re: Reference Question
Message-Id: <3EAF1475.6060904@acm.org>
Uri Guttman wrote:
>>>>>>"MS" == Michael Spertus <mps@geodesic.com> writes:
>
> MS> How do I create a reference to a list returned by subroutine.
>
> you can't get a reference to a list. you either return a list ref from
> the sub (if you coded that sub) or copy the list to a new anon array and
> use that:
>
> @array = [ sub_returning_list() ] ;
a typo, better use:
$array_ref = [ sub_returning_list() ];
Winfried Koenig
------------------------------
Date: 29 Apr 2003 14:27:18 -0700
From: sara_samsara5@yahoo.com (Sara)
Subject: Rounding the figures.....
Message-Id: <9365982e.0304291327.1c1255a0@posting.google.com>
Rounding the figures:
$line = 630;
$line = $line - ($line % 65);
$lines = $line/65;
The above given simply divides 630 by 65 and give the result for 9.692
in rounded figures i.e. 9 only.
---------
I also used the sprintf function to get the result in rounded figures
like...
$line = 630;
$line = $line - ($line % 65);
$lines = $line/65;
$rounded = sprintf("%.2f", $lines);
print "$rounded\n";
-------------
Both of these are working fine, but as you see if the result is
greater than 9.5, it should be rounded to 10 and if its less than 9.5
(as per rules of mathematics) it should be rounded to 9 and this piece
of code even round 9.99 to 9? Is there any way to round the figures
e.g. to 10 when its greater than 9.5
Any help?
TIA,
Sara.
------------------------------
Date: Tue, 29 Apr 2003 23:53:46 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Rounding the figures.....
Message-Id: <b8ms7h$birg9$1@ID-184292.news.dfncis.de>
Sara wrote:
> Rounding the figures:
>
> $line = 630;
> $line = $line - ($line % 65);
> $lines = $line/65;
>
> The above given simply divides 630 by 65
No it doesn't. At the second line, $line is assigned the value 585, so
it divides 585 by 65, which is _exactly_ 9.
http://www.perldoc.com/perl5.8.0/pod/perlop.html#Multiplicative-Operators
> I also used the sprintf function to get the result in rounded figures
> like...
And that's the way to go - when there is anything to round... ;-)
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 30 Apr 2003 09:38:16 +1000
From: "Sisyphus" <kalinabears@hdc.com.au>
Subject: Re: Rounding the figures.....
Message-Id: <3eaf0def$0$23941@echo-01.iinet.net.au>
"Sara" <sara_samsara5@yahoo.com> wrote in message
news:9365982e.0304291327.1c1255a0@posting.google.com...
<snip>
> Is there any way to round the figures
> e.g. to 10 when its greater than 9.5
>
> Any help?
>
> TIA,
>
> Sara.
I think most use sprintf(). (See perldoc -q round.)
I like to use:
my $x_rounded = int($x + 0.5);
Cheers,
Rob
------------------------------
Date: Tue, 29 Apr 2003 17:16:57 -0700
From: TruthXayer <TruthXayer@yahoo.com>
To: Sisyphus <kalinabears@hdc.com.au>
Subject: Re: Rounding the figures.....
Message-Id: <3EAF15F9.DBC22617@yahoo.com>
Sisyphus wrote:
> =
> "Sara" <sara_samsara5@yahoo.com> wrote in message
> news:9365982e.0304291327.1c1255a0@posting.google.com...
> =
> <snip>
> > Is there any way to round the figures
> > e.g. to 10 when its greater than 9.5
Check the following routines and use as required...
In your case you could just use ceil,floor POSIX functions
as well.
Here is a routine to round to as many digits after decimal
as you like...
my $y =3D round_to_digits($x,0);
my $z =3D round_to_digits($x,1);
print "Y:$y Z:$z\n";
##
## -> Y:10 Z:9.5
##
sub round_to_digits {
my $number =3D shift;
my $digits =3D shift;
my $multiple =3D 10 ** -$digits;
return round_to_multiple($number, $multiple);
}
sub round_to_multiple {
my $number =3D shift;
my $multiple =3D shift;
my $result;
if ($number > 0) {
$result =3D int($number / $multiple + 0.5) * $multiple
} elsif ($number < 0) {
$result =3D int($number / $multiple - 0.5) * $multiple
} else {
$result =3D 0
}
return $result;
}
-- =
thanks
-Tr=DCtH
------------------------------
Date: Tue, 29 Apr 2003 16:06:10 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: search, replace and insert.
Message-Id: <3EAEDB32.898127FD@earthlink.net>
Abhi wrote:
>
> Hi,
>
> I am making an rpm which involves enabling mod_proxy module in
> httpd.conf of apache
>
> Assume that original httpd.conf has been backedup and it is safe to
> make this change.
>
> What I need to do is to enable/uncomment the mod_proxy module entries
> i.e.
>
> perl -pi -e 's|^#LoadModule proxy_module|LoadModule proxy_module|g' /etc/httpd/conf/httpd.conf
> perl -pi -e 's|^#AddModule mod_proxy.c|AddModule mod_proxy.c|g' /etc/httpd/conf/httpd.conf
This could each be written shorter:
perl -pi -e 's,^#(?=LoadModule proxy_module),," /etc/httpd/conf/httpd.conf
perl -pi -e 's,^#(?=AddModule mod_proxy.c),," /etc/httpd/conf/httpd.conf
Or combined:
perl -pi -e 's,^#(?=LoadModule proxy_module|AddModule mod_proxy.c),," /etc/httpd/conf/httpd.conf
> but the problem is I also need to do this :
>
> perl -pi -e 's|^#<IfModule mod_proxy.c>|<IfModule mod_proxy.c>|g' /etc/httpd/conf/httpd.conf
>
> and insert a few entries on a new line afterwards, and then uncomment the
> *next* matching </IfModule>
>
> I can ofcourse do this with a seperate perl script file that reads the
> config file into an array, makes the necessary changes and writes back to
> the file.
>
> But is it possible to do this without including and invoking a seperate perl
> script file in the rpm ? I mean just using the perl -pi -e syntax in the rpm
> spec file ?
I don't know the syntax of rpm, but does it allow you to put a backslash
at the end of a line, and continue the command on the next line? If so,
then you could write:
perl -pi -e \
's,^#(?=LoadModule proxy_module|AddModule mod_proxy.c),,;' -e \
'(s,^#(?=<IfModule mod_proxy.c>)#, && ' -e \
' $_ .= "New Text Here") ..' -e \
's,^#(?=<IfModule mod_proxy.c>)#,;' \
/etc/httpd/conf/httpd.conf
Actually, you could do it without the \ wrapping, but putting that in makes
it significantly easier to read.
--
$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: Tue, 29 Apr 2003 16:21:40 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: setting a variable from a line in a file
Message-Id: <slrnbatr74.23h.tadmc@magna.augustmail.com>
Peter Wilson <peter_wilson@mail.com> wrote:
> "Tad McClellan" <tadmc@augustmail.com> wrote in message
> news:slrnbarhpu.inp.tadmc@magna.augustmail.com...
>> Peter Wilson <peter_wilson@mail.com> wrote:
>>
>> > open(filelist,$list_of_files_filename)
>>
>>
>> There are three things wrong with that line of code.
>>
>> Do you know what they are?
[snip full-quote]
> Yeah but it made the point and he
There are hundreds/thousand of other people here, reading posts and
copying the code they see. It should be good code.
> was happy.
He'll be less happy when the open() fails or when a new version
of Perl includes a filelist() function.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Tue, 29 Apr 2003 19:08:56 GMT
From: Andrew Lee <spamtrap@nowhere.com>
Subject: Re: Sybperl DBlib
Message-Id: <88jtav88346nani00l6chot77r88fm6ba8@4ax.com>
On Mon, 28 Apr 2003 13:57:35 -0700, "Alan" <arich@u.washington.edu>
wrote:
>I'm getting the below error when attempting to run a Sybperl module. @INC,
>whatever that is, is pointing to the wrong directory. How do I change @INC
>to point to c:\etc\perl\lib\site\Sybase instead?
>
>Can't locate Sybase/DBlib.pm in @INC (@INC contains: C:/Perl/lib
>C:/Perl/site/lib .) at
>F:\inetpub\wwwroot\clinical_apps\map\perl\clinical_cq.pl line 40. BEGIN
>failed--compilation aborted at
>F:\inetpub\wwwroot\clinical_apps\map\perl\clinical_cq.pl line 40.
>
First learn what @INC is.
perldoc perlvar
------------------------------
Date: Tue, 29 Apr 2003 20:17:16 GMT
From: Jeff Boes <jboes@nexcerpt.com>
Subject: Re: WTB: Programming PERL DBI
Message-Id: <cf9e772cb5a1b0707a22c8d33cdad45f@TeraNews>
On Sun, 27 Apr 2003 19:26:57 -0400, noipont wrote:
> Does anybody know where I can find this book? Possibly a used one in.
> TIA.. George
eBay has a copy on sale at least once a month.
--
Jeff Boes vox 269.226.9550 ext 24
Database Engineer fax 269.349.9076
Nexcerpt, Inc. http://www.nexcerpt.com
...Nexcerpt... Extend your Expertise
------------------------------
Date: Tue, 29 Apr 2003 20:24:10 GMT
From: William Goedicke <goedicke@goedsole.com>
Subject: Re: WTB: Programming PERL DBI
Message-Id: <m3y91tdpcx.fsf@mail.goedsole.com>
Dear George -
noipont@mailcity.com writes:
> Does anybody know where I can find this book? Possibly a used
> one in. TIA.. George
I'm a big fan of getting the book, but in this case don't
underestimate the thoroughness of perldoc (i.e. perldoc DBI).
Yours - Billy
============================================================
William Goedicke goedicke@goedsole.com
http://www.goedsole.com:8080
============================================================
Lest we forget:
In order to be valued at work you must get into the revenue
stream.
- William Goedicke
------------------------------
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 4912
***************************************