[23132] in Perl-Users-Digest
Perl-Users Digest, Issue: 5353 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Aug 13 18:05:53 2003
Date: Wed, 13 Aug 2003 15:05:09 -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 Wed, 13 Aug 2003 Volume: 10 Number: 5353
Today's topics:
'make' implemented in Perl (was: Windows user) <tzz@lifelogs.com>
Re: 'make' implemented in Perl <emschwar@pobox.com>
Re: 'make' implemented in Perl <tzz@lifelogs.com>
Re: CGI::POST_MAX Question... <zentara@highstream.net>
Re: Data::Dumper How to quote keys while dumping (James E Keenan)
FrontPage and perl (John M. Gamble)
Re: FrontPage and perl <simonis@myself.com>
Re: Gnuplot module <slaven@rezic.de>
Help w/ BNB Survey Script <-- <nospam@yahoo.com>
Re: Help w/ BNB Survey Script <-- <uri@stemsystems.com>
Re: Help w/ BNB Survey Script <-- <chessql@highstream.net>
Re: Help w/ BNB Survey Script <-- <uri@stemsystems.com>
Re: how big can a scalar get? ctcgag@hotmail.com
Re: How to Add Username/Password for SMTP Authenticatio <samik@frKKshKll.org>
Re: perl + mysql + apache on windows (raja babu)
Re: Perl scripts interconnectivity... Is it possible... nobull@mail.com
Re: Perl scripts interconnectivity... Is it possible... <scripts_you-know-the-drill_@hudsonscripting.com>
please critique...random link generator <scripts_you-know-the-drill_@hudsonscripting.com>
populating anonymous arrays inside for loop? (Matt DeFoor)
Re: populating anonymous arrays inside for loop? <pinyaj@rpi.edu>
Re: populating anonymous arrays inside for loop? <mpapec@yahoo.com>
Re: Problem with join and unicode <flavell@mail.cern.ch>
Re: substitute three random words in a string <scripts_you-know-the-drill_@hudsonscripting.com>
Re: To count a number of lines in C++ or Java or ASCII (John Smith)
Re: To count a number of lines in C++ or Java or ASCII <cwilbur@mithril.chromatico.net>
Two questions about perl (Weirong Zhu)
Re: Two questions about perl <wksmith@optonline.net>
Re: Two questions about perl (Lack Mr G M)
Re: <bwalton@rochester.rr.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 13 Aug 2003 15:10:43 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: 'make' implemented in Perl (was: Windows user)
Message-Id: <4nwudhtlu4.fsf_-_@lockgroove.bwh.harvard.edu>
On Tue, 12 Aug 2003, emschwar@pobox.com wrote:
> 'make' is used because it's available anywhere you have a C compiler
> (including, I might add, Windows), and because it's been used
> forever, and is the best and most portable way to ensure that
> software is built correctly. What would you have them use? Ant?
> Jam?
Actually there's quite a few Perl users, myself included, who think a
Perl-based make would be much better than relying on the standard
one that may or may not be installed, available, or functioning. For
modules that require C compilation, maybe. But for pure Perl
installs? That's silly, given Perl's power.
This comes up periodically in Perl discussion lists, and usually the
answer is "just wait for XYZ, it will do this and more." I'm not sure
what the current XYZ is/are, especially regarding why XYZ hasn't yet
replaced 'make' in CPAN installs and standard Perl usage. I'm very
interested in any information, as I have needed tighter integration
between Perl and 'make' many times.
Thanks
Ted
------------------------------
Date: Wed, 13 Aug 2003 13:26:49 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: 'make' implemented in Perl
Message-Id: <eto3cg5mk92.fsf@wormtongue.emschwar>
Ted Zlatanov <tzz@lifelogs.com> writes:
> Actually there's quite a few Perl users, myself included, who think a
> Perl-based make would be much better than relying on the standard
> one that may or may not be installed, available, or functioning. For
> modules that require C compilation, maybe. But for pure Perl
> installs? That's silly, given Perl's power.
Tell ya what, *you* try reimplementing make in Perl. and then come
crying back when it doesn't work right in all cases. :) Make is
*hard*, and another good reason to use it is that it's already had a
few decades of work behind it, and (if you leave out gmake-specific
extensions) is portable pretty much everywhere. As opposed to a
brand-new tool that doesn't have that kind of portability or history
or legions of people who know how to use it.
> This comes up periodically in Perl discussion lists, and usually the
> answer is "just wait for XYZ, it will do this and more."
I went away from clpm for a little while, but I don't recall seeing
these discussions, so I'm not sure what discussion lists are, or which
ones you're referring to.
> I'm not sure what the current XYZ is/are, especially regarding why
> XYZ hasn't yet replaced 'make' in CPAN installs and standard Perl
> usage.
I don't know of any such XYZ.
> I'm very
> interested in any information, as I have needed tighter integration
> between Perl and 'make' many times.
Such as? Offhand, I can't think of any time I've needed to integrate
Perl and make, other than having the one call the other (or vice
versa).
-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
------------------------------
Date: Wed, 13 Aug 2003 16:47:20 -0400
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: 'make' implemented in Perl
Message-Id: <4nk79hs2sn.fsf@lockgroove.bwh.harvard.edu>
On Wed, 13 Aug 2003, emschwar@pobox.com wrote:
> Ted Zlatanov <tzz@lifelogs.com> writes:
>> Actually there's quite a few Perl users, myself included, who think
>> a Perl-based make would be much better than relying on the standard
>> one that may or may not be installed, available, or functioning.
>> For modules that require C compilation, maybe. But for pure Perl
>> installs? That's silly, given Perl's power.
>
> Tell ya what, *you* try reimplementing make in Perl. and then come
> crying back when it doesn't work right in all cases. :)
I don't think it's fair to ask me to implement a tool when I'm just
asking for information about it. Anyhow, here are two such tools:
http://www.dsmit.com/cons/
http://dapfy.bei.t-online.de/make.pl/
I don't claim that they replace make, I'm just looking for
information on what's available and why it hasn't replaced make.
> Make is *hard*,
I don't think it's that hard, as evidenced by the billion make
reimplementations.
> and another good reason to use it is that it's already had a few
> decades of work behind it, and (if you leave out gmake-specific
> extensions) is portable pretty much everywhere.
Right, but the question remains, why use it? For simple (pure Perl)
module installations, running make is absolutely unnecessary. Perl
can do every step of the install. I'm not asking you to show me make
is useful - I know that, I've been using make for a while. I'm asking
why make should be used in the module installation process
specifically, and what tools similar to it with better Perl
integration exist already.
make may be portable, but that doesn't mean it's available,
functional, or accessible. Furthermore, it's a tool external to Perl
and my point was that Perl can do the same job.
> As opposed to a brand-new tool that doesn't have that kind of
> portability or history or legions of people who know how to use it.
I'm not sure how that's an argument. The horse also had legions of
users, history, and was very well-known before cars came along. For
installing CPAN modules, should it matter to the user whether make is
used or not, as long as the installation works? I'm saying that it
matters if make is broken or unavailable, for instance on Windows.
Perl can do the job by itself.
>> This comes up periodically in Perl discussion lists, and usually
>> the answer is "just wait for XYZ, it will do this and more."
>
> I went away from clpm for a little while, but I don't recall seeing
> these discussions, so I'm not sure what discussion lists are, or
> which ones you're referring to.
Perl 5 and 6 mailing lists. I haven't been lurking on those in a
while due to a lack of time, mostly, and I don't have pointers to old
discussions. Sorry.
>> I'm very interested in any information, as I have needed tighter
>> integration between Perl and 'make' many times.
>
> Such as? Offhand, I can't think of any time I've needed to
> integrate Perl and make, other than having the one call the other
> (or vice versa).
- installing Perl software (the step Makefile.PL -> Makefile could be
skipped)
- general dependency-driven actions that use Perl syntax inside the
Makefile
- class-based file hierarchies that drive actions when modified
- see the make.pl and Cons pages for more examples
Thanks
Ted
------------------------------
Date: Wed, 13 Aug 2003 13:42:18 -0400
From: zentara <zentara@highstream.net>
Subject: Re: CGI::POST_MAX Question...
Message-Id: <kqtkjvsunc35ftcv6o6hkhoc43oaet0lv6@4ax.com>
On Tue, 12 Aug 2003 15:53:39 +0200, George Magklaras
<georgios@ulrik.uio.no> wrote:
>In an attempt to control the file upload size on a PERL 5.6.1 CGI
>script, I used my own counters to set the maximum size of the file to
>around 4 MBytes. So I had my traditional while loop that looks like
>this (inside a subroutine):
>sub UploadFile {
> my $buffersize = 65_536;
> my $maxBuffers = 64;
> while(read( $fh, $buffer, $buffersize)) {
> $cnter++;
> if ($cnter <= $maxBuffers) {
> print UPLOAD $buffer;
> } else {
> $returnData = 'uploaded file too big';
> return $returnData;
> }
Try something like this to check the Content-Length first.
Right at the top of your script:
if($ENV{CONTENT_LENGTH} > $maxsize){
print "file too large - must be less than $maxsize bytes";
exit;
}
------------------------------
Date: 13 Aug 2003 10:41:40 -0700
From: jkeen@concentric.net (James E Keenan)
Subject: Re: Data::Dumper How to quote keys while dumping
Message-Id: <b955da04.0308130941.67ea0560@posting.google.com>
"James E Keenan" <jkeen@concentric.net> wrote in message news:<bhc9b0> use Data::Dumper;
> my %tmp ;
> $tmp{'1'} = "l";
> $tmp{'2'} = "u";
> $tmp{'alpha'} = "a";
> $tmp{'beta'} = "b";
>
> print Dumper(\%tmp);
> print "\n";
> {
> $Data::Dumper::Useqq = 1;
> print Dumper(\%tmp);
> }
To be more precise, for that last block I should have written:
{
local $Data::Dumper::Useqq = 1;
print Dumper(\%tmp);
}
------------------------------
Date: Wed, 13 Aug 2003 19:00:01 +0000 (UTC)
From: jgamble@ripco.com (John M. Gamble)
Subject: FrontPage and perl
Message-Id: <bhe1rh$k0p$1@e250.ripco.com>
Are there any known "gotchas" when developing with FrontPage
and perl? The ISP provides perl for the server side, and my
friend's husband is very insistent about using FrontPage for
designing the website.
It's not my first choice, but i'm willing to go along. So...
Anything i should look out for (excluding the usual MS-bashing)?
This will be my first foray into FrontPage.
--
-john
February 28 1997: Last day libraries could order catalogue cards
from the Library of Congress.
------------------------------
Date: Wed, 13 Aug 2003 19:49:16 GMT
From: simonis <simonis@myself.com>
Subject: Re: FrontPage and perl
Message-Id: <3F3A9625.4420A5FC@myself.com>
"John M. Gamble" wrote:
>
> Anything i should look out for (excluding the usual MS-bashing)?
>
No
------------------------------
Date: 13 Aug 2003 23:23:00 +0200
From: Slaven Rezic <slaven@rezic.de>
Subject: Re: Gnuplot module
Message-Id: <877k5hs157.fsf@vran.herceg.de>
dkcombs@panix.com (David Combs) writes:
> In article <87ispm1ma0.fsf@vran.herceg.de>,
> Slaven Rezic <slaven@rezic.de> wrote:
> >yuchung@mail.com (Yuchung Cheng) writes:
> >
> >> alythh@netscape.net (Alythh) wrote in message news:<6a25ba72.0307230050.57da7475@posting.google.com>...
> >> > I just installed Chart::Graph::Gnuplot, and I'm fairly satisfied.
> >> > But...
> >> >
> >> > My wish is to be able to make a gnuplot() call, make it display the
> >> > graph, and stay there while other data becomes available... while
> >> > replotting the updated data.
> >> >
> >> > Is there a way to communicate between the two processes in this way?
> >> > Or is this module just to output to a file?
> >> >
> >> AFAIK, gnuplot only parse static data and generate the graph, even with
> >> "gnuplot -persist" command. The simplist way to do above is to call
> >> gnuplot every once while and re-plot to the same file.
> >
> >No, it's perfectly possible to open a communication channel via
> >IO::Pipe and to send multiple commands to gnuplot. Example code on
> >demand.
> >
> >Regards,
> > Slaven
> >
> >--
> >Slaven Rezic - slaven@rezic.de
> >
> > tknotes - A knotes clone, written in Perl/Tk.
> > http://ptktools.sourceforge.net/#tknotes
>
>
> Demand.
>
> (not via email; here, so all can see it.)
>
The actual script is too large to post, see the distibution at
http://user.cs.tu-berlin.de/~eserte/src/tkplotwetter/
The interesting functions are start_gnuplot to create the
communication channel, and reset_gnuplot, print_gnuplot and calcplot
to see how to send command to gnuplot.
Regards,
Slaven
--
Slaven Rezic - slaven@rezic.de
Start a WWW browser - OS independent:
http://user.cs.tu-berlin.de/~eserte/src/perl/WWWBrowser/
------------------------------
Date: Wed, 13 Aug 2003 16:57:51 GMT
From: "-|Turbosyde|-" <nospam@yahoo.com>
Subject: Help w/ BNB Survey Script <--
Message-Id: <j6u_a.37115$A%3.479584@ord-read.news.verio.net>
Hello,
I have the 3.2.2 version of the big nose bird survey script and have a
problem with cookies. When i allow the survey users to view the
results, the cookies work and prevent multiple votes. But when i send
the users to a thank you page (via $JUMP_URL variable), the results
are logged, but a cookie isn't dropped and the user can vote multiple
times. Any suggestions, hints?
http://bignosebird.com/carchive/survey.shtml
------------------------------
Date: Wed, 13 Aug 2003 17:01:01 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Help w/ BNB Survey Script <--
Message-Id: <x7adad4hma.fsf@mail.sysarch.com>
>>>>> "-" == -|Turbosyde|- <nospam@yahoo.com> writes:
-> I have the 3.2.2 version of the big nose bird survey script and have a
-> problem with cookies. When i allow the survey users to view the
-> results, the cookies work and prevent multiple votes. But when i send
-> the users to a thank you page (via $JUMP_URL variable), the results
-> are logged, but a cookie isn't dropped and the user can vote multiple
-> times. Any suggestions, hints?
-> http://bignosebird.com/carchive/survey.shtml
ask the authors for help.
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, 13 Aug 2003 15:04:49 -0600
From: Lori Fleetwood <chessql@highstream.net>
Subject: Re: Help w/ BNB Survey Script <--
Message-Id: <Szx_a.759$Q5.75@fe01.atl2.webusenet.com>
Uri Guttman wrote:
>
> ask the authors for help.
>
don't you mean "ask the moron authors for help"?
------------------------------
Date: Wed, 13 Aug 2003 21:45:55 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Help w/ BNB Survey Script <--
Message-Id: <x7y8xx2pv1.fsf@mail.sysarch.com>
>>>>> "LF" == Lori Fleetwood <chessql@highstream.net> writes:
LF> Uri Guttman wrote:
>> ask the authors for help.
>>
LF> don't you mean "ask the moron authors for help"?
moron authors is always implied when someone asks for help with free
scripts.
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: 13 Aug 2003 20:26:49 GMT
From: ctcgag@hotmail.com
Subject: Re: how big can a scalar get?
Message-Id: <20030813162649.883$in@newsreader.com>
"Vassilis Tavoultsidis" <ixanthi@ixanthi.remove.gr> wrote:
> What happens if I make a simple scalar variable big?
It becomes big.
> What memory problems
> it can give me
You can run out of memory, or start paging to death.
Also, doing something with large amounts of memory
(well, something intelligent, anyway) requires large
numbers of CPU cycles, so you can really slam the CPU.
> and what is the limit?
Depends on your computer, your memory, and the pointer size.
>
> e.g.
>
> $t = "";
> $maxlen = 100000;
> while (length($t) < $maxlen)
> {
> $t = $t.$i."|";
> };
Hah! I thought you said big. That's microscopic.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: Wed, 13 Aug 2003 15:46:01 -0500
From: Samik Raychaudhuri <samik@frKKshKll.org>
Subject: Re: How to Add Username/Password for SMTP Authentication in MIME::Lite?
Message-Id: <bhe82l$aqo$1@news.doit.wisc.edu>
Check this out:
http://www.krkeegan.com/smtp_auth/
-Samik
On 8/12/2003 12:11 AM, Chinadian wrote:
> Is it possible to use MIME::Lite using a SMTP server that needs
> authentication?
>
> My provider now demands authentification when sending mail via SMTP.
>
> I liked MIME:Lite, because it is the only one working right for me
> with attachment. But I don't know how to added password/username.
>
> In Net::SMTP:
> auth ( USERNAME, PASSWORD )
> Attempt SASL authentication
>
> In MIME:Lite:
> send_by_smtp ARGS...
> Instance method. Send message via SMTP, using Net::SMTP. The optional
> ARGS are sent into Net::SMTP::new(): usually, these are
> MAILHOST, OPTION=>VALUE, ...
>
> But Auth has two inputs. So do I do
> $msg = MIME::Lite->new(
> To =>"a@a.com",
> Subject =>"$sub",
> auth => "username, password")
>
> or
> MIME::Lite->auth (username, password);
> MIME::Lite->send('smtp', "remotehost", Timeout=>60);
>
> or
> MIME::Lite->send('smtp', "remotehost", auth=> "username, password",
> Timeout=>60);
--
Samik Raychaudhuri
University of Wisconsin, Madison
http://samik.freeshell.org/
To email me, replace 'K' with 'e' in the 'From' field.
------------------------------
Date: 13 Aug 2003 10:32:38 -0700
From: raja_babu0@lycos.com (raja babu)
Subject: Re: perl + mysql + apache on windows
Message-Id: <67505fb2.0308130932.6b4ae469@posting.google.com>
OK - I finally got it to work. And the culprit is Apache on win32.
Somehow it does always tries to connect to mySQL using TCP ( which
explains the earlier error log entry : Can't connect to MySQL server
on 'localhost' (10061) ). So, I configured mySQL to use TCP/IP and
provide the host name in the dsn variable as suggested here : my $dsn
= "dbi:mysql:database=mydatabase:host=myhostname"; - and it worked
this time.
thanks for all the replies...
rb
raja_babu0@lycos.com (raja babu) wrote in message news:<67505fb2.0308130454.52dfd55c@posting.google.com>...
> well, I login to the machine as Administrator. The Apache config file
> ( httpd.conf ) has no mention of any user under which it is running -
> so it could be running under the Admnistrator account. When I do it
> from the command line I am running as Administrator. I do not know who
> has permissions on the named pipe - how do I find out?
>
> rb
>
> ctcgag@hotmail.com wrote in message news:<20030812170712.414$aG@newsreader.com>...
>
> > Pardon if this question doesn't make sense on Windows, but who is apache
> > running as? Who are you running as when you do it from the command
> > line? Who has permissions on the named pipe?
> >
> > Xho
------------------------------
Date: 13 Aug 2003 09:39:27 -0700
From: nobull@mail.com
Subject: Re: Perl scripts interconnectivity... Is it possible...
Message-Id: <4dafc536.0308130839.1e82f39@posting.google.com>
"Gregory Toomey" <NOSPAM@bigpond.com> wrote in message news:<bhd3si$10vokg$1@ID-202028.news.uni-berlin.de>...
> "Roman Khutkyy" <roman@sky.lviv.ua> wrote in message
> news:bhd2oe$1rqe$1@news.uar.net...
> > Is there any way for Perl script to use subroutines from another one?
>
> http://www.perldoc.com/perl5.8.0/pod/func/use.html
Using Perl5 modules is probably a better way of doing the OP's "X".
But to answer his "Y" directly it would be more relevant to point him
to:
http://www.perldoc.com/perl5.8.0/pod/func/require.html
Also if the OP you really wants a single Perl source file that is at
the same time both a standalone script and also a Perl4-style library
he's sick^H^H^H^H^H^H^H probably wants to put...
return 1 if caller;
...after the stuff library initialisation code but before the stuff
that's only applicable when running as a standalone script.
------------------------------
Date: Wed, 13 Aug 2003 17:29:48 -0700
From: Hudson <scripts_you-know-the-drill_@hudsonscripting.com>
Subject: Re: Perl scripts interconnectivity... Is it possible...
Message-Id: <4plljvcg3td80mgh5uuki4ie111aqtlp9g@4ax.com>
On Wed, 13 Aug 2003 13:08:51 +0300, "Roman Khutkyy"
<roman@sky.lviv.ua> wrote:
>Is there any way for Perl script to use subroutines from another one?
>
>Thanks.
>
I think you just want to make a module. This is not really so hard.
See perlmod and perlsub.
There is another method...I think it is
use "subroutine.pl";
and to make sure you throw a:
1;
at the end of the subroutine file for it to return true. I know this
is not the recommended way, though
------------------------------
Date: Wed, 13 Aug 2003 17:01:07 -0700
From: Hudson <scripts_you-know-the-drill_@hudsonscripting.com>
Subject: please critique...random link generator
Message-Id: <pujljvs3jtqq1dc76mmk0hvv3qcd6cgjfg@4ax.com>
Hi everyone,
Here's a subroutine I made using the fisher yates shuffle from the
perl faq's to print a random number of links to a web page. But I was
wondering if there is a simplier way to do this. The idea was to have
non-repeating links, so that's why I choose this method. Thanks in
advance and all criticism is welcome ;-)
# --------------------------------------- random links
sub print_random_links {
my @links = @keywords;
my $range = $kv{max_links} - $kv{min_links} + 1;
my $links_number = int( rand($range)) + $kv{min_links};
fisher_yates_shuffle( \@links );
my $i = 0;
while ($links_number > $i) {
my $link = shift(@links);
my $link_us = $link;
$link_us =~ s/ /_/g;
print " <a href=\"$link_us.html\"><b>$link</b></a> ";
$i++;
}
}
# --------------------------------------- fisher_yates_shuffle
sub fisher_yates_shuffle {
my $deck = shift; # $deck is a reference to an array
my $i = @$deck;
while ($i--) {
my $j = int rand ($i+1);
@$deck[$i,$j] = @$deck[$j,$i];
}
}
------------------------------
Date: 13 Aug 2003 12:50:31 -0700
From: mattd@myrealbox.com (Matt DeFoor)
Subject: populating anonymous arrays inside for loop?
Message-Id: <45c889e4.0308131150.41d9e762@posting.google.com>
I'm struggling with symbolic references and anonymous arrays. I'm
trying to create 4 arrays based on the contents of a larger array.
Here's an example of what I'm doing:
@array = qw( u1 u2 u3 u4 u5 u6 u7 u8 u9 u10 u11 );
$c = int @array/4;
for ($i=0; $i<4; $i++) { # this was chosen to create 4 arrays
$array_name = 't' . $i;
for ($j=0; $j<@array/$c; $j++) { # wanted to divide a much larger
array into chunks
push @{$array_name}, $array[$j];
shift(@array);
}
push(@array_names,$array_name);
}
for (@array_names) {
print $_," contains: ",join(",",@{$_}),"\n";
}
However, this produces:
t0 contains: u1,u3
t1 contains: u3,u5
t2 contains: u5,u7
t3 contains: u7,u9
I thought it would produce (or something similar):
t0 contains: u1,u2,u3
t1 contains: u4,u5,u6
t2 contains: u7,u8,u9
t3 contains: u10,u11
I'm hoping to divide a much larger array (say 8,000 entries) into 4
smaller arrays for later processing. Any thoughts?
Thanks.
------------------------------
Date: Wed, 13 Aug 2003 16:16:58 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: Matt DeFoor <mattd@myrealbox.com>
Subject: Re: populating anonymous arrays inside for loop?
Message-Id: <Pine.SGI.3.96.1030813160642.183992A-100000@vcmr-64.server.rpi.edu>
[posted & mailed]
On 13 Aug 2003, Matt DeFoor wrote:
>I'm struggling with symbolic references and anonymous arrays. I'm
>trying to create 4 arrays based on the contents of a larger array.
>Here's an example of what I'm doing:
Don't use symbolic references. They're not good. And, since your arrays
have names, their not anonymous.
>@array = qw( u1 u2 u3 u4 u5 u6 u7 u8 u9 u10 u11 );
>$c = int @array/4;
>
>for ($i=0; $i<4; $i++) { # this was chosen to create 4 arrays
> $array_name = 't' . $i;
> for ($j=0; $j<@array/$c; $j++) { # wanted to divide a much larger
>array into chunks
> push @{$array_name}, $array[$j];
> shift(@array);
You're shift()ing the array. This is going to cause problems, because
you're getting the $j'th element. If you had done $array[0] instead of
$array[$j], or even put shift(@array) in place of $array[$j], you wouldn't
be having problems.
When you shift() the array, you remove the first element. Your for loop
is using $j, though, to determine what elements to get out of the array.
The first time, you get $array[0], but then you remove it. When you next
get $array[1], it's really the THIRD element from the ORIGINAL array.
Here's a much easier way to do what you want:
use POSIX 'ceil'; # for the rounding you need
my @array = 'u01' .. 'u11';
my $div = 4;
my $size = ceil(@array / $div);
my @chunks;
for (1 .. $div) {
push @chunks, [ splice @array, 0, $size ];
}
That will give you an array of array-refs, @chunks. It also clears @array
as a side-effect.
--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)
------------------------------
Date: Wed, 13 Aug 2003 23:06:23 +0200
From: Matija Papec <mpapec@yahoo.com>
Subject: Re: populating anonymous arrays inside for loop?
Message-Id: <368ljv8ku5ah1gb9m5mujtk7a8id5mkc9u@4ax.com>
X-Ftn-To: Matt DeFoor
mattd@myrealbox.com (Matt DeFoor) wrote:
>I'm struggling with symbolic references and anonymous arrays. I'm
>trying to create 4 arrays based on the contents of a larger array.
>Here's an example of what I'm doing:
>
>@array = qw( u1 u2 u3 u4 u5 u6 u7 u8 u9 u10 u11 );
<snip>
Symbolic references are deprecated for a number of reasons and you'll be
better with array or hash references. @t here holds 4 array references,
use strict;
my @array = qw( u1 u2 u3 u4 u5 u6 u7 u8 u9 u10 u11 );
my @t;
my $i = 0;
while (@array) {
@{ $t[$i] } = splice(@array,0,3);
$i++;
}
for (0 .. $#t) {
print "\$t[$_] contains: ", join(',', @{ $t[$_] }), "\n";
}
>t0 contains: u1,u2,u3
>t1 contains: u4,u5,u6
>t2 contains: u7,u8,u9
>t3 contains: u10,u11
>
>I'm hoping to divide a much larger array (say 8,000 entries) into 4
>smaller arrays for later processing. Any thoughts?
Maybe you don't even need to divide larger array but you're the one who
decide about your algorithm. ;)
--
Matija
------------------------------
Date: Wed, 13 Aug 2003 17:45:37 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Problem with join and unicode
Message-Id: <Pine.LNX.4.53.0308131730350.755@lxplus081.cern.ch>
On Wed, Aug 13, derek / nul inscribed on the eternal scroll:
> >"extra" to what?
>
> extra to the \r\n's that are already there
Yup, I _said_ you already had some (and it appears you read them in
binmode(), otherwise there wouldn't have been \r to cope with as
well).
> >> I don't seen to be able to get rid of them.
> >
> >Presumably it's you who's putting them there.
>
> it would appear so
Well, you _did_ write this:
|| $linesengwagu = join("\n",@linesengwag1);
What more can I say than "don't do that!" ;-)
> >> I am 'join'ing the list so that I can encode it back to unicode.
When you say "back" to unicode - are you implying that it was unicode
to start with? (presumably utf-16LE also??). If so, then some of the
operations you're carrying out on it in binmode() seem wrong to me,
and unnecessarily confusing. That's why I recommended you go for
Perl's native unicode text coding internally.
There was a discussion here fairly recently in which utf-16LE was
involved, maybe it'll help if you hunt it down.
> >(Since you're working with 5.8.0, it seems to me that you're liable to
> >cause yourself additional problems by trying to work in binary (i.e
> >bytes mode). I'd recommend working in Perl's native unicode
> >representation (:utf8, i.e character mode) and using I/O layers to
> >convert to/from the utf-16LE that you apparently need externally.)
>
> pointers please
perluniintro and perlunicode, in your own documentation set or at
http://www.perldoc.com/perl5.8.0/pod/perluniintro.html
http://www.perldoc.com/perl5.8.0/pod/perlunicode.html
> I have tried that
How, exactly?
> but only cause more errors
Speak out, man! The PSI::ESP module is on the blink...
Are you perhaps looking for join('', @linesengwag1); ?
Good luck
------------------------------
Date: Wed, 13 Aug 2003 13:44:50 -0700
From: Hudson <scripts_you-know-the-drill_@hudsonscripting.com>
Subject: Re: substitute three random words in a string
Message-Id: <cp8ljv4rcch1ps4rf9pa0tnskr38m0ftro@4ax.com>
On 13 Aug 2003 11:24:27 GMT, Abigail <abigail@abigail.nl> wrote:
>Yeah, in the way taking a dip in the Pacific works if you go from
>New York to Washington.
>
>Why shuffle an entire array if you want a random element? If a magician
>asks you to pick a random card from a deck, would you take the deck,
>shuffle it, and pick the first one?
>
>Picking a random element from an array doesn't take more than:
>
> $one [rand @one]
thank you for saving me from my round about ways...this works very,
very nicely!
------------------------------
Date: 13 Aug 2003 09:59:13 -0700
From: clearguy02@yahoo.com (John Smith)
Subject: Re: To count a number of lines in C++ or Java or ASCII files by exluding white spaces and comments
Message-Id: <500f84f3.0308130859.51fba4b4@posting.google.com>
Bob Walton <bwalton@rochester.rr.com> wrote in message news:<3F396DAC.2000500@rochester.rr.com>...
> John Smith wrote:
>
> ...
>
>
> > We have huge files in Java and C++ and I need to count the total
> > number of lines in each of them by excluding white spaces (from the
> > beginning of a line) and comments (C++, Java comments etc).
> >
> > There must be some scripts in perl to do this job.
> >
> > Can anyone kindly let me know? Or, are there any third-party tools to
> > do this job?
> ...
>
>
> > John
> >
>
> Most of this is a FAQ, at least for the C++ part:
>
> perldoc -q comment
>
> Maybe that'll be good enough for Java too?
>
> Removing blank lines can be done with
>
> next if /^\s*$/;
>
> assuming you are reading and processing your lines in a loop.
Thanks Bob!
I am looking out for a third party tool t odo this job. We have
millions of code in one of our Parent directory. I want a total count
of lines, number of blank lines and number of comments in the entire
folder. I am not tlaking about a single file.
Thanks,
John
------------------------------
Date: Wed, 13 Aug 2003 20:54:34 GMT
From: Charlton Wilbur <cwilbur@mithril.chromatico.net>
Subject: Re: To count a number of lines in C++ or Java or ASCII files by exluding white spaces and comments
Message-Id: <87y8xxffb9.fsf@mithril.chromatico.net>
clearguy02@yahoo.com (John Smith) writes:
> I am looking out for a third party tool t odo this job. We have
> millions of code in one of our Parent directory. I want a total count
> of lines, number of blank lines and number of comments in the entire
> folder. I am not tlaking about a single file.
This is perhaps a 30-line perl program. If you insist on having a
third party tool, I'm sure someone could provide you with one.
Charlton
--
cwilbur at chromatico dot net
cwilbur at mac dot com
------------------------------
Date: 13 Aug 2003 08:57:16 -0700
From: weirong@capsl.udel.edu (Weirong Zhu)
Subject: Two questions about perl
Message-Id: <b6ed8fb0.0308130757.7b7d62a5@posting.google.com>
On linux
1. I have a perl script, the main body of which is a for loop. In each
iteration the script use "system" to call outside exe to do some work.
The whole script may run very long time. Sometimes, I want to use
Ctrl+C to terminate the script. However, when I use ctrl+c, I can only
terminate the child process invoked by system, the script itself is
still running. Then I have to open another term to kill the script by
its pid.
I want to know how can I kill the script process by ctrl+c directly in
this conditon. Please aware that I can not use the return value of
system to do this. Because even the return value of system means a
error, the script just think this iteration failed, it will continue
the next iteration.
2. It seems change the $ENV{"xxx"} only takes effect in child process.
How can I set the enviroment variable in the middle of a perl script?
For example, I want to change the $LANG several times, so that I can
print different language's time format by using "localtime"
Thanks
------------------------------
Date: Wed, 13 Aug 2003 18:49:41 GMT
From: "Bill Smith" <wksmith@optonline.net>
Subject: Re: Two questions about perl
Message-Id: <9Lv_a.59091$_R5.21257279@news4.srv.hcvlny.cv.net>
"Weirong Zhu" <weirong@capsl.udel.edu> wrote in message
news:b6ed8fb0.0308130757.7b7d62a5@posting.google.com...
> On linux
>
>
--snip question 1--
> 2. It seems change the $ENV{"xxx"} only takes effect in child process.
> How can I set the enviroment variable in the middle of a perl script?
> For example, I want to change the $LANG several times, so that I can
> print different language's time format by using "localtime"
>
> Thanks
It is not possible to pass any information from a child process to its
parent using variables. Refer to "perldoc -f die" and "perldoc -f exit"
to learn how to set the return value and "perldoc -f system" to learn
how
to use the return value or use a file to store the current language
name.
Bill
------------------------------
Date: Wed, 13 Aug 2003 19:59:45 BST
From: gml4410@ggr.co.uk (Lack Mr G M)
Subject: Re: Two questions about perl
Message-Id: <2003Aug13.195945@ukwit01>
In article <9Lv_a.59091$_R5.21257279@news4.srv.hcvlny.cv.net>, "Bill Smith" <wksmith@optonline.net> writes:
|>
|> > 2. It seems change the $ENV{"xxx"} only takes effect in child process.
|> > How can I set the enviroment variable in the middle of a perl script?
|> > For example, I want to change the $LANG several times, so that I can
|> > print different language's time format by using "localtime"
|>...
|> It is not possible to pass any information from a child process to its
|> parent using variables.
Whereas this is true, it is not what was asked.
The question was whether setting $ENV{LANG} within a script can
affect the output of a script.
It might be that Perl doesn't use this for localtime() anyway? I
can't get 5.6.1 to print anything other than English even if I set the
this in the environment *before* starting Perl, but the same system's
date command is happy to display in French.
--
--------- Gordon Lack --------------- gml4410@ggr.co.uk ------------
This message *may* reflect my personal opinion. It is *not* intended
to reflect those of my employer, or anyone else.
------------------------------
Date: Sat, 19 Jul 2003 01:59:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re:
Message-Id: <3F18A600.3040306@rochester.rr.com>
Ron wrote:
> Tried this code get a server 500 error.
>
> Anyone know what's wrong with it?
>
> if $DayName eq "Select a Day" or $RouteName eq "Select A Route") {
(---^
> dienice("Please use the back button on your browser to fill out the Day
> & Route fields.");
> }
...
> Ron
...
--
Bob Walton
------------------------------
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 5353
***************************************