[19977] in Perl-Users-Digest
Perl-Users Digest, Issue: 2172 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 21 11:10:37 2001
Date: Wed, 21 Nov 2001 08:10:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1006359010-v10-i2172@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 21 Nov 2001 Volume: 10 Number: 2172
Today's topics:
Re: multiple arrays as arguments <angenent@kabelfoon.nl>
Re: multiple arrays as arguments (Tad McClellan)
Re: need help with a seemingly simple regex <godzilla@stomp.stomp.tokyo>
Re: need help with a seemingly simple regex <keesh@users-dot-sf.net>
Re: Newbie module problem <simon.oliver@umist.ac.uk>
Re: Overwriting a part of text using a perl script! <bernard.el-hagin@lido-tech.net>
perlcc + require'd files (Daniel Ellard,,,)
printing to a piped filehandle of sybase bcp (Gareth Wheelton)
Re: saving floats not as ascii <bernard.el-hagin@lido-tech.net>
Re: saving floats not as ascii <bart.lateur@skynet.be>
Re: saving floats not as ascii <edgue@web.de>
Re: Using CGI.pm to obtain a list of params (Tad McClellan)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 21 Nov 2001 15:08:23 +0100
From: "GOGAR" <angenent@kabelfoon.nl>
Subject: Re: multiple arrays as arguments
Message-Id: <9tgcdc$1ubc$1@news.kabelfoon.nl>
is there any performance decrease by using references throughout the sub?
i can imagine perl has to follow the reference everytime it is used..
so should people use the reference themselves or first inport the arrays
into the sub by references?
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrn9vlleu.lmu.tadmc@tadmc26.august.net...
> Mark Sidarous <sidarous@isr6132.urh.uiuc.edu> wrote:
>
> >Right now I'm passing in 2 arrays to a function as
> >arguments. Now Perl just lumps them into @_.
>
> >So this all WORKS, but it seems to be a very inefficient, slow way of
> >doing things. Is there a better way to pass these arrays in and return
> >them?
>
>
> Pass references to arrays instead of lists.
>
>
> >Also, I've considered the possibility of just having all the functions in
> >my program directly modify the arrays instead of passing them in as
> >arguments and returning the arrays after modification. Is this a better
> >way of doing things?
>
>
> Yes, passing arguments in undoubtably better than working on
> global array variables.
>
>
> >I want to keep things modular, and it seems to me
> >that the argument thing works better in that respect and seems like
> >there's less potential to screw things up, although its probably slower.
>
>
> Passing 2 scalars (references) will be a *whole lot* faster than
> passing all of the scalars from both arrays.
>
>
> --
> Tad McClellan SGML consulting
> tadmc@augustmail.com Perl programming
> Fort Worth, Texas
------------------------------
Date: Wed, 21 Nov 2001 15:26:59 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: multiple arrays as arguments
Message-Id: <slrn9vnet5.o29.tadmc@tadmc26.august.net>
[ Please put your comments *following* the quoted text that you
are commenting on.
Please do not quote an entire article.
Please do not quote .sigs.
Thank you.
Text rearranged into actual chronology.
]
GOGAR <angenent@kabelfoon.nl> wrote:
>"Tad McClellan" <tadmc@augustmail.com> wrote in message
>news:slrn9vlleu.lmu.tadmc@tadmc26.august.net...
>> Mark Sidarous <sidarous@isr6132.urh.uiuc.edu> wrote:
>>
>> >Right now I'm passing in 2 arrays to a function as
>> >arguments. Now Perl just lumps them into @_.
>> Pass references to arrays instead of lists.
>> >I want to keep things modular, and it seems to me
>> >that the argument thing works better in that respect and seems like
>> >there's less potential to screw things up, although its probably slower.
>>
>>
>> Passing 2 scalars (references) will be a *whole lot* faster than
>> passing all of the scalars from both arrays.
>is there any performance decrease by using references throughout the sub?
If speed of execution is of primary importance to your application,
then Perl is probably not a good choice of programming language.
If speed of development/maintenance is of primary importance, then
Perl is a profoundly good choice.
:-)
If using refs throughout is slower, then that needs to be weighed
against the speed gained by pushing/popping (sub call) 2 scalars
compared to some unknown (but presumed sizeable) number of scalars.
How many elements are typically in the arrays?
Which runs faster depends on other things (eg. data) besides
just the code, so there is not one answer to your question.
Better to try it out yourself in a situation approximating
your actual situation.
>i can imagine perl has to follow the reference everytime it is used..
I get the feeling you are thinking about doing premature-optimization,
but if you really want to know, code it up both ways and compare
them using the Benchmark module.
>so should people use the reference themselves or first inport the arrays
>into the sub by references?
I don't understand the question. I think that is because you are
misusing the term "import".
"import" has to do with namespaces (packages) which aren't
needed for the problem you outlined.
I think maybe you meant "pass" (as arguments) instead of "import"?
Even after making that assumption, I _still_ can't figure out
what you are asking :-(
Please try asking again and be clear about whether you are talking
about in the main code or in the subroutine code. Maybe even try
to include some Perl code that illustrates your question.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 21 Nov 2001 07:19:46 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: need help with a seemingly simple regex
Message-Id: <3BFBC612.DEA9ADF9@stomp.stomp.tokyo>
Martien Verbruggen wrote:
> [Do not pay any attention to what Godzilla says. It is a troll, and has
> no decent working knowledge of Perl, or programming in general. Search
> groups.google.com to see a history of its posts and replies to these
> posts.]
> Godzilla! wrote:
> > Martien Verbruggen wrote:
> [A set of correct solutions]
> I arrive home, where I haven't change my killfile back yet, and guess
> what I find: a troll who has no fscking clue about how to program, and
> can't even test a program.
> > open (DATA, "test.htm");
> You did't test the return value of this, did you, troll? Try it again,
> and now make sure you do.
Oh but I did, be sure! Actually, I test examples very fairly.
I test examples in ways you boys never imagine nor do, as shown
by my test jig script. I do what I can to eliminate all potential
sources of error.
> I was going to put you back in my killfile, but I've decided otherwise.
> I'll join Uri in making sure everyone knows what sort of crap programs
> you produce, and what sort of troll you are.
My goodness, such a psychotic emotional reaction! You are
certainly headed for a nervous breakdown!
Such intense hatred.
Crap programs! That is funny. For this topic, I provided the
quickest and most efficient methods to tackle this problem
per parameters provided by the originating author.
They actually work, Frank.
Godzilla!
--
TEST JIG SCRIPT:
________________
#!perl
print "Content-type: text/plain\n\n";
use strict;
use HTML::Parser;
my ($key_name, @Array);
print "Main Environment:\n\n";
foreach $key_name (keys %main::)
{ print "$key_name \n"; }
open (DATA, "test.htm") || die;
print "\n\nInput Data:\n\n";
@Array = <DATA>;
print "@Array\n\n";
seek (DATA, 0, 0);
my $p = HTML::Parser->new(start_h => [\&start, "tagname,attr"]);
$p->parse_file(\*DATA);
my @img;
sub start
{
my ($tag, $attr) = @_;
return unless $tag eq "img";
return if $attr->{src} =~ !m#(?:^|/)tn_\w+\.jpg$#;
push @img, $attr->{src};
}
close (DATA);
print "\n\nOutput Data:\n\n";
if (@img)
{ print "@img"; }
else
{ print "FUBAR!"; }
exit;
PRINTED RESULTS:
________________
Main Environment:
STDOUT
@
ARGV
STDIN
attributes::
DB::
_<..\xsutils.c
_<perllib.c
UNIVERSAL::
<none>::
DynaLoader::
ARNING_BITS
SIG
Exporter::
Win32::
warnings::
BEGIN
]
stderr
INC
_
!
"
DATA
_<.\win32.c
$
stdout
HTML::
IO::
ENV
vars::
strict::
Carp::
stdin
CORE::
/
0
1
2
3
_<..\universal.c
STDERR
start
main::
Input Data:
<HTML>
GARBAGE
<img src="images/large/0010.jpg">
GARBAGE
<img src="images/tn/tn_0010.jpg">
<img src="images/large/0102.jpg">
GARBAGE
<img src="images/tn/tn_0102.jpg">
<img src="images/tn/tn_0215.jpg">
<img src="images/large/0215.jpg">
GARBAGE
</HTML>
Output Data:
FUBAR!
------------------------------
Date: Wed, 21 Nov 2001 15:32:02 GMT
From: Ciaran McCreesh <keesh@users-dot-sf.net>
Subject: Re: need help with a seemingly simple regex
Message-Id: <SNPK7.13754$%j6.1374449@news1.cableinet.net>
Godzilla! wrote:
> print "Content-type: text/plain\n\n";
Oh dear... Shurely some mishtake? That would be \r\n\r\n , no?
------------------------------
Date: Wed, 21 Nov 2001 14:53:28 +0000
From: Simon Oliver <simon.oliver@umist.ac.uk>
To: Perry Wheeler <pwheeler@kentports.org>
Subject: Re: Newbie module problem
Message-Id: <3BFBBFE8.D15E1D9B@umist.ac.uk>
> OK I understand that it's a path problem and you're right - the @INC I
> get as a scheduled job is totally different to the one I get when
> running it in a shell it clearly refers back to a much earlier perl
> version.
Make your scheduled job use the same version of perl by editing the
shebang. This should fix all your problems.
--
Simon Oliver
------------------------------
Date: 21 Nov 2001 14:16:53 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: Overwriting a part of text using a perl script!
Message-Id: <slrn9vngpg.n27.bernard.el-hagin@gdndev25.lido-tech>
[please place your reply *after* what it is you're replying to]
On Wed, 21 Nov 2001 13:40:56 -0000, brian norman <brian.norman@gecm.com> wrote:
> "Kevin VAZ" <vazkevin@hotmail.com> wrote in message
> news:241f7389.0111202031.85cef2d@posting.google.com...
>> Dear All,
>>
>> Greetings!
>>
>> I'am new to perl, but use it for simple scripting. I'am facing a
>> problem in substituting the date in the header of a file. Was
>> wondering if we could overwrite only a selected portion of text.
>> Awating your response.
>
>
> open TMP,"<$file>";
> @Line=<TMP>;
> close TMP;
>
> $Line[0]="whatever you want to do with it";
>
> open TMP,">$file";
> print TMP @Lines;
> close TMP;
1. you didn't "use strict"
2. you didn't enable warnings
3. you didn't test the return value of open
4. twice
5. you have a typo (which would have been found if you weren't
guilty of 1 and 2)
6. you top-posted
Are you actually trying to *help* the OP or confuse him?
Cheers,
Bernard
------------------------------
Date: 21 Nov 2001 15:11:19 GMT
From: ellard2@is04.fas.harvard.edu (Daniel Ellard,,,)
Subject: perlcc + require'd files
Message-Id: <9tgg6n$461$1@news.fas.harvard.edu>
I've got a perl program that is composed of a bunch of small packages
that are all sucked into the main program via "require". I'd like to
use perlcc to speed up the execution of this program (I've had great
success with perlcc for other programs). Unfortunately, when I run
perlcc on the "main" file, it only compiles the main file and doesn't
touch the others. (I was hoping that it would pull in the packages
that this file requires, but that doesn't happen.)
Any suggestions for how to compile the entire program? I could
rewrite it or do some preprocessing to create one monster file, and
then compile it that way, but the guiding perl principles of laziness
and impatience require that I make at least some attempt to find a
better way...
I'm running perl 5.00503,
Thanks,
-Dan
--
Daniel J. Ellard - ellard2@fas.harvard.edu
------------------------------
Date: 21 Nov 2001 07:11:35 -0800
From: gareth@bulitproof.demon.co.uk (Gareth Wheelton)
Subject: printing to a piped filehandle of sybase bcp
Message-Id: <2a536f66.0111210711.593d3323@posting.google.com>
Hi I'm using a piped filehandle of Sybase bcp to load data from an
array into a tempdb table, like so..
@arrayofdata = ( 0, 1, 2, 3, 4, blah blah blah .... );
$bcpcmdline = "| bcp tempdb..tlTmp in /dev/stdin -S$SVR -U$USR
-P$PWD -c";
open (fhBCPIN, $bcpcmdline ) || die ("Couldn't open:
$bcpcmdline\n");
print fhBCPIN join( "\n", @arrayofdata), "\n";
close fhBCPIN;
when I run this I get the expected output, confirming everything
worked OK.
Starting copy...
1000 rows sent to SQL Server.
2000 rows sent to SQL Server.
3000 rows sent to SQL Server.
4000 rows sent to SQL Server.
5000 rows sent to SQL Server.
5122 rows copied.
Clock Time (ms.): total = 1 Avg = 0 (5122000.00 rows per sec.)
but not so :-( the table is empty! so I run it through the debugger
and it works fine! What gives?
A first point of call was playing with the 'autoflush' setting on the
filehandle and no joy, maybe I don't understand how this works
properly :-(
Please note I'm using the unix bcp and it's taking input from
/dev/stdin. There is nothing wrong with this technique as the
following command line works fine.
$ cat somefile | bcp tempdb..sometable in /dev/stdin -SSRVR -UUSER
-PPWD -c
any help will be greatly appreciated as I kinda like it's simplicity
cheers gareth
------------------------------
Date: 21 Nov 2001 14:08:53 GMT
From: Bernard El-Hagin <bernard.el-hagin@lido-tech.net>
Subject: Re: saving floats not as ascii
Message-Id: <slrn9vng8u.n27.bernard.el-hagin@gdndev25.lido-tech>
On Wed, 21 Nov 2001 15:02:15 +0100, GOGAR <angenent@kabelfoon.nl> wrote:
> Hey,
> for a while i've been making all sort of little programs in perl..
> for example logging stock market values..
> now i have like 50mb of data lol
> the values are stored in plain ascii.. taking up a byte for each digit..
> like umm for example
>
> 3.455
> 3.455
> 3.567
>
>
> these files can be much smaller right?
> isn't there a way to store floats in a more compact way?
There's the pack function:
perldoc -f pack
> thank for reading ;o)
Thank for writing.
Cheers,
Bernard
------------------------------
Date: Wed, 21 Nov 2001 14:21:10 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: saving floats not as ascii
Message-Id: <6qdnvtcaa02jc38sq6dmhabvm0uk06ohhq@4ax.com>
GOGAR wrote:
>now i have like 50mb of data lol
>the values are stored in plain ascii.. taking up a byte for each digit..
>like umm for example
>
>3.455
>3.455
>3.567
>
>
>these files can be much smaller right?
>isn't there a way to store floats in a more compact way?
>thank for reading ;o)
Look into pack()/unpack(). There must be a template letter for floats...
Yup: "f" for single precision and "d" for double precision, native
fromat only.
But as 3.455 consists only of 5 bytes and a float commonly of 4 or 8, I
doubt if you'll save a lot of space.
print length pack 'd', 3.455;
-->
8
The expression returning the value-to-save starts with the keyword
"pack". BTW don't forget binmode() on your filehandles to avoid data
corruption.
--
Bart.
------------------------------
Date: Wed, 21 Nov 2001 15:22:53 +0100
From: Edwin =?iso-8859-1?Q?G=FCnthner?= <edgue@web.de>
Subject: Re: saving floats not as ascii
Message-Id: <3BFBB8BD.F73BD4C0@web.de>
Bart Lateur wrote:
> But as 3.455 consists only of 5 bytes and a float commonly of 4 or 8, I
> doubt if you'll save a lot of space.
Maybe it might be a better idea to zip/unzip the whole file after/before
processing - if your primary target is to reduce the amount of used
disk space.
------------------------------
Date: Wed, 21 Nov 2001 14:09:36 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Using CGI.pm to obtain a list of params
Message-Id: <slrn9vnakm.nm2.tadmc@tadmc26.august.net>
Wiliam Stephens <wil@fbagroup.co.uk> wrote:
>
>I'm trying, but with great failiure, to loop through all params sent
>to a script by using the CGI.pm module.
I would guess that this section of the documentation for the
module that you are using might be germane:
FETCHING THE NAMES OF ALL THE PARAMETERS PASSED TO YOUR SCRIPT:
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
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 2172
***************************************