[19140] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 1335 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jul 19 14:10:51 2001

Date: Thu, 19 Jul 2001 11:10:14 -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: <995566214-v10-i1335@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 19 Jul 2001     Volume: 10 Number: 1335

Today's topics:
    Re: Including flock in code while developing in Windows <newspost@coppit.org>
    Re: Including flock in code while developing in Windows <mjcarman@home.com>
    Re: Including flock in code while developing in Windows <jeff@vpservices.com>
    Re: Including flock in code while developing in Windows <m.grimshaw@salford.ac.uk>
    Re: Including flock in code while developing in Windows <jeff@vpservices.com>
    Re: is the UK serious about perl? <uri@sysarch.com>
    Re: map and split combination slow (Anno Siegel)
    Re: Modem::Vgetty problems, please help! thedoctor@space.net
    Re: Pattern Matching Questions (Tad McClellan)
    Re: Perl or PHP? <tore@extend.no>
        Perl Programmers Wanted In The UK  2306 cv@gngassociates.co.uk
    Re: Perl Programmers Wanted In The UK  2306 <mjcarman@home.com>
    Re: Request for Comments ... ConvertColorspace.pm <mjcarman@home.com>
    Re: Request for Comments ... ConvertColorspace.pm (Anno Siegel)
    Re: Request for Comments ... ConvertColorspace.pm <mniles@itm.com>
    Re: Request for Comments ... ConvertColorspace.pm <mniles@itm.com>
    Re: Request for Comments ... ConvertColorspace.pm <mniles@itm.com>
        tab sperated line to named hash? <twanGEENSPAM@twansoft.com>
    Re: tab sperated line to named hash? (Tad McClellan)
    Re: tab sperated line to named hash? <twanGEENSPAM@twansoft.com>
    Re: Trouble extracting strings - help needed nobull@mail.com
        while($f = readdir(...)) question <macintsh@cs.bu.edu>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Thu, 19 Jul 2001 08:53:21 -0400
From: David Coppit <newspost@coppit.org>
Subject: Re: Including flock in code while developing in Windows for Unix??
Message-Id: <3B56D841.6010909@coppit.org>

Philip Newton wrote:

>>>David Coppit wrote:
>>Okay. I thought fork simulation was part of the MS contribution to Perl. 
> 
> Er, 'fork' ne 'flock'.

Sigh... I asked my brain to think, and it said "I'm sorry Dave, I can't 
do that."

David





------------------------------

Date: Thu, 19 Jul 2001 08:06:46 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Including flock in code while developing in Windows for Unix??
Message-Id: <3B56DB66.D4A269D2@home.com>

Bart Lateur wrote:
> 
> Michael Carman wrote:
> 
>>> What's wrong with string eval?
>>
>> It's slow. [...] Using eval EXPR requires EXPR to be parsed
>> -- at runtime -- each time it is encountered.
> 
> Since this is supposed to be run only once, this argument isn't
> really relevant. Once you know, you know.

You must be skimming, Bart. I said the same thing a little farther 
down. =)

What I completely forgot about is the dangers of eval'ing user supplied
data, as Jeff said. Security is a bigger concern that efficiency, but I
almost never use eval that way, so I tend to forget about that argument.
But again, that doesn't matter here.

So for those playing along at home: there are good reasons to not use
eval EXPR -- they just don't apply to this situation.

-mjc


------------------------------

Date: Thu, 19 Jul 2001 09:23:23 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Including flock in code while developing in Windows for Unix??
Message-Id: <3B57097B.2164D6A7@vpservices.com>

Mark Grimshaw wrote:
> 
> Michael Carman wrote:
> >
> > Mark Grimshaw wrote:
> > >
> > > Jeff Zucker wrote:
> > >>
> > >> Bart Lateur wrote:
> > >>>
> > >>>     if(eval "use Fcntl qw(:flock); 1")      # has flock()
> > >>
> <snip>
>
> BEGIN   {
>                 if(eval "use Fcntl qw(:flock)") # no flock()
>                 {
>                         print "has flock: $@\n\n";
>                 }
>                 else
>                 {
>                         use Fcntl;
>                         print "no flock: $@\n\n";
>                 }
>         }
> 
> prints "no flock: " with nothing in $@.  I certainly do have flock and
> am able to use it.

You are forgetting the "; 1" that is in Bart's version and is critical
to making this kind of test work.  Consider the following:

  my $x = eval { die if 6 == 9; 1 };  # thx Jimi
  my $y = eval { die if 6 == 6; 1 };
  print "x = $x\n" if $x;
  print "y = $y\n" if $y;

That prints "x = 1" and all because of the "; 1".  This relates to the
following line in "perldoc eval":

    ... the value returned is the value of the last
    expression evaluated inside the mini-program;

With $x the first statement in the eval doesn't die, so it progresses on
to the second statement.  The second statement is "1" so $x becomes 1. 
But with $y the first statement in the eval dies so it never gets to the
second statement and $y is not set to 1 or to anything else.

If you add the "; 1" to your eval, it will work on winNT. 
Unfortunately, it will not work on many versions of win32 perl on non-NT
boxes because, as Bart pointed out, the binaries for NT and non-NT perl
are often the same and therefore you'll get a false positive on many
non-NT boxes.

-- 
Jeff



------------------------------

Date: Thu, 19 Jul 2001 18:34:18 +0100
From: Mark Grimshaw <m.grimshaw@salford.ac.uk>
Subject: Re: Including flock in code while developing in Windows for Unix??
Message-Id: <3B571A1A.33B02F2E@salford.ac.uk>



Jeff Zucker wrote:
> 
> Mark Grimshaw wrote:
> >
> >
> > BEGIN   {
> >                 if(eval "use Fcntl qw(:flock)") # no flock()
> >                 {
> >                         print "has flock: $@\n\n";
> >                 }
> >                 else
> >                 {
> >                         use Fcntl;
> >                         print "no flock: $@\n\n";
> >                 }
> >         }
> >
> > prints "no flock: " with nothing in $@.  I certainly do have flock and
> > am able to use it.
> 
> You are forgetting the "; 1" that is in Bart's version and is critical
> to making this kind of test work.  Consider the following:
> 
>   my $x = eval { die if 6 == 9; 1 };  # thx Jimi
>   my $y = eval { die if 6 == 6; 1 };
>   print "x = $x\n" if $x;
>   print "y = $y\n" if $y;
> 
> That prints "x = 1" and all because of the "; 1".  This relates to the
> following line in "perldoc eval":
> 
>     ... the value returned is the value of the last
>     expression evaluated inside the mini-program;
> 
> With $x the first statement in the eval doesn't die, so it progresses on
> to the second statement.  The second statement is "1" so $x becomes 1.
> But with $y the first statement in the eval dies so it never gets to the
> second statement and $y is not set to 1 or to anything else.
> 
> If you add the "; 1" to your eval, it will work on winNT.
> Unfortunately, it will not work on many versions of win32 perl on non-NT
> boxes because, as Bart pointed out, the binaries for NT and non-NT perl
> are often the same and therefore you'll get a false positive on many
> non-NT boxes.

But as I said in a previous post, is that not forcing the issue when
used with an if(...) statement?  i.e.:
                if(eval "use Fcntl qw(:flock)"; 1) # has flock()?
                {
                        print "has flock: $@\n\n";
                 }

which will be true on any system in which case there's no point doing
it. ??

I'm puzzled by the example on p 404 of Perl Cookbook:

# $mod == some *.pm file
if(eval "require $mod")
{
	$mod->import();
	$found = 1;
}
# if($found), $mod has been loaded

which seems to be similar to my script above except that I replace
'require' and 'import' with 'use'.


------------------------------

Date: Thu, 19 Jul 2001 10:48:08 -0700
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: Including flock in code while developing in Windows for Unix??
Message-Id: <3B571D58.7F768F3C@vpservices.com>

Mark Grimshaw wrote:
> 
>                 if(eval "use Fcntl qw(:flock)"; 1) # has flock()?
>                 {
>                         print "has flock: $@\n\n";
>                  }

Wrong place, try:

   if( eval "use Fcntl qw(:flock); 1" ) # MAYBE has flock()

> which will be true on any system

No, on systems that die at the statement to use flock, the one will not
be returned, as per my previous post.

-- 
Jeff



------------------------------

Date: Thu, 19 Jul 2001 17:44:29 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: is the UK serious about perl?
Message-Id: <x7r8vcvmo2.fsf@home.sysarch.com>

>>>>> "Jc" == Jacqui caren <Jacqui.Caren@ig.co.uk> writes:

  Jc> US based companies seem to use perl for serious business
  Jc> critical systems whereas UK based vacancies imply 'toy'
  Jc> web usage of perl/DBI. Also adverts from UK companies
  Jc> lack that quality feel that the majority of US posters
  Jc> seem to give out. I honestly wonder if any decent perl
  Jc> folks even bother to reply to such badly structured
  Jc> 'desperate sounding' adverts.

i see regular posts for perl hackers in the UK on the perl jobs
list. search the archive to see them.

	jobs.perl.org

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


------------------------------

Date: 19 Jul 2001 14:00:13 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: map and split combination slow
Message-Id: <9j6p5d$ok8$1@mamenchi.zrz.TU-Berlin.DE>

According to Uri Guttman  <uri@sysarch.com>:
> >>>>> "JWK" == John W Krahn <krahnj@acm.org> writes:
> 
>   JWK> "Randy Da.y" wrote:
>   >> 
>   >> I'm processing a DB extraction file. This is a flat text file with
>   >> fixed length fields. I'm using the following segment within a
>   >> format_date function:
>   >> if ($date =~ m/\s/) {
>   >> map{ $len += $hlen{$_} } split //, $fmt2;
>   >> return($datestr = " " x $len);
>   >> }
>   >> This is running extremely slow. When left in the function, 10K records
>   >> are processed in approximately 3 minutes 20 seconds, without it, it is
>   >> 25 seconds.
>   >> 
>   >> Suggestions, comments?
> 
>   JWK> This is about twice as fast:
> 
>   JWK> if ( $date =~ m/\s/ ) {
>   JWK>     $len += $hlen{substr $fmt2, $_, 1} for 0 .. length($fmt2) - 1;
>   JWK>     return $datestr = " " x $len;
>   JWK>     }
 
Oh, are we making it fast?  This is twice as fast again:

         if ( $date =~ m/\s/ ) {
             $fmt2 =~ tr {mdyY/} {\02\02\02\04\01\00};
             return ' ' x unpack( '%32C*', $fmt2);
         }

tr/// replaces each format character with (the character whose code
is) the corresponding length. (Works only for lengths below 256.)
Other characters are replaced by \0 and so effectively ignored.
Then unpack builds a 32-bit checksum of all the bytes, which will
be the total length.  It also destroys $fmt2.

I *don't* recommend this technique except for desperate cases.
It's hard to understand and harder to maintain.  Memoizing the
total lengths, as has been suggested in this thread, will be
just as fast or faster, and is much clearer.

[snip]

Anno


------------------------------

Date: Thu, 19 Jul 2001 16:08:24 GMT
From: thedoctor@space.net
Subject: Re: Modem::Vgetty problems, please help!
Message-Id: <3b570667$1$oeczf$mr2ice@news.earthlink.net>

In <ce3f4c90.0107071643.5296300f@posting.google.com>, on 07/07/01 
   at 05:43 PM, law_40@hotmail.com (Laron) said:

>Hello, I found you address in a news group.  I hope that you don't mind
>my contacting you....

>I'm trying to use the Modem::Vgetty package to simple call a phone number
>through my modem..  I'm using active perl on windows 2000. Everytime I
>try to run a script, I get an error similar to

>Can't call method "dial" on an undefined value at te.pl line 4.

>here's some example code..

>use Modem::Vgetty;
>my $v = new Modem::Vgetty;
>$number="5555555";
>$v->dial($number);
>$v->waitfor('READY');
>$v->shutdown;

>Have I failed to install all of the proper packages?

I'm also trying to use the package [RH7.1].  Have seen that same error
when the new command fails [maybe line not hooked up, ....]. Windows and
linux are so different, I can't guess what your problem is.  Is there an
equivalent to  vm diagnostics
for your installation?

Paul Schwartz
-- 
-----------------------------------------------------------
Reply to brpms at earthlink dot net
-----------------------------------------------------------



------------------------------

Date: Thu, 19 Jul 2001 10:41:58 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Pattern Matching Questions
Message-Id: <slrn9ldsdm.h23.tadmc@tadmc26.august.net>

Bart Lateur <bart.lateur@skynet.be> wrote:
>Tad McClellan wrote:
>
>>>>Question - I'd like to be able to keep other .txt files in the same
>>>>directory, that is, I'd like to only match on the foo*.txt files.  I tried a
>>>>few variations of the grep, but couldn't seem to get it to work.  Any
>>>>suggestions?
>>
>>
>>   @txt_files = grep { /foo.*\.txt$/} readdir (DIR);
>
>You forgot the leading anchor:


No I didn't.


>   @txt_files = grep { /^foo.*\.txt$/} readdir (DIR);


I didn't read the specification as saying that it started with "foo",
only that it contained "foo".

I thought it was a bug in the spec, but I did not correct it,
just did what it said to do.


Poor specifications often lead to unsatisfactory implementations :-)


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Thu, 19 Jul 2001 17:57:26 +0200
From: Tore Aursand <tore@extend.no>
Subject: Re: Perl or PHP?
Message-Id: <MPG.15c121cd2d7535298969a@news.online.no>

In article <srj66cq1zjp.fsf@w3proj1.ze.tu-muenchen.de>, hafner-
usenet@ze.tu-muenchen.de says...
> 1) Normally you embed PHP code in HTML Pages.
> 2) Normally you embed HTML in Perl scripts.

Well.  I don't agree to these statements.  I would rather put 
it this way;

1. With PHP, it's normal to put PHP in HTML.
2. With Perl, it's normal to _choose_ between embedding the 
code in HTML, or embedding the HTML inside your Perl 
application.

For me, the difference between Perl and PHP is nothing more 
than the fact that I can do _a lot_ more with Perl than I can 
do with PHP.


-- 
Tore Aursand - tore@extend.no - www.aursand.no


------------------------------

Date: 19 Jul 2001 13:19:00 GMT
From: cv@gngassociates.co.uk
Subject: Perl Programmers Wanted In The UK  2306
Message-Id: <9j6mo4$pbl$4@neptunium.btinternet.com>

My client internet solutions provider and the biggest webhosting
company in the UK requires Developers on Unix/Linux. You must have  Perl,
C/C++, Shell Scripting, SQL or other backend databases. This is a varied
role and a great opportunity with the potential of training for Java
You Must Live in The UK.
uxrnmbdciefrexfkh



------------------------------

Date: Thu, 19 Jul 2001 08:54:55 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Perl Programmers Wanted In The UK  2306
Message-Id: <3B56E6AF.220CF782@home.com>

cv@gngassociates.co.uk wrote:
> 
> My client [...] requires Developers on Unix/Linux. You must have
> Perl, [...]
> You Must Live in The UK.

You must not post job listings on technical newsgroups. Thank you.

(Go get 'em DHA.)

-mjc


------------------------------

Date: Thu, 19 Jul 2001 08:48:47 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Request for Comments ... ConvertColorspace.pm
Message-Id: <3B56E53F.273D14D0@home.com>

Melissa Niles wrote:
> 
> I would like comments on the following module. It is not completed
> as of yet.

*ignites flamethrower* (just kidding)

> 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.

Have you read the perlmod manpage yet? If not, you should.

> The main portion is included as text, and the full module is
> attached.

Plaintext is fine, but please don't post attatchments on Usenet. Thanks.
 
> 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 $

You might want to make rgb2cmyk() exportable so that people can bring in
into their namespace if they want. (But don't forcibly export it.)

> sub rgb2cmyk {
>         my $self  = shift;
>         my $class = ref($self) || $self;

You don't have a constructor anywhere in your module, which means that
this is a function, not a method. As such, you shouldn't be shifting off
the first arg as an object. (It will suck up your red value.)

>         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);

I don't see the point of formatting these, so I wouldn't bother with
sprintf(). Since you're doing the same thing to each value, it collapses
nicely to a loop:

foreach ($r, $g, $b) {
    $_ /= 254;
}

Better still, do it as you get the data out of @_:

my ($r, $g, $b) = map {$_ / 254} @_;

Hrm. $b is a special var used in sortsubs. Better to not use it (you'll
see why later.) Normally uppercase is used to denote globals, but we can
make an exception here and use them to avoid $b and be consistent with
your names for CMYK:

my ($R, $G, $B) = map {$_ / 254} @_;

>         my $C = 0.00;
>         my $M = 0.00;
>         my $Y = 0.00;
>         my $K = 0.00;

No need to initialize.

my ($C, $M, $Y, $K);
 
>         # 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;

$K = (sort {$a <=> $b} map {1 - $_} ($R, $G, $B))[0];

Okay, so that's probably doesn't seem clearer at first, but it's how I'd
write it.

>         $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?

Again, I don't see the point of using sprintf() here. I'd let the user
decide how much precision they want. The CMY lines are parallel, which
lends itself nicely to another map:

($C, $M, $Y) = map {1 - $_ - $K)/(1 - $K)} ($R, $G, $B);
 
>         return $C,$M,$Y,$K;
> }
> 
> return 1;
> 
> __END__

To summarize my suggestions on the sub:

sub rgb2cmyk {
    my ($R, $G, $B) = map {$_ / 254} @_;

    # find the lowest value minimum(R,G,B)
    my $K = (sort {$a <=> $b} map {1 - $_} ($R, $G, $B))[0];

    my ($C, $M, $Y) = map {(1 - $_ - $K)/(1 - $K)} ($R, $G, $B);

    $K = 0 if $K < 0; # adjust if neg number?

    return($C, $M, $Y, $K);
}

Mostly stylistic changes that come from having spent more time with
Perl.

One other thought -- many people use hex for RGB values, you may want to
think about supporting that directly.

-mjc


------------------------------

Date: 19 Jul 2001 14:42:40 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Request for Comments ... ConvertColorspace.pm
Message-Id: <9j6rl0$qap$1@mamenchi.zrz.TU-Berlin.DE>

According to Michael Carman  <mjcarman@home.com>:

[...]

> To summarize my suggestions on the sub:
> 
> sub rgb2cmyk {
>     my ($R, $G, $B) = map {$_ / 254} @_;
> 
>     # find the lowest value minimum(R,G,B)
>     my $K = (sort {$a <=> $b} map {1 - $_} ($R, $G, $B))[0];
> 
>     my ($C, $M, $Y) = map {(1 - $_ - $K)/(1 - $K)} ($R, $G, $B);
> 
>     $K = 0 if $K < 0; # adjust if neg number?
> 
>     return($C, $M, $Y, $K);
> }
> 
> Mostly stylistic changes that come from having spent more time with
> Perl.

The case $K == 1 needs special treatment.

Out of curiosity, is 254 really the correct denominator here?  Negative
$K, and all?

Anno


------------------------------

Date: Thu, 19 Jul 2001 10:12:51 -0700
From: Melissa Niles <mniles@itm.com>
Subject: Re: Request for Comments ... ConvertColorspace.pm
Message-Id: <3B571513.11727A29@itm.com>

First, I thank everyone for their suggestions, both with improving the
coding and with the subject of conversions ....

To answer your question, there are 255 values for each RGB color, which
is 0-254.

Of course, please correct me if I'm wrong, or if my brain just can't
fathom what you are meaning. :)


Anno Siegel wrote:
> 
> According to Michael Carman  <mjcarman@home.com>:
> 
> [...]
> 
> > To summarize my suggestions on the sub:
> >
> > sub rgb2cmyk {
> >     my ($R, $G, $B) = map {$_ / 254} @_;
> >
> >     # find the lowest value minimum(R,G,B)
> >     my $K = (sort {$a <=> $b} map {1 - $_} ($R, $G, $B))[0];
> >
> >     my ($C, $M, $Y) = map {(1 - $_ - $K)/(1 - $K)} ($R, $G, $B);
> >
> >     $K = 0 if $K < 0; # adjust if neg number?
> >
> >     return($C, $M, $Y, $K);
> > }
> >
> > Mostly stylistic changes that come from having spent more time with
> > Perl.
> 
> The case $K == 1 needs special treatment.
> 
> Out of curiosity, is 254 really the correct denominator here?  Negative
> $K, and all?
> 
> Anno


------------------------------

Date: Thu, 19 Jul 2001 10:16:06 -0700
From: Melissa Niles <mniles@itm.com>
Subject: Re: Request for Comments ... ConvertColorspace.pm
Message-Id: <3B5715D6.ABE095C3@itm.com>

I do understand the 'controversy' with color conversions - I do not
think for a moment that this isn't fool proof, but my hopes are that it
may make it easier for simple screen representations (web apps) and
printing.

I will make sure I warn any user of this ...and try to get my hands on
some of the papers (etc) you mentioned.

Thanks!!


Walter Hafner wrote:
> 
> Melissa Niles <mniles@itm.com> writes:
> 
> > 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.
> 
> For all questions regarding color spaces / color science etc. please
> have a look at the sci.engr.color newsgroup. They have very good FAQs
> over there. I can especially recommend all the Poynton papers.
> 
> Color conversion is a non trivial task. I should know. I wrote a PhD
> thesis about adaptive color classification. :-)
> 
> Have a look at my thesis bibliography (german):
> http://www.tu-muenchen.de/~hafner/diss/node91.html
> 
> For color conversions I'd read Hun95, Jac93, Jai89, the OKS80 paper,
> Poy96 and maybe Mac85 (all in english!).
> 
> The "bible" of color science is WS82 - about 1300 pages for about
> 100$. ;-)
> 
> (Ok, so CMYK / RGB conversion isn't very complicated, but as soon as you
> add conversions based upon XYZ or the CIE color spaces you're in
> trouble without guidance).
> 
> > 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.
> 
> Maybe that's because Perl isn't very much used in the color science
> world. Since the whole topic is highly numeric, they normally use Maple,
> Mathemetica and especially Matlab! You should have no trouble finding
> Matlab modules for color conversion. I even wrote one myself, long, long
> ago. If you port one of them to Perl always remember that floating point
> arithmetic in Perl isn't nearly as accurate as it is in the math tools!
> 
> Regards
> 
> -Walter
> 
> PS: before you ask me for sources etc: I have left the color science
> scene about 3 years ago and changed my employer twice. I don't have
> access to my program sources anymore.


------------------------------

Date: Thu, 19 Jul 2001 10:38:11 -0700
From: Melissa Niles <mniles@itm.com>
Subject: Re: Request for Comments ... ConvertColorspace.pm
Message-Id: <3B571B03.C0E501C8@itm.com>

Thank you so much, very constructive!!!



Michael Carman wrote:
 
> > 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.
> 
> Have you read the perlmod manpage yet? If not, you should.

I'm going through it, and modlib and the tutorials, by the time I'm
finished with the module, I'm hoping to be fully compliant.
 
[...]


> To summarize my suggestions on the sub:
> 
> sub rgb2cmyk {
>     my ($R, $G, $B) = map {$_ / 254} @_;
> 
>     # find the lowest value minimum(R,G,B)
>     my $K = (sort {$a <=> $b} map {1 - $_} ($R, $G, $B))[0];
> 
>     my ($C, $M, $Y) = map {(1 - $_ - $K)/(1 - $K)} ($R, $G, $B);
> 
>     $K = 0 if $K < 0; # adjust if neg number?
> 
>     return($C, $M, $Y, $K);
> }
> 
> Mostly stylistic changes that come from having spent more time with
> Perl.

Wow, gorgeous :) Thank you so much for taking the time to spell these
things out. That helps!!

 
> One other thought -- many people use hex for RGB values, you may want to
> think about supporting that directly.

Would it be best to do this as another function or as an added option to
this existing function ..ie:

rgb2cmyk($r,$g,$b,$option);

where options would be:

number (0-254)
decimal (0;1)
hex (hex)



Thanks so much!


------------------------------

Date: Thu, 19 Jul 2001 16:03:25 +0200
From: Twan Kogels <twanGEENSPAM@twansoft.com>
Subject: tab sperated line to named hash?
Message-Id: <topdltkasbtluaq1t6kf8ua2riv6c9mckr@4ax.com>

Greetings,

How can i optimize the following code snippet:

--------------------------------
chomp($dataline);
my @data=split("\t", $dataline);

%forumprop=();
$forumprop{'forum_title'}=$data[0];
$forumprop{'bg_header'}=$data[1];
$forumprop{'tb_normal_tags'}=$data[2];
$forumprop{'fg_header'}=$data[3];
$forumprop{'font_name'}=$data[4];
$forumprop{'font_color'}=$data[5];
$forumprop{'bg_page'}=$data[6];
$forumprop{'smiley_extra'}=$data[9];
 ...
$forumprop{'new_only_admin'}=$data[182];
$forumprop{'flood'}=$data[183];
$forumprop{'keur'}=$data[184];
--------------------------------

I use $forumprop{'name_of_prop'} everywhere in my script. As you can
see, i have almost 200 lines of code which convert a tab seperated
line, to a hash.

Thanks!
Twan


------------------------------

Date: Thu, 19 Jul 2001 11:04:21 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: tab sperated line to named hash?
Message-Id: <slrn9ldtnk.h23.tadmc@tadmc26.august.net>

Twan Kogels <twanGEENSPAM@twansoft.com> wrote:
>
>How can i optimize the following code snippet:
           ^^^^^^^^

Optimize what?

Memory usage?

File size?

Execution speed?

Development time?

Maintenance time?

 ...?


>--------------------------------
>chomp($dataline);
>my @data=split("\t", $dataline);
                ^^^^

A pattern should *look like* a pattern:    /\t/


>%forumprop=();
>$forumprop{'forum_title'}=$data[0];
>$forumprop{'bg_header'}=$data[1];
>$forumprop{'tb_normal_tags'}=$data[2];
>...
>$forumprop{'flood'}=$data[183];
>$forumprop{'keur'}=$data[184];
>--------------------------------


   my @colnames = qw/forum_title bg_header tb_normal_tags ... flood keur/;

   my %forumprop;
   @forumprop{ @colnames } = split(/\t/, $dataline);  # a "hash slice"


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Thu, 19 Jul 2001 18:34:13 +0200
From: Twan Kogels <twanGEENSPAM@twansoft.com>
Subject: Re: tab sperated line to named hash?
Message-Id: <kd2eltsjqcs8s7cu0dbfri8lht1c733rf1@4ax.com>

On Thu, 19 Jul 2001 11:04:21 -0400, tadmc@augustmail.com (Tad
McClellan) wrote:

>Twan Kogels <twanGEENSPAM@twansoft.com> wrote:
>>
>>How can i optimize the following code snippet:
>           ^^^^^^^^
>
>Optimize what?
>
>Memory usage?
>
>File size?
>
>Execution speed?
>
>Development time?
>
>Maintenance time?
>
>...?

Sorry, that i was not detailed enough, i hoped i could reduce the cpu
usage / execution speed. Because this part of the script takes a big
part of execution time of the total script (40% i think, including IO
functions).

>
>
>>--------------------------------
>>chomp($dataline);
>>my @data=split("\t", $dataline);
>                ^^^^
>
>A pattern should *look like* a pattern:    /\t/
>
>
>>%forumprop=();
>>$forumprop{'forum_title'}=$data[0];
>>$forumprop{'bg_header'}=$data[1];
>>$forumprop{'tb_normal_tags'}=$data[2];
>>...
>>$forumprop{'flood'}=$data[183];
>>$forumprop{'keur'}=$data[184];
>>--------------------------------
>
>
>   my @colnames = qw/forum_title bg_header tb_normal_tags ... flood keur/;
>
>   my %forumprop;
>   @forumprop{ @colnames } = split(/\t/, $dataline);  # a "hash slice"

This looks much shorter and cleaner ;) I will run a benchmark
tomorrow.

Thanks for your reply,
Twan


------------------------------

Date: 19 Jul 2001 17:45:30 +0100
From: nobull@mail.com
To: Mark.S.Smith@marconi.com
Subject: Re: Trouble extracting strings - help needed
Message-Id: <u9puawvped.fsf@wcl-l.bham.ac.uk>

Mark.S.Smith@marconi.com (Mark Smith) writes:

> 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.

Other people have answerd your immediate question but for some
radically different approaches to the whole thing take a look at the
current thread "Generic Language interpreter in Perl?".

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


------------------------------

Date: 19 Jul 2001 17:23:33 GMT
From: John Siracusa <macintsh@cs.bu.edu>
Subject: while($f = readdir(...)) question
Message-Id: <9j752l$ojh$1@news3.bu.edu>

Can someone help me reconcile this?

---

% perl -v

This is perl, v5.6.0 built for sun4-solaris
[...]

% perldoc -f readdir
     readdir DIRHANDLE
             Returns the next directory entry for a directory
             opened by `opendir'.  If used in list context,
             returns all the rest of the entries in the
             directory.  If there are no more entries, returns an
             undefined value in scalar context or a null list in
             list context.
[...]

% perldoc perldiag
[...]
     Value of %s can be "0"; test with defined()
         (W misc) In a conditional expression, you used <HANDLE>,
         <*> (glob), "each()", or "readdir()" as a boolean value.
         Each of these constructs can return a value of "0"; that
         would make the conditional expression false, which is
         probably not what you intended.  When using these
         constructs in conditional expressions, test their values
         with the "defined" operator.
[...]

% mkdir tmp
% cd tmp
% touch 0
% touch temp
% ls
0      temp
% perl -we 'opendir(D, "."); while($f = readdir(D)) { \
            print "File $f is ", ($f) ? "true" : "false", "\n" }'
File . is true
File .. is true
File 0 is false
File temp is true

---

I've been doing:

    while(defined($f = readdir(...))) { ... }

for years, because I thought it was The Right Thing.  The perldiag
documentation seems to agree, but perl 5.6.0 doesn't behave the
way I expect it to.  I checked the Changes file, and even took a
look in pp_sys.c to see if i could figure out if/when a change was
made.  Can anyone shed some light on this?  Is the defined() no
longer necessary?  Or was it never necessary?  Or am I totally
confused?  Thanks.

-----------------+----------------------------------------
  John Siracusa  | If you only have a hammer, you tend to
 macintsh@bu.edu | see every problem as a nail. -- Maslow


------------------------------

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 1335
***************************************


home help back first fref pref prev next nref lref last post