[18473] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 641 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 6 00:10:54 2001

Date: Thu, 5 Apr 2001 21:10:20 -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: <986530219-v10-i641@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 5 Apr 2001     Volume: 10 Number: 641

Today's topics:
    Re: Q: Units of Measurement in Convert-Units <ritchie@fnal.gov>
    Re: Q: Units of Measurement in Convert-Units <ren@tivoli.com>
    Re: Remove every other character? (Craig Berry)
    Re: Remove every other character? <jeffp@crusoe.net>
    Re: Remove every other character? <joe+usenet@sunstarsys.com>
    Re: Sending data from CGI script to other application <moiraine{NOSPAM}@qwest.net>
    Re: speed of strings and arrays? <dan@tuatha.sidhe.org>
    Re: Using ftell() and fseek() <ren@tivoli.com>
    Re: using modules over a network (Tad McClellan)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 05 Apr 2001 18:10:05 -0500
From: "David J. Ritchie" <ritchie@fnal.gov>
Subject: Re: Q: Units of Measurement in Convert-Units
Message-Id: <3ACCFB4D.B7A3C466@fnal.gov>



Robert Rothenburg wrote:

> Ok, I'm doing a long-needed re-write of the Convert-Units package in
> Perl and need some advice as to how to implement certain features.

You might find it useful to look at:

http://www.fnal.gov/fermitools/abstracts/siunits/abstract.html

A portion of the abstract follows...


> Abstract
>
> The SI Library of Unit-Based Computation
>
> Scientific programmers typically make heavy use of a programming language's native numeric data types. Such practice, however, obscures the diverse
> intentions (e.g., distances, masses, energies, momenta, etc.) that any such purely numeric value could represent.
>
> While limitations in programming language expressiveness and compiler technology have historically made such efforts difficult, the SI Library, known as SIunits,
> provides, in a modern programming language (C++), a convenient means of expressing, computing with, and displaying numeric values with attached units. The
> fundamental requirements, (1) to apply compile-time type-checking while (2) avoiding time and space overhead at run-time, have been met. Thus, SIunits
> enables automated (compile-time) checking of the dimensions of the numeric values within a computer program, and so provides the well-known benefits of
> type-safety to a new category of computing contexts.
>

David

--
ritchie@fnal.gov
http://home.fnal.gov/~ritchie/




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

Date: 05 Apr 2001 16:07:14 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Q: Units of Measurement in Convert-Units
Message-Id: <m3itkjcayl.fsf@dhcp9-175.support.tivoli.com>

On Thu, 05 Apr 2001, wlkngowl@unix.asb.com wrote:

> The latter seems like the best way, but things get messy with
> loading different sets of ratios. So if I have one system:
> 
>   centimeters-inches = 2.54
>   centimeters-meters = 100
> 
> and another
> 
>   inches-feet  = 12
>   inches-yards = 36
> 
> and I want to combine the ratio matrices so that it can handle
> centimeters, meters, inches, feet and yards... what's the best
> algorithm to combine these or build the matrices?

I haven't given it much thought, but it seems that using matrices
complicates the problem.  It would be much easier to just have a
base unit for every type of measurement, and then define all other
units of that measurement as a ratio of the base unit.  So, for
example, you could use "meter" as the base unit of distance and then
define "inch" as .0254, "foot" as .3048, etc.

Now that I have given it some thought (though still not a lot), I
suppose it might be advantageous to have a base unit per system.  But
I would still think that an overall base unit is the way to define the
system base units.  This way, you would still have "meter" as the base
unit, but then perhaps "foot" would be designated the system unit for
whatever that system is, and defined in terms of meter.  Then all of
the other units in that system (which is what, not English as that's
what you're using to refer to the more esoteric units) would be
defined as a ratio from "foot".

> Another question/issue is for naming schemes. Say I have different
> definitions for a unit depending on the system:
> 
>   point = 1/120th inch (traditional English)
>   point = 1/72 inch    (Typography/PostScript)
>   point = 1/72.27 inch (Typograph/European)
> 
> It's easy to say in a context what a default "point" is. But what if
> I want to convert PostScript points to European points? My thoughts
> are to have a naming scheme like the following:
> 
>   postscript-point
>   european-point
>   traditional-point
> 
> with "point" being an alias for a default (in the above,
> "postscript-point").  This seems like the closest to a natural
> language way of differentiating schemes rather than something
> computeresque like "point::postscript".

Honestly, I prefer System::Unit (eg. "PostScript::point").  But you
could certainly allow for aliases, and have default aliases of
system-unit.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Thu, 05 Apr 2001 22:34:09 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Remove every other character?
Message-Id: <tcpsn15b0cq381@corp.supernews.com>

Dmitry Epstein (mitiaNOSPAM@northwestern.edu.invalid) wrote:
: What would be an elegant (and preferably efficient) way to remove every
: other character from a string?  What if the values of all such
: characters are the same (but there are other characters with this value
: as well)?

  s/(.).?/$1/sg;

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "When the going gets weird, the weird turn pro."
   |               - Hunter S. Thompson


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

Date: Thu, 5 Apr 2001 19:22:33 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Remove every other character?
Message-Id: <Pine.GSO.4.21.0104051920370.23266-100000@crusoe.crusoe.net>

On Apr 5, Craig Berry said:

>Dmitry Epstein (mitiaNOSPAM@northwestern.edu.invalid) wrote:
>: What would be an elegant (and preferably efficient) way to remove every
>: other character from a string?  What if the values of all such
>: characters are the same (but there are other characters with this value
>: as well)?
>
>  s/(.).?/$1/sg;


#!/usr/bin/perl

use Benchmark;

my $str = random_string(101);

timethese(-5, {
  craig => \&craig,
  japhy => \&japhy,
  unpack => \&unpack,
});


sub craig {
  my $string = $str;
  $string =~ s/(.).?/$1/sg;
  return $string;
}


sub japhy {
  my $string = reverse $str;
  my $len = length $string;
  my $new;
  do { $new .= chop($string), chop($string) } while ($len -= 2) > 0;
  return $new;
}


sub unpack {
  my $string = $str;
  my $len = length $string;
  my $fmt = 'A x ' x ($len/2);
  $fmt .= 'A' if $len & 1;
  return join '', unpack $fmt, $string;
}


sub random_string {
  return join '', map +('A' .. 'Z')[rand 26], 1 .. shift;
}


__END__

Benchmark: running craig, japhy, unpack, each for at least 5 CPU seconds...
     craig:   406.87/s (n=2132)
     japhy:   855.60/s (n=4278)
    unpack:  1147.65/s (n=6094)


-- 
Jeff "japhy" Pinyan      japhy@pobox.com      http://www.pobox.com/~japhy/
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734




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

Date: 05 Apr 2001 20:41:07 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: Remove every other character?
Message-Id: <m3n19usvvg.fsf@mumonkan.sunstarsys.com>

Jeff Pinyan <jeffp@crusoe.net> writes:

> #!/usr/bin/perl
> 
> use Benchmark;
> 
> my $str = random_string(101);
> 
> timethese(-5, {
>   craig => \&craig,
>   japhy => \&japhy,

    mask => \&mask,

>   unpack => \&unpack,
> });

  sub mask {
    my $string = $str;
    return "$string" & ("\xff\x00" x length $string);
  }

[...]

> __END__
> 
> Benchmark: running craig, japhy, unpack, each for at least 5 CPU seconds...
>      craig:   406.87/s (n=2132)
>      japhy:   855.60/s (n=4278)

        mask:  ???????/s (n=??????)

>     unpack:  1147.65/s (n=6094)

-- 
Joe Schaefer       "Technological progress is like an axe in the hands of a
                                   pathological criminal."
                                               --Albert Einstein


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

Date: Thu, 05 Apr 2001 18:50:20 -0700
From: A_Geekette <moiraine{NOSPAM}@qwest.net>
Subject: Re: Sending data from CGI script to other application
Message-Id: <3ACD20DC.98F6CFFC@qwest.net>

David Pratt wrote:

> I have tried the FAQ and books and google.com to find the answer to this.
> It's probably easy so apologies if it is.
>
> Using CGI.pm, I have a front end CGI script to an program that generates a
> file related to protein structures (not particularly important that bit).
> The CGI script allows options to be set by the user. Once submitted the
> script reads these options and I want now to send them to the other program
> which generates the output. Initially I was simply sending them via
>
> system "make_surf -radius $radius -size $size" etc.
>
> However, when running under perl -T as I have to to allow this to be safe,
> perl complains about unsafe usage.
>
> What is the safe way of passing information, having untainted it, to
> subsiduary applications. This information also includes the random number of
> the CGITempxxxxx file.
>
> Thanks for any help
>
> Dave

Part of the problem is forking.  Under -wT forking is bad.
IMHO:
formA.cgi - generates form where user can enter choices.  The submit then calls
output.cgi.
output.cgi - This script includes a generation module.

GenData.pm-This module accepts choices given, and outputs the data.

output.cgi-displays the output generated by GenData.pm.

www.perldoc.org  POD: perlmod.
There are others as well that will help with formatting of the module.


--
Geekette

"Try Not.  Do or do not.  There is no try."
-If you don't know who said this,
I don't want to talk to you. ;-)

"Nothing is impossible, no matter how improbable."
-Anonymous




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

Date: Fri, 06 Apr 2001 01:42:41 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: speed of strings and arrays?
Message-Id: <la9z6.87806$Ok4.6956139@news1.rdc1.ct.home.com>

Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
>> Using arrays, i wonder if the (push, pop) and (shift,unshift) operators are
>> of same efficiency. The perlfunc manpage speaks of 'moving everything'
>> for the latter. I guess, this is just a picture, or?

> No, it's for real.  A Perl array is an actual array (of pointers to the
> scalar values).  The push and pop operators work on the upper end of
> the array and take unit time (unless push requires re-allocation).
> shift and unshift operate at the beginning and the rest of the array
> is copied every time.  Again, arrays are rarely so big that it matters.

This isn't entirely true. Perl keeps a pointer to the 'real' beginning of
the array under the hood. If you shift and then unshift, perl doesn't copy
anything because it doesn't need to. It's only when you unshift things
such that there is no 'extra' space on the beginning that perl has to move
things.

>> Are (huge) strings and arrays (with a dynamic history) contiguous in memory,
>> or twofold addressed and scattered? I think the latter would make sense for
>> 'liquid' data with todays processors, but then again, i am just a fortraner.

> AFAIK Perl strings must be contiguous.  Unless the hardware and the
> C compiler conspire to do scattered storage in an absolute transparent
> way, Perl doesn't do it.

Both the primary array structure and strings must be contiguous. This is
generally not a problem unless you've managed to eat up all your process'
virtual memory, though that is certainly possible. (Not enourmously easy,
but certainly doable if you've fragmented things badly enough)

				Dan


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

Date: 05 Apr 2001 15:51:05 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Using ftell() and fseek()
Message-Id: <m3n19vcbpi.fsf@dhcp9-175.support.tivoli.com>

On Thu, 5 Apr 2001, milliwave@rfengineering.freeserve.co.uk wrote:

> I would like someone to inform me how I would go about using the
> above two functions ftell() and fseek() to move within a file

ftell() and fseek() ??  Those are the system calls, but the Perl
functions are simply tell and seek.

> for example if I want to move to "five" and print everything which
> follows into another file how would I go about using the above
> functions in Perl?

'move to "five"' isn't really the type of thing for which you use
seek.  Is there some reason that you want (or need) to solve this
problem with tell and seek?  Otherwise, just use:

[file.txt contents moved to DATA section]

#!/usr/bin/perl
while (<DATA>) {
  print if /^five$/ .. 0;
}
__DATA__
one
tow
ther
five
two
three
four
__END__

-- 
Ren Maddox
ren@tivoli.com


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

Date: Thu, 5 Apr 2001 20:13:25 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: using modules over a network
Message-Id: <slrn9cq2h5.kd2.tadmc@tadmc26.august.net>

Kim C <kimmfc@mydeja.com> wrote:
>
>Is it possible to use a module located across a network?


What does "across a network" mean when you say it?

I think your real question is in Perl FAQ, part 8:

   "How do I add a directory to my include path at runtime?"

You must have missed that one when you searched the Perl FAQ
before posting.


>push @INC , '\\some_box\shared_dir' ## location of 'foreign_module.pm'
              ^^

So "across a network" means "on NFS" or similar then?

Try running this Perl code and look at the output:

   $_ = '\\some_box\shared_dir';  # 2 backslashes
   print "$_\n";

   $_ = '\some_box\shared_dir';   # 1 backslash
   print "$_\n";


I am pretty sure that you can use sane slashes even on your platform.

It is easy to get things wrong with backslashes and quoting.

I recommend using forward slashes even on Windows.

(it is only the command interpreter that insists on backwards slashes).


>use foreign_module;

>This generates the error: 
>	"Can't locate foreign_module.pm in @INC..."


All of the messages that perl might issue are documented in the
perldiag.pod man page. If you had looked up your message de jure
(or had perl look it up for you by putting "use diagnostics;"
near the top of your program), you would have avoided
your error above.


>and then displays all valid paths in @INC (all are local).  The
>network path that was added in the first line of code is not
>displayed, though it is there if the contents of @INC are explicitly
>printed.  This leads me to believe the paths in @INC are validated
>before use 


No, the "use" happens *before* your push() happens though.


>and I'm making some kind of error in defining the network
>path I need.


"use" is compile-time.

push() is run-time.

compiling happens before running  :-)


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


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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


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