[16093] in Perl-Users-Digest
Perl-Users Digest, Issue: 3505 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 29 00:06:16 2000
Date: Wed, 28 Jun 2000 21:05:10 -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: <962251510-v9-i3505@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 28 Jun 2000 Volume: 9 Number: 3505
Today's topics:
Character Conversion (Arthur Merar)
Check out this site...:) akashgoel@my-deja.com
command line params @ARGV pettyr@hotmail.com
Re: command line params @ARGV (Brandon Metcalf)
Re: command line params @ARGV (Mike)
Re: command line params @ARGV (Brandon Metcalf)
Re: command line params @ARGV <juex@deja.com>
Deriving a list of modules present (Peter L. Berghold)
Re: Deriving a list of modules present <randy@theory.uwinnipeg.ca>
Re: different behaviour when running from web and comma (Shao Zhang)
Re: Does anyone have some exercises? (Brandon Metcalf)
Re: Golf problem (Gwyn Judd)
Re: Golf problem (Gwyn Judd)
Re: Golf problem (Gwyn Judd)
Re: HELP ME PLEASE !!!! <sumus@aut.dk>
Re: hopdelta program? (Cameron Kennedy)
Hot swap modules without shutdown <johnlin@chttl.com.tw>
Re: how to count number of line in a file ? <hyagillot@tesco.net>
Keeping track of open files <peter.sundstrom@eds.com>
Re: Keeping track of open files <tina@streetmail.com>
Re: Keeping track of open files <peter.sundstrom@eds.com>
Re: Net::FTP not on CPAN <elaine@chaos.wustl.edu>
Nmake error ---- need help <rob9428@swbell.net>
Re: Nmake error ---- need help <ivoz@starmail.com>
Re: Nmake error ---- need help <rob9428@swbell.net>
opening a filehandle-newbie quetzlcotl@my-deja.com
Re: opening a filehandle-newbie <stephenk@cc.gatech.edu>
please help in an Dbi programme coonecting with mysql <joydip_chaklader@my-deja.com>
Re: start a programm under windows via cgi <bwalton@rochester.rr.com>
Statistics <cghansen@micron.com>
Re: Statistics <randy@theory.uwinnipeg.ca>
Re: weirdness accessing a hash <bwalton@rochester.rr.com>
Where do uninitialized values come from? <fbartlet@optonline.net>
Re: Where do uninitialized values come from? <bwalton@rochester.rr.com>
Re: Where do uninitialized values come from? <ivoz@starmail.com>
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 28 Jun 2000 23:23:57 GMT
From: amerar@unsu.com (Arthur Merar)
Subject: Character Conversion
Message-Id: <395a88b3.73000220@news.iwc.net>
Hello,
Here is a good one. I need to write a Perl script to search my hard
drive for a filename entered by the user. Simple enough. However,
the file names are in Korean character set.
Is there a Perl for Win32 that I can use to accomplish this??
Please cc a copy to: amerar@unsu.com
Thanks,
Arthur
amerar@unsu.com
------------------------------
Date: Thu, 29 Jun 2000 03:01:00 GMT
From: akashgoel@my-deja.com
Subject: Check out this site...:)
Message-Id: <8jee55$dpq$1@nnrp1.deja.com>
Hi,
The Links Archive (http://tla.swo.net) is a comprehensive database of
links ranging in all sorts of categories from Computers and Internet to
Education and Music. We link to over 500 top-notch websites, which are
actually relevant to the section you are in. We only opened this Friday
we've already gained a lot of popularity, well because we speak the
truth about the website. If we don't like it, we mention it! The
sections covered at our site include: Computers and Internet,
Education, Software, Webmaster, Music, Desktop, Gaming and more:) Each
section is also further divided up into subsections like MP3, Banner
Services, Nintendo 64, etc. We are also working on a "Fun" section as
you read:) Also, you won't find more than one ad at our site (We need
one to host our site:) So please come check us out, I'm sure you'll
bookmark it. You can also submit your website if you feel it has a
chance to qualify as being a "TLA Site". Please email us or post back
your comments/suggestions. The URL is http://tla.swo.net/
Thanks,
Akash Goel
Webmaster
The Links Archive
http://tla.swo.net/
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 28 Jun 2000 22:30:04 GMT
From: pettyr@hotmail.com
Subject: command line params @ARGV
Message-Id: <8jdu8m$2f2$1@nnrp1.deja.com>
Ok, I'm truly hoping this won't be too difficult!
I have written a shell to a shell of sorts...
If I call 'shell' with parameters, I need them passed to the
inner system'd shell fully. This is illustrated as such:
# shell -c 'echo world'
output looks like:
>> print "\@ARGV:\t@ARGV\n";
@ARGV: -c echo hello
Notice the apostrophe's are stripped!
How do I preserve them so they may travel to the inner
system'd shell?
Thanks!
Rob
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: 28 Jun 2000 23:50:08 GMT
From: bmetcalf@baynetworks.com (Brandon Metcalf)
Subject: Re: command line params @ARGV
Message-Id: <8je2vg$h95$2@bcrkh13.ca.nortel.com>
pettyr@hotmail.com writes:
> # shell -c 'echo world'
>
> output looks like:
> >> print "\@ARGV:\t@ARGV\n";
> @ARGV: -c echo hello
>
> Notice the apostrophe's are stripped!
> How do I preserve them so they may travel to the inner
> system'd shell?
shell -c \'echo world\'
Brandon
------------------------------
Date: 28 Jun 2000 18:04:47 -0700
From: tcsh@holly.colostate.edu (Mike)
Subject: Re: command line params @ARGV
Message-Id: <slrn8ll4kv.pij.tcsh@faure.cs.colostate.edu>
pettyr@hotmail.com (pettyr@hotmail.com):
>
> If I call 'shell' with parameters, I need them passed to the
> inner system'd shell fully. This is illustrated as such:
>
> # shell -c 'echo world'
The 's won't get passed in ARGV ("'echo world'" passed in would
be 'echo world') . But, you know echo world is one argument in
your script because it's in $ARGV[1].
> >> print "\@ARGV:\t@ARGV\n";
print "\@argv : $ARGV[0] - $ARGV[1]\n";
--
Mike
------------------------------
Date: 29 Jun 2000 01:10:07 GMT
From: bmetcalf@baynetworks.com (Brandon Metcalf)
Subject: Re: command line params @ARGV
Message-Id: <8je7lf$k5b$1@bcrkh13.ca.nortel.com>
tcsh@holly.colostate.edu writes:
> > If I call 'shell' with parameters, I need them passed to the
> > inner system'd shell fully. This is illustrated as such:
> >
> > # shell -c 'echo world'
>
> The 's won't get passed in ARGV ("'echo world'" passed in would
> be 'echo world') . But, you know echo world is one argument in
> your script because it's in $ARGV[1].
>
> > >> print "\@ARGV:\t@ARGV\n";
>
> print "\@argv : $ARGV[0] - $ARGV[1]\n";
Huh? See my other post.
Brandon
------------------------------
Date: Wed, 28 Jun 2000 18:34:47 -0700
From: "Jürgen Exner" <juex@deja.com>
Subject: Re: command line params @ARGV
Message-Id: <395aa7b6@news.microsoft.com>
<pettyr@hotmail.com> wrote in message news:8jdu8m$2f2$1@nnrp1.deja.com...
> # shell -c 'echo world'
>
> output looks like:
> >> print "\@ARGV:\t@ARGV\n";
> @ARGV: -c echo hello
>
> Notice the apostrophe's are stripped!
> How do I preserve them so they may travel to the inner
> system'd shell?
Has nothing to do with Perl.
The quotes are being used by the shell to indicate that "echo" and "world"
together are one single argument "echo world".
If you want literal single quotes you will have to escape them. See the man
page of your shell for details.
jue
------------------------------
Date: Wed, 28 Jun 2000 23:59:34 GMT
From: peter@berghold.net (Peter L. Berghold)
Subject: Deriving a list of modules present
Message-Id: <slrn8ll4c3.psq.peter@localhost.localdomain>
Keywords: Perl Modules
Hi folks,
Somebody asked me this question a while ago and I haven't thought of a
real good answer yet. I figured I'd trot by eveybody on this NG and
see what happens.
The question I have is two fold: How do I derive a list of all modules
that are installed in the @INC path and secondly how can a query CPAN to
see if they are up to date.
I already use a method where if I know the module I am looking for and
I want to see if it in particular is on the system I do some thingy like
eval { use My::Module; };
if ( $@ blah blah blah....
But what if I just want to figure out what modules exist?
--
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
Peter L. Berghold http://www.berghold.net
Peter@Berghold.Net Linux Bigot at Large
"Linux renders ships... Windows NT renders ships useless..."
------------------------------
Date: Wed, 28 Jun 2000 20:03:57 -0500
From: "Randy Kobes" <randy@theory.uwinnipeg.ca>
Subject: Re: Deriving a list of modules present
Message-Id: <8je7eb$7jj$1@canopus.cc.umanitoba.ca>
Peter L. Berghold <peter@berghold.net> wrote
in message news:slrn8ll4c3.psq.peter@localhost.localdomain...
> Somebody asked me this question a while ago and I haven't thought of a
> real good answer yet. I figured I'd trot by eveybody on this NG and
> see what happens.
>
> The question I have is two fold: How do I derive a list of all modules
> that are installed in the @INC path and secondly how can a query CPAN to
> see if they are up to date.
The first question comes up regularly - do a dejanews
search of this newsgroup in the last couple of
months, and you'll get a number of possibilities.
As for the second question, using the CPAN.pm
module:
perl -MCPAN -e shell
typing 'r' at the prompt will give you a list
of recommended upgrades.
best regards,
randy kobes
------------------------------
Date: 29 Jun 2000 11:05:54 +1000
From: shao@linux.cia.com.au (Shao Zhang)
Subject: Re: different behaviour when running from web and command line
Message-Id: <395aa0f2@news>
In article <slrn8ljr9i.1ib.tadmc@magna.metronet.com>, Tad McClellan wrote:
> On 28 Jun 2000 18:16:02 +1000, Shao Zhang <shao@linux.cia.com.au> wrote:
>
> > I have wrote a simple perl script that basically does a query from a
> > website, however, it only works when run from command line, not
> > from the web...
>
>
> Perl FAQ, part 9:
>
> "My CGI script runs from the command line but not the browser.
> (500 Server Error)"
I don't have a 500 server error. The script executes fine, but just no
output.
>
> > Here is the code:
> >
> >print "<h3>looking up aunic for $domain ...</h3>\n";
>
>
> Where do you output the headers?
I did not include them. It is a huge script, I am only showing the part that do
not work.
Regards,
Shao.
--
____________________________________________________________________________
Shao Zhang - Running Debian 2.1 ___ _ _____
Department of Communications / __| |_ __ _ ___ |_ / |_ __ _ _ _ __ _
University of New South Wales \__ \ ' \/ _` / _ \ / /| ' \/ _` | ' \/ _` |
Sydney, Australia |___/_||_\__,_\___/ /___|_||_\__,_|_||_\__, |
Email: shao@cia.com.au |___/
_____________________________________________________________________________
------------------------------
Date: 28 Jun 2000 23:50:07 GMT
From: bmetcalf@baynetworks.com (Brandon Metcalf)
Subject: Re: Does anyone have some exercises?
Message-Id: <8je2vf$h95$1@bcrkh13.ca.nortel.com>
E.C.vEersel@KUB.NL writes:
> I tried to track down some exercises on the WWW, but no elaborate "exercise
> page" was to be found. Can someone help me out here? Does anyone has
> some old homework problems around in a dusty drawer? I'd like to test my
> knowledge by making some exercises that I don't define myself.
You should read problems posted to this newsgroup, solve the problems,
and then compare your solutions against solutions posted by others.
Brandon
------------------------------
Date: Thu, 29 Jun 2000 03:28:30 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Golf problem
Message-Id: <slrn8llgo2.2q5.tjla@thislove.dyndns.org>
I was shocked! How could Leo Schalkwyk <schalkwy@minnie.molgen.mpg.de>
say such a terrible thing:
>Gwyn Judd (tjla@guvfybir.qlaqaf.bet) wrote:
>: I was shocked! How could Peter Marksteiner <hump@katz.cc.univie.ac.at>
>: >Suppose you want to find words with exactly ten non-repeating letters such
>
>perl -pe'%c=();$_=""if!/^.{10}$/|grep{$c{+lc}++}/./g' Andrew
^^^^^^^^^^
Just wanted to say that anyone who does this can save a stroke easily
since "my%c;" has the same effect.
--
Gwyn Judd (tjla@guvfybir.qlaqaf.bet)
My return address is rot13'ed
Moon, n.:
1. A celestial object whose phase is very important to hackers. See
PHASE OF THE MOON. 2. Dave Moon (MOON@MC).
------------------------------
Date: Thu, 29 Jun 2000 03:54:04 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Golf problem
Message-Id: <slrn8lli7v.2q5.tjla@thislove.dyndns.org>
I was shocked! How could Abigail <abigail@delanet.com>
say such a terrible thing:
>Gwyn Judd (tjla@guvfybir.qlaqaf.bet) wrote on MMCDXCIII September
>MCMXCIII in <URL:news:slrn8lk5la.pg5.tjla@thislove.dyndns.org>:
>||
>|| perl -F// -pae '$_=""if(keys%{{map{$_,1}@F}})*@F!=121' /usr/dict/words
>
>And saving one more stroke:
>
> perl -F// -pae 'my%F;@F{@F}=();$_=""if@F*keys%F!=121' /usr/dict/words
perl -F// -pae 'my%F;@F{@F}=1;$_=""if@F*keys%F!=121' /usr/dict/words
saves yet another stroke making us equal with the "other" thread :).
>But that's still one more that from the other subthread:
>
> perl -pe 'my%c;$_=""if!/^.{10}$/|grep{$c{$_}++}/./g' /usr/dict/words
>
>Howeverm we can do better, by twisting the problem statement. It
>didn't say we have to find all words from /usr/dict/words matching the
>criteria. If we settle for a subset of words, we can do:
>
> perl -F// -pae 'my%F;@F{@F}=();$_=""if@F*%F!=121' /usr/dict/words
perl -F// -pae 'my%F;@F{@F}=1;$_=""if@F*%F!=121' /usr/dict/words
what subset is it though? What happens when you treat a hash as a
scalar? I can't find that anywhere in the docs.
--
Gwyn Judd (tjla@guvfybir.qlaqaf.bet)
My return address is rot13'ed
There is no reason anyone would want a computer in their home.
--Ken Olson, president, chairman and founder of Digital Equipment Corp.,
1977
------------------------------
Date: Thu, 29 Jun 2000 03:57:43 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Golf problem
Message-Id: <slrn8llieq.2q5.tjla@thislove.dyndns.org>
I was shocked! How could Martin Pauley <marty@deimos.kasei.com>
say such a terrible thing:
>In article <slrn8ljm2r.ka1.abigail@alexandra.delanet.com>, Abigail wrote:
>>Peter Marksteiner (hump@katz.cc.univie.ac.at) wrote on MMCDXCIII
>>September MCMXCIII in <URL:news:8jcgqm$29vm$1@www.univie.ac.at>:
>>][ perl -pe '$_=""if(keys%{{map{$_,1}split""}})*length!=121' /usr/dict/words
>>][
>>][ Is there anybody who can do it with fewer keystrokes?
>>
>>Saving one stroke:
>>
>> perl -pe '%c=();/^.{10}$/&!grep{$c{$_}++}split""or$_=""' /usr/dict/words
>
>Saving another 2 strokes (but retaining the 'Stravinsky' problem):
>
> perl -F'""' -ane 'my%c;@c{@F}=1;@F*keys%c==121&&print' /usr/dict/words
perl -F// -ane 'my%c;@c{@F}=1;@F*keys%c==121&&print' /usr/dict/words
saves two more retaining the Stravinski thing. I have no idea what a
good score is at the moment though.
--
Gwyn Judd (tjla@guvfybir.qlaqaf.bet)
My return address is rot13'ed
PHONOGRAPH
n. An irritating toy that restores life to dead noises.
------------------------------
Date: 29 Jun 2000 02:34:12 +0200
From: Jakob Schmidt <sumus@aut.dk>
Subject: Re: HELP ME PLEASE !!!!
Message-Id: <hfad2um3.fsf@macforce.sumus.dk>
David Meyers <dmeyers@panix.com> writes:
> Note, of course, that the script doesn't necessarily (or even likely)
> live in '.'.
Much to my surprise it seems you're right. Except about the likelyhood
perhaps. It depends on whether the script was invoked 'from' it's own
directory and that can be pretty likely :-)
So to get the scripts living-dir you actually have to use
( $mydir ) = $0 =~ m#^(.*)/[^/]+$#;
or something similar. This will get the invocation path (be it relative
or not) as it is.
> > while ( $_ = readdir DIR ) { -d $_ and print $_, "\n" }
>
> Nicely done.
Thank you
> Add error checking to the opendir
Oh - I _did_ comment on that myself...
--
Jakob
------------------------------
Date: Wed, 28 Jun 2000 15:40:23 -0800
From: kenned57@pilot.msu.edu (Cameron Kennedy)
Subject: Re: hopdelta program?
Message-Id: <kenned57-2806001540230001@alexthinkpad.salk.edu>
> Does anyone have a copy of the hopdelta program from the Perl
> Cookbook, pages 87-89? I'd rather not type it in if I don't have
> to!
Example 3.1: hopdelta
#!/usr/bin/perl
# hopdelta - feed mail header, produce lines
# showing delay at each hop.
use strict;
use Date::Manip qw (ParseDate UnixDate);
# print header; this should really use format/write due to
# printf complexities
printf "%-20.20s %-20.20s %-20.20s %s\n",
"Sender", "Recipient", "Time", "Delta";
$/ = ''; # paragraph mode
$_ = <>; # read header
s/\n\s+/ /g; # join continuation lines
# calculate when and where this started
my($start_from) = /^From.*\@([^\s>]*)/m;
my($start_date) = /^Date:\s+(.*)/m;
my $then = getdate($start_date);
printf "%-20.20s %-20.20s %s\n", 'Start', $start_from, fmtdate($then);
my $prevfrom = $start_from;
# now process the headers lines from the bottom up
for (reverse split(/\n/)) {
my ($delta, $now, $from, $by, $when);
next unless /^Received:/;
s/\bon (.*?) (id.*)/; $1/s; # qmail header, I think
unless (($when) = /;\s+(.*)$/) { # where the date falls
warn "bad received line: $_";
next;
}
($from) = /from\s+(\S+)/;
($from) = /\((.*?)\)/ unless $from; # some put it here
$from =~ s/\)$//; # someone was too greedy
($by) = /by\s+(\S+\.\S+)/; # who sent it on this hop
# now random mungings to get their string parsable
for ($when) {
s/ (for|via) .*$//;
s/([+-]\d\d\d\d) \(\S+\)/$1/;
s/id \S+;\s*//;
}
next unless $now = getdate($when); # convert to Epoch
$delta = $now - $then;
printf "%-20.20s %-20.20s %s ", $from, $by, fmtdate($now);
$prevfrom = $by;
puttime($delta);
$then = $now;
}
exit;
# convert random date strings into Epoch seconds
sub getdate {
my $string = shift;
$string =~ s/\s+\(.*\)\s*$//; # remove nonstd tz
my $date = ParseDate($string);
my $epoch_secs = UnixDate($date,"%s");
return $epoch_secs;
}
# convert Epoch seconds into a particular date string
sub fmtdate {
my $epoch = shift;
my($sec,$min,$hour,$mday,$mon,$year) = localtime($epoch);
return sprintf "%02d:%02d:%02d %04d/%02d/%02d",
$hour, $min, $sec,
$year + 1900, $mon + 1, $mday,
}
# take seconds and print in pleasant-to-read format
sub puttime {
my($seconds) = shift;
my($days, $hours, $minutes);
$days = pull_count($seconds, 24 * 60 * 60);
$hours = pull_count($seconds, 60 * 60);
$minutes = pull_count($seconds, 60);
put_field('s', $seconds);
put_field('m', $minutes);
put_field('h', $hours);
put_field('d', $days);
print "\n";
}
# usage: $count = pull_count(seconds, amount)
# remove from seconds the amount quantity, altering caller's version.
# return the integral number of those amounts so removed.
sub pull_count {
my($answer) = int($_[0] / $_[1]);
$_[0] -= $answer * $_[1];
return $answer;
}
# usage: put_field(char, number)
# output number field in 3-place decimal format, with trailing char
# suppress output unless char is 's' for seconds
sub put_field {
my ($char, $number) = @_;
printf " %3d%s", $number, $char if $number || $char eq 's';
}
Sender Recipient Time Delta
Start wall.org 09:17:12 1998/05/23
wall.org mail.brainstorm.net 09:20:56 1998/05/23 44s 3m
mail.brainstorm.net jhereg.perl.com 09:20:58 1998/05/23 2s
------------------------------
Date: Thu, 29 Jun 2000 09:45:25 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Hot swap modules without shutdown
Message-Id: <8je9jm$qds@netnews.hinet.net>
Dear all,
Can I "hot swap" modules?
That is, without shutting down the main program, can I unload
a module and then reload the module of a modified version?
I did a experiment by my imagination:
--------------------------------------- ModelX.pm
package ModelX;
sub new { bless [] }
sub hello { print "ModelX version 1.0\n" }
# sub hello { print "ModelX version 2.0\n" } change to 2.0 later
1
--------------------------------------- main.pl
local $|=1;
require ModelX;
my $object=new ModelX;
$object->hello;
print "Now modify ModelX without shutting down main program\n";
print "Press Enter to continue..."; <>; print "\n";
eval "no ModelX"; # unload
require ModelX; # and reload a new version
$object=new ModelX;
$object->hello;
__END__
ModelX version 1.0
Now modify ModelX without shutting down main program
Press Enter to continue...
ModelX version 2.0
Of course, my code doesn't work. The second output is still
ModelX version 1.0 not 2.0.
How can I achieve the "hot swap"? What is the opposit of "require"?
Thank you.
John Lin
------------------------------
Date: Wed, 28 Jun 2000 21:07:20 +0100
From: "B Kemp" <hyagillot@tesco.net>
Subject: Re: how to count number of line in a file ?
Message-Id: <8jduct$jab$1@epos.tesco.net>
>Your solution offers no speed advantage (maybe a slight speed
>disadvantage thanks to spawning three processes instead of zero
>processes). As well, your solution has a distict portability
>disadvantage.
The above must be worth thinking about,
but I did test it on my apache access log, and my suggestion was 10x slower.
Please note, though, that my suggestion was for discussion purposes only
(ie not something I'd really want to do), something that I thought I made
clear. But obviously not clear enough.
------------------------------
Date: Thu, 29 Jun 2000 11:33:04 +1200
From: "Peter Sundstrom" <peter.sundstrom@eds.com>
Subject: Keeping track of open files
Message-Id: <8je22q$phv$1@hermes.nz.eds.com>
What's the best way to handle keeping track of what files have been opened?
I have a set of input data that determines what the name of the output file
will be. The number and name of the output files will vary with each new
set of input data.
Once I've opened my output file using a variable filehandle, I'll be writing
data to it. I need to make sure that I only open the file once.
I was thinking of something like creating a hash of the filehandles and
doing a check to see if I need to open the file before writing to it, eg:
if (! defined $filehandle{$filename}) {
open $filehandle{$filename}, ">$filename" or die "Can not write to
$filename $!\n";
}
print $filehandle{$filename} "$somedata";
Is there a better way to do this?
------------------------------
Date: 29 Jun 2000 00:32:25 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: Keeping track of open files
Message-Id: <8je5eo$dmii$1@ID-24002.news.cis.dfn.de>
hi,
Peter Sundstrom <peter.sundstrom@eds.com> wrote:
> What's the best way to handle keeping track of what files have been opened?
perldoc -f fileno
> I have a set of input data that determines what the name of the output file
> will be. The number and name of the output files will vary with each new
> set of input data.
> Once I've opened my output file using a variable filehandle, I'll be writing
> data to it. I need to make sure that I only open the file once.
> I was thinking of something like creating a hash of the filehandles and
> doing a check to see if I need to open the file before writing to it, eg:
> if (! defined $filehandle{$filename}) {
> open $filehandle{$filename}, ">$filename" or die "Can not write to
> $filename $!\n";
> }
how do you initialize $filehandle{$filename}?
you should do it like
$filehandle{$filename} = *FILEHANDLE;
unless (fileno $filehandle{$filename}) {
open $filehandle{$filename}, ">$filename" or die $!;
}
tina
--
http://tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
"The Software required Win98 or better, so I installed Linux."
------------------------------
Date: Thu, 29 Jun 2000 13:51:26 +1200
From: "Peter Sundstrom" <peter.sundstrom@eds.com>
Subject: Re: Keeping track of open files
Message-Id: <8jea66$3ti$1@hermes.nz.eds.com>
Tina Mueller wrote in message <8je5eo$dmii$1@ID-24002.news.cis.dfn.de>...
>hi,
>Peter Sundstrom <peter.sundstrom@eds.com> wrote:
>> What's the best way to handle keeping track of what files have been
opened?
>
>perldoc -f fileno
I read through this, but I don't see how it helps me. I'm writing to one
file for each execution of a loop, so I don't need select a filehandle.
Maybe I'm missing the relevance.
>
>> I have a set of input data that determines what the name of the output
file
>> will be. The number and name of the output files will vary with each new
>> set of input data.
>
>> Once I've opened my output file using a variable filehandle, I'll be
writing
>> data to it. I need to make sure that I only open the file once.
>> I was thinking of something like creating a hash of the filehandles and
>> doing a check to see if I need to open the file before writing to it, eg:
>
>> if (! defined $filehandle{$filename}) {
>> open $filehandle{$filename}, ">$filename" or die "Can not write to
>> $filename $!\n";
>> }
>
>how do you initialize $filehandle{$filename}?
It happens after the open:
$filehandle{$filename}=$filename;
>you should do it like
>$filehandle{$filename} = *FILEHANDLE;
>unless (fileno $filehandle{$filename}) {
> open $filehandle{$filename}, ">$filename" or die $!;
>}
I don't see how this is any better. Perhaps I'm missing something obvious.
------------------------------
Date: Thu, 29 Jun 2000 02:04:37 GMT
From: Elaine Ashton <elaine@chaos.wustl.edu>
Subject: Re: Net::FTP not on CPAN
Message-Id: <B58026F2.6991%elaine@chaos.wustl.edu>
in article 8jditd$dqv$1@news.service.uci.edu, Gabe at grichard@uci.edu
quoth:
> No, it's pretty easy to miss. Particularly if you're not familiar with
> "bundles", the "libnet bundle" in particular, have never used the search
> portion of the site before, and are expecting something that looks like the
> descriptions you find when browsing the modules on the website. Also, when
> you type in the search criteria, the most prominent link is "Net::FTP", but
> that's a readme. So in other words, the most obvious link to get to what I
> want is not what I want, so I missed the correct link quite easily.
Hmmm. What part of
http://search.cpan.org/search?mode=module&query=Net%3A%3AFtp
is easy to miss? What were you expecting and what about the result from
above was misleading? The line '6 modules found in 1 distribution matching
'Net::Ftp' ' and the highlighting should be giving people a really easy way
to find their way, but if it isn't then what would you suggest?
e.
------------------------------
Date: Wed, 28 Jun 2000 20:14:31 -0500
From: "Rob" <rob9428@swbell.net>
Subject: Nmake error ---- need help
Message-Id: <dtx65.123$1l6.43521@nnrp2.sbc.net>
OK, I installed a bandaid to Net::SSLeay 1.05. I ran the Perl Makefile.PL,
no probs things look good. But I try and run the Nmake command and here is
what I got;
C:\temp\Net_SSLeay.pm-1.05>nmake
Microsoft (R) Program Maintenance Utility Version 1.62.7022
Copyright (C) Microsoft Corp 1988-1997. All rights reserved.
cl -c -I/usr/local/ssl/include -O1 -MD -DNDEBUG -DWIN32 -D_CONSOLE -DNO_STRI
CT -DHAVE
_DES_FCRYPT -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -DPERL_MSVCRT_READFI
X -O1 -MD -DNDEBU
G -DVERSION=\"1.05\" -DXS_VERSION=\"1.05\" -IC:\Perl\lib\CORE
SSLeay.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 11.00.7022 for 80x86
Copyright (C) Microsoft Corp 1984-1997. All rights reserved.
SSLeay.c
"Running Mkbootstrap for Net::SSLeay ()"
C:\Perl\bin\Perl.exe -IC:\Perl\lib -IC:\Perl\lib -MExtUtils::Command -e
chmod 644 SSL
eay.bs
link -out:blib\arch\auto\Net\SSLeay\SSLeay.dll -dll -nologo -nodefaultlib -r
elease -
libpath:"C:\Perl\lib\CORE" -machine:x86 SSLeay.obj
C:\Perl\lib\CORE\perl56.lib "\Program F
iles\DevStudio\VC\lib\oldnames.lib" "\Program
Files\DevStudio\VC\lib\kernel32.lib" "\Program
Files\DevStudio\VC\lib\user32.lib" "\Program
Files\DevStudio\VC\lib\gdi32.lib" "\Program File
s\DevStudio\VC\lib\winspool.lib" "\Program
Files\DevStudio\VC\lib\comdlg32.lib" "\Program Fil
es\DevStudio\VC\lib\advapi32.lib" "\Program
Files\DevStudio\VC\lib\shell32.lib" "\Program Fil
es\DevStudio\VC\lib\ole32.lib" "\Program
Files\DevStudio\VC\lib\oleaut32.lib" "\Program Files
\DevStudio\VC\lib\netapi32.lib" "\Program Files\DevStudio\VC\lib\uuid.lib"
"\Program Files\De
vStudio\VC\lib\wsock32.lib" "\Program Files\DevStudio\VC\lib\mpr.lib"
"\Program Files\DevStud
io\VC\lib\winmm.lib" "\Program Files\DevStudio\VC\lib\version.lib" "\Program
Files\DevStudio\
VC\lib\odbc32.lib" "\Program Files\DevStudio\VC\lib\odbccp32.lib" "\Program
Files\DevStudio\V
C\lib\msvcrt.lib" "\usr\local\ssl\bin\libeay32.lib"
"\usr\local\ssl\bin\RSAglue.lib" "\usr\lo
cal\ssl\bin\ssleay32.lib" -def:SSLeay.def
C:\Perl\lib\CORE\perl56.lib : fatal error LNK1106: invalid file or disk
full: cannot seek to
0x38de8e9f
NMAKE : fatal error U1077: 'link' : return code '0xc'
Stop.
Any Idea how to fix or identify the problem?
Thanks Again,
Rob
------------------------------
Date: Thu, 29 Jun 2000 06:42:53 +0300
From: "Ivo Zdravkov" <ivoz@starmail.com>
Subject: Re: Nmake error ---- need help
Message-Id: <395ac554_1@news.nwlink.com>
"Rob" <rob9428@swbell.net> wrote in message
news:dtx65.123$1l6.43521@nnrp2.sbc.net...
> OK, I installed a bandaid to Net::SSLeay 1.05. I ran the Perl Makefile.PL,
> no probs things look good. But I try and run the Nmake command and here
is
> what I got;
....
> C:\Perl\lib\CORE\perl56.lib : fatal error LNK1106: invalid file or disk
> full: cannot seek to
> 0x38de8e9f
> NMAKE : fatal error U1077: 'link' : return code '0xc'
> Stop.
>
>
> Any Idea how to fix or identify the problem?
Check for enough disk space, ( I recommend ~100 MB free ) then run
scandisk or something !
>
> Thanks Again,
> Rob
>
>
------------------------------
Date: Wed, 28 Jun 2000 22:57:06 -0500
From: "Rob" <rob9428@swbell.net>
Subject: Re: Nmake error ---- need help
Message-Id: <FRz65.101$Eh1.88172@nnrp1.sbc.net>
LOL, its not the space, I have over 18 gigs available also the file
"perl56.lib" is also present which is what has me baffled.
"Ivo Zdravkov" <ivoz@starmail.com> wrote in message
news:395ac554_1@news.nwlink.com...
>
> "Rob" <rob9428@swbell.net> wrote in message
> news:dtx65.123$1l6.43521@nnrp2.sbc.net...
> > OK, I installed a bandaid to Net::SSLeay 1.05. I ran the Perl
Makefile.PL,
> > no probs things look good. But I try and run the Nmake command and here
> is
> > what I got;
> ....
> > C:\Perl\lib\CORE\perl56.lib : fatal error LNK1106: invalid file or disk
> > full: cannot seek to
> > 0x38de8e9f
> > NMAKE : fatal error U1077: 'link' : return code '0xc'
> > Stop.
> >
> >
> > Any Idea how to fix or identify the problem?
>
> Check for enough disk space, ( I recommend ~100 MB free ) then run
> scandisk or something !
>
> >
> > Thanks Again,
> > Rob
> >
> >
>
>
>
------------------------------
Date: Thu, 29 Jun 2000 02:46:02 GMT
From: quetzlcotl@my-deja.com
Subject: opening a filehandle-newbie
Message-Id: <8jed97$d91$1@nnrp1.deja.com>
Howdy,
I have a problem opening filehandles under win98.
I am typing this exactly(read from "sams teach youself perl in 24hrs"-
excellent book btw Mr Clinton Pierce:))obviously sunstituting the names
below for valid filenames and my own filehandle name:
open (FILEHANDLE, "filename");
I get this error message:
Name "main::FILEHANDLE" used only once:possible typo at hedge.pl line 3
I have checked online documentation for the key to my solving my prob,
and also in this forum but am stuck.
I would appreciate it if someone would be able to enlighten me.
Thanks heaps:)
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Wed, 28 Jun 2000 23:33:46 -0400
From: Stephen Kloder <stephenk@cc.gatech.edu>
Subject: Re: opening a filehandle-newbie
Message-Id: <395AC399.D4F6ABBE@cc.gatech.edu>
quetzlcotl@my-deja.com wrote:
> Howdy,
>
> I have a problem opening filehandles under win98.
>
> I am typing this exactly(read from "sams teach youself perl in 24hrs"-
> excellent book btw Mr Clinton Pierce:))obviously sunstituting the names
> below for valid filenames and my own filehandle name:
>
> open (FILEHANDLE, "filename");
>
> I get this error message:
>
> Name "main::FILEHANDLE" used only once:possible typo at hedge.pl line 3
>
> I have checked online documentation for the key to my solving my prob,
> and also in this forum but am stuck.
>
> I would appreciate it if someone would be able to enlighten me.
>
> Thanks heaps:)
This warning (distinguish from error) is one of the effects of the -w
switch. Since without 'use strict', variables can be declared at any point
in the program, any mistyped variable name will be interpreted as a
distinct variable. Thus perl -w is suspicious of any variable name used
only once (and presumes typo). Using the filehandle twice (you'll need a
close statement, after all) should take care of this message.
For more info see perlrun.
--
Stephen Kloder | "I say what it occurs to me to say.
stephenk@cc.gatech.edu | More I cannot say."
Phone 404-874-6584 | -- The Man in the Shack
ICQ #65153895 | be :- think.
------------------------------
Date: Thu, 29 Jun 2000 01:24:37 GMT
From: Joydip Chakladar <joydip_chaklader@my-deja.com>
Subject: please help in an Dbi programme coonecting with mysql
Message-Id: <8je8g7$9uf$1@nnrp1.deja.com>
Hi everybody,
I am new at DBI.
This is an sample programme I am building for connecting to mysql. I
have mentioned a part of it here where it is giving a compilation error
mesage in Use DBI;line.
Error Message :-
Can't locate loadable object for module DBI in @INC contain
c:\Perl\lib and C:\Perl\site\lib .) at c:\Perl\site\lib\dbi.pm at line
164.
BEGIN FAILED COMPILATION ABORTED AT C:\PERL\LIB\DBI.PM LINE 164
I cannot find what kind of error it is . Anyway I have been running
mysql daemon from c:\mysql\bin and this programme from c:\perl\bin.
Thanx in advance for help . I need an urgent response. please help.
$host= shift || "";
$test_db="test";
$opt_user=$opt_password="";
use DBI;
$|= 1; # Autoflush
$table="test_big_record";
$rows=20; # Test of blobs up to ($rows-1)*10000+1
bytes
print "Connection to database $test_db\n";
$dbh = DBI->connect("DBI:mysql:$test_db:$host",$opt_user,$opt_password)
|| die "Can't connect: $DBI::errstr\n";
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Thu, 29 Jun 2000 01:52:27 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: start a programm under windows via cgi
Message-Id: <398237C8.BE1FB458@rochester.rr.com>
YK wrote:
>
> how can i start, (within a cgi script), a
> windows console programm with parameters?
> eg. a .bat file?
> thanx
> yk
Well, maybe something like:
system("start progname.bat $param1 $param2");
would work.
--
Bob Walton
------------------------------
Date: Wed, 28 Jun 2000 16:43:48 -0600
From: "Colby Hansen" <cghansen@micron.com>
Subject: Statistics
Message-Id: <8jdv39$itm$1@admin-srv3.micron.com>
Has anyone ever done ANOVA calculations or Kruskal-Wallis calculations using
Perl? I haven't been able to find much in the way of statistics modules.
Yes, I have checked CPAN...
------------------------------
Date: Wed, 28 Jun 2000 19:48:52 -0500
From: "Randy Kobes" <randy@theory.uwinnipeg.ca>
Subject: Re: Statistics
Message-Id: <8je6i2$792$1@canopus.cc.umanitoba.ca>
Colby Hansen <cghansen@micron.com> wrote in
message news:8jdv39$itm$1@admin-srv3.micron.com...
> Has anyone ever done ANOVA calculations or Kruskal-Wallis calculations
using
> Perl? I haven't been able to find much in the way of statistics modules.
> Yes, I have checked CPAN...
Did you come across the Statistics::Table::F module?
Documentation describing it is available at, eg,
http://theoryx5.uwinnipeg.ca/CPAN/data/Statistics-Table-F/Table/F/blib/Stati
stics/Table/F.html.
There's a number of other statistics modules on CPAN -
look under the category Data Type Utilities -> Statistics.
best regards,
randy kobes
------------------------------
Date: Thu, 29 Jun 2000 01:58:25 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: weirdness accessing a hash
Message-Id: <3982392D.61787265@rochester.rr.com>
darren chamberlain wrote:
>
> Here is a situation I discovered by accident. Can anyone explain this?
>
> bash$ perl
> my %hash = ( foo => 1,
> bar => 2,
> baz => 3,
> );
> printf "%d\n",%hash->{foo};
> ^D
> 1
> bash$
>
> Accessing an element of a regular hash (not a hashref) using hashref
> syntax with the leading % (not a $). It works for more than just simple
> integers as well -- any valid hash key works (references, strings, objects).
>
> Any explanations?
>
> Thanks,
>
> darren
That's just another way to do it. See perldoc perlop, in the "arrow
operator" section.
--
Bob Walton
------------------------------
Date: Thu, 29 Jun 2000 01:34:16 GMT
From: Fred Bartlett <fbartlet@optonline.net>
Subject: Where do uninitialized values come from?
Message-Id: <395AA794.41F86AD7@optonline.net>
While this doesn't seem to make any difference to the correct output of
my little script, I would like to know what causes the warning.
When I run my script with -w, I get warnings of the form
Use of uninitialized value at HashIt.pl line 67.
When I don't use -w, I don't get warned.
Now, line 67 is the 4th line below:
if($level > 1){
for($i=1 ; $i < $level ; $i++){
last if (($ArrayIndex-$i) < 0);
$combinedTag=$startTags[$ArrayIndex -
$i].$combinedTag;
}
}
The purpose of this script is to show the nesting of tags in an sgml
file; $level holds the depth of the nesting. Before we reach this point,
$combinedTag has been given the value of the current tag. $startTags is
an array that has all the start tags from the SGML file; they are popped
off as end tags are encountered.
I would have thought that the presence of the "last if" test would have
prevented any uninitialized values; obviously, I thought wrong.
Any and all clues gratefully accepted.
Fred
------------------------------
Date: Thu, 29 Jun 2000 01:47:09 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Where do uninitialized values come from?
Message-Id: <3982367D.41E0B5D6@rochester.rr.com>
Fred Bartlett wrote:
>
> While this doesn't seem to make any difference to the correct output of
> my little script, I would like to know what causes the warning.
>
> When I run my script with -w, I get warnings of the form
> Use of uninitialized value at HashIt.pl line 67.
> When I don't use -w, I don't get warned.
>
> Now, line 67 is the 4th line below:
>
> if($level > 1){
> for($i=1 ; $i < $level ; $i++){
> last if (($ArrayIndex-$i) < 0);
> $combinedTag=$startTags[$ArrayIndex -
> $i].$combinedTag;
> }
> }
>
...
> Fred
I recommend you run your script with the -d switch to use Perl's
debugger. Set a breakpoint ahead of the problem area and look at the
values of the various variables.
Also, use strict; may point out the problem directly.
--
Bob Walton
------------------------------
Date: Thu, 29 Jun 2000 06:20:59 +0300
From: "Ivo Zdravkov" <ivoz@starmail.com>
Subject: Re: Where do uninitialized values come from?
Message-Id: <395ac030_1@news.nwlink.com>
if your script begins with:
use strict;
then probably $startTags[$ArrayIndex - $i] is not set
otherwise - correct beggining :-)
regards
Ivo Z.
"Fred Bartlett" <fbartlet@optonline.net> wrote in message
news:395AA794.41F86AD7@optonline.net...
> While this doesn't seem to make any difference to the correct output of
> my little script, I would like to know what causes the warning.
>
> When I run my script with -w, I get warnings of the form
> Use of uninitialized value at HashIt.pl line 67.
> When I don't use -w, I don't get warned.
>
> Now, line 67 is the 4th line below:
>
> if($level > 1){
> for($i=1 ; $i < $level ; $i++){
> last if (($ArrayIndex-$i) < 0);
> $combinedTag=$startTags[$ArrayIndex -
> $i].$combinedTag;
> }
> }
>
> The purpose of this script is to show the nesting of tags in an sgml
> file; $level holds the depth of the nesting. Before we reach this point,
> $combinedTag has been given the value of the current tag. $startTags is
> an array that has all the start tags from the SGML file; they are popped
> off as end tags are encountered.
>
> I would have thought that the presence of the "last if" test would have
> prevented any uninitialized values; obviously, I thought wrong.
>
> Any and all clues gratefully accepted.
>
> Fred
------------------------------
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 3505
**************************************