[17046] in Perl-Users-Digest
Perl-Users Digest, Issue: 4458 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Sep 28 11:05:29 2000
Date: Thu, 28 Sep 2000 08:05:11 -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: <970153511-v9-i4458@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 28 Sep 2000 Volume: 9 Number: 4458
Today's topics:
Re: [Q] Sorting an array of arrays of references (Rafael Garcia-Suarez)
Re: [Q] Sorting an array of arrays of references (Jens)
Re: accessing global variables in another perl module <ren.maddox@tivoli.com>
Re: ASAP: How $SCALAR = $LIST <ren.maddox@tivoli.com>
Re: Can't get opendir working in win32 (Helgi Briem)
Re: Can't get opendir working in win32 <jluongonospam@draper.com>
Re: Candidate for the top ten perl mistakes list (Lars Gregersen)
Re: Candidate for the top ten perl mistakes list (Lars Gregersen)
Re: cgi that grabs html into @ from another cgi page <hartleh1@westat.com>
Re: CGI to CGI question <hartleh1@westat.com>
Re: dereferencing an array from within a hash value (Abigail)
Getting FILEVERSION info using Perl <kolonay@micro.ti.com>
Re: Hash of Hashes Problem kevin_mcfarlane@my-deja.com
Re: Help needed to copy files (Clay Irving)
Re: Help needed to copy files <yanick@babyl.sympatico.ca>
Re: Help needed to copy files (Abigail)
Re: Help with Unix processes. (Urgent!) <kperrier@blkbox.com>
How to monitor end of text file mikewise99@my-deja.com
Re: How to monitor end of text file (Mark-Jason Dominus)
Re: how to read dir info ? <ren.maddox@tivoli.com>
Re: Improving Script Efficiency <thunderbear@bigfoot.com>
Re: Improving Script Efficiency (Abigail)
Memory Mapped Files <fb@geo-guide.com>
Re: need help with LWP/https/proxy (Wolfgang Schauer)
Perl Programmer needed for a quick gig (Phillip Smith)
Problem w/ associative arrays lishy1950@my-deja.com
Re: Problem w/ associative arrays (John J. Trammell)
Re: Shortest code for Fibonacci? (Mark-Jason Dominus)
Sorry - TOTAL newbie <paulmaguire@ntlworld.com>
Re: Sorry - TOTAL newbie <Seiu@DesertLINC.com>
Re: Sorry - TOTAL newbie (Helgi Briem)
Re: Sorry - TOTAL newbie <sariq@texas.net>
Re: Syslog module problems <fs.mail@wanadoo.be>
Re: What does this do?! <yanick@babyl.sympatico.ca>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 28 Sep 2000 13:14:05 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: [Q] Sorting an array of arrays of references
Message-Id: <slrn8t6hdd.k6f.rgarciasuarez@rafael.kazibao.net>
Wolfgang Schauer wrote in comp.lang.perl.misc:
>Hi there,
>
>as you might know the DBI-method fetchall_arrayref returns
>a reference to an array of arrays of references to each row
>of data.
You mean, a reference to an array of references to arrays of data.
>The example below prints all data from an SQL statement
>row by row.
Yes -- an ugly example with ugly C-like loops. Well, not so C-like, but
they use counters.
>I fruitlessly tried to sort the rows numerically ascending
>depending on a specific field like
>@array = sort {$a <=> $b} $table->[2];
>which I hoped would sort the rows depending on the third column,
>but didn't do so.
my $table = $sth->fetchall_arrayref or die "$sth->errstr\n";
my @sorted = sort { $a->[2] <=> $b->[2] } @$table;
for my $row (@sorted) {
for my $value (@$row) {
print "$value\t";
}
print "\n";
}
>Any help on how to do this is highly appreciated.
perldoc -f sort
($a and $b are elements of @$table, i.e. array references.)
>Regards,
>
>Wolfgang
>
>
>------------- snip -------------
>my $table = $sth->fetchall_arrayref
> or die "$sth->errstr\n";
> my($i, $j);
> for $i ( 0 .. $#{$table} ) {
> for $j ( 0 .. $#{$table->[$i]} ) {
> print "$table->[$i][$j]\t";
> }
> print "\n";
> }
>------------- snap -------------
>(from MySQL Reference Manual)
--
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
------------------------------
Date: Thu, 28 Sep 2000 15:34:56 +0200
From: "Ellegiers, J. M. (Jens)" <jellegie@ford.com>
Subject: Re: [Q] Sorting an array of arrays of references
Message-Id: <39D34900.89094029@ford.com>
Wolfgang Schauer wrote:
>
> Hi there,
>
> as you might know the DBI-method fetchall_arrayref returns
> a reference to an array of arrays of references to each row
> of data.
> The example below prints all data from an SQL statement
> row by row.
> I fruitlessly tried to sort the rows numerically ascending
> depending on a specific field like
> @array = sort {$a <=> $b} $table->[2];
> which I hoped would sort the rows depending on the third column,
> but didn't do so.
>
What about sorting in the SQL?? This can be done with:
select myfield1, myfield2, myfield3, ... order by myfield3;
This is much faster as well than using perl for sorting.
You use much less memory as well if you walk through the result set with
while ( my $row = $sth->fetchrow_arrayref ) {
my @row = @{$row};
foreach my $item ( @row ) {
print $_, "\t";
}
print "\n";
}
instead of slurping all results into one big array.
> Any help on how to do this is highly appreciated.
>
> Regards,
>
> Wolfgang
>
> ------------- snip -------------
> my $table = $sth->fetchall_arrayref
> or die "$sth->errstr\n";
> my($i, $j);
> for $i ( 0 .. $#{$table} ) {
> for $j ( 0 .. $#{$table->[$i]} ) {
> print "$table->[$i][$j]\t";
> }
> print "\n";
> }
> ------------- snap -------------
> (from MySQL Reference Manual)
--
Viele Gruesse, regards, saludos
Jens Ellegiers
---------------------------------------------------------------
FORD-Werke AG, Spessartstrasse, 50725 Koeln
Jens Ellegiers Email: jellegie@ford.com /"\
Engineer (I-Engine CAE) Phone: +49-221-90-31467 \ /
Mail Sym: D-ME/PN-S Fax : +49-221-90-33025 X
ASCII Ribbon campaign against HTML E-mail & Usenet News >------> / \
------------------------------
Date: 27 Sep 2000 22:10:45 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: accessing global variables in another perl module
Message-Id: <m3bsx99poq.fsf@dhcp11-177.support.tivoli.com>
jason iversen <jasoniversen@my-deja.com> writes:
> hi there,
>
> i am having trouble with accessing a global variable defined in main()
> in a second perl module.
>
> i need the following...
>
> A.pl creates and sets global variable $D, then calls a sub in B.pm
> B.pm accesses $D (perhaps modifying it)
>
>
> how do i do it? i cant figure it out. i have tried "use vars qw($D)" in
> B.pm, but that doesnt work. i have tried using Exporter and have had no
> luck.
First of all, Perl doesn't *really* have global variables. It has
package variables (and lexical variables, which may also be
important). If A.pl has no package statement, then it defaults to
package "Main". Presumably B.pm has a "package B;" statement. To
access a variable in a different package, simply prefix it with the
package name and "::". For example, if $D is a package variable in
package "Main", accessing it from another package is done via
$Main::D or even simply $::D.
This all assumes that $D is a package variable and not a lexical
variable. Lexical variables are only available outside of their scope
via references. So if you are doing "my $D;" within A.pl, then B.pm
will not normally be able to access this variable. If you are doing
"our $D;" then you're OK.
For more and better information, see "perldoc perlsub".
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: 27 Sep 2000 21:45:56 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: ASAP: How $SCALAR = $LIST
Message-Id: <m3hf719qu2.fsf@dhcp11-177.support.tivoli.com>
jason <elephant@squirrelgroup.com> writes:
> amonotod wrote ..
> >In article <39D259DC.7DE580A8@webimpact.com>,
> > Don Vaillancourt <donv@webimpact.com> wrote:
> >> How to I get the number of elements in a list that is only accessible
> >> through a reference from a scalar.
> >>
> >> I have the following of code:
> >>
> >> $properties->{columns}=[];
> >> $columns=$properties->{columns};
> >>
> >> $columns->[0]={"name" => "delete",
> >> "type" => $NUMBER,
> >> "size" => 1,
> >> "unique" => $FALSE,
> >> "primary_key" => $FALSE,
> >> "required" => $TRUE,
> >> "allow_null" => $FALSE};
> >>
> >> How do I find how many elements the list pointed to by
> >> $properties->{columns} contains.
> >
> >You already have... $columns is a scalar value of the number of fields
> >in $properties->{columns}, and @columns is an array (with a hash as the
> >first field).
>
> look again amonotod .. $properties->{columns} contains a reference to an
> empty list .. which is also what $columns contains
>
> >Try :
> >print $columns ,"\n";
>
> I think you should try this .. you might see the error of your ways ;)
You neglected to quote the very next thing that amonotod wrote:
> >At this point, since you had
> >$properties->{columns}=[]; #This is empty, as in 0 fields.
> >
> >you should get
> >
> >
> >Yeah, nothing.
(Except that you should get "0", not nothing.)
amonotod's point was that the OP had code that basically gave him what
he wanted, he just needed to use it at the right time in the right
place.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Thu, 28 Sep 2000 13:54:04 GMT
From: helgi@NOSPAMdecode.is (Helgi Briem)
Subject: Re: Can't get opendir working in win32
Message-Id: <39d34d3f.105512348@news.itn.is>
On Wed, 27 Sep 2000 20:13:06 GMT, "James"
<jluongo@SPAMISBADmediaone.net> wrote:
>This is the beginning of a script I am writing that will change filenames to
>a different format. I am testing now. But I can't even open a directory
>with opendir. I try to open a directory and then get all the files and
>store them in an array.
>
>The script asks for a directory to be input. I input, for example,
>"D:\downloads" and then perl says:
>"Bad symbol for filehandle at renamer.pl line 8, <STDIN> line 1."
>Here, is my script. What is going on? I am confused
>
>use strict;
>
>print "Which directory?\n";
>my ($dir);
>$dir = <STDIN>;
>chomp ($dir);
>opendir (DIR, $dir) || die "Cannot open $dir:$!\n";
>my @files = readdir($dir);
>print "@files\n";
The mistake is in the readdir line, should be:
my @files = readdir(DIR);
Readdir works on a DIRHANDLE, not a
filename.
Regards,
Helgi Briem
------------------------------
Date: Thu, 28 Sep 2000 10:20:11 -0400
From: "James M. Luongo" <jluongonospam@draper.com>
Subject: Re: Can't get opendir working in win32
Message-Id: <39D3539B.26E17CE9@draper.com>
>
> then get a better newsreader .. Outlook Express is rubbish .. might I
> recommend Gravity .. http://www.microplanet.com/
> </OT>
>
> --
> jason -- elephant@squirrelgroup.com --
You are right, Outlook Express is garbage. I actually find reading the
newsgroups easier with Netscape at work.
--
------------------------
James M. Luongo x1427
Draper Laboratory Room 4207
------------------------
------------------------------
Date: Thu, 28 Sep 2000 15:09:48 GMT
From: lg@kt.dtu.dk (Lars Gregersen)
Subject: Re: Candidate for the top ten perl mistakes list
Message-Id: <39d35edf.1733684293@news.dtu.dk>
On Thu, 21 Sep 2000 00:55:52 GMT, clintp@geeksalad.org (Clinton A.
Pierce) wrote:
>[Posted and mailed]
>
>In article <Pine.GSO.4.21.0009201131470.15465-100000@crusoe.crusoe.net>,
> Jeff Pinyan <jeffp@crusoe.net> writes:
>>>> 1: didn't use -w
[snip of a very long list of good choices, but it is simply impossible
to add to two lists each going in opposite directions]
> 1. forgot -w
0. PERL, Pearl etc.
Lars
------------------------------
Lars Gregersen (lg@kt.dtu.dk)
http://www.gbar.dtu.dk/~matlg
Check out the Perl search utility findgrep at:
http://members.nbci.com/gregersenweb/findgrep/
------------------------------
Date: Thu, 28 Sep 2000 15:11:47 GMT
From: lg@kt.dtu.dk (Lars Gregersen)
Subject: Re: Candidate for the top ten perl mistakes list
Message-Id: <39d35f77.1733836866@news.dtu.dk>
On Wed, 20 Sep 2000 17:07:30 GMT, Uri Guttman <uri@sysarch.com> wrote:
>>>>>> "A" == Abigail <abigail@foad.org> writes:
>
> A> Russ Jones (russ_jones@rac.ray.com) wrote on MMDLXXVII September MCMXCIII
> A> in <URL:news:39C8DD4C.2FD4B394@rac.ray.com>:
> A> || Abigail wrote:
> A> || > Nah. The latter seldomly leads to an error.
> A> ||
> A> || Seldomly?
>
> A> How often do you see a program here where the cause of something not
> A> working was the use of @array[$index] vs $array[$index]?
>
>he was refering to your use of the non-word seldomly. it is just seldom.
I just remembered an old post (7/10/1999) from Tom Christiansen going
like this:
"It is therein marked as being of colloquial adverbial usage, where it
finds itself in the august company of such similarly marked terms as
"indeedy", "ratherish", and "vurry", and well as their more adjectival
cohorts, "all-overish", "bettermost", "come-at-able", "decentish",
"invalidy", "judgmatical", "moreish", "nicey", "phrasey", "prestigey",
"shambolic", "statusy", "swellish", "twistical", and "ucky".
I don't meant to be judgmaticalistical and call it super invalidy in
vurry ripped and clipped jargon, but it's just not a decentish or
statusy thing to be writing thusly in the bettermost fora. Sure, that
kind of phrasey lingo might thusly sound more come-at-able to some of
the more swellish kiddies, but it's a ratherish shambolic stunt that
thusly leaves the vurry, vurry nicey reader in search of something,
well, moreish; you know, something a tad more primmy and prestigey.
It's hard to avoid getting an ucky taste all-overish when thusly
stumbling through twistical turns of tongue. Yes indeedy, Bob!"
Lars
------------------------------
Lars Gregersen (lg@kt.dtu.dk)
http://www.gbar.dtu.dk/~matlg
Check out the Perl search utility findgrep at:
http://members.nbci.com/gregersenweb/findgrep/
------------------------------
Date: Thu, 28 Sep 2000 09:06:05 -0400
From: Henry Hartley <hartleh1@westat.com>
Subject: Re: cgi that grabs html into @ from another cgi page
Message-Id: <39D3423D.94ACD7@westat.com>
Brian Lavender wrote:
>
> When you say cgi in comp.lang.perl.misc, people start to get real
> sensitive because PERL didn't start as a CGI language, and while it is
> an excellent tool for CGI scripting/programs, it does a whole more.
The same is true of Perl, of course.
--
Henry Hartley
------------------------------
Date: Thu, 28 Sep 2000 09:17:53 -0400
From: Henry Hartley <hartleh1@westat.com>
Subject: Re: CGI to CGI question
Message-Id: <39D34501.F3B588DE@westat.com>
Seiu wrote:
>
> I'm on a beginner's level with PERL and so the advanced techniques are
> far beyond my abilities at this time ~ however I'm hoping somebody can
> explain a way for me to create the following type of script...
Word of warning. It's Perl, not PERL.
> I want to make a PERL script on one server to send data to a PERL script
> on a completely different server. Example:
The LWP module is what you want.
--
Henry Hartley
------------------------------
Date: 28 Sep 2000 14:45:40 GMT
From: abigail@foad.org (Abigail)
Subject: Re: dereferencing an array from within a hash value
Message-Id: <slrn8t6ma6.lo9.abigail@alexandra.foad.org>
nobull@mail.com (nobull@mail.com) wrote on MMDLXXXV September MCMXCIII in
<URL:news:u9lmwc92bl.fsf@wcl-l.bham.ac.uk>:
{}
{} In that case you'll also need:
{}
{} local @" = ', ';
And the purpose of this might be... ?
Abigail
--
my $qr = /^.+?(;).+?\1|;Just another Perl Hacker;|;.+$/;
$qr =~ s/$qr//g;
print $qr, "\n";
------------------------------
Date: Thu, 28 Sep 2000 09:24:49 -0400
From: "Paul Kolonay" <kolonay@micro.ti.com>
Subject: Getting FILEVERSION info using Perl
Message-Id: <8qvgki$mjv$1@tilde.csc.ti.com>
I would like to get the version information for dlls from a Perl script (on
WIN32). Is there already a module out there that already does this ? If not,
is there a way to call the win32 api to get this info ? I would prefer that
this solution be in the standard perl distribution and not have an active
state Perl be a requirement.
Thanks
Paul
------------------------------
Date: Thu, 28 Sep 2000 13:03:46 GMT
From: kevin_mcfarlane@my-deja.com
Subject: Re: Hash of Hashes Problem
Message-Id: <8qvfje$ufb$1@nnrp1.deja.com>
In article <8qvdi9$g9n$2@news.enteract.com>,
ebohlman@omsdev.com wrote:
> ebohlman@omsdev.com wrote:
> > Because the scope of %prim_node_span extends outside the loop,
taking a
> > reference to it inside the loop will always give a reference to the
same
> > place (which, at the end of the loop, will contain only the last
thing put
> > there). You need to declare %prim_node_span_ref inside the loop,
which
> ^^^^^^^^^^^^^^^^^^^
> > will ensure that a new place is created each time around the loop.
>
> That should, of course, be %prim_node_span.
>
>
I tried your suggestion and it fixes the problem. Many thanks for this.
I'm very new to Perl and I've been thrown in at the deep end in trying
to provide some enhancements to a script.
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 28 Sep 2000 14:35:03 GMT
From: clay@panix.com (Clay Irving)
Subject: Re: Help needed to copy files
Message-Id: <slrn8t6lon.koo.clay@panix3.panix.com>
On Thu, 28 Sep 2000 07:49:28 GMT, Janek <janekj@online.ee> wrote:
>I am beginner in Perl and I have a little problem.
>Please help me with the piece of code to copy many files to one.
>Something like: File1.txt + File2.txt + File3.txt = newFile.txt
>I can do it under MS-DOS:
>
>copy *.txt newFile.txt
Open a file for writing. Open each of the files to copy and print them to
the filehandle of the file opened for writing.
#!/usr/local/bin/perl -w
open N, ">newFile.txt" or die "Can't open newFile.txt: $!\n";
while ($file = <DATA>) {
chomp $file;
open F, $file or die "Can't open $file: $!\n";
while (<F>) {
print N;
}
}
close N;
close F;
__DATA__
File1.txt
File2.txt
File3.txt
Result:
$ wc -l File*
44 File1.txt
90 File2.txt
138 File3.txt
272 total
$ wc -l new*
272 newFile.txt
--
Clay Irving <clay@panix.com>
DIARY, n. A daily record of that part of one's life, which he can relate
to himself without blushing.
- Ambrose Bierce
------------------------------
Date: Thu, 28 Sep 2000 14:37:41 GMT
From: Yanick Champoux <yanick@babyl.sympatico.ca>
Subject: Re: Help needed to copy files
Message-Id: <VIIA5.277524$Gh.7404311@news20.bellglobal.com>
Janek <janekj@online.ee> wrote:
: Hi!
: I am beginner in Perl and I have a little problem.
: Please help me with the piece of code to copy many files to one.
: Something like: File1.txt + File2.txt + File3.txt = newFile.txt
: I can do it under MS-DOS:
: copy *.txt newFile.txt
perl -pe'BEGIN{open STDOUT,">".pop}' *.txt newFile.txt
Joy,
Yanick
--
($_,$y)=('Yhre lo .kePnarhtretcae', '(.) (.)');
$y=~s/\(/(./gwhile s/$y/$2$1/xg;print # @
# `---'
------------------------------
Date: 28 Sep 2000 14:40:13 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Help needed to copy files
Message-Id: <slrn8t6lvu.lo9.abigail@alexandra.foad.org>
Janek (janekj@online.ee) wrote on MMDLXXXV September MCMXCIII in
<URL:news:cKCA5.14$GY4.1370@nreader1.kpnqwest.net>:
`' Hi!
`' I am beginner in Perl and I have a little problem.
`' Please help me with the piece of code to copy many files to one.
`' Something like: File1.txt + File2.txt + File3.txt = newFile.txt
`' I can do it under MS-DOS:
`'
`' copy *.txt newFile.txt
`'
`' This command is in my .bat file and it works fine.
Then why the need to change?
system 'copy *.txt newFile.txt';
Abigail
--
BEGIN {$^H {q} = sub {pop and pop and print pop}; $^H = 2**4.2**12}
"Just "; "another "; "Perl "; "Hacker\n";
------------------------------
Date: 28 Sep 2000 09:35:07 -0500
From: Kent Perrier <kperrier@blkbox.com>
Subject: Re: Help with Unix processes. (Urgent!)
Message-Id: <AFB687CB82416671.5411A35042743B9B.028E95C5BF797326@lp.airnews.net>
logan@cs.utexas.edu (Logan Shaw) writes:
>
> By the way, a completely different solution to your problem
> is to install a batch processing system onto your machine and
> to tell it it can use two processors. Then, just submit each
> separate command as a job, and the system will take care of
> scheduling them for you. Depending on which one you choose,
> it might also do things like temporarily suspending the
> job(s) when someone wants to use the machine interactively.
This may be the "better" solution in the long term. This way, the processing
code will not have to change if you get access to a 4 (or 8 or 16 or 64..)
CPU box to process your data on.
Kent
--
"They say that nobody is perfect. Then they tell you practice makes
perfect. I wish they'd make up their minds." -- Wilt Chamberlain
------------------------------
Date: Thu, 28 Sep 2000 13:42:10 GMT
From: mikewise99@my-deja.com
Subject: How to monitor end of text file
Message-Id: <8qvhrh$gm$1@nnrp1.deja.com>
Hi,
I want a perl demon to watch a big log file and react when certain
messages appear there. Efficiently.
Obviously I could just watch for the date to change, then read to the
end of the file, but this is a big log file, and that is an ugly
solution.
If it were C, I could seek to the end and go back to the newline,
but I wonder if there isn't a niftier way to do it in perl.
Please enlighten me...
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 28 Sep 2000 11:29:33 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: How to monitor end of text file
Message-Id: <39d350df.334e$2fd@news.op.net>
Keywords: Compton, Dolores, hothead, way
In article <8qvhrh$gm$1@nnrp1.deja.com>, <mikewise99@my-deja.com> wrote:
>If it were C, I could seek to the end and go back to the newline,
>but I wonder if there isn't a niftier way to do it in perl.
This is what I use:
#!/usr/bin/perl
use Symbol;
unless (@ARGV) {
die "Usage: $0 files...\n";
}
foreach $file (@ARGV) {
my $fh = gensym;
(my $tag = $file) =~ s:.*/::;
if (open $fh, $file) {
$fh{$file} = [1, $fh, $tag];
seek $fh, 0, 2; # Seek to end
} else {
warn "Couldn't open file `$file': $!; ignoring\n";
}
}
@files = keys %fh;
for (;;) {
my $goodfiles = 0;
foreach $file (@files) {
my $lines = 0;
my ($good, $fh, $tag) = @{$fh{$file}};
seek $fh, 0, 1 unless $good;
while (defined ($line = <$fh>)) {
$lines++;
print "$tag: $line" ;
}
$goodfiles += $fh{$file}[0] = ($lines > 0);
}
sleep 5 unless $goodfiles;
}
------------------------------
Date: 27 Sep 2000 21:59:28 -0500
From: Ren Maddox <ren.maddox@tivoli.com>
Subject: Re: how to read dir info ?
Message-Id: <m3em259q7j.fsf@dhcp11-177.support.tivoli.com>
Larry Rosler <lr@hpl.hp.com> writes:
> In article <m3r965pj77.fsf@dhcp11-177.support.tivoli.com> on 27 Sep 2000
> 17:24:12 -0500, Ren Maddox <ren.maddox@tivoli.com> says...
>
> ...
>
> > #!/usr/local/bin/perl -w
> > use strict;
> >
> > my $dir = shift || '.';
> > opendir DIR, $dir or die "Could not open $dir, $!\n";
> > $\=$,="\n";
> > print grep -d, readdir(DIR)
>
> Wrong if any argument that doesn't specify the current directory is
> given.
Yeah.. posted a correction (but only after seeing you correct someone
else -- doh!).
> Where is that top-ten list? Surely this one is or should be in it.
> Look how many wrong answers there are in this thread alone!
This should definitely be on there... the only reason it shouldn't be
very high is that opendir/readdir simply aren't used that often. In
fact, in all the years I've been programming Perl I've seldom used
them (which at least partially explains my error... :} ).
The other side of that coin is, naturally, that it just *seems* like
it should work. I understand why it doesn't, even why it shouldn't,
but it still feels like what readdir should return isn't simply a
string representing the filename, but something more. How 'bout an
unopened filehandle for the file? One that stringifies to the bare
filename, but would work with the -X operators and such without
needing to add the path or chdir to it.
Perhaps a new module, Abigail? :)
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Thu, 28 Sep 2000 15:43:48 +0200
From: =?iso-8859-1?Q?Thorbj=F8rn?= Ravn Andersen <thunderbear@bigfoot.com>
Subject: Re: Improving Script Efficiency
Message-Id: <39D34B14.488114F3@bigfoot.com>
Adam T Walton wrote:
> Thanks for looking at it Tony but it has to be slightly more complicated
> than I was indicating. The script will eventually offer people the chance to
> check out Number 1 single and album information for whatever country they
> come from in the world, hence the need to have .txt files that contain a
> month's number 1 information at a time (which the script then has to search
> through to find the information correct for that particular day). If I had
> simple one line text files containing Number 1 information for every day of
> the year since 1952 (albums, singles, different countries) as you are
> perhaps recommending, then I would end up with tens of thousands of files...
> 48*365*however many countries I implement! It might be easier on the server,
> but the administration of such a site would be a nightmare!
Sounds like your data would be easier to manage if you put them in a
well-designed database schema.
--
Thorbjørn Ravn Andersen "...plus...Tubular Bells!"
http://bigfoot.com/~thunderbear
------------------------------
Date: 28 Sep 2000 14:43:26 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Improving Script Efficiency
Message-Id: <slrn8t6m5v.lo9.abigail@alexandra.foad.org>
Adam T Walton (waltonic@earbuzz.demon.co.uk) wrote on MMDLXXXV September
MCMXCIII in <URL:news:970143231.20558.0.nnrp-13.d4e441b4@news.demon.co.uk>:
:: Thanks for looking at it Tony but it has to be slightly more complicated
:: than I was indicating. The script will eventually offer people the chance to
:: check out Number 1 single and album information for whatever country they
:: come from in the world, hence the need to have .txt files that contain a
:: month's number 1 information at a time (which the script then has to search
:: through to find the information correct for that particular day). If I had
:: simple one line text files containing Number 1 information for every day of
:: the year since 1952 (albums, singles, different countries) as you are
:: perhaps recommending, then I would end up with tens of thousands of files...
:: 48*365*however many countries I implement! It might be easier on the server,
:: but the administration of such a site would be a nightmare!
Why? It isn't that the top 10 of 13 February 1963 is going to change...
Just don't put them all in one directory.
Abigail
--
$" = "/"; split $, => eval join "+" => 1 .. 7;
*{"@_"} = sub {foreach (sort keys %_) {print "$_ $_{$_} "}};
%{"@_"} = %_ = (Just => another => Perl => Hacker); &{%{%_}};
------------------------------
Date: Thu, 28 Sep 2000 17:02:08 +0200
From: "Frode Bjerkholt" <fb@geo-guide.com>
Subject: Memory Mapped Files
Message-Id: <A1JA5.1934$o9.32175@news1.online.no>
Hi :-)
Is there a module out there, that handles memory mapped files on Linux?
Thanks in advance :-)
Frode Bjerkholt
------------------------------
Date: 28 Sep 2000 13:32:16 GMT
From: w-s@gmx.de (Wolfgang Schauer)
Subject: Re: need help with LWP/https/proxy
Message-Id: <8qvh8v$gc873$1@fu-berlin.de>
mbudash@sonic.net (Michael Budash) wrote in
<tzuA5.80$QH1.85022@news.pacbell.net>:
>hey all -
>
>has anyone out there ever used LWP to access a secure url thru a proxy? i
>encounter a "communications error (-8192)" when doing so... anybody got a
>clue? this is a high profile project at my current contract - i'd like to
>come out a hero!
there is a bug in libwww concernig https through a proxy server, you might
want to check
http://www.ics.uci.edu/pub/websoft/libwww-perl/archive/2000h1/0419.html
or
http://www.ics.uci.edu/pub/websoft/libwww-perl/archive/2000h2/0163.html
Regards,
Wolfgang
------------------------------
Date: Thu, 28 Sep 2000 14:25:08 GMT
From: phillip.smith@sympatico.ca (Phillip Smith)
Subject: Perl Programmer needed for a quick gig
Message-Id: <39d35365.51210279@news1.on.sympatico.ca>
Hi,
We've had a Perl script developed... and we're convinced it's trash.
It does what it's supposed to -- but barely and it's not very smooth
or secure.
You are a Perl programmer with a free afternoon ('cause that's all it
will take) and enjoy laughing at other people's sloppy work. You would
like to make some bucks and help out a small web development company
in Canada.
You're a star! We're happy! World peace is next on your agenda...
Please contact me for details.
------------------------------
Date: Thu, 28 Sep 2000 14:23:16 GMT
From: lishy1950@my-deja.com
Subject: Problem w/ associative arrays
Message-Id: <8qvk8a$2m8$1@nnrp1.deja.com>
Hello
I'm working with an array and getting the following error message:
Didn't enter because index = *filename*
I set my array base to 1, which is what I want:
$[ = 1;
It seems the array is off by 1. The script is very long, but basically I
set the @files=("numerous file names");, set variables in the files into
hashes: %somevar= ("blah","N","blah","N");. Any ideas or suggestions?
I consulted the Programming Perl book, but I'm not sure where to
specifically find examples of this.
Thanks
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 28 Sep 2000 14:50:09 GMT
From: trammell@nitz.hep.umn.edu (John J. Trammell)
Subject: Re: Problem w/ associative arrays
Message-Id: <slrn8t5sbp.eet.trammell@nitz.hep.umn.edu>
On Thu, 28 Sep 2000 14:23:16 GMT, lishy1950@my-deja.com
<lishy1950@my-deja.com> wrote:
>I set my array base to 1, which is what I want:
>$[ = 1;
<snip>
>Any ideas or suggestions?
Don't do that.
--
John J. Trammell
johntrammell@yahoo.com
------------------------------
Date: Thu, 28 Sep 2000 11:38:16 GMT
From: mjd@plover.com (Mark-Jason Dominus)
Subject: Re: Shortest code for Fibonacci?
Message-Id: <39d352eb.339d$3cc@news.op.net>
In article <39D2CD7F.3E73455C@home.com>,
Rick Delaney <rick.delaney@home.com> wrote:
>My change eliminates a function call whenever n is odd.
Yeah, I cancelled my article about ten minutes afterwards.
Post in haste, repent at leisure.
>That was the point of the slice.
I still don't like the slice though.
------------------------------
Date: Thu, 28 Sep 2000 14:50:55 +0100
From: "eyedunno" <paulmaguire@ntlworld.com>
Subject: Sorry - TOTAL newbie
Message-Id: <CWHA5.994$7h.10028@news2-win.server.ntlworld.com>
Hi,
Sorry about this but could somebody please take 3 seconds to show me how to
write this in Perl
--------------------------------
mystr$ = "heres a short one"
for i = 0 to len(mystr$) step 2
....
======================
I've tried
-------------------------------
open (MYFILE, "myfile.txt");
my @myfile = <MYFILE>;
close (MYFILE);
for ( $i = 0; $i <= $#myfile; $i=$i+2 ) {
....}
===========================
but it doesn't work :-(
Thanx
Paul
------------------------------
Date: Thu, 28 Sep 2000 07:18:11 -0700
From: Seiu <Seiu@DesertLINC.com>
Subject: Re: Sorry - TOTAL newbie
Message-Id: <39D35323.57D7@DesertLINC.com>
eyedunno wrote:
>
> Hi,
>
> Sorry about this but could somebody please take 3 seconds to show me how to
> write this in Perl
>
> --------------------------------
> mystr$ = "heres a short one"
>
> for i = 0 to len(mystr$) step 2
> ....
> ======================
>
> I've tried
>
> -------------------------------
> open (MYFILE, "myfile.txt");
> my @myfile = <MYFILE>;
> close (MYFILE);
>
> for ( $i = 0; $i <= $#myfile; $i=$i+2 ) {
> ....}
> ===========================
> but it doesn't work :-(
>
> Thanx
>
> Paul
open FILE, 'MyFile.txt' or die('File not found!');
@aMyFile = <FILE>;
close FILE;
for ($i=0; $i <= $#aMyFile; $i+=2) {
# $i = 0, 2, 4, etc...
}
------------------------------
Date: Thu, 28 Sep 2000 14:46:22 GMT
From: helgi@NOSPAMdecode.is (Helgi Briem)
Subject: Re: Sorry - TOTAL newbie
Message-Id: <39d35931.108570826@news.itn.is>
On Thu, 28 Sep 2000 14:50:55 +0100, "eyedunno"
<paulmaguire@ntlworld.com> wrote:
>I've tried
>
>-------------------------------
>open (MYFILE, "myfile.txt");
>my @myfile = <MYFILE>;
>close (MYFILE);
>
>for ( $i = 0; $i <= $#myfile; $i=$i+2 ) {
>....}
>===========================
>but it doesn't work :-(
>
>
Well you are not saying in what way it fails.
"It doesn't work" is the useless and
uninformative lamentation of the
perennial newbie. However, my
guess is that you want to step through
the number of lines in myfile and in
that case you have an off by one error.
Your for loop should be:
for ( $i = 0; $i <= $#myfile+1; $i=$i+2 ) {
....}
Regards,
Helgi Briem
------------------------------
Date: Thu, 28 Sep 2000 14:50:43 GMT
From: Tom Briles <sariq@texas.net>
Subject: Re: Sorry - TOTAL newbie
Message-Id: <39D35B17.46E8992A@texas.net>
eyedunno wrote:
>
> Hi,
Hello.
Please read the following on Choosing Good Subject Lines:
http://www.perl.com/CPAN/authors/Dean_Roehrich/subjects.post
> Sorry about this but could somebody please take 3 seconds to show me how to
> write this in Perl
>
> --------------------------------
> mystr$ = "heres a short one"
>
> for i = 0 to len(mystr$) step 2
> ....
> ======================
>
> I've tried
>
> -------------------------------
> open (MYFILE, "myfile.txt");
*Always* check the return value of open().
open MYFILE, 'myfile.txt' or die "Open of myfile.txt failed: $!";
You should also enable warnings, and use the strict pragma.
> my @myfile = <MYFILE>;
> close (MYFILE);
It doesn't hurt to test the success of the close(), either. Though it
isn't strictly necessary here, it's still good practice.
> for ( $i = 0; $i <= $#myfile; $i=$i+2 ) {
Using the strict pragma will require you to declare $i as a lexical
variable here. Read:
perldoc strict
> ....}
> ===========================
> but it doesn't work :-(
Saying "it doesn't work :-(" is not giving us any information at all
about the problem. If it *did* work, you'd be unlikely to be posting
here.
My guess is that the open() is failing.
- Tom
------------------------------
Date: Thu, 28 Sep 2000 17:03:53 +0200
From: "Frank Sonnemans" <fs.mail@wanadoo.be>
Subject: Re: Syslog module problems
Message-Id: <20000928.170349.652@scuba.sbs-online.com>
Using &Sys::Syslog::LOG_WARNING works!
In article <u9aecu9sqg.fsf@wcl-l.bham.ac.uk>, nobull@mail.com wrote:
> "Frank Sonnemans" <fs.mail@wanadoo.be> writes:
>
>> I tried to set the logmask priority using the following:
>>
>> use Sys::Syslog require 'syslog.ph'
>>
>> $maskpri = &LOG_UPTO(&LOG_WARNING);
>> $oldmask = setlogmask($maskpri);
>
> I just piped that through "perl -c" and, not supprisingly, it failed the
> syntax check.
>
> Could you show us some actual code that manifests the problem you
> desribe.
>
>> However I continuously get "&main::LOG_WARNING not defined". What am I
>> doing wrong. I checked syslog.ph and it does define the LOG_WARNING
>> function.
>
> A required file is only loaded the first time it is encountered. A
> required file that modifies the symbol table package in which it is
> required will only modify the symbol table of the _first_ package to
> require it - in this case Sys::Syslog:: not main::.
>
> You could try &Sys::Syslog::LOG_WARNING but I don't know if this is the
> approved idiom.
>
------------------------------
Date: Thu, 28 Sep 2000 13:48:07 GMT
From: Yanick Champoux <yanick@babyl.sympatico.ca>
Subject: Re: What does this do?!
Message-Id: <r_HA5.21299$vZ.1054393@news20.bellglobal.com>
Gwyn Judd <tjla@guvfybir.qlaqaf.bet> wrote:
: I was shocked! How could Yanick Champoux <yanick@babyl.sympatico.ca>
: say such a terrible thing:
:> My second guess it that it was a typo of the original poster
:>and that the real line is '$o=~s/X*$/ if $d;'. Would make sense
:>too. Of course, it is very possible that the line has been thrown in
:>as a gratuitous monkeywrench for the poor reverse-engineers' mind. :)
: Yes you are right. I just checked my copy of the original source and it
: is $o =~ etc...; That makes much more sense too.
Eh. The statement '$o.='X' while length ($o)%5&&!$d;' suddenly
also make much more sense. Talk of karma balance. My humble entry
at the Perl obfuscated contest was abusing the similarity between
$o, $O and $0. Not very clever, but I always wanted to write
'$O++ while --$0;' somewhere. :)
:> Can an encryption program really be 'too weird'?
:>I mean, by definition, weird is unearthly and
:>unexplainable. So, the weirder a program is
:>(past a sufficient large value of weirdness), the
:>better the encryption will be, no? :)
: Security by obscurity is no security I thought :)
Only if you don't obfuscate enough. ;)
There is three kinds of encrypted programs. The ones
you can decypher, the ones you can't decypher, and the
ones you don't want to decypher. Programs falling in
the second category will eventually shift to the first
one, but truly loathsome code can remain in the third
category forever.
:>hum... 54 values... pack labeled as 'punny'...
:>cryptic mention of cards...
:>
:>Are we looking at a demented implementation of
:>the solitaire game, per any chance?
: Very good, I knew you'd get the name right eventually!
Well, considering that the name solitaire.pl has already
been mentioned in this thread, and the various clues and hints
you sprinkled here and there, I was bound to fall on it sooner
or later. Just like an infinity army of baboons punching on
an infinite amount of typewriters are bound to write a phonetic
rendition of Hamlet in Romanian sooner or later. :)
: Although it's not
: a version of the game per-se but rather an encryption algorithm that can
: be carried out with a pack of cards, hence the name solitaire. I think
: if you read the code with that in mind you will be able to understand
: how it works much more easily.
Indeed.
Thank for the hints, explanations and reference!
Joy,
Yanick
--
eval" use 'that poor Yanick' ";
print map{ (sort keys %{{ map({$_=>1}split'',$@) }})[hex] }
qw/8 b 15 1 9 10 11 15 c b 13 1 12 b 13 f 1 c 9 a e b 13 0/;
------------------------------
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 4458
**************************************