[15824] in Perl-Users-Digest
Perl-Users Digest, Issue: 3237 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jun 2 14:10:30 2000
Date: Fri, 2 Jun 2000 11:10:19 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <959969419-v9-i3237@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Fri, 2 Jun 2000 Volume: 9 Number: 3237
Today's topics:
Re: Networking Perl for NT <hakon.alstadheim@oslo.mail.telia.com>
Re: Non-reuse of memory for lexically-scoped variables? <dwhaskin@earthlink.net>
NT & Sockets <tserface@ims.msn.com>
Re: Perl and notepad aren't playing nice. <tina@streetmail.com>
Re: Perl and notepad aren't playing nice. <randythefirstNOraSPAM@hotmail.com.invalid>
Re: Perl and notepad aren't playing nice. <Hans.de.Bruin@Chello.nl>
Perl vs Python for Numerical Analysis <lr@hpl.hp.com>
Re: perl-5.6.0 and UTF8 character weirdness sendrate@my-deja.com
Re: Printing on a Remote Printer <Petri_member@newsguy.com>
Problems to install modules <toxlists@canada.com>
Re: Problems to install modules <toxlists@canada.com>
REGEXP newbie question <vecernik@aon.at>
Re: REGEXP newbie question nobull@mail.com
Secure File Transfer <weidmann@informatik.uni-freiburg.de>
Re: Speed (Abigail)
Re: the end of perl? (Peter J Scott)
Re: Trouble with Arrays of Hashes <abe@ztreet.demon.nl>
Re: Trouble with Arrays of Hashes nobull@mail.com
Re: Using awk in perl? <gellyfish@gellyfish.com>
Re: Using awk in perl? zenin@bawdycaste.org
Re: Web-based email solutions (Intern)
Re: Web-based email solutions <apietro@my-deja.com>
Re: Web-based email solutions <gellyfish@gellyfish.com>
Re: Web-based email solutions (Intern)
Re: Web-based email solutions <apietro@my-deja.com>
Why is while inside a while so slow <rrauer@mitre.org>
Re: Why is while inside a while so slow nobull@mail.com
Re: Will flock(...) wait? (Abigail)
Win32::AdminMisc::LogonAsUser (John Chajecki)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 02 Jun 2000 12:40:49 -0300
From: Hakon Alstadheim <hakon.alstadheim@oslo.mail.telia.com>
Subject: Re: Networking Perl for NT
Message-Id: <m04s7cay66.fsf@alstadhome.cyberglobe.net>
Here is how I did it with perl 5.5
If you have a C compiler and don't need to use 'perlscript' in asp
web-pages, the easiest is to make sure everybody has the share mapped
to the same drive-letter, and then compile/install perl into that
share from the source. Setup on idividual workstations then just means
changing the PATH env-var to unclude:
X:\perl\<scriptbin>;X:\perl\<arch-bin>.
You _can_ also compile/install into a path given like //Machine/Share
(== UNC Name ??), but any script that tries to cd into some directory
under there may* fail then. Some installation and pod-munging scripts
do just that, so I wouldn't even bother trying installing to a UNC
name.
If you compile with PerlCrt.lib you must make sure you place that in
the <arch-bin>.
The next paragraph is quite dense, so here, as an example, is a
picture of the pieces that comprise the Compress::Zlib extension
module:
(from 'make install') Load
+----------------+ +---------+ / z.dll
|Compress\Zlib.pm| -Loads xs module->| zlib.dll|-either
+----------------+ +---------+ \ Link static
z.lib
Any ddl's needed by modules you install also go in <archbin>. I.e not
the dlls created by 'make install', but any dlls _referenced_ by those
modules. See the individual Makefile.PL to find what they are. (For
the case of zlib make sure it's not called just that, call it just z
or whatever to avoid name clash with the xs module ). This means some
book-keeping, so it is usually easiest to build stuff like z.lib and
db.lib as static libraries. Make sure you get the compiler switches
right when you do that. You want the _output_ to be static libraries,
but you want the defines and the symbols those libraries import to be
from MT dlls, so that the dlls that are made when you build a perl
extension with them will function in the context of perl as a whole.
-- Notes:
* cd to the UNC named perl dir _may_ succeed, because somtimes a UNC
path wil get automatically translated to whatever drive-letter you
have mapped the share to locally.
------------------------------
Date: Fri, 02 Jun 2000 16:47:08 GMT
From: Denis Haskin <dwhaskin@earthlink.net>
Subject: Re: Non-reuse of memory for lexically-scoped variables?
Message-Id: <3937E472.1CA1A81D@earthlink.net>
[cc'd Ilya]
In article <8h6sng$dcp$1@charm.magnus.acs.ohio-state.edu>, Ilya Zakharevich
wrote:
> > > Only one of these Ms is recoverable, one in $b, and only by explicit
> > >
> > > undef $b;
>
> > Shouldn't this be considered a bug?
>
> No, it is a feature.
>
> > {
> > my $b; # yes I know I can my and init at same time.
> > $b = 'x' x 1e6;
> > }
> > even though $b is out of scope once I'm out of the block, that memory has
> > been allocated and is not reused?
>
> Allocated 2 or 3 times and then no reused.
>
> > Is there a (good) reason that things work this way?
>
> Space vs speed. (Re)Allocation is slow.
Okay, the subsequent discussion on the newsgroup helped my understanding that
lexical variables are not released for general reuse but their storage space is
reused on subsequent calls to a method. I was able to demonstrate that with a
simple test case.
But when I try to apply some of this thinking to a more real-world example,
using some of the LWP classes, I still seem to have a leak:
<CODE>
package test;
use LWP;
sub new {
my $proto = shift;
my $class = ref($proto) || $proto;
my $self = {};
bless ($self, $class);
$self->{UA} = LWP::UserAgent->new();
$self->{Request} = HTTP::Request->new('GET',
'http://someplacemadeup.com/big.html');
return($self);
}
sub getit {
my $self = shift;
$self->{Response} = $self->{UA}->request($self->{Request});
# Dump($self);
$self->{Response} = undef;
delete($self->{Response});
return(1);
}
package main;
use Devel::Peek;
$a = test->new();
foreach (1..10) {
$a->getit();
mstat("Marker $_");
}
</CODE>
Based on what I've heard, and some review of additional docs (e.g.
perldebguts), I would *not* expect the memory usage of this test to continually
grow, but it does.
I tried moving the new()s of LWP::UserAgent and HTTP::Request (and
undef/delete'ing them as well) into test::getit(), but that doesn't help.
Getting the response into a lexical variable in test::getit() (instead of a
member variable) didn't help either.
Is this happening because of how LWP::UserAgent::request() (or methods it
calls) is written? Am I up a creek? Would behavior change if I recompiled my
Perl with the system malloc() instead of Perl's malloc()?
Much thanks to all for any insights that could be shared...
dwh
------------------------------
Date: Fri, 2 Jun 2000 10:59:29 -0700
From: "tserface" <tserface@ims.msn.com>
Subject: NT & Sockets
Message-Id: <eyPB#xLz$GA.326@cpmsnbbsa09>
OK, I've been through all of the documents, purchased 3 books, and read
everything I can find on the web about Perl and sockets. I got sockets
working in my Perl program on NT, but when I go to read it always blocks
(waits) unless the packet ends with a NL (\n) character. 2 of the books I
purchased talk about using fcntl (like in C) to turn off blocking, but these
don't seem to work on NT (for whatever reason). I know it is possible to
turn off blocking because the same sort of stuff works in C++, C, and Java.
I need to do this through a web interface so I will end up either using Perl
or Java servlets. I really want to use Perl, but the whole thing runs
really slowly. Here's what I'm doing:
- Connecting to a server program using TCP/IP interface (sockets).
- Requesting status information from said server.
- Receiving status information and displaying the info in the browser.
- Waiting for a while and getting more information.
Unless all of the packets end with NL it takes around 8 seconds before the
read operation times out. The read looks like this:
$newvalue = <$socket>;
I open the socket like this:
$socket = IO::Socket::INET->new(
Proto => "tcp",
PeerAddr => "myserver",
PeerPort => "11112",
Type => SOCK_STREAM);
Anyone else figure this one out?
Thanks,
Tom
------------------------------
Date: 2 Jun 2000 15:14:25 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: Perl and notepad aren't playing nice.
Message-Id: <8h8j0h$2itia$1@fu-berlin.de>
hi,
randythefirst <randythefirstNOraSPAM@hotmail.com.invalid> wrote:
> When I try to save as "hello.plx", it saves as "hello.plx.txt",
> Perl will run it anyway if you type the whole thing out, but
> what a pain.
i think it could help also to set up the type of file
at the configuration. go to the explorer and the dialog
where you can setup an application which should be started
for a file type and add plx. i'm not sure, haven't worked with
windows for a long time.
tina
--
http://www.tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
------------------------------
Date: Fri, 02 Jun 2000 09:46:49 -0700
From: randythefirst <randythefirstNOraSPAM@hotmail.com.invalid>
Subject: Re: Perl and notepad aren't playing nice.
Message-Id: <0a2d42c4.19bd988a@usw-ex0101-008.remarq.com>
Daniel Winsor - HESE
Tina Mueller
I Thank You both for your responses, but, at this time I am not
that far.(Hopefully won't be long before I lose this darn "deer
in the headlights look", in other words, for the moment, type s
l o w) :-)
Once again Thank You for responding.
Randy
* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!
------------------------------
Date: Fri, 02 Jun 2000 17:33:11 GMT
From: Hans <Hans.de.Bruin@Chello.nl>
Subject: Re: Perl and notepad aren't playing nice.
Message-Id: <3937F003.6BDD27E6@Chello.nl>
randythefirst wrote:
>
> I did subsearch "notepad", read many excellent messages, which
> is why I am not asking about "What is a good editor?"(horse has
> already been beat to death). But did not get answer to this
> question. Help!!!
> Taking Perl class, teacher has instructed us to use notepad to
> create our program files. How do you save a notepad file with
> just a .plx extension without notepad adding the .txt extension
> also.
> When I try to save as "hello.plx", it saves as "hello.plx.txt",
> Perl will run it anyway if you type the whole thing out, but
> what a pain.
> Thank you in advance
> Randy
Maybe you should use its bigger brother wordpad and save the files as
ms-dos text. You could associate .plx with wordpad or with perl.exe. in
the last case windows NT/9x will execute the script from explorer. If
you use NT joe could even execute a script by typing its name on de
commandprompt. If you associate .plx with perl you could add a edit menu
to your file options to start wordpad.
Hans
------------------------------
Date: Fri, 2 Jun 2000 10:20:26 -0700
From: Larry Rosler <lr@hpl.hp.com>
Subject: Perl vs Python for Numerical Analysis
Message-Id: <MPG.13a18cb397a8ab0398ab1b@nntp.hpl.hp.com>
I have been considering joining a team that is heavily into numerical
analysis, specifically image processing. The leader of the team (who
considers himself a physicist, not a programmer) vigorously advocates
Python, for the following reasons:
Easier than Perl to integrate with C or C++.
Better numerical-analysis support.
Inherently object-oriented (multiple inheritance, operator
overloading).
I would appreciate help in understanding these issues. The 'Perl vs.
Python' article
<URL:http://www.perl.com/pub/language/versus/python.html>
was posted by Tom Christiansen on June 2, 1995 (Happy Fifth Birthday!),
and can hardly be presumed to reflect current reality.
I searched CPAN for numerical analysis modules, and couldn't find
fundamental stuff, such as the FFT (Fast Fourier Transform), the BLAs
(Basic Linear Algorithms) or LNPACK. The home page at
<URL:http://search.cpan.org> doesn't even have a category for math or
numerical analysis, nor does the category list at
<URL:http://www.perl.com/CPAN-local/modules/by-category/>.
The modules in
<URL:http://www.perl.com/CPAN-local/modules/by-module/Math/>
don't seem particularly promising. I found this, which is hardly
reassuring:
NAME
Math::ematica - Perl extension for connecting Mathematica(TM)
SYNOPSIS
use Math::ematica qw(:PACKET :TYPE :FUNC);
WARNING
This is alpha software. User visible changes can happen any time.
Is Math::Pari the catch-all answer to this question? I know nothing
about its contents.
I would appreciate comments and advice on this issue, because a career
decision is involved. I imagine that learning Python would be easy, and
brushing up on my dormant numerical-analysis skills would be necessary
regardless of the interface language. Similarly, Tk would be the basis
for the GUI, which is available in either language.
But if I can persuade the leader that Perl is an adequate vehicle for
this type of program, ... If, if, if...
Please help!
--
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com
------------------------------
Date: Fri, 02 Jun 2000 15:07:22 GMT
From: sendrate@my-deja.com
Subject: Re: perl-5.6.0 and UTF8 character weirdness
Message-Id: <8h8iiu$ord$1@nnrp1.deja.com>
En artikolo <3937b5fc.252105@news.skynet.be>,
bart.lateur@skynet.be (Bart Lateur) skribis:
> sendrate@my-deja.com wrote:
>
> ># Unicode value of first letter returns 196, should be 265!
> ># Am I doing something stupid?
> ># Any way around the problem?
> >
> >require 5.6.0;
> >use utf8;
> >
> >$i = "\x{109}efa";
> >@literoj = split //, $i;
> >foreach $litero (@literoj)
> >{
> > print "UTF8 estas: $litero , Unikodo estas: ".ord($litero)."\n";
> >}
>
> ...
> I sincerely have the feeling that UTF-8 support in Perl 5.6.0 is still
> in it's very infancy.
> ...
I fear you are right. And perltk (on Windows) didn't get the Unicode
stuff at all; but I didn't try very hard.
> ...
> definitely not on a non-ISO-Latin-1 platform! The pregrammer should
> ALWAYS remain in control! So, no implicit conversions to/from Unicode,
> please.
> ...
Yes yes, the programmer must keep control. I'd want to play with both
UTF8 strings and octet strings in the same piece of code. I tried this:
use utf8;
my octetstring = "Ha\xFFes";
but it expanded the FF into two UTF8 octets. Is there anything like:
my octetstring = qq_interpret_as_octets_not_utf8(Ha\xFFes);
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 2 Jun 2000 08:50:04 -0700
From: Petri Oksanen <Petri_member@newsguy.com>
Subject: Re: Printing on a Remote Printer
Message-Id: <8h8l3c$1vm6@edrn.newsguy.com>
In article <8h8h0u$a5i$1@bob.news.rcn.net>, "Paul says...
> I ran into an interesting problem while writing a simple script
> to print formatted Perl scripts on a remote jet-direct printer
> from my NT4 Workstation.
> We do know that it works on a shared, local printer.
> my $PrinterName = "\\\\server\\printer";
> my $PrintFileName = "prttst.txt";
> open (PRINTER, "> $PrinterName")
> || die "Can't open printer - $PrinterName!: $!\n";
> print PRINTER "Start of Job....\n";
If it works on a local port, try something like this:
system("net use lpt2: \\\\server\\printer");
my $PrinterName = "lpt2:";
# Continue your script as before...
system("net use lpt2: /d");
It's worth a try, I'd say.
Petri Oksanen
------------------------------
Date: Fri, 02 Jun 2000 11:16:15 -0400
From: Jennifer <toxlists@canada.com>
Subject: Problems to install modules
Message-Id: <3937CFBF.2C50C524@canada.com>
I'm trying to install Crypt::Blowfish
I have perl 5.00503 on my system. I am on a UNIX platform and
I am connected with SSH.
when I type perl Makefile.PL I get the following error
syntax error in file Makefile.PL at line 3, next 2 tokens "use ExtUtils"
Execution of Makefile.PL aborted due to compilation errors.
I couldn't find any error and neither could PerlBuilder's
Run/Debug
I added a line to print a header and ran it from my browser and
got the following output:
Checking if your kit is complete... Looks good Warning: I could
not locate your pod2man program. Please make sure, your pod2man
program is in your PATH before you execute 'make' Writing
Makefile for Crypt::Blowfish
I tried to type make anyway and got the following output:
Unrecognized switch: -MExtUtils::Command.
*** Error code 255
Stop.
What could be wrong?
Jennifer
------------------------------
Date: Fri, 02 Jun 2000 12:45:04 -0400
From: Jennifer <toxlists@canada.com>
Subject: Re: Problems to install modules
Message-Id: <3937E490.7B437B0B@canada.com>
Jennifer wrote:
>
> I'm trying to install Crypt::Blowfish
>
> I have perl 5.00503 on my system. I am on a UNIX platform and
> I am connected with SSH.
>
> when I type perl Makefile.PL I get the following error
>
> syntax error in file Makefile.PL at line 3, next 2 tokens "use ExtUtils"
> Execution of Makefile.PL aborted due to compilation errors.
As it turns out the _machine_ default is perl 4. I have a
virtual server on this machine and it came pre-installed with
it's own perl 5. So from a browser it was running the virtual
server's perl, but from the command prompt it was running the
machine's perl. I also needed to use the PREFIX. I am used to FTP
which automatically puts me in my home directory and shows it as
/ but from the command prompt it's different.
I typed
perl5 Makefile.PL PREFIX=/my_home_dir/local/lib
instead and all is well now.
Jennifer
------------------------------
Date: Fri, 02 Jun 2000 18:19:31 +0200
From: Oliver Vecernik <vecernik@aon.at>
Subject: REGEXP newbie question
Message-Id: <3937DE93.ED5B0D03@aon.at>
Hi,
can anyone give me a hint? I'd like to split following data:
field1 field2 field3 "another field" field5 "another field 2"
The fields are separated by one or more blanks. I used following:
foreach $zeile (@inhalt) {
chomp($zeile);
($field1, $field2, $field3, $field4, $field5, $field6) = split (/\s+/,
$zeile);
}
But unfortunately fields 4 and 6 are delmited by quotes and should be
stored without them. How do I have to modify my regexp?
Thanks a lot,
Oliver
------------------------------
Date: 02 Jun 2000 18:23:39 +0100
From: nobull@mail.com
Subject: Re: REGEXP newbie question
Message-Id: <u94s7c3skk.fsf@wcl-l.bham.ac.uk>
Oliver Vecernik <vecernik@aon.at> writes:
> can anyone give me a hint?
Hint: You should read the FAQ before posting. You'll annoy fewer
people.
(Your question appears there as: How can I split a [character]
delimited string except when inside [character]? (Comma-separated
files))
Hint: You should use the subject line to tell us about what you want
to do. "newbie" and "question" tell us nothing (except that you are
asking a question is probably answered in the FAQ). "REGEXP" tells us
about your guess of how to solve the problem - not the problem itself.
Please check out this helpful information on choosing good subject
lines.
http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 02 Jun 2000 18:32:17 +0200
From: "Nils B. Weidmann" <weidmann@informatik.uni-freiburg.de>
Subject: Secure File Transfer
Message-Id: <3937E191.2E9A653D@informatik.uni-freiburg.de>
Hi,
how can I transfer files with perl in an encrypted way (like unix scp
does)?
Which module is to be used?
thanks ,
nils
------------------------------
Date: 2 Jun 2000 17:48:05 GMT
From: abigail@arena-i.com (Abigail)
Subject: Re: Speed
Message-Id: <8h8s0l$pqm$1@news.panix.com>
On Fri, 02 Jun 2000 14:07:40 GMT,
newbie@db-networks.com <newbie@db-networks.com> wrote:
++ I have a real fast computer and it takes 2.5hrs to process a file with
++ 7 million lines.
++
++ How can I speed it up? Help will be appreciated.
The obvious way is to have less lines in the to be processed file. ;-)
++ while(<INFILE>) {
++ chomp;
++ undef @data;
++ push(@data, defined($1) ? $1:$3)
++ while m/([^,]+)/g;
Where's $3 coming from, and how could $1 ever be undefined? Perhaps you
want:
my @data = split /,+/;
++ $asked = substr($data[0],5,6);
++ $original = $data[1];
++ $string1 = uc($data[1]);
++ $string1 =~ s/\%([1-F][A-F])+/ /g;
Why backwack the %?
Why capture if you don't use $1?
And what do you think the character class [1-F] matches?
++ $string1 =~ s/_/ /g;
++ $string1 =~ s/\W/ /g;
++ $string1 =~ s/\s+/ /g;
The 3 lines above can be written as:
$string1 =~ y/a-zA-Z0-9/ /cs;
++ $string1 =~ s/^\s+//;
++ $string1 =~ s/\s+$//;
++
++ undef %seen;
++ @tosave = ();
++ @words = ();
++ @words = split(/ /, uc($string1));
++
++ foreach $item (@noisewords) {
++ $seen{$item} = 1
++ }
Since noisewords doesn't change, you should build %seen outside of the
loop, and don't do this 7 million times.
++ foreach $item (@words) {
++ unless (($seen{$item}) or ($item =~ m/\d/) or length($item) <
++ 3){
++ push(@tosave, $item)
++ }
++ }
my @tosave = grep {!$seen {$item} && $item !~ /\d/
&& length ($item) > 2} split / / => uc $string1;
++ $toprint = join(" ",@tosave);
++ if (length($toprint) > 2){
++ $firstchar = substr($toprint,0,1);
++ if ($firstchar lt 'D') {
++ print OUTFILE1 $toprint, "," , $original, "," ,$asked ,
++ "\n";
++ } elsif ($firstchar lt 'G') {
++ print OUTFILE2 $toprint, "," , $original, "," ,$asked ,
++ "\n";
++ } elsif ($firstchar lt 'K') {
++ print OUTFILE3 $toprint, "," , $original, "," ,$asked ,
++ "\n";
++ } elsif ($firstchar lt 'Q') {
++ print OUTFILE4 $toprint, "," , $original, "," ,$asked ,
++ "\n";
++ } elsif ($firstchar lt 'T') {
++ print OUTFILE5 $toprint, "," , $original, "," ,$asked ,
++ "\n";
++ } else {
++ print OUTFILE6 $toprint, "," , $original, "," ,$asked ,
++ "\n";
++ }
++ }
++ }
++
++ Thanks
------------------------------
Date: Fri, 02 Jun 2000 16:44:57 GMT
From: peter@PSDT.com (Peter J Scott)
Subject: Re: the end of perl?
Message-Id: <dwRZ4.5481$F9.168420@news1.gvcl1.bc.home.com>
In article <959937509.19427.0.nnrp-12.c3ad6973@news.demon.co.uk>,
"W Kemp" <bill.kemp@wire2.com> writes:
>by the way, what is the shift and backquote thingy (¬) supposed to be
>anyway. I have read that it is 'not' , something that I have never come
>across before.
Boy, is that a blast from the past. That is how twiddle (~) printed on the
line printers when I was at Cambridge University. (If anyone's not seeing the
character he just quoted properly, it looks like an L that's been flipped
around the vertical axis and then rotated counter-clockwise 90 degrees.) It
was also how the lecturers wrote logical NOT.
--
Peter Scott
------------------------------
Date: Fri, 02 Jun 2000 19:22:52 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: Trouble with Arrays of Hashes
Message-Id: <n6ofjs0j7rvpr9bto9v5unlnike44u1e2r@4ax.com>
On Fri, 02 Jun 2000 06:48:04 -0700, Tony Lanier
<tlanierNOtlSPAM@atmel.com.invalid> wrote:
> Hi everyone,
Hi again,
>
> Well, the problem, as Sam pointed out, was the %library being
> called as a global variable. I put my %library in the for loop
> and now everything works!
>
> However, I'm still puzzled. I can get this same problem to work
> using an Array of Arrays, which looks like this:
>
> elsif (/Library:/)
> {
> #my %library;
> #$library{$line[1]} = $line[2];
> #push @AoH, {%library};
>
> @lib = ($line[1], $line[2]);
> push @AoA, [@lib];
> }
>
> Notice I don't declare @lib a local variable.
That's a 'lexical', and don't be proud :-)
You have experienced what happens if you don't use properly scoped
variables. This should put you off, using global variables. To help you
notice these things, you will want to put the '-w' switch in the shebang
line, and 'use strict;' on the next:
#!/usr/bin/perl -w
use strict;
Let perl help you where it can.
> I print the results like this:
>
> for $i (0 .. $#AoA)
> {
> $aref = $AoA[$i]; # create reference to @AoA
> $sim_libraries .= "-y $cbic_kit\/$aref->[0]\/$aref->[1] ";
> }
That could also be written as:
foreach my $aref (@AoA) {
$sim_libraries .= "-y $cbic_kit\/$aref->[0]\/$aref->[1] ";
}
>
> This is almost exactly the same thing I did with the AoH, but I
> don't get the extra stuff at the end.
Which extra stuff? The stuff Sam told you about? I understand that was
history once you properly scoped %library.
> Can someone fill me in as
> to why the AoA works, but the AoH did not?
This is what I tried to explain to you.
Consider the case where there is @line as with your read loop. You want
to store the second and third element of @line in such a way, that you
can later retrieve them as a pair.
When you use a list to hold the values, you know exactly *where* they
are, but you don't know *what* they are.
my $aref = [ $line[1], $line[2] ];
my $first = $aref->[0];
my $second = $aref->[1];
When you put them in a hash, using the first value as a key to the
second, you will have to use keys() to get the first value back (as you
don't know what it is) in order to access the hash and get the second
value.
my $href = { $line[1] => $line[2] };
my $first = (keys %$href)[0]; #hopefully :-)
my $second = $href->{$first};
This is why I suggested to assign the values to *known* keys in the
hash, but that is almost the same as using the list.
--
Good luck,
Abe
------------------------------
Date: 02 Jun 2000 18:27:03 +0100
From: nobull@mail.com
Subject: Re: Trouble with Arrays of Hashes
Message-Id: <u93dmw3sev.fsf@wcl-l.bham.ac.uk>
Tony Lanier <tlanierNOtlSPAM@atmel.com.invalid> writes:
> {
> #my %library;
> #$library{$line[1]} = $line[2];
> #push @AoH, {%library};
>
> @lib = ($line[1], $line[2]);
> push @AoA, [@lib];
> }
>
> Notice I don't declare @lib a local variable.
> This is almost exactly the same thing I did with the AoH, but I
> don't get the extra stuff at the end. Can someone fill me in as
> to why the AoA works, but the AoH did not?
Because for a fair comparison you'd have to do:
%libray = ($line[1], $line[2]);
@lib = ($line[1], $line[2]);
or
$library{$line[1]} = $line[2];
push @lib, $line[1], $line[2];
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Fri, 02 Jun 2000 15:50:42 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Using awk in perl?
Message-Id: <mJQZ4.1797$6T1.379332@news.dircon.co.uk>
On Fri, 2 Jun 2000 14:09:00 +0100, A Pietro Wrote:
> Thanks for your reply. I'll check a2p out...
>
>>You can use a2p to convert your awk stuff into slightly less than idiomatic
> Perl.<
>
> It wasn't what I was thinking of, exactly.
> I was thinking of temporarily running awk from the shell -- might this be
> faster than doing awk stuff in Perl?
Then you dont have a Perl question.
/J\
------------------------------
Date: 02 Jun 2000 17:14:02 GMT
From: zenin@bawdycaste.org
Subject: Re: Using awk in perl?
Message-Id: <959966269.915647@thrush.omix.com>
A Pietro <apietro@my-deja.com> wrote:
: Thanks for your reply. I'll check a2p out...
:
:>You can use a2p to convert your awk stuff into slightly less than idiomatic
: Perl.<
:
: It wasn't what I was thinking of, exactly. I was thinking of temporarily
: running awk from the shell -- might this be faster than doing awk stuff in
: Perl?
Actually, it wouldn't. You're fork()ing an external process to do
something that Perl is just as much...if not more optimized to
handle.
There is slim to no reason to call sed or awk from perl, ever.
--
-Zenin (zenin@archive.rhps.org) From The Blue Camel we learn:
BSD: A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts. Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.) The full chemical name is "Berkeley Standard Distribution".
------------------------------
Date: Fri, 02 Jun 2000 10:31:32 -0500
From: "Joel Meyer (Intern)" <Joel.Meyer@tellabs.com>
Subject: Re: Web-based email solutions
Message-Id: <3937D353.68C79131@tellabs.com>
That means that the only part of your post that was related to Perl (and
hence this newsgroup) was the part where you asked if it could be done
using Perl. The answer to your question is "Yes, maybe you could."
Joel
A Pietro wrote:
> >answering your only Perl question -> "Yes, maybe you could." <
>
> Whats this supposed to mean?
>
> AP
------------------------------
Date: Fri, 2 Jun 2000 16:43:08 +0100
From: "A Pietro" <apietro@my-deja.com>
Subject: Re: Web-based email solutions
Message-Id: <8h8kmr$fh3$1@sshuraaa-i-1.production.compuserve.com>
>That means that the only part of your post that was related to Perl (and
hence this newsgroup) was the part where you asked if it could be done
using Perl. The answer to your question is "Yes, maybe you could."<
That is really helpful. Not.
AP
------------------------------
Date: Fri, 02 Jun 2000 16:14:32 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Web-based email solutions
Message-Id: <I3RZ4.1804$6T1.379332@news.dircon.co.uk>
On Fri, 2 Jun 2000 16:43:08 +0100, A Pietro Wrote:
>>That means that the only part of your post that was related to Perl (and
> hence this newsgroup) was the part where you asked if it could be done
> using Perl. The answer to your question is "Yes, maybe you could."<
>
> That is really helpful. Not.
>
A) This newsgroup is not a search engine.
B) <http://freshmeat.net>
C) *plonk*
/J\
------------------------------
Date: Fri, 02 Jun 2000 12:45:26 -0500
From: "Joel Meyer (Intern)" <Joel.Meyer@tellabs.com>
Subject: Re: Web-based email solutions
Message-Id: <3937F2B6.5A19B67@tellabs.com>
Sorry, I don't know the answer to any of your other questions or I would
have tried to help. No offense was intended.
A Pietro wrote:
> >That means that the only part of your post that was related to Perl (and
> hence this newsgroup) was the part where you asked if it could be done
> using Perl. The answer to your question is "Yes, maybe you could."<
>
> That is really helpful. Not.
>
> AP
------------------------------
Date: Fri, 2 Jun 2000 19:00:56 +0100
From: "A Pietro" <apietro@my-deja.com>
Subject: Re: Web-based email solutions
Message-Id: <8h8sp9$3uf$1@sshuraab-i-1.production.compuserve.com>
>A) This newsgroup is not a search engine<
I know that. A newsgroup is an open forum where people are allowed to ask
questions isn't it?
If you think my posting is a waste of time or off-topic just ignore it.
AP
------------------------------
Date: Fri, 02 Jun 2000 09:04:46 -0700
From: Ron Auer <rrauer@mitre.org>
Subject: Why is while inside a while so slow
Message-Id: <3937DB1E.DDCD2679@mitre.org>
I need to read a large flat file. I started testing with a test flat
file of 480,000 lines.
I put in a while loop to read the file, then I put a while loop inside
this to perform some checks. Took hours to run. So I did a benchmark.
I did the while loop to read the flat file and incremented a counter
and printed the counter. Took 3 1/2 minutes. Then I added the inside
while loop and the time increased to 94 minutes. And, the inside while
loop only looped once (for testing purposes). The code follows, any
thoughts as to why it takes to long? Any thoughts on how to get around
this? Thanks.
$start_time=`date`;
$ctr=0;
while (<>){
$ctr++
print $ctr , "\n";
}
$end_time = `date`;
print "Start time: ", $start_time, "end time: ", $end_time, "\n";
This while loop took 3 1/2 minutes. So then I added the inside while
loop:
$start_time=`date`;
$ctr=0;
$ktr=0;
@array =qw(one two);
while (<>){
$ctr++;
print $ctr , "\n";
while (<@array>) {
$ktr++;
}
$end_time = `date`;
print "Start time: ", $start_time, "end time: ", $end_time, "\n";
This took 94 minutes. I was expecting maybe 8 to 12 minutes -- boy was I
surprised. From this test I can assume this is a "bad thing to do."
Ron Auer
------------------------------
Date: 02 Jun 2000 17:49:17 +0100
From: nobull@mail.com
Subject: Re: Why is while inside a while so slow
Message-Id: <u98zwo3u5u.fsf@wcl-l.bham.ac.uk>
Ron Auer <rrauer@mitre.org> writes:
> @array =qw(one two);
> while (<@array>) {
This is read as:
while(glob("@array")) {
Which is effectively the same as:
for(split(/\s+/,`echo @array`)) {
Or if you are feeling _really_ verbose:
for(split(/\s+/,readpipe('echo ' . join $", @array))) {
Since @array in your example contains no shell metacharaters this is
just a very very slow way to do:
for(@array) {
> This took 94 minutes. I was expecting maybe 8 to 12 minutes -- boy was I
> surprised. From this test I can assume this is a "bad thing to do."
Yes, joining an array into a string, spawning off a subshell, getting the
shell to echo the string back to you, splitting the string back into
an array and then interating over that array is a "bad thing to do" -
unless of course you really do have an array of shell fileglobs you want
to expand.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 2 Jun 2000 17:30:49 GMT
From: abigail@arena-i.com (Abigail)
Subject: Re: Will flock(...) wait?
Message-Id: <8h8r09$p1o$1@news.panix.com>
On Fri, 2 Jun 2000 13:38:46 +0200, Thomas Plehn <thommy-p@bigfoot.com> wrote:
++ Hi,
++ can anyone help me with these flock questions?
++
++ I have to use LOCK_EX for a special listfile, because it would be fatal if
++ another script tried to read from it while it is modified.
++
++ Is there any better solution to wait for read-access than the one below?
++
++ while(not(-r "myfile.dat")){sleep(1);}
This will loop untill "myfile.dat" exists and is readable by the process.
It has *nothing* to do with locking.
++ open(FILE, "<myfile.dat");
++
++ I wondered what will happen if LOCK_EX is called while another script is
++ reading from the file without any lock.
Then the lock will succeed. Locking only works well for those who
participate - a process that doesn't either screws itself, or others.
++ It is important that my list_read()-routines don't use any flock()-call,
Why?
++ however my list_update()-routine _must_ use LOCK_EX.
Well, that will prevent you from two processes writing at the same time,
but they will happely overwrite what another process is reading. If the
readers don't participate; they get screwed.
Abigail
------------------------------
Date: 2 Jun 2000 17:03:11 GMT
From: jchaj@nvcs.freeserve.co.uk (John Chajecki)
Subject: Win32::AdminMisc::LogonAsUser
Message-Id: <8h8pcf$m33$1@soap.pipex.net>
Hi,
I am using a Win32 version of Perl and trying to exploit the
Win32:AdminMisc::LogonAsUser function to create a sudo user type session so
that I can run a process as Administrator. Unfortunately I can't get it to
work.
I have done as follows:
1. I have created a group called Sudo Users.
2. Assigned the following user rights to the group:
- Act as pert of the operating system
- Bypass traverse checking (already assigned to everyone)
- Replace a process level token
- Increase quotas (not required by Perl but used by other SU tools)
3. Assigned users to the group.
I have logged on as one of the users in the Sudo Users group and tried to run
the following test Perl script, which is a modification to the example in Dave
Roths Win32 Perl Programming - The Standard Extensions book:
-------------------------------------------------------------
use Win32;
use Win32::AdminMisc;
Win32::AdminMisc::LogonAsUser("","Administrator","adminpassword");
$UserName = Win32::AdminMisc::GetLogonName();
&Notify("Logged in as: ".$UserName."\n");
if ("\L$UserName" eq "\LAdministrator"){
&Notify("Logged in successfully.\n");
Win32::AdminMisc::LogoffAsUser();
}else{
&Notify("Did not log in as Administrator.");
}
------------------------------------------------------------------
The script always returns the user name I am logged in as (rather than
Administrator) along with 'Did not log in as Administrator' indicating that
Administrator level login was not successfull.
Testing using an SU tool shows that the operating system and (Windows NT 4.0)
and Sudo Users are set up correctly to run processes with Administrator
priviledges.
Can anyone figure out why this does not log me in as Administrator?
Also, how can I tell from Perl wether the user has the appropriate rights to
use the Win32::AdminMisc::LogonAsUser function?
Any help would be greatly appreciated.
Regards.
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
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 V9 Issue 3237
**************************************