[19708] in Perl-Users-Digest
Perl-Users Digest, Issue: 1903 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 10 09:05:34 2001
Date: Wed, 10 Oct 2001 06:05:12 -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: <1002719111-v10-i1903@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 10 Oct 2001 Volume: 10 Number: 1903
Today's topics:
[Newbie] length of a multidim.-array (nurdogan erdem)
Re: [Newbie] length of a multidim.-array <eric@urbanrage.com>
Can I do these with the debugger? <rtrahan@monmouth.com>
Re: Checking Network Access <MrsKensingtonUK@yahoo.co.uk>
Re: Checking Network Access nobull@mail.com
Re: Checking Network Access (John J. Trammell)
Re: Date calculation <hafner@augusta.de>
Re: dynamic printer format (PDF?) with perl (mbower)
Re: errors when i use 2 modules (Clinton A. Pierce)
exceute an external shell command? <divetolife@yahoo.com>
Re: exceute an external shell command? (Anno Siegel)
Re: exceute an external shell command? <divetolife@yahoo.com>
Re: exceute an external shell command? (Anno Siegel)
Re: Grouped column sum <justin.devanandan.allegakoen@intel.com>
Re: How to go up stack trace? <bill02115@hotmail.com>
Re: integer division <bart.lateur@skynet.be>
Re: integer division <s.warhurst@rl.ac.uk>
Re: Need help - pragmatic modules not available nobull@mail.com
Re: Need help - pragmatic modules not available <kevin@vaildc.net>
perlsec + taint (perl misk)
Re: perlsec + taint <Thomas@Baetzler.de>
Re: please check my script (Kimo R.)
Re: please check my script (Anno Siegel)
Re: please check my script (Damian James)
Re: pointers and perl nobull@mail.com
Pushing new values on to a hash <justin.devanandan.allegakoen@intel.com>
Re: Pushing new values on to a hash (Anno Siegel)
Quicker way to loop through directories? <s.warhurst@rl.ac.uk>
Re: Sort unique Very large file (Rafael Garcia-Suarez)
split into filename and extension (need help before I g <johan@basberg.comNOSPAM>
Re: split into filename and extension (need help before <qvyht@removejippii.fi>
Re: split into filename and extension (need help before (Anno Siegel)
Re: split into filename and extension (need help before <wyzelli@yahoo.com>
Re: split into filename and extension (need help before <Thomas@Baetzler.de>
Re: split into filename and extension (need help before (Anno Siegel)
Re: symbolic references to built-in functions <nospam-abuse@ilyaz.org>
Thanks ! Re: Simple Pattern Matching Problem <gvandyke@voyager.net>
wildcard in argument of script <qvyht@removejippii.fi>
Re: wildcard in argument of script (Damian James)
Re: YOU ARE ALL GAY! <geoffrey@bigpond.net.au>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 10 Oct 2001 05:50:20 -0700
From: nurdogan.erdem@astrium-space.com (nurdogan erdem)
Subject: [Newbie] length of a multidim.-array
Message-Id: <9df4686c.0110100450.7a0ddc33@posting.google.com>
hi,
i have a array with includes 2 arrays. Like this:
@menus=(['Link1',
'http://www.Verweis1.de'],
['Link2',
'http://www.Verweis2.de',
'Link3',
'http://www.Verweis3.de'],
);
How can i find out i.e, the length of the first array?
$length=@menus[0]; does not work :-(
Best Regards,
nurdogan
------------------------------
Date: Wed, 10 Oct 2001 08:04:23 -0500
From: eric <eric@urbanrage.com>
Subject: Re: [Newbie] length of a multidim.-array
Message-Id: <3BC44757.10DC384C@urbanrage.com>
nurdogan erdem wrote:
>
> hi,
>
> i have a array with includes 2 arrays. Like this:
>
> @menus=(['Link1',
> 'http://www.Verweis1.de'],
>
> ['Link2',
> 'http://www.Verweis2.de',
> 'Link3',
> 'http://www.Verweis3.de'],
> );
>
> How can i find out i.e, the length of the first array?
>
> $length=@menus[0]; does not work :-(
>
> Best Regards,
> nurdogan
$length = @{$menus[0]};
Eric
------------------------------
Date: Wed, 10 Oct 2001 06:03:01 -0700
From: Richard Trahan <rtrahan@monmouth.com>
Subject: Can I do these with the debugger?
Message-Id: <3BC44705.75F3BC5C@monmouth.com>
I would like to do some things with the Perl debugger, but they
aren't documented. They include:
(1) b FILENAME LINE
(2) moving the program counter (the next line to be executed)
(3) setting up an init file that will execute debugger commands
(like setting breakpoints) at startup.
Does anybody know how to do any of these?
------------------------------
Date: Wed, 10 Oct 2001 08:25:09 +0100
From: "MrsKensingtonUK" <MrsKensingtonUK@yahoo.co.uk>
Subject: Re: Checking Network Access
Message-Id: <1002698701.22344.0.nnrp-08.3e31b93c@news.demon.co.uk>
Surely if i new the reason I wouldn't be asking what I was doing wrong, I
would be asking something along the lines of "what can I do to stop this?",
but I didn't.
Anyway thank you for your "helpful" reply, I didn't mean to escape the e...
but fixing that has not stopped it returning 0
Mrs K
<nobull@mail.com> wrote in message news:u9vgholoav.fsf@wcl-l.bham.ac.uk...
> "MrsKensingtonUK" <MrsKensingtonUK@yahoo.co.uk> writes:
>
> > if (copy($file, "c:\emptyFile"))
> >
> > for some reason it always returns 0!
>
> What $! reason?
>
> > What am I doing wrong?
>
> Not telling us the reason.
>
> BTW: Are you sure you want an escape ( chr(27) aka "\e" ) in the file
name.
>
> --
> \\ ( )
> . _\\__[oo
> .__/ \\ /\@
> . l___\\
> # ll l\\
> ###LL LL\\
------------------------------
Date: 10 Oct 2001 08:54:08 +0100
From: nobull@mail.com
Subject: Re: Checking Network Access
Message-Id: <u9k7y3lugy.fsf@wcl-l.bham.ac.uk>
"MrsKensingtonUK" <MrsKensingtonUK@yahoo.co.uk> writes rudely in
untrimmed jeopardy style[1] and without enough of a Usenet sense of
humor:
> <nobull@mail.com> wrote in message news:u9vgholoav.fsf@wcl-l.bham.ac.uk...
> > "MrsKensingtonUK" <MrsKensingtonUK@yahoo.co.uk> writes:
> >
> > > if (copy($file, "c:\emptyFile"))
> > >
> > > for some reason it always returns 0!
> >
> > What $! reason?
>
> Surely if i new the reason I wouldn't be asking what I was doing
> wrong,
I think you missed my point. When I say "What $! reason?" I meant
"What is the proximate reason for failure that can be found in the $!
variable?". More detail may also be found in the $^E variable.
[1] Persistant jeopardy-quoting will get you killfiled by many of the
most knowledgible people here. That does not include me[2]
because I'm not a plonker[3] (yet).
[2] I hope I do count as knowledgible but that's not really for me to
judge.
[3] At least not in the sense of one who "*plonk!*"s :-).
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 10 Oct 2001 07:27:06 -0500
From: trammell@haqq.hypersloth.invalid (John J. Trammell)
Subject: Re: Checking Network Access
Message-Id: <slrn9s8fkp.vvr.trammell@haqq.hypersloth.net>
On Wed, 10 Oct 2001 08:25:09 +0100, MrsKensingtonUK wrote:
[top-quoting fixed -- answers come *after* questions!]
><nobull@mail.com> wrote in message news:u9vgholoav.fsf@wcl-l.bham.ac.uk...
>> "MrsKensingtonUK" <MrsKensingtonUK@yahoo.co.uk> writes:
>>
>>> if (copy($file, "c:\emptyFile"))
>>>
>>> for some reason it always returns 0!
>>
>> What $! reason?
>>
>>> What am I doing wrong?
>>
>> Not telling us the reason.
>>
>> BTW: Are you sure you want an escape ( chr(27) aka "\e" ) in the
>> file name.
>
> Surely if i new the reason I wouldn't be asking what I was doing
> wrong, I would be asking something along the lines of "what can
> I do to stop this?", but I didn't.
>
> Anyway thank you for your "helpful" reply, I didn't mean to escape
> the e... but fixing that has not stopped it returning 0
>
So, what is this "copy()" function? Is it something you got from a
standard Perl module, or something you wrote yourself? Does it have
any documentation? The world waits with bated breath.
If it's from the File::Copy module, I see this gem:
Like copy, rmscopy returns 1 on success. If an error
occurs, it sets $!, deletes the output file, and returns 0.
So what does $! say?
--
IAAMOAC.
------------------------------
Date: 10 Oct 2001 14:09:26 +0200
From: Walter Hafner <hafner@augusta.de>
Subject: Re: Date calculation
Message-Id: <qdfbsjfd7d5.fsf@www.ibexnet.de>
anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) writes:
> Time::Local does that. It's a base module.
Just curious: Is the implementation the same as in POSIX 'mktime'?
-Walter [going to do some benchmarks]
------------------------------
Date: Wed, 10 Oct 2001 10:44:09 GMT
From: mbower@ibuk.bankgesellschaft.de (mbower)
Subject: Re: dynamic printer format (PDF?) with perl
Message-Id: <3bc42638.958438140@news>
>Any body knows of any module, program, library,... that generates PDF or any
>other *good* printer format from a template document??
http://www.pdflib.com/
There's a perl module you can use.
------------------------------
Date: Wed, 10 Oct 2001 12:06:20 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: errors when i use 2 modules
Message-Id: <0RWw7.159925$K6.76259301@news2>
[Posted and mailed]
In article <9dr7st8vkmdg3phnmcu0420lv2fvg9s75r@4ax.com>,
Philip Newton <pne-news-20011010@newton.digitalspace.net> writes:
> Or you could narrow down your import from CGI if you're using
> LWP::Simple's head subroutine. Or, if you want to use *both*
> LWP::Simple::head and CGI's head, you could switch to the OO interface
> of CGI.pm.
Or you can ask nicely not to get head from LWP::Simple and call it
explicitly:
use CGI qw(:standard);
use LWP::Simple ();
head(); # This is CGI's head()
LWP::Simple::head(); # This is L:S's head
--
Clinton A. Pierce Teach Yourself Perl in 24 Hours *and*
clintp@geeksalad.org Perl Developer's Dictionary
"If you rush a Miracle Man, for details, see http://geeksalad.org
you get rotten Miracles." --Miracle Max, The Princess Bride
------------------------------
Date: Wed, 10 Oct 2001 16:33:34 +0800
From: Liu Wen <divetolife@yahoo.com>
Subject: exceute an external shell command?
Message-Id: <MPG.162e88b74a83f422989680@news.cuhk.edu.hk>
I want to execute several external shell command in a program, such as
"nslookup" "route"... Sorry, I cannot get it in manual. Thank you.
------------------------------
Date: 10 Oct 2001 08:38:02 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: exceute an external shell command?
Message-Id: <9q11da$5ti$1@mamenchi.zrz.TU-Berlin.DE>
According to Liu Wen <divetolife@yahoo.com>:
> I want to execute several external shell command in a program, such as
> "nslookup" "route"... Sorry, I cannot get it in manual. Thank you.
Oh, but you can. The magic word is "perldoc -q system". Take it from
there.
Anno
------------------------------
Date: Wed, 10 Oct 2001 17:00:41 +0800
From: Liu Wen <divetolife@yahoo.com>
Subject: Re: exceute an external shell command?
Message-Id: <MPG.162e8f111abf8d5c989681@news.cuhk.edu.hk>
In article <9q11da$5ti$1@mamenchi.zrz.TU-Berlin.DE>, anno4000@lublin.zrz.tu-berlin.de
says...
> According to Liu Wen <divetolife@yahoo.com>:
> > I want to execute several external shell command in a program, such as
> > "nslookup" "route"... Sorry, I cannot get it in manual. Thank you.
>
> Oh, but you can. The magic word is "perldoc -q system". Take it from
> there.
>
> Anno
>
sorry,I remember "exec" immediately ,then perldoc -f exec,then got
"system" as well, but I cannot see how to get the output.Its return
value is exit code. Will I have to
$command="nslookup";
$arg1=$url1;
$result=$ip;
@ARGS=($command,$arg1,">",$result);
system(@ARGS);;
??
------------------------------
Date: 10 Oct 2001 09:14:39 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: exceute an external shell command?
Message-Id: <9q13hv$5ti$4@mamenchi.zrz.TU-Berlin.DE>
According to Liu Wen <divetolife@yahoo.com>:
> In article <9q11da$5ti$1@mamenchi.zrz.TU-Berlin.DE>,
> anno4000@lublin.zrz.tu-berlin.de
> says...
> > According to Liu Wen <divetolife@yahoo.com>:
> > > I want to execute several external shell command in a program, such as
> > > "nslookup" "route"... Sorry, I cannot get it in manual. Thank you.
> >
> > Oh, but you can. The magic word is "perldoc -q system". Take it from
> > there.
> >
> > Anno
> >
> sorry,I remember "exec" immediately ,then perldoc -f exec,then got
> "system" as well, but I cannot see how to get the output.Its return
> value is exit code. Will I have to
> $command="nslookup";
> $arg1=$url1;
> $result=$ip;
> @ARGS=($command,$arg1,">",$result);
> system(@ARGS);;
perldoc -f system covers that. Quoting:
This is not what you
want to use to capture the output from a command,
for that you should use merely backticks or
"qx//", as described in the section on "`STRING`"
in the perlop manpage.
Take it from there.
Anno
------------------------------
Date: Wed, 10 Oct 2001 13:31:28 +0800
From: "Just in" <justin.devanandan.allegakoen@intel.com>
Subject: Re: Grouped column sum
Message-Id: <9q0mfk$rmu@news.or.intel.com>
You need to read up on hashes . . .
Anyway:-
while(Some loop you've created)
{
# stuff to split each row/line into variables
# Heres what you're after
$Sigma{$Group} += $Val;
}
# Now we're out of the loop lets print it
while((my $Header, my $Value) = each(%Sigma))
{
# prints it out in the order of which it was assigned
print "$Header = $Value\n";
}
"Dustin Gregory" <dgregory@mmcable.com> wrote in message
news:ptQw7.99784$ME2.15234736@typhoon.kc.rr.com...
> I've seen some posts that had examples that almost had the solution to my
> problem, but being the newbie I am, I couldn't figure out how to do this.
> Here's an example of what data I have and what I'm trying to do with it.
>
> What I have:
>
> group1 15
> group2 2
> group5 4
> group2 18
> group4 20
> group3 9
> group3 6
> group1 2
>
>
> What I'm trying to get: (group = sum)
>
> group1 = 17
> group2 = 20
> group3 = 15
> group4 = 20
> group5 = 4
>
> I've looked around with no luck on a solution. Any help would be
> appreciated.
>
> Thanks in adv,
> -dg
>
>
------------------------------
Date: 10 Oct 2001 08:46:48 -0400
From: bill <bill02115@hotmail.com>
Subject: Re: How to go up stack trace?
Message-Id: <9q1fvo$3mt$1@panix3.panix.com>
In <3BC37322.C292C635@indra.com> Ron Reidy <ron@indra.com> writes:
>bill wrote:
>>
>> In the perl debugger, how can I go up the stack trace? I need to
>> examine the value of certain variables high up in the stack trace.
>See 'perldoc perldebug'
That was the first thing I did, and found nothing (I read around all
occurrences of the word "stack"). I guess this means that,
unbelievable as it may be, one just can't go up the stack with the
perl debugger. But hope springs eternal.
------------------------------
Date: Wed, 10 Oct 2001 08:04:04 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: integer division
Message-Id: <8308sto3kmgfjjvjtrug6vttq9kl7rfr4g@4ax.com>
Philip Newton wrote:
>> Or use sprintf.
>
>That would result in 12, rather than 11.
No it doesn't. Not if you use "%d".
print sprintf '%d', 11.999;
-->
11
print sprintf '%.0f', 11.9999;
-->
12
--
Bart.
------------------------------
Date: Wed, 10 Oct 2001 09:33:26 +0100
From: "S Warhurst" <s.warhurst@rl.ac.uk>
Subject: Re: integer division
Message-Id: <9q114n$uk2@newton.cc.rl.ac.uk>
"Zimmen Gnauh" <yah00204052@yahoo.com> wrote in message
news:3BC108E1.736EB0CB@yahoo.com...
> $a1=1150
> $a2=100
> $quotient=$a1/$a2
> the result is 11.50. What change has to be made to obtain 11?
POSIX (http://www.perldoc.com/perl5.6.1/lib/POSIX.html) gives you access to
floor() & ceil() commands among other things.
So:
use POSIX;
$quotient=floor($a1/$a2);
should do the trick.
Spencer
------------------------------
Date: 10 Oct 2001 12:30:51 +0100
From: nobull@mail.com
Subject: Re: Need help - pragmatic modules not available
Message-Id: <u9eloblok4.fsf@wcl-l.bham.ac.uk>
rojo@mindspring.com (RoJo) writes:
> I've tried the use PSI::ESP; you suggested, but it errors out.
LOL! (Literally - nearly choked on my apple).
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 10 Oct 2001 08:29:34 -0400
From: Kevin Michael Vail <kevin@vaildc.net>
Subject: Re: Need help - pragmatic modules not available
Message-Id: <101020010829343628%kevin@vaildc.net>
In article <u9eloblok4.fsf@wcl-l.bham.ac.uk>, <nobull@mail.com> wrote:
> rojo@mindspring.com (RoJo) writes:
>
> > I've tried the use PSI::ESP; you suggested, but it errors out.
>
> LOL! (Literally - nearly choked on my apple).
I didn't know you were a Mac user! :-) :-)
--
Kevin Michael Vail | a billion stars go spinning through the night,
kevin@vaildc.net | blazing high above your head.
. . . . . . . . . | But _in_ you is the presence that
. . . . . . . . . | will be, when all the stars are dead. (Rainer Maria Rilke)
------------------------------
Date: 10 Oct 2001 01:33:13 -0700
From: perlmisk@yahoo.co.uk (perl misk)
Subject: perlsec + taint
Message-Id: <7fe42fcd.0110100033.e6b3130@posting.google.com>
sub get_hostname {
$ENV{'PATH'} = '/bin:/usr/bin'; # taint checking :)
delete @ENV{'IFS', 'CDPATH', 'ENV', 'BASH_ENV'};
if ($ENV{HOSTNAME}) { # first attempt
return;
}
else {
if (`uname -a` =~m/^\w+\s+(\w+)\s/g) { # second attempt
return $1;
}
else { # failed :(
return 'UNKNOWN';
}
}
}
my $hostname = get_host_name();
Is $hostname once again "tainted" as all the changes to ENV happen
within {}'s so they have expired.
Is it "bad practice" to use system or ``'s?
------------------------------
Date: Wed, 10 Oct 2001 12:15:26 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: perlsec + taint
Message-Id: <3r78st8oltpjtnclibm3hldd4up05s68tq@4ax.com>
On 10 Oct 2001 01:33:13 -0700, perlmisk@yahoo.co.uk (perl misk) wrote:
>sub get_hostname {
[...]
You could also try Sys::Hostname.
HTH,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: 10 Oct 2001 01:42:13 -0700
From: kimor79@hotmail.com (Kimo R.)
Subject: Re: please check my script
Message-Id: <e5a5752b.0110100042.7927ae64@posting.google.com>
$match++ if /^$user\b/o while <USER>;
Is giving me syntax error near "/^$user\b/o while". What does the o
do? Does there have to be () or {} around something in this line? I
thought if statements went like:
if (condition) {
result;
}
Kimo R.
------------------------------
Date: 10 Oct 2001 08:55:41 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: please check my script
Message-Id: <9q12ed$5ti$2@mamenchi.zrz.TU-Berlin.DE>
According to Kimo R. <kimor79@hotmail.com>:
> $match++ if /^$user\b/o while <USER>;
>
> Is giving me syntax error near "/^$user\b/o while". What does the o
> do? Does there have to be () or {} around something in this line? I
> thought if statements went like:
>
> if (condition) {
> result;
> }
If the only thing in the if-block ("result") is a simple statement,
the above can equivalently be written
result if condition;
Similar variants exist of "unless", "while" "until" and "foreach".
(See "statement modifiers" in, uh, perlsyn, I guess.)
The above example doesn't work because statement modifiers don't
nest: If the inner statement is already modified, it is no longer
simple. Someone didn't test their code...
Anno
------------------------------
Date: 10 Oct 2001 13:00:25 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: please check my script
Message-Id: <slrn9s8hdk.she.damian@puma.qimr.edu.au>
On 10 Oct 2001 08:55:41 GMT, Anno Siegel said:
>According to Kimo R. <kimor79@hotmail.com>:
>> $match++ if /^$user\b/o while <USER>;
>>
>> Is giving me syntax error near "/^$user\b/o while".
>...
>The above example doesn't work because statement modifiers don't
>nest: If the inner statement is already modified, it is no longer
>simple. Someone didn't test their code...
>
Gack! Indeed, and I already spotted another obvious mistake. My bad,
but then I was providing interspersed snippets rather than real code.
Not prepending 'something like' often enough, bleh.
To the OP:
[untested]
while (<USER>) { $match++ if /^$user\b/o };
is the correct rewrite.
Have a look at perlre for info about the /o modifier.
[OP] I guess you already spotted the other obvious mistake :-).
Cheers,
Damian
--
@:=grep!(m!$/|#!..$|),split//,<DATA>;@;=0..$#:;while($:=@;){$;=rand
$:--,@;[$;,$:]=@;[$:,$;]while$:;push@|,shift@;if$;[0]==@|;select$,,
$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker,### http://home.pacific.net.au/~djames.hub
------------------------------
Date: 10 Oct 2001 12:28:23 +0100
From: nobull@mail.com
Subject: Re: pointers and perl
Message-Id: <u9het7loo8.fsf@wcl-l.bham.ac.uk>
balsellathurai@hotmail.com (bal) writes:
> I am new to perl so please forgive me if this a is a silly question!
"Silly" we can forgive, "covered in the FAQ" is somewhat harder to
forgive.
> ...linked lists are feasible in perl?
FAQ: "How do I handle linked lists?"
> Because of the presence of -> does this mean pointers,
The thing on the LHS of a -> is usually[1] a reference. A reference
is like a pointer except that the thing pointed to keeps track of how
many references point to it so you don't need to worry[2] about when
to destroy it.
[1] As others point out, not in the case you happen to cite.
[2] Unless you have cyclic linked structures in which case you need to
weaken[3] some references or take other measures to make sure
stuff is destroyed at the relevant time.
[3] See the Scalar::Util module.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 10 Oct 2001 12:36:18 +0800
From: "Just in" <justin.devanandan.allegakoen@intel.com>
Subject: Pushing new values on to a hash
Message-Id: <9q0j85$ph6@news.or.intel.com>
All,
I'm looking for an elegant and smart way to do the following:-
Say if I had two hashes with the same keys, with values that refer to
two different entities.
These keys may exist in one or the other hash, but not necessarily both.
That said, I would like to have a final hash of Key, Val1, Val2. (Called
Array of Arrays under perldsc). Where Val1 has a value of NULL
if Val2's key exists where Val1's key doesn't.
TIA
------------------------------
Date: 10 Oct 2001 09:09:04 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Pushing new values on to a hash
Message-Id: <9q137g$5ti$3@mamenchi.zrz.TU-Berlin.DE>
According to Just in <justin.devanandan.allegakoen@intel.com>:
> All,
>
> I'm looking for an elegant and smart way to do the following:-
>
> Say if I had two hashes with the same keys, with values that refer to
> two different entities.
>
> These keys may exist in one or the other hash, but not necessarily both.
The last two sentences cannot both be true. Either the hashes have the
same keys or they haven't.
> That said, I would like to have a final hash of Key, Val1, Val2. (Called
> Array of Arrays under perldsc).
No, what you are building is a hash of arrays.
> Where Val1 has a value of NULL
> if Val2's key exists where Val1's key doesn't.
What is "NULL"? You probably mean "undef".
This ought to work whether the keys in both arrays are the same or not:
my %combi;
@combi{ keys %hash1, keys %hash2} = (); # insert all keys into %combi
$combi{ $_} = [ $hash1{ $_}, $hash2{ $_}] for keys %combi;
If the keys are the same in both hashes, the code can be simplified a bit.
Anno
------------------------------
Date: Wed, 10 Oct 2001 13:33:07 +0100
From: "S Warhurst" <s.warhurst@rl.ac.uk>
Subject: Quicker way to loop through directories?
Message-Id: <9q1f65$ht6@newton.cc.rl.ac.uk>
I currently have a routine that searches through each of several thousand
subdirectories and totals up the size of a specific type of file. It goes
like this:
if(opendir(DIR, "f:/list-logs"))
{
while($dir = readdir(DIR))
{
if(-d "f:/list-logs/$dir" and $dir ne "." and $dir ne "..")
{
if(opendir(SUB, "$listlogs/$dir"))
{
while($file = readdir(SUB))
{
if($file =~ /\.log.+/i)
{
$total += -s "$listlogs/$dir/$file";
}
}
closedir(SUB);
}
}
}
closedir(DIR);
}
Under f:/list-logs there are about 3800 subdirectories and inside each I
only want to total the size of files with the file extension ".logxxxx",
hence the "/\.log.+/" match.
Now, this routine takes ~15 minutes on my test machine. Can anyone think of
an imginative way of speeding it up?
Thanks
Spencer
------------------------------
Date: 10 Oct 2001 10:06:32 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Sort unique Very large file
Message-Id: <slrn9s87d1.71l.rgarciasuarez@rafael.kazibao.net>
jzh wrote in comp.lang.perl.misc:
} I have a very large file over 3million records "<FH> in example below" with
} nonunique records.
} I am looking to sort without putting the contents of the file into an array
} or hash.
}
} I would like to do a very low level operation line by line not to put any
} strain on memory limits.
}
} My code is this:
}
} # Get unique key
} #
} sub get_key_sub {
} open (FH, "$file") or die "Err File open $file";
} open (FHKEY, ">$filekey") or die "Err File open $filekey";
} for (<FH>) {
This will load the entire file in memory.
You should use "while (<FH>)" instead.
} if ($_=~/^S/) {$unique{$_}=$_ }
As you're not using the value in this hash, you can save some memory by
doing "$unique{$_} = 1".
} }
} for (sort keys %unique) {
} chomp ($_);
} print FHKEY "$_\n";
It's probably useless to chomp if you add a \n for printing.
print for sort keys %unique;
} }
} close (FH);
} close (FHKEY);
} }
}
} This exert reads in <FH> and prints out the unique values in <FHKEY>
If your file is very large, you'll have to avoid to load it entirely in
%unique.
You can sort it by chunks. I don't know what the file looks like, but
you can try a simple algorithm like this :
sort each line beginning with 'SA', put the result in 'filekey.A'
sort each line beginning with 'SB', put the result in 'filekey.B'
etc...
Finally, concat filekey.A, filekey.B .... and you get the whole file
sorted.
--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
Could Marconi have invented the radio if he hadn't by pure chance
spent years working at the problem? -- Monty Python, Penguins
------------------------------
Date: Wed, 10 Oct 2001 12:09:15 +0200
From: "JHWB" <johan@basberg.comNOSPAM>
Subject: split into filename and extension (need help before I go insane)
Message-Id: <9q16q3$4or$1@maud.ifi.uio.no>
Ok, I have spent hours trying to figure out this simple task:
how to split a filename into the name and the extension when the filename
is:
1. any length
2. ends in either .jpg eller .gif
3. can include any character in the name
As I have to insert a date between the name and the extension I (think I)
will be using two variables $name and $ext.
Please, this is a ridiculous question, but still I have found no answers
anywhere. (Might have to do with not getting any sleep the past 48 hours).
JHWB
------------------------------
Date: Wed, 10 Oct 2001 10:13:26 GMT
From: Hessu <qvyht@removejippii.fi>
Subject: Re: split into filename and extension (need help before I go insane)
Message-Id: <3BC41DFF.7CCD4026@removejippii.fi>
JHWB wrote:
>
> Ok, I have spent hours trying to figure out this simple task:
>
> how to split a filename into the name and the extension when the filename
> is:
> 1. any length
> 2. ends in either .jpg eller .gif
> 3. can include any character in the name
>
> As I have to insert a date between the name and the extension I (think I)
> will be using two variables $name and $ext.
>
> Please, this is a ridiculous question, but still I have found no answers
> anywhere. (Might have to do with not getting any sleep the past 48 hours).
>
> JHWB
Can't you split it with dot "($name,$ext)=split(/./,$filename);" ?!
------------------------------
Date: 10 Oct 2001 10:23:42 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: split into filename and extension (need help before I go insane)
Message-Id: <9q17je$ff5$1@mamenchi.zrz.TU-Berlin.DE>
According to JHWB <johan@basberg.comNOSPAM>:
> Ok, I have spent hours trying to figure out this simple task:
>
> how to split a filename into the name and the extension when the filename
> is:
> 1. any length
> 2. ends in either .jpg eller .gif
> 3. can include any character in the name
>
> As I have to insert a date between the name and the extension I (think I)
> will be using two variables $name and $ext.
>
> Please, this is a ridiculous question, but still I have found no answers
> anywhere. (Might have to do with not getting any sleep the past 48 hours).
my ( $name, $ext) = m{(.*)\.([^./]+)};
This will leave $name and $ext undefined when the filename in $_ doesn't
have an extension. It also assumes Unix filename conventions. For more
portability and a general in-depth treatment of file names, see
perldoc File::Basename
Anno
------------------------------
Date: Wed, 10 Oct 2001 20:24:27 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: split into filename and extension (need help before I go insane)
Message-Id: <GoVw7.2$Ua.174@wa.nnrp.telstra.net>
"Hessu" <qvyht@removejippii.fi> wrote in message
news:3BC41DFF.7CCD4026@removejippii.fi...
> JHWB wrote:
> >
> > Ok, I have spent hours trying to figure out this simple task:
> >
> > how to split a filename into the name and the extension when the
filename
> > is:
> > 1. any length
> > 2. ends in either .jpg eller .gif
> > 3. can include any character in the name
> >
> > As I have to insert a date between the name and the extension I (think
I)
> > will be using two variables $name and $ext.
> >
> > Please, this is a ridiculous question, but still I have found no answers
> > anywhere. (Might have to do with not getting any sleep the past 48
hours).
> >
> > JHWB
>
> Can't you split it with dot "($name,$ext)=split(/./,$filename);" ?!
Umm no? Firstly the dot is special in a regex, and needs to be escaped, and
secondly, most systems support the use of more than one dot in the name, so
you need to split it on the last dot, not just a dot.
($name, $ext) = $filename =~ m/(.*)\.(.*)/;
will do the trick.
However, use of the File::Basename module is often recommended.
Wyzelli
--
#Modified from the original by Jim Menard
for(reverse(1..100)){$s=($_==1)? '':'s';print"$_ bottle$s of beer on the
wall,\n";
print"$_ bottle$s of beer,\nTake one down, pass it around,\n";
$_--;$s=($_==1)?'':'s';print"$_ bottle$s of beer on the
wall\n\n";}print'*burp*';
------------------------------
Date: Wed, 10 Oct 2001 12:47:39 +0200
From: =?ISO-8859-1?Q?Thomas_B=E4tzler?= <Thomas@Baetzler.de>
Subject: Re: split into filename and extension (need help before I go insane)
Message-Id: <l798st8422pkb475i6v4640ulgfpfn866u@4ax.com>
On Wed, 10 Oct 2001 10:13:26 GMT, Hessu <qvyht@removejippii.fi> wrote:
>> how to split a filename into the name and the extension when the filename
>> is:
>> 1. any length
>> 2. ends in either .jpg eller .gif
>> 3. can include any character in the name
>Can't you split it with dot "($name,$ext)=split(/./,$filename);" ?!
Counterexample: my.ingenious.example.gif
I'd try
if( my($name, $ext) = ( $filename =~ m/(.*)\.(.*)/ ) ){
# code goes here
} else {
# match failed - complain!
}
Since .* is greedy, the first parenthesis will capture everything up to
the last dot in the string, and leave the extension in the second
parenthesis.
If the OP wanted to make sure he only gets *.gif and *.jpg, he could
then flesh that second capture out to something like (gif|jpg), while
probably adding a /i to make that match case-independant.
HTH,
--
use strict;my($i,$t,@r)=(0,'5 -.@BHJPT4acd6e2hk2lmn2o4r2s3tuz',map{ord}
split//,unpack('u*','L#`T&)QD5#0`#!!`#%1D)#08`#P05!!(3``$$"``#"0L&``('.
'"`P<!`````0$`'));$t=~s/(\d)(.)/$2x$1/eg;map{$t.=substr$t,$i,1,''while
$_--;$i++}@r;print"$t\n";# Thomas@Baetzler.de - http://baetzler.de/perl
------------------------------
Date: 10 Oct 2001 12:14:16 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: split into filename and extension (need help before I go insane)
Message-Id: <9q1e2o$rh7$1@mamenchi.zrz.TU-Berlin.DE>
According to Hessu <qvyht@removejippii.fi>:
>
>
> JHWB wrote:
> >
> > Ok, I have spent hours trying to figure out this simple task:
> >
> > how to split a filename into the name and the extension when the filename
> > is:
> > 1. any length
> > 2. ends in either .jpg eller .gif
> > 3. can include any character in the name
> >
> > As I have to insert a date between the name and the extension I (think I)
> > will be using two variables $name and $ext.
> >
> > Please, this is a ridiculous question, but still I have found no answers
> > anywhere. (Might have to do with not getting any sleep the past 48 hours).
> >
> > JHWB
>
> Can't you split it with dot "($name,$ext)=split(/./,$filename);" ?!
You forgot to escape the ".", this will split $filename into single
characters. But even correctly splitting on /\./ would fail if the
name has more than one dot in it, as "../some.tar".
Split looks tempting in this context, as does rindex, but both don't
seem to lead to simple solutions. Anyway, all this and more is dealt
with in File::Basename.
Anno
------------------------------
Date: Wed, 10 Oct 2001 12:44:49 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: symbolic references to built-in functions
Message-Id: <9q1fs1$162n$1@agate.berkeley.edu>
[A complimentary Cc of this posting was sent to
Mark Jason Dominus
<mjd@plover.com>], who wrote in article <3bc32259.2d80$38@news.op.net>:
> >Correct. But this is a bug. Taking a reference as in \&CORE::cos
> >should be equivalent to
> >
> > sub CORE::CORE::cos (;$) { cos (@_ ? shift: $_) }
> > \&CORE::CORE::cos
>
> This cannot be done reliably in all cases, since there is no
> equivalent for \&CORE::print, \&CORE::tied, etc.
So what??? If there is no equivalent, then the reference would not be
useful anyway.
If you cannot do something, you throw an exception.
Ilya
------------------------------
Date: Wed, 10 Oct 2001 05:27:54 -0500
From: "George Vandyke" <gvandyke@voyager.net>
Subject: Thanks ! Re: Simple Pattern Matching Problem
Message-Id: <3bc423f1$0$18896$272ea4a1@news.execpc.com>
Thanks! For the patient answers to a simple question.
George
--
George Vandyke
gvandyke@voyager.net
------------------------------
Date: Wed, 10 Oct 2001 08:54:26 GMT
From: Hessu <qvyht@removejippii.fi>
Subject: wildcard in argument of script
Message-Id: <3BC40B78.3FF7478@removejippii.fi>
I have script which is doing fine but
now I'm finishing it and I'd like it
handle files by wildcards.
these works fine:
- perl myscript file.ext
- perl myscript a.txt b.txt c.txt d.dat
- perl myscript -f=files.lst (filelist u know)
but I 'd like make these work too:
- perl myscript *.*
- perl myscript *.txt *.dat
is ther build-in way to do this perl,
similar to glob? Way to do this without
generating wildcards to filelist and going to
-f -option mentioned above?
------------------------------
Date: 10 Oct 2001 12:43:37 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: wildcard in argument of script
Message-Id: <slrn9s8ge2.she.damian@puma.qimr.edu.au>
On Wed, 10 Oct 2001 08:54:26 GMT, Hessu said:
>I have script which is doing fine but
>now I'm finishing it and I'd like it
>handle files by wildcards.
>...
> - perl myscript *.*
> - perl myscript *.txt *.dat
>...
The expansion would be done by your shell (even if that is DOS).
Have you tried it?
The output of:
perl -le 'print for @ARGV' *
looks very much like an approximation of `ls` (or `dir`) to me.
Cheers,
Damian
--
@:=grep!(m!$/|#!..$|),split//,<DATA>;@;=0..$#:;while($:=@;){$;=rand
$:--,@;[$;,$:]=@;[$:,$;]while$:;push@|,shift@;if$;[0]==@|;select$,,
$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker,### http://home.pacific.net.au/~djames.hub
------------------------------
Date: Wed, 10 Oct 2001 09:48:05 GMT
From: Geoffrey Pointer <geoffrey@bigpond.net.au>
Subject: Re: YOU ARE ALL GAY!
Message-Id: <B7EA57F6.81F0%geoffrey@bigpond.net.au>
It's funny about that isn't it? Go figure.
--
Cheers - Geoff %^>
------------------------------
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 1903
***************************************