[21965] in Perl-Users-Digest
Perl-Users Digest, Issue: 4187 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 27 06:05:44 2002
Date: Wed, 27 Nov 2002 03:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 27 Nov 2002 Volume: 10 Number: 4187
Today's topics:
Re: =?iso-8859-1?Q?Inspired_by_the_Anders_Hejlsberg's_p (Walter Roberson)
Re: @INC, use, $LD_LIBRARY_PATH, & modules <nospam-abuse@ilyaz.org>
Re: Adding values to a hash? <nobull@mail.com>
clustering <vvikas@cse.buffalo.edu>
Re: Converting UTF-8 to ISO-8859-1 <bart.lateur@pandora.be>
Re: File::Basename::fileparse: Problem extracting file (Ronald Fischer)
Re: File::Basename::fileparse: Problem extracting file (Ronald Fischer)
Re: File::Basename::fileparse: Problem extracting file <tassilo.parseval@post.rwth-aachen.de>
Re: GDGraph module <mgjv@tradingpost.com.au>
Getopt::Std (qanda)
Re: Getopt::Std <tassilo.parseval@post.rwth-aachen.de>
Help writing a script simulating CSS word-break of IE <ahj6@hotmail.com>
Re: Help writing a script simulating CSS word-break of <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Re: Help writing a script simulating CSS word-break of <ahj6@hotmail.com>
help: multi-dimensional hash from flat array <tako@luigios.com>
Re: help: multi-dimensional hash from flat array <bernard.el-hagin@DODGE_THISlido-tech.net>
Re: help: multi-dimensional hash from flat array <tako@luigios.com>
how to call an external script and using the env-defini <michael.kirchner@unibw-muenchen.de>
Re: how to test for empty nonexistent array??? <usenet@dwall.fastmail.fm>
Re: Inspired by the Anders Hejlsberg's presentation... <extendedpartition@NOSPAM.yahoo.com>
Re: invoking script as perl <scriptname> vs. ./scriptna <mgjv@tradingpost.com.au>
Re: IP and Host differences (Marc Rasell)
Looking for Perlmonks module <elf@ee.ryerson.ca>
Re: Looking for Perlmonks module <usenet@dwall.fastmail.fm>
Re: Out Of Memory while parsing CVS rlog output <krahnj@acm.org>
Re: rounding numbers <BROWNHIK@Syntegra.Bt.Co.Uk>
Re: splice() is fast when shrinking and slow when growi (Patrick Ditchen)
Re: SQLite help please <bart.lateur@pandora.be>
TCP client server request <lois@hotmail.com>
Re: TCP client server request <tassilo.parseval@post.rwth-aachen.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 27 Nov 2002 06:06:27 GMT
From: roberson@ibd.nrc.ca (Walter Roberson)
Subject: Re: =?iso-8859-1?Q?Inspired_by_the_Anders_Hejlsberg's_presentation...?=
Message-Id: <as1nd3$s7d$1@canopus.cc.umanitoba.ca>
In article <G4XE9.4582$sn5.246068618@newssvr13.news.prodigy.com>,
dan marinescu <support@danmarinescu.com> wrote:
:Inspired by the Anders Hejlsberg's presentation (when c# launched) and =
:feeling somehow sad about MS Notepad, I decided to write my own =
:programmer notepad, called Total Notepad.
: b.. Editor
: a.. File size: unlimited
Sounds suspicious to me. I've never yet met a real program that
could operate on files of unlimited size: the ones I've seen
have always been limited to no more than the maximum file size
allowed by the underlying operating system.
--
Warhol's Second Law of Usenet: "In the future, everyone will troll
for 15 minutes."
------------------------------
Date: Wed, 27 Nov 2002 08:09:04 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: @INC, use, $LD_LIBRARY_PATH, & modules
Message-Id: <as1uj0$22l$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Abernathey Family
<family2@aracnet.com>], who wrote in article <3DE23123.BAFBFB8A@aracnet.com>:
> > I'm in the same boat at work as the original poster (we probably work at
> > different sites together). We've developed some rather ugly workarounds
> > involving creative use of the "pound-bang" header to run setup scripts.
> > That aside, setting the LD_LIBRARY_PATH in BEGIN{} does not work on
> > some architectures (security issues, I suppose), and it's often
> > necessary to condition it before starting perl.
> My "ugly" solution to the this was to put a shell script wrapper around
> my Perl script. The wrapper sets the variables and then executes my
> script. This "ugly" approach is extended to handle multi-module scripts
> where the script starts up pointing to one set of libraries and in later
> execution needs to point to other libraries - although I think this
> could go away by modifying LD_LIBRARY_PATH correctly so that my new path
> is appended. Do you have a less "ugly" solution to this LD_LIBRARY_PATH
> issue?
What issue? Setting $ENV{LD_LIBRARY_PATH} modifies environ; do you
suggest that on your system the value of LD_LIBRARY_PATH in environ at
the moment of dlopen() does not matter? I may imagine some botched
implementations where only the value at the script startup time matters...
Please be more specific.
BTW, $ENV{LD_LIBRARY_PATH} should not matter at all to load Perl DLLs.
AFAIU, it may only matter if a Perl DLL needs loading some third-party
DLL. Is it your situation?
Ilya
------------------------------
Date: 27 Nov 2002 09:13:40 +0000
From: Brian McCauley <nobull@mail.com>
Subject: Re: Adding values to a hash?
Message-Id: <u9smxn8jej.fsf@wcl-l.bham.ac.uk>
Stuart Flowers <stuart.flowers@t-online.de> writes:
> Bob wrote:
>
> > How do you 'push' name/value pairs to a hash? I have a loop where I
> > have new name/value pairs being generated and would like them to be
> > added to an existing hash:
>
> $hashname{$name} = $value;
That is the correct solution most of the time but it's not the only
tool in the box.
It is also worth knowing about the alternatives if you want to add many
entries
It can be more readable to say:
%hashname = ( %hashname, $name => $value, $name2 => $value2 );
Note that is unrolls and re-rolls the hash so it's not exactly
run-time efficient for adding a small number of addtional entries to
an already large hash. It's really most useful when creating a new
hash that is the same as an existing hash but with some
additions/overrides.
Also know about:
@hashname{@names} = @values;
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 27 Nov 2002 02:59:24 -0500
From: Vikas <vvikas@cse.buffalo.edu>
Subject: clustering
Message-Id: <Pine.SOL.4.30.0211270258220.1628-100000@pollux.cse.buffalo.edu>
Hi,
Can anyone suggest any module which does clustering (kmeans etc) in perl?
Thanks,
Vikas.
------------------------------
Date: Wed, 27 Nov 2002 07:42:00 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Converting UTF-8 to ISO-8859-1
Message-Id: <9ft8uugq1lds40b7d2h8tp6h85ku6oai2c@4ax.com>
Francesco Moi wrote:
>I've got 5.006001 version installed on my server. Do you know
Yes, the very course
$latin = pack "C*", unpack "U*", $utf8;
will work. For Latin to UTF8 conversion, you can do the reverse: swap
the "U" and "C".
Don,'t make your strings to convert too huge at once, because Perl will
build and intermediate list of character codes.
--
Bart.
------------------------------
Date: 27 Nov 2002 01:25:07 -0800
From: ronaldf@eml.cc (Ronald Fischer)
Subject: Re: File::Basename::fileparse: Problem extracting file part
Message-Id: <219750c.0211270125.27e24765@posting.google.com>
"Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de> wrote in message news:<arvv44$m5g$1@nets3.rz.RWTH-Aachen.DE>...
> Also sprach Ronald Fischer:
>
> > I would like to split a filename at the rightmost 'dot' position. i.e.
> >
> > ab/cd/ef.gh.ij
> >
> > should be split into
> >
> > ab/cd ef.gh and ij
> >
> > I have problems writing the correct pattern for the fileparse
> > function: They always split
> > to the first dot:
> >
> > print ((fileparse('ab/cd/ef.gh.ij','[.].+?'))[0],"\n");
> >
> > outputs
> >
> > ef
> >
> > and not, as I had hoped,
> >
> > ef.gh
> You are doing it the wrong way around. From the documentation to
> fileparse:
>
> [...] The remainder of the input file
> specification is then divided into "name" and "suffix"
> based on the optional patterns you specify in
> @suffixlist. Each element of this list is interpreted
> as a regular expression, and is matched against the
> end of "name". If this succeeds, the matching portion
> of name is removed and prepended to suffix.
>
> That means you must come up with a pattern that only matches the
> extension. Since the extension is at the end, your pattern should be
> geared to the end of the string as well:
>
> fileparse('ab/cd/ef.gh.ij', '\.[^.]+$')
Your solution is indeed correct, but for a different reason than you
are suggesting:
First, as you are citing correctly, the pattern list ' is matched
against the end of "name".
Therefore, the final $ which you are suggesting, is redundant.
Therefore, the pattern
I gave, i.e. '[.].+?' is - in the context of the fileparse function -
equivalent to '[.].+?$',
and your solution is equivalent to '\.[^.]+'.
The real reason why my solution did not work, is that I misunderstood
the non-greedy
variant of regular expressions. My idea was that the final $ - either
given implicitly or
explicitly - would anchor the pattern to the right side, and using '?'
would produce
the *shortestmost* substring of arbitrary characters, which still has
a dot to its right.
But pattern matching is always tried from left to right. Thus, [.].+?
tries first to match
the smallest (because it is non-greedy) part of the basename of this
filename, i.e.
yielding '.g', but then the $ does not match, so the pattern matcher
has no alternative
than trying the next longer one, ie. '.gh', and so on, until it ends
up with .gh.ij as the
final solution.
So the real problem with my solution was, that non-greedy pattern
matching does
not help in retrieving the smallest possible suffix of a string
(though it could be applied
to retrieve the smallest possible prefix of a string).
Ronald
------------------------------
Date: 27 Nov 2002 01:46:00 -0800
From: ronaldf@eml.cc (Ronald Fischer)
Subject: Re: File::Basename::fileparse: Problem extracting file part
Message-Id: <219750c.0211270145.ce99d4b@posting.google.com>
"J rgen Exner" <jurgenex@hotmail.com> wrote in message news:<caME9.595$qe.586@nwrddc03.gnilink.net>...
> Maybe I'm totally wrong is isn't a split at the last dot the default
> behaviour of fileparse if no pattern is given?
Unfortunately, you are totally wrong in this respect (though it would
be a handy feature).
Ronald
------------------------------
Date: 27 Nov 2002 10:46:24 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: File::Basename::fileparse: Problem extracting file part
Message-Id: <as27q0$1cr$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Ronald Fischer:
> "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de> wrote in message news:<arvv44$m5g$1@nets3.rz.RWTH-Aachen.DE>...
>> You are doing it the wrong way around. From the documentation to
>> fileparse:
>>
>> [...] The remainder of the input file
>> specification is then divided into "name" and "suffix"
>> based on the optional patterns you specify in
>> @suffixlist. Each element of this list is interpreted
>> as a regular expression, and is matched against the
>> end of "name". If this succeeds, the matching portion
>> of name is removed and prepended to suffix.
>>
>> That means you must come up with a pattern that only matches the
>> extension. Since the extension is at the end, your pattern should be
>> geared to the end of the string as well:
>>
>> fileparse('ab/cd/ef.gh.ij', '\.[^.]+$')
>
> Your solution is indeed correct, but for a different reason than you
> are suggesting:
>
> First, as you are citing correctly, the pattern list ' is matched
> against the end of "name".
> Therefore, the final $ which you are suggesting, is redundant.
> Therefore, the pattern
> I gave, i.e. '[.].+?' is - in the context of the fileparse function -
> equivalent to '[.].+?$',
> and your solution is equivalent to '\.[^.]+'.
You are right. fileparse() appends a "\$" to the end of the pattern as I
just saw in the source. I didn't know that and thought I would myself
have to care about letting it only match the end of the string.
> The real reason why my solution did not work, is that I misunderstood
> the non-greedy
> variant of regular expressions. My idea was that the final $ - either
> given implicitly or
> explicitly - would anchor the pattern to the right side, and using '?'
> would produce
> the *shortestmost* substring of arbitrary characters, which still has
> a dot to its right.
>
> But pattern matching is always tried from left to right. Thus, [.].+?
> tries first to match
> the smallest (because it is non-greedy) part of the basename of this
> filename, i.e.
> yielding '.g', but then the $ does not match, so the pattern matcher
> has no alternative
> than trying the next longer one, ie. '.gh', and so on, until it ends
> up with .gh.ij as the
> final solution.
>
> So the real problem with my solution was, that non-greedy pattern
> matching does
> not help in retrieving the smallest possible suffix of a string
> (though it could be applied
> to retrieve the smallest possible prefix of a string).
When looking closer at your pattern and mine there is one significant
difference:
/[.].+?$/ # which is equiv to
/\..+?$/
compared to
/\.[^.]+/
You omit the important condition that there must not be another dot
behind \. Finding the actual extension of a file can be thusly put into
words: Find the last dot in the string. Everything following that is the
extension.
As for non-greediness, it indeed wont help here. Non-greedy patterns are
needed when you try to extract the shortest substring somewhere within a
string or at its beginning.
That reminds me of something called 'sexeger': you reverse both the
string and the pattern which can be more efficient if you want something
matched at the end of the string (and the string is possibly very long):
$_ = "file.1.ext";
reverse($_) =~ /([^.]+)/;
print scalar reverse($1);
__END__
ext
There is an article by our regex-wizard Jeff Pinyan worth reading:
http://japhy.perlmonk.org/sexeger/sexeger.html
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Wed, 27 Nov 2002 05:15:23 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: GDGraph module
Message-Id: <slrnau8lbq.mmn.mgjv@verbruggen.comdyn.com.au>
On Tue, 26 Nov 2002 23:02:47 -0600,
brian d foy <comdog@panix.com> wrote:
> In article <uu7si2qrf36d16@corp.supernews.com>, Mick Z.
><knjaz@hotmail.com> wrote:
>
>> I am experimenting with the GD Graph module in creating a Bar Chart.
>> The following code produces a 3 column bar chart, but I cannot get the
>> columns to have different colors. They are all being set to the first value
>> in the 'dclrs' array. Any ideas?
>
>> my $data = GD::Graph::Data->new([
>> ["1ST","2ND","3ND"],
>> [100,200,150],
>> ]);
>
> each data set gets one color. i don't think you can use GDGraph
> to do what you're trying to do.
You can, but I don't encourage it :)
Look up the "cycle_clrs" attribute in the GD::Graph documentation.
Martien
--
|
Martien Verbruggen |
Trading Post Australia | Can't say that it is, 'cause it ain't.
|
------------------------------
Date: 27 Nov 2002 02:24:47 -0800
From: fumail@freeuk.com (qanda)
Subject: Getopt::Std
Message-Id: <62b4710f.0211270224.2cdfe4b@posting.google.com>
Hi all
I've just started with perl and am having trouble. I want to use
Getopt::Std calling getopts so I can use something like 'a:b:cde:' for
options; a, b and e are mandatory, c and d are optional and overide a,
b and e. I can do everything I want exept throw a usage screen under
one condition - when extra arguments are specified, I can call a
normal usage and pod2usage function. The actual problem is having
some condition to tell me when there are extra arguemnts. For example
I can handle
prg
prg -c
prg -d
prg -a arg -b arg -e arg
then I can handle all invalid entries except
prg -a arg -b arg -e arg extra_arg
It's the extra_arg on the end I can't trap. That is, I don't know how
to check for extra arguments, extra options are picked up by getopts
but I'm totally confused with the extra argument, I can't use @ARGV
for range checking as we can specify options with operands without
spaces so the equivalent argc count would be invalid.
This is driving me up the wall, any help is greatly appreciated.
Thanks
------------------------------
Date: 27 Nov 2002 10:49:51 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Getopt::Std
Message-Id: <as280f$1hr$1@nets3.rz.RWTH-Aachen.DE>
Also sprach qanda:
> I've just started with perl and am having trouble. I want to use
> Getopt::Std calling getopts so I can use something like 'a:b:cde:' for
> options; a, b and e are mandatory, c and d are optional and overide a,
> b and e. I can do everything I want exept throw a usage screen under
> one condition - when extra arguments are specified, I can call a
> normal usage and pod2usage function. The actual problem is having
> some condition to tell me when there are extra arguemnts. For example
> I can handle
>
> prg
> prg -c
> prg -d
> prg -a arg -b arg -e arg
>
> then I can handle all invalid entries except
>
> prg -a arg -b arg -e arg extra_arg
>
> It's the extra_arg on the end I can't trap. That is, I don't know how
> to check for extra arguments, extra options are picked up by getopts
> but I'm totally confused with the extra argument, I can't use @ARGV
> for range checking as we can specify options with operands without
> spaces so the equivalent argc count would be invalid.
I don't understand the explanation why you can't use @ARGV. After
calling getopts() @ARGV contains all the extra arguments, so wouldn't it
be enough to simple do:
getopts(...);
if (@ARGV) {
die "Trailing arguments";
}
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: Wed, 27 Nov 2002 14:13:00 +0900
From: "Hyungjin Ahn" <ahj6@hotmail.com>
Subject: Help writing a script simulating CSS word-break of IE
Message-Id: <as1ipe$jai$1@news1.kornet.net>
Hi,
I happened to find out that there is CSS word-break property in IE.
For exmple, when i try to display non-space-inserted long word such as URLs
(ex:
http://www.google.co.kr/search?q=cache:Y_X4mEbRNLAC:www.afghan-web.com/+afgh
anistan&hl=ko&ie=UTF-8) ,
the word breaks the boundry of the table tags in html page.
In IE browser, inserting "style='word-break:break-all;'" property in table
tag breaks the above long word automatically case by case to fit in the
width of the table. But since word-break is not included in standard CSS,
Mozilla & Navigator do not automatically break a word so that the display of
the page becomes chaos.
If anyone knows the script somebody already made for this, please reply me.
I appriciate as well any idea.
So I tried to write a simple script which simulate word-break independent of
broswer specific settings. It was simple that it reads a document and
applies s/// to insert spaces when matching series of non-space characters.
In this case, I defined the number of series of characters as 40. It's
because a word consisted of 40 characters is not common.
But with this method I couldn't avoid trouble when I tried to apply it to a
narrow width table. Width independent script was needed. It's what i'm
working now.
I began to use well adapted fonts only such as Times & Arial to avoid
incompatibility problem with anonymous browsers. I applied CSS property
font-size;(n)px to fix the font size which is independent of browser
specific settings. (but the browser to apply this must abide by CSS. Tested
with IE, Mozilla, and Navigator. Showed exactly te same size and
gap-distance between each font.) It was successful.
Now i'm calculating each font's height & width, and I'll be able to display
long word to fit exactly to the table width in any of three browsers. For
the present, I don't think of those environments such as system settings
like large fonts or high contrast for accessibility support.
In addition, this is not about client side script such as php, asp, and
javascript. It's about a mere perl script of which file name ends with *.pl
or *.cgi. I mean *.pl print html tags out to clients' STDOUT. Of course
modifying long word into slices will be done by server side *.pl script.
Please forgive me that I compose too long article to read. I wish you to
regard this is caused since i'm not native english user.
I thank you for any comment and help in advance! -Hyungjin
Ahn(ahj6@hotmail.com)
------------------------------
Date: Wed, 27 Nov 2002 09:44:07 +0100
From: Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Subject: Re: Help writing a script simulating CSS word-break of IE
Message-Id: <newscache$k9886h$xxa$1@news.emea.compuware.com>
Hyungjin Ahn wrote:
> Hi,
>
> I happened to find out that there is CSS word-break property in IE.
[snip]
> In IE browser, inserting "style='word-break:break-all;'" property in table
> tag breaks the above long word automatically case by case to fit in the
> width of the table. But since word-break is not included in standard CSS,
> Mozilla & Navigator do not automatically break a word so that the display
> of the page becomes chaos.
Don't fix browser problems. That is a dead end. Fix the browser instead. The
next browser version behave differently for sure (almost by definition).
Stick to the standards. You are in contradiction to yourself: you want to
support a *specific implementation* of CSS. That is not possible. It is
either CSS or it isn't. I can't be a bit.
--
KP
------------------------------
Date: Wed, 27 Nov 2002 19:00:11 +0900
From: "Hyungjin Ahn" <ahj6@hotmail.com>
Subject: Re: Help writing a script simulating CSS word-break of IE
Message-Id: <as23jt$9qi$1@news1.kornet.net>
"Koos Pol" <koos_pol@NO.nl.JUNK.compuware.MAIL.com> wrote in message
news:newscache$k9886h$xxa$1@news.emea.compuware.com...
> Hyungjin Ahn wrote:
> > I happened to find out that there is CSS word-break property in IE.
> [snip]
> > In IE browser, inserting "style='word-break:break-all;'" property in
table
> > tag breaks the above long word automatically case by case to fit in the
> > width of the table. But since word-break is not included in standard
CSS,
> > Mozilla & Navigator do not automatically break a word so that the
display
> > of the page becomes chaos.
> Don't fix browser problems. That is a dead end. Fix the browser instead.
The
> next browser version behave differently for sure (almost by definition).
> Stick to the standards. You are in contradiction to yourself: you want to
> support a *specific implementation* of CSS. That is not possible. It is
> either CSS or it isn't. I can't be a bit.
Suppose that you visit a Message board which allows visiters to attach
articles to the end of the previous article in one page. Yes,
http://ezboard.com is actually servicing such a message board now. Peoples
are discussing about interesting topic adding tens of articles in one page.
But if someone decides to attach an article which includes non-spacing long
word such as URLs or medical terms, all at once the page including tens of
articles should crack into wide. At the present time, Ezboard support
text-like URL into reduced form of anchor, but no way about non-URL texts.
If you provided word-break script, posters should be free of worring their
ill posting.
I don't agree with you. specific implementation such as word-break of CSS is
implemented now by me in my web site with CJK unicode as well as western
europe characters.
Hyungjin Ahn(ahj6@hotmail.com)
>
> --
> KP
>
------------------------------
Date: Wed, 27 Nov 2002 03:06:01 -0500
From: Chef Tako <tako@luigios.com>
Subject: help: multi-dimensional hash from flat array
Message-Id: <3DE47CE9.2010503@luigios.com>
i need to create an arbitrary multi-dimensional hash
from a flat array. i don't understand why the simple
$h{a}{b}{c}{d}{e}='x' ain't working.
thanks
--tako
====================================================
use strict;
## starting point:
## string contains flattened representation of variable
## could be arbitrarly deep , # of -'s
my $var = "a-b-c-d-e";
my %h =();
my @j=split '-',$var;
## creates the hash syntax from the names in array
my $m="";
foreach (@j) {
$m .="{$_}";
}
## let eval do the assignment
my $r="%h->$m=823";
eval {$r};
warn() if $@;
my $q=%h->{a}{b}{c}{d}{e};
## should come back as 823 but it aint even there
print $q;
------------------------------
Date: Wed, 27 Nov 2002 08:50:28 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: help: multi-dimensional hash from flat array
Message-Id: <as210k$2e1$1@korweta.task.gda.pl>
In article <3DE47CE9.2010503@luigios.com>, Chef Tako wrote:
> i need to create an arbitrary multi-dimensional hash
> from a flat array. i don't understand why the simple
> $h{a}{b}{c}{d}{e}='x' ain't working.
What you're doing below is butt ugly and very evil. If you're doing it
for educational purposes then read on.
> use strict;
>
> ## starting point:
> ## string contains flattened representation of variable
> ## could be arbitrarly deep , # of -'s
> my $var = "a-b-c-d-e";
>
> my %h =();
>
> my @j=split '-',$var;
my @j = split /-/, $var; # if it's a regex make it look like one
> ## creates the hash syntax from the names in array
>
> my $m="";
> foreach (@j) {
> $m .="{$_}";
> }
>
>
> ## let eval do the assignment
> my $r="%h->$m=823";
my $r = '$h' . "$m=823";
> eval {$r};
eval $r;
> warn() if $@;
>
> my $q=%h->{a}{b}{c}{d}{e};
my $q=$h{a}{b}{c}{d}{e};
> ## should come back as 823 but it aint even there
> print $q;
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: Wed, 27 Nov 2002 04:10:38 -0500
From: Chef Tako <tako@luigios.com>
Subject: Re: help: multi-dimensional hash from flat array
Message-Id: <3DE48C0E.2010101@luigios.com>
evil yes; but necessary. i found myself in a hole where
i need to create flat variable names (through a cgi- web page form) and
need to get it uniquely back into my session hash.
i have aribitrary widgets and associated error correction modules
for the widgets. i just ran into the case where i needed multiple blocks
of the same widgets on the same page. the different being each block of
widgets has a uid.
so to keep all my existing orthognal modules, i just added a function
call to each variable read/write with this butt ugly mapping.
What do you percieve and suggest as an elegant solution?
--tako
btw, thanks for the elgance of $r ='$h' . "$m=823";
i had forgotten that sometimes it's easier to split a string into small
pieces that to expand it in one shot.
Bernard El-Hagin wrote:
> In article <3DE47CE9.2010503@luigios.com>, Chef Tako wrote:
>
>>i need to create an arbitrary multi-dimensional hash
>>from a flat array. i don't understand why the simple
>>$h{a}{b}{c}{d}{e}='x' ain't working.
>
>
>
> What you're doing below is butt ugly and very evil. If you're doing it
> for educational purposes then read on.
>
>
>
>>use strict;
>>
>>## starting point:
>>## string contains flattened representation of variable
>>## could be arbitrarly deep , # of -'s
>>my $var = "a-b-c-d-e";
>>
>>my %h =();
>>
>>my @j=split '-',$var;
>
>
>
> my @j = split /-/, $var; # if it's a regex make it look like one
>
>
>
>>## creates the hash syntax from the names in array
>>
>>my $m="";
>>foreach (@j) {
>> $m .="{$_}";
>>}
>>
>>
>>## let eval do the assignment
>>my $r="%h->$m=823";
>
>
>
> my $r = '$h' . "$m=823";
>
>
>
>>eval {$r};
>
>
>
> eval $r;
>
>
>
>>warn() if $@;
>>
>>my $q=%h->{a}{b}{c}{d}{e};
>
>
>
> my $q=$h{a}{b}{c}{d}{e};
>
>
>
>>## should come back as 823 but it aint even there
>>print $q;
>
>
>
>
> Cheers,
> Bernard
> --
> echo 42|perl -pe '$#="Just another Perl hacker,"'
------------------------------
Date: Wed, 27 Nov 2002 09:54:42 +0100
From: Michael Kirchner <michael.kirchner@unibw-muenchen.de>
Subject: how to call an external script and using the env-definitions?
Message-Id: <3DE48852.9000603@unibw-muenchen.de>
Hi,
during the last days I thought about a special problem and I have no
idea how to solve it. Maybe you have...
I use a quite big measurement processing software package, which is in
fact a collection of many single scrips and programs. Before starting
the processing it is necessary to execute a start-script which sets a
lot of environment variables needed for the other programs.
Up to now I used for automatic processing via crontab a shell-script
which calls the start-script with the command ". $HOME/foo_start". Due
to the dot ". " no new (child) shell has been started for execution the
start-script and it was possible to use the new defined
environment-variables afterwards in my own script for automatic
processing. Fine.
Now the problem:
It is necessary to rewrite my script for automatic processing in perl
but it is not possible to rewrite the start-script. How can I call the
start-script form perl without starting a child-shell, so that I can use
the environment-definitions afterwards?
Thanks a lot
Michael
------------------------------
Date: Wed, 27 Nov 2002 07:18:44 GMT
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: how to test for empty nonexistent array???
Message-Id: <Xns92D317861C34Bdkwwashere@63.240.76.16>
tadmc@augustmail.com (Tad McClellan) wrote:
> Bruno Boettcher <bboett@bboett.dyndns.org> wrote:
>>
>> i have the problem of the following error message:
>> Use of uninitialized value in join or string at test.pm line
>> 1969.
>
> That is NOT an error message.
>
> That is a warning message.
You're right, of course.
In my own defense (and that of the OP), I have a tendency to call
warnings "error messages", since they generally mean I've made a
mistake somewhere and should pay closer attention to my code. Still,
since I insist on the difference between Perl and perl, I should be
more precise in my own usage. :-)
--
David Wall - me@dwall.fastmail.fm
"Oook."
------------------------------
Date: Tue, 26 Nov 2002 23:42:56 -0600
From: "Extended Partition" <extendedpartition@NOSPAM.yahoo.com>
Subject: Re: Inspired by the Anders Hejlsberg's presentation...
Message-Id: <3de45c37_1@nntp2.nac.net>
>Perfect complement for free .net framework, java framework, gcc and bcc
(free set of gnu compilers). Hey, hey, hey, like I said, >it's FREE! (under
GNU) - I am NOT trying to sell you anything. This is simply the perfect tool
for real programmers, students, >whoever wants to get the job done fast,
clean and without paying big bucks for super huge tools doing anything but
you want them >to do here and now. :-)
Just downloaded the program. Very nice!
But you probably should avoid commercial posting here.
------------------------------
Date: Wed, 27 Nov 2002 05:18:24 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: invoking script as perl <scriptname> vs. ./scriptname (with sciptname x perms)
Message-Id: <slrnau8lhg.mmn.mgjv@verbruggen.comdyn.com.au>
On 26 Nov 2002 20:59:53 -0800,
Matt Oefinger <oefinger@mit.edu> wrote:
> Why is the behaviour different when I run my script as perl
><scriptname>
> as opposed to doing a chmod +x then running ./scriptname. In the
> former case I
> have no problems with @INC, while in the latter some of my includes
> aren't found in @INC. From what I understand I'd have to recompile
> Perl to get @INC changed, so I'm currently using a workaround of just
> calling my scripts via perl <scriptname>. Why the difference in
> behaviour?
My guess is that the perl in your path is not the same one as the one
you specify on the first line of your script.
I am assuming you're on some unix-like system. Compare the result of
$ which perl
with
$ head -1 scriptname
If they are the same, then you have a problem, but I doubt that very
much. I would guess that they are different.
Martien
--
|
Martien Verbruggen | The four horsemen of the apocalypse are
Trading Post Australia | called Abort, Retry, Ignore and Fail.
|
------------------------------
Date: 27 Nov 2002 01:44:54 -0800
From: mrasell@hotmail.com (Marc Rasell)
Subject: Re: IP and Host differences
Message-Id: <df4cdf85.0211270144.5b9fd9c8@posting.google.com>
sorry for the confusion, it is a perl script, perhaps not strictly
speaking a perl question, but if someone can point me to a better
forum please let me know. I am getting the values using the
environment variables, but was not sure of the significance of them.
i.e. can an IP have a different Host and if so what does it mean.
thanks for all the replies.
------------------------------
Date: 27 Nov 2002 00:13:43 -0500
From: Luis Fernandes <elf@ee.ryerson.ca>
Subject: Looking for Perlmonks module
Message-Id: <x0r8d7iohk.fsf@ee.ryerson.ca>
I was wondering if some one has written a Perlmonks module.
For example:
#!/usr/local/bin/perl
use Perlmonks::Guru;
# 1000 lines of your code...
When you run this program, the Perlmonks module figures out what your
1000 lines of code does and replaces them with 3 lines of guru code
(2 lines including the modules you didn't know existed (but wish you
did, before you wrote your 1000 lines of code) and 1 line of actual
code).
------------------------------
Date: Wed, 27 Nov 2002 07:28:08 GMT
From: "David K. Wall" <usenet@dwall.fastmail.fm>
Subject: Re: Looking for Perlmonks module
Message-Id: <Xns92D3191DC4E99dkwwashere@63.240.76.16>
Luis Fernandes <elf@ee.ryerson.ca> wrote:
> I was wondering if some one has written a Perlmonks module.
>
> For example:
>
> #!/usr/local/bin/perl
> use Perlmonks::Guru;
>
> # 1000 lines of your code...
>
> When you run this program, the Perlmonks module figures out what
> your 1000 lines of code does and replaces them with 3 lines of
> guru code (2 lines including the modules you didn't know existed
> (but wish you did, before you wrote your 1000 lines of code) and 1
> line of actual code).
use Perlmonks::Guru::Randal;
or even
use Perlmonks::Guru::Damian;
Be careful with the second of these. It occasionally has the
tendency to turn your Perl into Latin. Or Morse code. Just when it
does this is subject to some indeterminancy.
--
David Wall - me@dwall.fastmail.fm
"Oook."
------------------------------
Date: Wed, 27 Nov 2002 06:06:39 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Out Of Memory while parsing CVS rlog output
Message-Id: <3DE460D0.FD89A888@acm.org>
Jacob wrote:
>
> I'm new to perl but I've been working on a script that will parse a
> large amount of text and while it's going through it, it will store
> data in a few different hashes I have (a one dimensional hash, and
> two-two dimensional hashes). Once I read in all the data, I then
> sort the hashes and output all of this to a set of log files.
>
> Here's the main chunk of my code that start the text coming in...
> # Build up the command string appropriately, depending on what
> # options have been set.
> my $command =
> ($rlog_module ne "") ? "cvs -n -d $cvsdir rlog $rlog_module" : "cvs
> log";
> print "Executing \"$command\"\n" if $debug;
>
> open (CVSLOG, "$command |") || die "Couldn't execute
> \"$command\"";
> while (<CVSLOG>)
You don't close CVSLOG anywhere but you should, and test the return
value.
perldoc -q "return an error when a pipe open fails"
[snip]
> elsif (/^keyword substitution: b$/)
> {
> # This is a binary file, ignore it.
> undef($file_branch_number{$working_file});
> undef($file_number_branch_revisions{$working_file});
You should use delete instead of undef. (This is probably your memory
problem.)
perldoc -q 'the difference between "delete" and "undef" with hashes'
> $search_file = 1;
> print "Excluding binary file \"$working_file\"\n" if $debug;
> }
> elsif (/^=============================================================================$/)
Ick!
elsif ( /^={77}$/ )
> {
> # End of the log entry for this file, start parsing for the
> # next file.
> $search_file = 1;
> next;
> }
> elsif (/^----------------------------$/)
Ick redux!
elsif (/^-{28}$/)
[snip]
> print "Executing $lccmd\n" if $debug;
> $number_lines = `$lccmd 2>/dev/null | wc -l`;
> chop $number_lines;
> $number_lines =~ s/ //g;
($number_lines) = `$lccmd 2>/dev/null | wc -l` =~
/(\d+)/;
John
--
use Perl;
program
fulfillment
------------------------------
Date: Wed, 27 Nov 2002 10:35:15 -0000
From: "Kevin Brownhill" <BROWNHIK@Syntegra.Bt.Co.Uk>
Subject: Re: rounding numbers
Message-Id: <as27h5$5cd$1@pheidippides.axion.bt.co.uk>
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnau7cc7.47d.tadmc@magna.augustmail.com...
> Kevin Brownhill <BROWNHIK@Syntegra.Bt.Co.Uk> wrote:
> > "Andras Malatinszky" <nobody@dev.null> wrote in message
> > news:3DE389F8.5070805@dev.null...
> >> RC wrote:
> >>
> >> > does anyone know how to round numbers with lots of decimal places to
a
> >> > certain amount. eg 2 decimal places or 0 decimal places
> >>
> >>
> >>
> >> Use the printf() function. I'd explain how, but it is so much more
> >> eloquently done in the perlfaq4 manpage.
Is that sarcasm or just plain unhelpfulness?
>
>
> > Surely printf() just prints the number in a certain format.
> ^^^^^^
>
>
> You are surely wrong.
>
> If you want to know what a function does, you read the docs
> for that function.
>
> perldoc -f printf
>
> says:
>
> Equivalent to "print FILEHANDLE sprintf(FORMAT, LIST)"
What is that if not printing a value in a user specified format?
>
> so you see what sprintf() does:
>
> perldoc -f sprintf
>
> it clearly says the sprintf can round floating point numbers.
it clearly says that it returns a string which is a series of characters - a
rounded number is a number which is a binary representaion of a decimal
number.
>
>
> > To round the number to 2 places, use the following:
> > $rounded = int($number * 100 + 0.5) / 100;
>
>
> Do not use that to round to 2 places.
>
> It only works for "some" numbers.
It works accurately for all non-negative numbers. It wouldn't be too hard to
modify it to work for negative numbers. I'd point you at perldoc -f if, but
there isn't one.
>
> sprintf() works for all numbers.
>
But it is sometimes wrong, eg.
sprintf("%.2f", 4.005)
returns "4.00"
when the correct answer is "4.01"
>
> Please do not try to reanswer a FAQ, you are likely to get it
> wrong, as you did here.
>
> That increases confusion rather than decreasing it.
>
I am not re-answering any FAQ, I am answering the original question which
was "does anyone know how to round numbers with lots of decimal places to a
certain amount. eg 2 decimal places or 0 decimal places"
The question others seem to be answering is "how do you print a string
representation of a number rounded to n places". This may be what is really
wanted, but is not the question asked.
Has anyone read the phrase - "there's more than one way to do it"?
------------------------------
Date: 27 Nov 2002 01:40:38 -0800
From: ditchen@web.de (Patrick Ditchen)
Subject: Re: splice() is fast when shrinking and slow when growing an array. Why?
Message-Id: <8943921e.0211270140.3719444d@posting.google.com>
Thanks for your help.
I know, that Perl doesn't have to move the real values stored in the
array, when splicing. It only concerns the Array of pointers. An array
is a list of pointers to seperate skalar values. I wonder, how Perl
manages to reorganize this pointer-array after a splice(). You can see
the difference between a shrinking and a growing splice, when you do
just one single splice on a very big array. Growing (even if just one
field) consumes a lot of time, shrinking not.
#!/usr/bin/perl
print "Start: ", (localtime)[0], "\n" ;
$#arr = 20_000_000 ;
print "After building: ", (localtime)[0], "\n" ;
@arr[2,2000,20_000,900_000] = (1,2,3,4) ;
print "After initial.: ", (localtime)[0], "\n" ;
splice @arr,10_000_000, 2, (5,6,7);
print "After one splice:", (localtime)[0], "\n" ;
print "After one splice:", (localtime)[0], "\n" ;
-------------
Result:
bash-2.03# test_splice.pl
Start: 7
After building: 8
After initial.: 8
After one splice:15
Replacing
splice @arr,10_000_000, 2, (5,6,7);
with
splice @arr,10_000_000, 5, (5,6,7);
Result:
bash-2.03# test_splice.pl
Start: 39
After building: 40
After initial.: 40
After one splice:40
In the second case, the splice is done immediately!
Whyyyy ?
greatings
Patrick
ctcgag@hotmail.com wrote in message news:<20021126215051.661$wa@newsreader.com>...
> ditchen@web.de (Patrick Ditchen) wrote:
> > What exactly does splice() do with an array?
>
> A lot.
>
> > I thougt, an array is a
> > list of pointers to skalar-values. After a splice()-command, Perl
> > should have to rebuild the whole list, no matter if shrinking or
> > growing.
>
> It shouldn't have to rebuild it, just slide the values in it around.
> Unless you have expanded the list beyond it's current capabilities,
> then it has to allocate new space for a bigger list, and copy all the
> pointers into this new space. Of course, it never has to do this when
> shrinking an array.
>
>
>
> > But when I test its behaviour, splice() with shrinking size
> > is done at once while splice() with growing size takes a lot of time.
> > Why doesn't Perl have to copy the array in the first case?
>
> It must depend greatly on the test. I don't get those results for my
> test:
>
> count wall tm cpu time line
> 0 0.000000 0.000000 1:use strict;
> 1 0.123445 0.120000 2:my @x=map $_ % 10, 1..100_000;
> 0 0.000000 0.000000 3:
> 1 0.000021 0.000000 4:my $y;
> 0 0.000000 0.000000 5:
> 100001 0.203196 1.220000 6:foreach (0..$#x) {
> 100000 9.558496 10.90000 7: $y=splice @x,$_,1;
> 100000 9.078559 10.11000 8: splice @x,$_,0,$y;
> 100000 0.580952 1.530000 9: print $y;
> 0 0.000000 0.000000 10:};
>
> Xho
------------------------------
Date: Wed, 27 Nov 2002 08:04:04 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: SQLite help please
Message-Id: <3fu8uucqh89gq3p71d7d5ndqbd4r5df42v@4ax.com>
Bob X wrote:
>$rows = $dbh->do("INSERT family (last_name, first_name)"
> . " VALUES('Mix', 'Tom')");
>Error Msg: DBD::SQLite::db do failed: near "family": syntax error at
>dbtest.pl line 17.
You need an "INTO" between the "INSERT" and the table name.
>Shouldn't the above do the following:
>
>#1 Connect to the test_db or create one and then connect
It works. The above is the database complaining about your SQL syntax.
>#2 Insert a table called "family" with "Tom Mix" as the first data
No, because you have a syntax error.
Eh, what? Insert a table? No: to insert a table, you need a "CREATE
TABLE" SQL statement. The "INSERT" SQL statement serves to insert data
into an existing table.
You can see a simple sample SQL program here:
<http://www.sqlite.org/sqlite.html>
near the top. A reference for the syntax SQLite understands can be found
here:
<http://www.sqlite.org/lang.html>
--
Bart.
------------------------------
Date: Wed, 27 Nov 2002 06:35:54 GMT
From: "Lois" <lois@hotmail.com>
Subject: TCP client server request
Message-Id: <eJZE9.144268$NH2.10422@sccrnsc01>
Hi all,
On the client side, I will receive some getopts values that need to
be send over to server side to retrieve the corresponding record in the
database and then send the resultsets back. eg
at the client
$ client1 -u lpf23604
at the server
retrieve the record with username lpf23604
and send back the data
and my question : is it a good idea to send a "reference" of %opts over to
the server or the %opts itself or the whole string over? Basically I fork a
new child to do the retrieving. Basically, I want to know, which is more
efficient or "more appropriate" way.
Thank you,
lois
------------------------------
Date: 27 Nov 2002 08:24:37 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: TCP client server request
Message-Id: <as1vg5$li8$1@nets3.rz.RWTH-Aachen.DE>
Also sprach Lois:
> On the client side, I will receive some getopts values that need to
> be send over to server side to retrieve the corresponding record in the
> database and then send the resultsets back. eg
>
> at the client
> $ client1 -u lpf23604
>
> at the server
> retrieve the record with username lpf23604
> and send back the data
>
> and my question : is it a good idea to send a "reference" of %opts over to
> the server or the %opts itself or the whole string over? Basically I fork a
> new child to do the retrieving. Basically, I want to know, which is more
> efficient or "more appropriate" way.
You can't send a native Perl data-structure through the network and
expect the other side to magically understand it. You could of course
write:
print $server %opts;
but then the server would receive
key1val1key2val2...
and would have no means to split it into keys and corresponding values.
What you want is serialization of data. There are several ways of doing
that. You could use Storable for that:
# Client
use Storable qw(nfreeze);
...
print $server nfreeze(\%opt);
# Server
use Storable qw(thaw);
# receive data from client
my %opt = %{ thaw($client_data) };
Tassilo
--
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 4187
***************************************