[19621] in Perl-Users-Digest
Perl-Users Digest, Issue: 1816 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Sep 25 18:10:43 2001
Date: Tue, 25 Sep 2001 15:10:16 -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: <1001455815-v10-i1816@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 25 Sep 2001 Volume: 10 Number: 1816
Today's topics:
Single line if Statement <nomail@please.com>
Re: Single line if Statement (David Wall)
Re: Single line if Statement <Laocoon@eudoramail.com>
Re: Single line if Statement (David Wall)
Re: Single line if Statement <uri@sysarch.com>
Re: Single line if Statement <Laocoon@eudoramail.com>
Re: Single line if Statement (David Wall)
Re: sub key index sorting <goldbb2@earthlink.net>
Re: Transforming HTML nobull@mail.com
Re: What good is the hyphen for named parameters? <goldbb2@earthlink.net>
Re: What good is the hyphen for named parameters? <uri@sysarch.com>
Re: What's wrong with this code ? (David Wall)
Re: What's wrong with this code ? <uri@sysarch.com>
Re: What's wrong with this code ? (David Wall)
Re: who said this? (Malcolm Dew-Jones)
Re: who said this? <acolvin@bbn.com>
Why use Sys::Hostname instead of just $ENV{SERVER_NAME} (Justin)
Re: Why use Sys::Hostname instead of just $ENV{SERVER_N <tony_curtis32@yahoo.com>
Win32::Perms slowness (svenasse)
Re: Windows2000: CPAN.pm woes <randy@theoryx5.uwinnipeg.ca>
Re: Windows2000: CPAN.pm woes <weiss@kung.foo.at>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 25 Sep 2001 14:50:57 -0400
From: "Victor Menendez" <nomail@please.com>
Subject: Single line if Statement
Message-Id: <6l4s7.30947$Dz6.658809@e3500-atl2.usenetserver.com>
I would like to print an item based on an expression that is true.
print OUT if expression returns TRUE other wise skip goto next line."
Content "\n";
Is there a way to do this using just a single line command?
Thanks
------------------------------
Date: Tue, 25 Sep 2001 19:10:45 -0000
From: darkon@one.net (David Wall)
Subject: Re: Single line if Statement
Message-Id: <Xns91279A4A6773Cdarkononenet@207.126.101.97>
"Victor Menendez" <nomail@please.com> wrote on 25 Sep 2001:
> I would like to print an item based on an expression that is true.
> print OUT if expression returns TRUE other wise skip goto next line."
> Content "\n";
> Is there a way to do this using just a single line command?
You could do something like
while ( <> ) {
print and next if EXPRESSION;
}
where EXPRESSION is what you're testing.
--
David Wall
darkon@one.net
------------------------------
Date: Tue, 25 Sep 2001 21:30:58 +0200
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: Single line if Statement
Message-Id: <Xns9127DC3AD23E7Laocooneudoramailcom@62.153.159.134>
Sure.. you can use modifiers..
example:
print OUT "\n" if $a eq $b;
------------------------------
Date: Tue, 25 Sep 2001 20:11:11 -0000
From: darkon@one.net (David Wall)
Subject: Re: Single line if Statement
Message-Id: <Xns9127A489985FCdarkononenet@207.126.101.97>
darkon@one.net (David Wall) wrote on 25 Sep 2001:
> "Victor Menendez" <nomail@please.com> wrote on 25 Sep 2001:
>
>> I would like to print an item based on an expression that is true.
>> print OUT if expression returns TRUE other wise skip goto next line."
>> Content "\n";
>> Is there a way to do this using just a single line command?
>
> You could do something like
>
> while ( <> ) {
> print and next if EXPRESSION;
> }
>
> where EXPRESSION is what you're testing.
Oops, I should have read the original post more carefully.
while ( <> ) {
EXPRESSION ? print : next;
# other stuff happens here when EXPRESSION is true
}
prints the input line if EXPRESSION is true, otherwise it goes to the next
line. And "Laocoon" has already showed you another example of statement
modifiers that may be exactly what you want.
"Laocoon"? Are you telling us to beware of emails bearing attachments?
Remind me not to be around when the worms come for you... :-)
--
David Wall
darkon@one.net
------------------------------
Date: Tue, 25 Sep 2001 20:52:09 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Single line if Statement
Message-Id: <x7elovat7w.fsf@home.sysarch.com>
>>>>> "DW" == David Wall <darkon@one.net> writes:
DW> darkon@one.net (David Wall) wrote on 25 Sep 2001:
>> "Victor Menendez" <nomail@please.com> wrote on 25 Sep 2001:
>>
>>> I would like to print an item based on an expression that is true.
>>> print OUT if expression returns TRUE other wise skip goto next line."
>>> Content "\n";
>>> Is there a way to do this using just a single line command?
>>
>> You could do something like
>>
>> while ( <> ) {
>> print and next if EXPRESSION;
>> }
>>
>> where EXPRESSION is what you're testing.
DW> Oops, I should have read the original post more carefully.
DW> while ( <> ) {
DW> EXPRESSION ? print : next;
GACK!
that is such an odd use of the condtional expression. in general it
should be only used to return a value and not have side effects, let
alone both i/o AND control flow effects.
DW> # other stuff happens here when EXPRESSION is true
DW> }
much clearer to just do:
while( <> ) {
next unless expression ;
print OUT ;
}
why the OP wants a single line for that is not clear. there is no
advantage to it.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs -------------------------- http://jobs.perl.org
------------------------------
Date: Tue, 25 Sep 2001 22:53:37 +0200
From: Laocoon <Laocoon@eudoramail.com>
Subject: Re: Single line if Statement
Message-Id: <Xns9127EA3E2FA0ALaocooneudoramailcom@62.153.159.134>
:-)
------------------------------
Date: Tue, 25 Sep 2001 21:16:30 -0000
From: darkon@one.net (David Wall)
Subject: Re: Single line if Statement
Message-Id: <Xns9127AF9C8BAFFdarkononenet@207.126.101.97>
Uri Guttman <uri@sysarch.com> wrote on 25 Sep 2001:
> why the OP wants a single line for that is not clear. there is no
> advantage to it.
Hehe. I agree, I was just giving him what he asked for. :-)
--
David Wall
darkon@one.net
------------------------------
Date: Tue, 25 Sep 2001 15:04:25 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: sub key index sorting
Message-Id: <3BB0D539.D2052750@earthlink.net>
Scott Wessels wrote:
>
> I was wondering if I might improve upon a sort routine for the
> following data structure:
>
> my $logData = {
> 1 => {
> _create => '20010919',
> _modify => '20010919',
> },
> 2 => {
> _create => '20010920',
> _modify => '20010921'
> },
> ...
> };
>
> Where the primary sort key will be $logData->{$a}->{_create} and the
> secondary will be $logData->{$a}. This needs to be a numeric sort and
> the data returned to be an index of $logData's keys;
>
> I've append to the end of this post, my current attempts at this sort,
> and presently the sprintf routine beats the others out by over
> two-fold though I have concerns that it may not be the most efficient
> of routines.
Your sprintf routine is what's known as either a GRT or a "packed
default sort". As Dave Tweed said, using the default comparison
function os sort is generally the fastest.
However, the data format you convert to via sprintf is not the smallest,
and thus not the fastest it could be... [smaller strings generally
compare faster than longer strings]. Using pack/unpack rather than
sprintf/substr can result in something better.
Try this:
my @idx = map unpack("x4N", $_),
sort
map pack("NN", $_->{_create}, $_),
keys %$logData;
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: 25 Sep 2001 18:58:39 +0100
From: nobull@mail.com
Subject: Re: Transforming HTML
Message-Id: <u97kunw3sg.fsf@wcl-l.bham.ac.uk>
"Raj" <oneconcept@yahoo.co.uk> writes:
>
> Basically, I would like to turn:
>
> <INPUT TYPE="text" NAME="xFname">
>
> into:
>
> <INPUT TYPE=text" NAME="xFname" VALUE="Raj">
>
> I'm sure its quite simple
That would be your error. As we point out in this newsgroup several
times a week trasforming HTML is not simple. That's why we have
modules to do it.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Tue, 25 Sep 2001 15:19:50 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: What good is the hyphen for named parameters?
Message-Id: <3BB0D8D6.BB6A1401@earthlink.net>
Bart Lateur wrote:
>
> I don't see the point for using hyphens for "named parameters" for
> subroutines. Although it doesn't prevent bareword quoting on the left
> side of a "=>", it doesn't appear to add anything else. So what are
> they good for?
Well, in CGI.pm, it helps differentiate parameters for a tag from the
contents of a tag. I think.
--
"I think not," said Descartes, and promptly disappeared.
------------------------------
Date: Tue, 25 Sep 2001 20:46:37 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: What good is the hyphen for named parameters?
Message-Id: <x7hetrath4.fsf@home.sysarch.com>
>>>>> "BG" == Benjamin Goldberg <goldbb2@earthlink.net> writes:
BG> Bart Lateur wrote:
>>
>> I don't see the point for using hyphens for "named parameters" for
>> subroutines. Although it doesn't prevent bareword quoting on the left
>> side of a "=>", it doesn't appear to add anything else. So what are
>> they good for?
BG> Well, in CGI.pm, it helps differentiate parameters for a tag from the
BG> contents of a tag. I think.
it is not needed for that. cgi.pm uses key/value pairs for much of its
api and the key could be any string. you tell the difference between the
key and value just by positions in the arg list. lincoln stein just
decided to use -foo for visual reasons and his taste. there is no
syntactic advantage to using it. later on, since cgi.pm and perl/tk and
other modules use - prefixes, the tokenizer was modified to allow them
in barewords and not need hard quoting. i don't think -foo is a good
idea and don't use it in any key/value api's i design.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs -------------------------- http://jobs.perl.org
------------------------------
Date: Tue, 25 Sep 2001 19:43:40 -0000
From: darkon@one.net (David Wall)
Subject: Re: What's wrong with this code ?
Message-Id: <Xns91279FDF792D7darkononenet@207.126.101.97>
kenlaird@yahoo.com (Laird) wrote on 25 Sep 2001:
> I've got this file
>
> ---
> # name-1
> service numberone COMMENTS
> # name-2
> service numbertwo COMMENTS
> # name-3
> service numberthree
> # name-4 name-5 COMMENTS
> service numberfour
> service numberfive
> # name-6 name-7 COMMENTS
> #service numbersix
> #service numberseven
> # name-other COMMENTS
> service numberother
>
> ---
>
>
> I'm trying to put numberone after name-1
> numbertwo after name-2
> numberthree after name-3
> numberfour after name-4
> numberfive after name-5
> numberother after name-other
>
>
> The lines with name-6,name-7 and service numbersix and numberseven
> should be skipped because the service is commented.
The following code is fragile, that is, it makes a LOT of assumptions about
your data, but it does produce the desired output for your supplied test
data:
use strict;
use warnings;
while ( <DATA> ) { # change to your filehandle
my @names = $_ =~ m/(name-\S+)/g ;
for my $name (@names) {
$_ = <DATA>; # change to your filehandle
next if /^#\s*service/;
$_ =~ /^service\s+(\S+)/;
print "name = $name\nservice = $1\n";
}
}
It might get you started, anyway, and give other people here something else
to critique.
--
David Wall
darkon@one.net
------------------------------
Date: Tue, 25 Sep 2001 20:56:01 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: What's wrong with this code ?
Message-Id: <x7bsjzat1g.fsf@home.sysarch.com>
>>>>> "DW" == David Wall <darkon@one.net> writes:
DW> while ( <DATA> ) { # change to your filehandle
DW> my @names = $_ =~ m/(name-\S+)/g ;
no test if the regex worked. you don't know what will be put into
@names.
also no need for the $_ as that is the default for m///.
DW> for my $name (@names) {
DW> $_ = <DATA>; # change to your filehandle
DW> next if /^#\s*service/;
DW> $_ =~ /^service\s+(\S+)/;
again, no checking if the regex worked and useless use of $_
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs -------------------------- http://jobs.perl.org
------------------------------
Date: Tue, 25 Sep 2001 21:45:10 -0000
From: darkon@one.net (David Wall)
Subject: Re: What's wrong with this code ?
Message-Id: <Xns9127B4788DEDdarkononenet@207.126.101.97>
Uri Guttman <uri@sysarch.com> wrote on 25 Sep 2001:
>>>>>> "DW" == David Wall <darkon@one.net> writes:
>
> DW> while ( <DATA> ) { # change to your filehandle
> DW> my @names = $_ =~ m/(name-\S+)/g ;
>
> no test if the regex worked. you don't know what will be put into
> @names.
>
> also no need for the $_ as that is the default for m///.
I suppose I should have polished it a bit. How's this?
use strict;
use warnings;
while ( <DATA> ) {
if ( my @names = m/(name-\S+)/g ) {
for my $name (@names) {
$_ = <DATA>;
if ( /^service\s+(\S+)/ ) {
print "name = $name\nservice = $1\n";
}
else {
next;
}
}
}
}
It still makes lots of assumptions, though.
--
David Wall
darkon@one.net
------------------------------
Date: 25 Sep 2001 11:55:23 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: who said this?
Message-Id: <3bb0d31b@news.victoria.tc.ca>
Dave Stafford (Dave.Stafford@globis.net) wrote:
: > I remember a saying like:
: >
: > In the windoze world, I am limited by the tools that I can use, In
: > Unix, I am limited by my own wisdom.
: >
: > I want to know who said it (I know he is very famous), and I want to
: > know the original quote. Thanks
: Bill Gates I think.
Gill Bates more likely.
------------------------------
Date: Tue, 25 Sep 2001 21:40:17 GMT
From: Alex Colvin <acolvin@bbn.com>
Subject: Re: who said this?
Message-Id: <3BB0F897.FBBA517D@bbn.com>
> : > I remember a saying like:
> : >
> : > In the windoze world, I am limited by the tools that I can use, In
> : > Unix, I am limited by my own wisdom.
> : >
> : > I want to know who said it (I know he is very famous), and I want to
> : > know the original quote. Thanks
>
> : Bill Gates I think.
>
> Gill Bates more likely.
no, it's the *other* Bill Gates, publisher of "Midnight Engineering"
http://www.EntEng.com/midnight.htm
or maybe it's William Gaines, publisher of Mad Magazine
------------------------------
Date: 25 Sep 2001 11:06:46 -0700
From: amiwebguy@yahoo.com (Justin)
Subject: Why use Sys::Hostname instead of just $ENV{SERVER_NAME} with inet_ntoa(scalar gethostbyname($ENV{SERVER_NAME} || 'localhost'))
Message-Id: <19caa707.0109251006.61f51a16@posting.google.com>
I'm concearned about speed in my script where I'm trying to find the
IP of the web server. Can anyone please expand on why i should/not use
Sys::Hostname instead of just $ENV{SERVER_NAME} with inet_ntoa(scalar
gethostbyname($ENV{SERVER_NAME} || 'localhost')) to get the IP?
Thanks,
Justin
------------------------------
Date: Tue, 25 Sep 2001 13:10:28 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Why use Sys::Hostname instead of just $ENV{SERVER_NAME} with inet_ntoa(scalar gethostbyname($ENV{SERVER_NAME} || 'localhost'))
Message-Id: <87y9n3m99n.fsf@limey.hpcc.uh.edu>
>> On 25 Sep 2001 11:06:46 -0700,
>> amiwebguy@yahoo.com (Justin) said:
> I'm concearned about speed in my script where I'm trying
> to find the IP of the web server. Can anyone please
> expand on why i should/not use Sys::Hostname instead of
> just $ENV{SERVER_NAME} with inet_ntoa(scalar
> gethostbyname($ENV{SERVER_NAME} || 'localhost')) to get
> the IP?
virtual hosts.
And I think you mean you want to find the name(s)
associated with the address, rather than the Internet
(Protocol) address itself (which you already have).
A DNS (or whatever) lookup isn't (shouldn't unless badly
misconfigured) take long at all. The time difference
would not be discernible to a person at the client end.
(only tangentially on-topic for clpmisc)
--
Yes way! Mmmmkay?
------------------------------
Date: 25 Sep 2001 13:21:51 -0700
From: Seamus.Venasse@gov.yk.ca (svenasse)
Subject: Win32::Perms slowness
Message-Id: <ff688d2b.0109251221.2bd7d3cb@posting.google.com>
Hi!
I am writing a simple script which will backup and restore file
permissions on an NTFS drive. I've tried to use Win32::FileSecurity,
while referencing Dave Roth's Win32 Perl Programming, but found that
it fails a lot on Win32::LookupAccountName to be considered reliable.
I then found Win32::Perms on Dave Roth's website. At first, I just
stored the security descriptor which was retireved from
Win32::Perms::GetSD. This worked extremely fast, but then I realised
that if a server was rebuilt, the SIDs would not match to any known
groups or users. So, I stored the results from Win32::Perms::Dump.
When I restore my permissions however, it takes forever! I have
included the following script which saves the permissions from one
directory (c:\test1) in a hash and then restores it to another
directory copy (c:\test2). Using File::Find is not a problem for
speed as it worked great when storing and applying just security
descriptors.
Any feedback would be greatly appreciated!
Thanks,
Seamus
use File::Find;
use Win32::Perms;
my %filePermissions = ();
find( { wanted => \&backupPermissions, no_chdir => 1 }, 'c:/test1' );
find( { wanted => \&restorePermissions, no_chdir => 1 }, 'c:/test2' );
sub backupPermissions {
my ( $path, $perms, @permArray );
# strip top directory name for storage
$path = $File::Find::name;
$path .= '/' if ( -d $path );
$path =~ s/${File::Find::topdir}//g;
print "BACKUP: ", $File::Find::name, "\n";
$perms = new Win32::Perms( $File::Find::name );
$perms->Dump( \@permArray );
$filePermissions{ $path } = \@permArray;
}
sub restorePermissions {
my ( $path, $perms, @permArray );
# strip top directory name for retrieval
$path = $File::Find::name;
$path .= '/' if ( -d $path );
$path =~ s/${File::Find::topdir}//g;
if ( defined( $filePermissions{ $path } ) ) {
print "RESTORE: ", $File::Find::name, "\n";
@permArray = @{$filePermissions{ $path }};
$perms = new Win32::Perms( $File::Find::name );
$perms->Remove( -1 );
$perms->Add( @permArray );
$perms->Set();
}
}
------------------------------
Date: 25 Sep 2001 18:12:13 GMT
From: Randy Kobes <randy@theoryx5.uwinnipeg.ca>
Subject: Re: Windows2000: CPAN.pm woes
Message-Id: <9oqhdt$6u2$1@canopus.cc.umanitoba.ca>
In comp.lang.perl.misc, Alicia <alicia090677@hotmail.com> wrote:
[ ... ]
> Thanks. That did the trick. But now I have another problem. When I
> tried to install Bundle::CPAN, CPAN.pm eventually typed:
> If you live behind a firewall or your favourite WAIT server is down,
> the test fot this module may block for minutes.
>
> Should I run the tests anyway? [n] y
> Running make test
> t\basic............ok 2/5
> Could not connect to the WAIT server at
> ls6.informatik.uni-dortmund.de port 1404
> (whew! That was a lot of typing! The blasted cmd.exe window doesn't
> seem to have cut and paste!)
Hi,
Try
whatever_command > some_file.txt
to save the output of "whatever_command" to "some_file.txt".
> I'm at a loss. Never heard of ls6.informatik.uni-dortmund.de, and I
> really don't have a "favourite WAIT server", whatever that is.
CPAN::WAIT is used for looking up stuff in the documentation within
the CPAN.pm shell (it uses the 'WAIT server' being referred to), but
this is an optional plug-in. The error message resulted
from not being able to connect to this server - that could mean
the server itself is down, or perhaps your machine wasn't connected
at the time. If all you want to do for now is use CPAN.pm to
search for and install modules, you can ignore this error.
best regards,
randy kobes
------------------------------
Date: Tue, 25 Sep 2001 20:34:12 +0200
From: "Stefan Weiss" <weiss@kung.foo.at>
Subject: Re: Windows2000: CPAN.pm woes
Message-Id: <1001443133.812871@newsmaster-04.atnet.at>
<OT>
"Alicia" <alicia090677@hotmail.com> wrote:
> (whew! That was a lot of typing! The blasted cmd.exe window doesn't
> seem to have cut and paste!)
Yes it does: highlight the text with your mouse, then press the right
mouse button. The highlighted part should be in the clipboard now.
Similarly, you can paste into the console window with a right mouse
click.
</OT>
cheers,
stefan
------------------------------
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 1816
***************************************