[19136] in Perl-Users-Digest
Perl-Users Digest, Issue: 1331 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 18 21:10:31 2001
Date: Wed, 18 Jul 2001 18:10: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: <995505012-v10-i1331@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 18 Jul 2001 Volume: 10 Number: 1331
Today's topics:
Re: Request for Comments ... ConvertColorspace.pm <schabernackel@hotmail.com>
Re: Strange thing happened today! <millettNOSPAM@lblueyonder.co.uk>
Re: Ternary Conditional Operator Question (Jonathan Cunningham)
Re: Ternary Conditional Operator Question <dbe@wgn.net>
Re: Ternary Conditional Operator Question (Tad McClellan)
Re: timeout of gethostbyaddr and gethostbyname <dbe@wgn.net>
Re: trace function calls (Rene Nyffenegger)
Re: Trouble extracting strings - help needed <dbe@wgn.net>
Re: Trouble extracting strings - help needed <krahnj@acm.org>
Upgrade (HotMail\)
Re: Upgrade (Tad McClellan)
Yet Another use/require Question <marshall@chezmarshall.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 18 Jul 2001 22:55:27 GMT
From: Haber Schabernackel <schabernackel@hotmail.com>
Subject: Re: Request for Comments ... ConvertColorspace.pm
Message-Id: <1103_995497309@f3bpc14>
On Wed, 18 Jul 2001 14:01:59 -0700, Melissa Niles <mniles@itm.com> wrote:
> This is a multi-part message in MIME format.
> --------------1B83EEB8797F0ECB1346CE54
> Content-Type: text/plain; charset=x-user-defined
> Content-Transfer-Encoding: 7bit
>
> I would like comments on the following module. It is not completed as of
> yet.
>
> It's purpose is to allow the retrieval of colorspace values from a
> different set of colorspace values, ie: get CMYK values from a set of
> RGB values.
>
> As far as I can find, there's no other module like it, but I have seen
> others with a need for this sort of module.
Have you looked in some GD- or ImageMagik-modules? (but maybe
to "fat" to import/install for just this such a simple task).
> As you are sure to see, this is the first perl module that I have
> written, and would like suggestions/comments on making it better. The
> main portion is included as text, and the full module is attached.
>
> Thank you,
>
> Melissa
>
>
>
> package ConvertColorspace; # for testing
> #package Image::ConvertColorspace;
>
> # Copyright (c) 2001 Melissa Niles. All rights reserved.
> # This program is free software; you can redistribute it and/or
> # modify it under the same terms as Perl itself.
>
> use strict;
> use vars qw($VERSION);
> $VERSION = "0.58"; # $Date: 2001/07/18 12:50:21 $
use Exporter();
@ISA=qw(Exporter);
@EXPORT = qw(
rgb2cmyk
);
# the caller can now call just: rgb2cmyk(...)
# instead of Image::ConvertColorspace::rgb2cmyk(...)
> sub rgb2cmyk {
> my $self = shift;
> my $class = ref($self) || $self;
I would drop the two my-lines above. (Why someone makes even the
simplest modules into object oriented ones never stops to puzzle me.
OO-brainwashed by teachers that never do real programming
themselves, my best theory :-)
> my ($r,$g,$b) = @_;
>
> #turn RGB values into decimal...
> $r = sprintf("%1.2f", $r/254);
> $g = sprintf("%1.2f", $g/254);
> $b = sprintf("%1.2f", $b/254);
>
>
> my $C = 0.00;
> my $M = 0.00;
> my $Y = 0.00;
> my $K = 0.00;
>
> # find the lowest value minimun(R,G,B)
> $K = 1-$r;
> $K = 1-$g if 1-$g < $K;
> $K = 1-$b if 1-$b < $K;
Are you sure you want to do those sprintf's
and loose decimals? Seems to me the cmyk colors returned
have less "precission" than the rgb input. Maybe its the callers
job to round the cmyk's. You could add a sub to help the caller:
@cmyk=roundem(2,@cmyk); #round to 2 decimals
(but if you know what you are doing...)
> $K = sprintf("%1.2f", $K);
> $C = sprintf("%1.2f", (1-$r-$K)/(1-$K));
> $M = sprintf("%1.2f", (1-$g-$K)/(1-$K));
> $Y = sprintf("%1.2f", (1-$b-$K)/(1-$K));
> $K = 0 if $K < 0; # adjust if neg number?
>
> return $C,$M,$Y,$K;
> }
>
> return 1;
>
> __END__
>
> --------------1B83EEB8797F0ECB1346CE54--
>
------------------------------
Date: Thu, 19 Jul 2001 00:18:43 GMT
From: "millside" <millettNOSPAM@lblueyonder.co.uk>
Subject: Re: Strange thing happened today!
Message-Id: <DHp57.2105$Ii1.407432@news1.cableinet.net>
> You are looking for the problem in the wrong place.
>
> Your problem has nothing to do with Perl.
>
No I agree, nothing at all to do with "Perl" you say? shouldn't that be
"perl"? Just thought I'd share the experience since it was a perl program I
was working on that caused it.
<snip>
Anyway, I found the problem.. a relative url in the code!
hmm, think I'll head on over to alt.html
Thanks
------------------------------
Date: 18 Jul 2001 15:40:05 -0700
From: dawfun@seanet.com (Jonathan Cunningham)
Subject: Re: Ternary Conditional Operator Question
Message-Id: <4d6fd5fc.0107181440.7a9e8ad0@posting.google.com>
"Wyzelli" <wyzelli@yahoo.com> wrote in message news:<zy557.11$0b5.675@vic.nntp.telstra.net>...
> > Could someone out there please let me know why this doesn't work:
> >
> > # @_ == ('d:/some/path');
> > # $slash == '';
> >
> > for(@_) {
> > $slash =~ m{/} ? s{\\}{/}g : s{/}{\\}g;
> >
> > # This doesn't work either...
> > # ($slash =~ m{/}) ? s{\\}{/}g : s{/}{\\}g;
> > }
> >
>
> I'll jump in and ask 'are you trying to solve the wrong problem?'
>
> What are you trying to achieve?
>
> You do realise that forward slashes are quite acceptable in a Perl program
> on a Win32 box?
>
> Wyzelli
Sorry for being so vague, but I expected it not to work for you the
same way it didn't work for me. :) First of all, I'm trying to
change all backslashes to forwards and likewise because I'm writing
some code for a poorly planned system that sometimes requires forward
slashes and sometimes not (lame).
When I run the above code I get an "unable to modify [something
something]" with -w (without -w the code just stopped running with no
complaints).
Basically it doesn't want to modify the individual elements of @_
(which happed to be the params passed to my sub. I fixed it by
setting @_ to @strings, and it worked fine....I still don't know why
it wouldn't work tho'.
Is that better?
Thanks,
JC
Here's the whole thing:
package TeamSite::Utils;
use strict;
sub new {
my $self = {};
bless $self;
return $self;
}
sub slashFix {
# Takes an array of strings or an array of variables as it's
# first argument(s) and an optional slash (/) as its last.
# If the last argument is not a slash, all of the previoius
# arguments will have their slashes changed to backslashes(\).
# If the last argument is a slash, all previous arguments will
# have their backslashes changed to slashes. Returns an array
# of processed arguments if called in list context, and
# returns a string if called in string context.
my $self = shift;
@{ $self->{SLASHFIX} } = ();
my $slash = pop(@_) if($_[$#_] =~ m{^/$});
my @strings = @_; # for some reason this assignment is required
for(@strings) {
($slash =~ m{/}) ? s{\\}{/}g : s{/}{\\}g;
(@strings == 1) ? return $_ : (push @{ $self->{SLASHFIX} },
$_);
}
return @{ $self->{SLASHFIX} };
}
1; # True-Value Hardcode
------------------------------
Date: Wed, 18 Jul 2001 16:14:31 -0700
From: "$Bill Luebkert" <dbe@wgn.net>
Subject: Re: Ternary Conditional Operator Question
Message-Id: <3B561857.A6DF28B1@wgn.net>
Wyzelli wrote:
>
> You do realise that forward slashes are quite acceptable in a Perl program
> on a Win32 box?
Not everywhere - shelling out can be a problem.
--
,-/- __ _ _ $Bill Luebkert ICQ=14439852
(_/ / ) // // DBE Collectibles Mailto:dbe@todbe.com
/ ) /--< o // // http://dbecoll.webjump.com/ (Free site for Perl)
-/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/
------------------------------
Date: Wed, 18 Jul 2001 19:31:10 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Ternary Conditional Operator Question
Message-Id: <slrn9lc71u.eu6.tadmc@tadmc26.august.net>
Jonathan Cunningham <dawfun@seanet.com> wrote:
>"Wyzelli" <wyzelli@yahoo.com> wrote in message news:<zy557.11$0b5.675@vic.nntp.telstra.net>...
>
>> > Could someone out there please let me know why this doesn't work:
[ snip code that *does* work ]
>> What are you trying to achieve?
>Sorry for being so vague, but I expected it not to work for you the
^^^^^^^^^^
Just write it in the form of a short and complete program, then
run the program, _then_ post that code.
Then we will be troubleshooting the same code that you have,
instead of wasting time on code that does not even really exist.
>When I run the above code I get an "unable to modify [something
>something]" with -w (without -w the code just stopped running with no
>complaints).
You should include the exact message text if you want help diagnosing
the problem.
>Basically it doesn't want to modify the individual elements of @_
>(which happed to be the params passed to my sub. I fixed it by
>setting @_ to @strings, and it worked fine....I still don't know why
>it wouldn't work tho'.
Because function args are aliases.
>Is that better?
No. It does not execute either.
We cannot see the method call. I'll bet the args in the call
are not lvalues, but I can't really tell because I am troubleshooting
invisible code...
>Here's the whole thing:
>
>package TeamSite::Utils;
>sub slashFix {
> my $self = shift;
> @{ $self->{SLASHFIX} } = ();
>
> my $slash = pop(@_) if($_[$#_] =~ m{^/$});
^^^^^^
Perl has operators for testing equality. You should use one of
them when you want to test for equality:
my $slash = pop(@_) if($_[$#_] eq '/');
> my @strings = @_; # for some reason this assignment is required
^^^^^^^^^^^
The reason would be revealed if we could see the method call.
But we can't. So we cannot help with your real problem...
> for(@strings) {
> ($slash =~ m{/}) ? s{\\}{/}g : s{/}{\\}g;
^^^^^^^^^ ^^^^^^^^^
$_ is (was) from @_. You are trying to s/// against something in
the caller. That would be OK with:
$util->slashFix( @stuff );
but would complain with:
$util->slashFix( qw/zero one two three/ );
because the are not lvalues in the second case.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 18 Jul 2001 17:18:35 -0700
From: "$Bill Luebkert" <dbe@wgn.net>
Subject: Re: timeout of gethostbyaddr and gethostbyname
Message-Id: <3B56275B.23B4FE14@wgn.net>
Haber Schabernackel wrote:
>
> I use these sub's to convert between, say 208.201.239.56 and www.perl.com:
>
> print hostname_to_ipnumber("www.perl.com")."\n"; # 208.201.239.56
>
> sub ipnumber_to_hostname{ gethostbyaddr(pack("C4",split("\\.",shift)),2) }
> sub hostname_to_ipnumber{ join(".",unpack("C4",gethostbyname(shift))) }
>
>
> But sometimes the sub's hangs "forever", often up to a minute.
> How can i make them time out after 5 seconds?
> (I'm not interested in the result if it takes longer to find it).
If you're on UNIX, you could use alarm - or fork off parallel copies if
you have a bunch so they can run simultaneously.
--
,-/- __ _ _ $Bill Luebkert ICQ=14439852
(_/ / ) // // DBE Collectibles Mailto:dbe@todbe.com
/ ) /--< o // // http://dbecoll.webjump.com/ (Free site for Perl)
-/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/
------------------------------
Date: 18 Jul 2001 23:34:26 GMT
From: rene.nyffenegger@gmx.ch (Rene Nyffenegger)
Subject: Re: trace function calls
Message-Id: <Xns90E28C6B5DDE3gnuegischgnueg@130.133.1.4>
>
>Uh, he wants to parse javascript, not Perl.
>
>Anno
Hm, replied to fast, obviously.
Rene
--
http://www.adp-gmbh.ch/
rene dot nyffenegger at adp-gmbh dot ch
------------------------------
Date: Wed, 18 Jul 2001 16:55:02 -0700
From: "$Bill Luebkert" <dbe@wgn.net>
Subject: Re: Trouble extracting strings - help needed
Message-Id: <3B5621D6.33E86F15@wgn.net>
Mark Smith wrote:
>
> I have a perl script that reads in a file. The contents of this file
> may vary but at several points it contains a filename between double
> quotes. I need to extract every instance of the filename in quotes as
> I need to then process each of these files.
>
> The file would roughly be in this kind of format.
>
> files {
> "somefile.mst",
> "Anotherfile.mst",
> "further-file.mst"
> }
> config {
>
> }
>
> Can anyone help as I can't seem to devise a working method to get just
> the filenames? Also if possible could you mail me directly and
> explain what your method is doing so I will have an understanding.
>
> Once again this file could contains lots of information and I don't
> know the filenames in advance so I need something that will not just
> work with the above but would extract whatever lies between the two
> quotes.
use strict;
open IN, 'files.txt' or die "open files.txt: $!\n";
my @files;
my $found = 0;
while (<IN>) {
last if $found and /}/; # quit after }
next if not $found and /^files/ && ++$found; # start at ^files
next if not $found and not /^files/; # skip till files found
s/^[\s"]+|[",\s]+$//g; # drop " and , and \s
push @files, $_; # save file
}
close IN;
__END__
Other part - reading files - in Bernard's response.
--
,-/- __ _ _ $Bill Luebkert ICQ=14439852
(_/ / ) // // DBE Collectibles Mailto:dbe@todbe.com
/ ) /--< o // // http://dbecoll.webjump.com/ (Free site for Perl)
-/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/
------------------------------
Date: Thu, 19 Jul 2001 00:11:48 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Trouble extracting strings - help needed
Message-Id: <3B562615.4A7D48C6@acm.org>
Mark Smith wrote:
>
> I have a perl script that reads in a file. The contents of this file
> may vary but at several points it contains a filename between double
> quotes. I need to extract every instance of the filename in quotes as
> I need to then process each of these files.
>
> The file would roughly be in this kind of format.
>
> files {
> "somefile.mst",
> "Anotherfile.mst",
> "further-file.mst"
> }
> config {
>
> }
>
> Can anyone help as I can't seem to devise a working method to get just
> the filenames? Also if possible could you mail me directly and
> explain what your method is doing so I will have an understanding.
>
> Once again this file could contains lots of information and I don't
> know the filenames in advance so I need something that will not just
> work with the above but would extract whatever lies between the two
> quotes.
#!/usr/bin/perl -w
use strict;
open IN, '< file' or die "Cannot open 'file': $!";
my @files;
while ( <IN> ) {
if ( /^files {$/ .. /^}$/ ) {
if ( /^"(.*)",?$/ ) {
push @files, $1;
}
}
}
John
--
use Perl;
program
fulfillment
------------------------------
Date: 18 Jul 2001 22:36:48 GMT
From: "Jason Yang \(HotMail\)" <jasonyang88@hotmail.com>
Subject: Upgrade
Message-Id: <9j5320$ib3@dispatch.concentric.net>
Is there any way to upgrade perl from old version?
------------------------------
Date: Wed, 18 Jul 2001 19:34:00 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Upgrade
Message-Id: <slrn9lc778.eu6.tadmc@tadmc26.august.net>
Jason Yang \(HotMail\) <jasonyang88@hotmail.com> wrote:
>Is there any way to upgrade perl from old version?
No.
Everybody just uses version 1.0
New versions keep coming out, but that is not very useful since
perl cannot be upgraded.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Wed, 18 Jul 2001 22:19:48 GMT
From: David Marshall <marshall@chezmarshall.com>
Subject: Yet Another use/require Question
Message-Id: <MPG.15bfd58222b8e706989684@news.earthlink.net>
Disclaimer: Yes, I know that use Blah (); is the same as BEGIN { require
Blah;}. However, I'd prefer to have a better answer than "so what?" if
someone says, "Why'd you load that with use/require and not require/use?"
Suppose I have a set of scripts (a.pl, b.pl, and c.pl) that each
variously employ some modules (Foo.pm, Bar.pm, and Zotz.pm). Any time
one of the scripts employs one of the modules, it's done with "use," no
problems there. For instance
::::
a.pl
::::
#!whatever
use Foo;
::::
The modules here employ each other in various combinations, but they load
other modules with either "require" or "use" at suited the whim of the
programmer that day. Certainly, when someone wanted to pollute a
package's namespace, he'd load a module with "use." Also, those times
when it was desired to only load a module under certain circumstances,
the module would be loaded with "require."
For example:
::::::
Foo.pm
::::::
package Foo;
use Bar;
use Zotz;
::::::
Bar.pl
::::::
package Bar;
require Exporter;
require Zotz;
::::::
Suppose further that now I want to always load modules by either "use" or
"require" unless there's a specific reason to load them the other way.
Some questions:
* Assuming that a module doesn't @ISA Exporter and I know I always want
to load it (such at the top of another module), is there ever a good
reason to prefer "require" to "use"?
* Making the above question more general, if I know I always want to load
a module, is there a good reason not to always load it with "use" and
explicitly control what gets imported to my namespace?
* For modules that I know I always want to load, is there any drawback to
replacing every appearance of "require Furgle;" with "use Furgle ();" ?
I have observed in .pm files under my /usr/local/lib/perl5/5.6.1, there
are 33 lines that match '^use Exporter' and 55 lines that match '^require
Exporter'. Other than personal preference, is there any real
significance to the choice between "use" and "require" in this instance?
OK, now suppose I make some awesome decision about whether module A
should load module B via "use" or "require." Is such a decision
overridden by the decision of whoever loads module A? That is, if A
loads B via "use," but A is loaded by "require," B doesn't get loaded
until "require A;" is executed, correct? And if A loads B via "require,"
but A is loaded with "use," it doesn't really matter how A loads B,
because all that happens within a BEGIN block anyway. Correct?
TIA.
------------------------------
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 1331
***************************************