[18471] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 639 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 5 18:06:35 2001

Date: Thu, 5 Apr 2001 15:05:17 -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: <986508315-v10-i639@ruby.oce.orst.edu>
Content-Type: text

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

Today's topics:
        Authen::PAM Question... <bhess@techrg.com>
        changing package variables k_k@planet.nl
    Re: changing package variables <jeffp@crusoe.net>
        ftell() an fseek() <milliwave@rfengineering.freeserve.co.uk>
        ftell() and fseek() with perl <milliwave@rfengineering.freeserve.co.uk>
        HELP NEEDED!!!!! <F8864@jingting.edu>
    Re: HELP NEEDED!!!!! (Steve)
    Re: How to do Quasi search engine in Perl? <nickysantoro@yahoo.com>
    Re: maximum value of a list <djberge@uswest.com>
    Re: Most efficient way to extract unique array elements <iltzu@sci.invalid>
    Re: Newbies welcome <centreman_19@NOSPAMyahoo.com>
        opening several Sendmail processes with Perl <ghardisty@asia-net.com>
    Re: Perl script causing Apache to hang under MS Win 200 (Steve)
    Re: Please Help <datm@qwest.net>
        Q: Units of Measurement in Convert-Units <wlkngowl@unix.asb.com>
    Re: Q: Units of Measurement in Convert-Units (Abigail)
    Re: Regular Expression Help (Easy Question) - Another O (Randal L. Schwartz)
    Re: Regular Expression Help (Easy Question) - Another O (Sweth Chandramouli)
    Re: Regular Expression Help (Easy Question) - Another O <magrav@wnt.sas.com>
    Re: Regular Expression Help (Easy Question) - Another O <magrav@wnt.sas.com>
    Re: Regular Expression Help (Easy Question) - Another O (Sweth Chandramouli)
    Re: Regular Expression Help (Easy Question) - Another O <ren@tivoli.com>
        Using ftell() and fseek() <milliwave@rfengineering.freeserve.co.uk>
        Want Lisp-like state machine impl. <cadet@alum.mit.edu>
    Re: What level of Perl needed for my system() call to w <gary@db.stanford.edu>
    Re: Where to find Register script ? <bcoon@sequenom.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 5 Apr 2001 14:35:26 -0400
From: "Bill Hess" <bhess@techrg.com>
Subject: Authen::PAM Question...
Message-Id: <tcpekb4ddtqn30@corp.supernews.com>

Is it possible using Authen::PAM to autenticate a user's login password if
the user is not running the script himself.  A good example of this would be
in trying this in a CGI script where the script it typically run by 'nobody'
(if you are using Apache)
When running my test program shown below, I can validate myself, but not
another user...
Am I approching this wrong by using Authen::PAM?



--

Bill Hess - Technology Resource Group






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

Date: Thu, 05 Apr 2001 22:02:23 +0200
From: k_k@planet.nl
Subject: changing package variables
Message-Id: <3ACCCF4F.1585622D@planet.nl>

hello,

Is it possible to change variables in a package and reuse the changed
values without having to recompile that particular package.
Something like this:

XXX.pm
------------------------
package variables;

$var1 = 0x00;
$var2 = 0x01;
$var3 = 0x02;


@message1 = ($var1, $var2, $var3);


test1.scr
-------------------------

Send( \@message1 );


$XXX::var1 = 0x04;
$XXX::var2 = 0x05;
$XXX::var3 = 0x06;

# Send message again with changed parameters (does not work this way)
Send( \@message1);

--------------
How does one change parameters defined in a package? Another way is
define the parameters in a separate file and recompile that package
after changing its values, but is not recommended Perl style.
Any suggestions ??



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

Date: Thu, 5 Apr 2001 16:32:54 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: changing package variables
Message-Id: <Pine.GSO.4.21.0104051625160.23266-100000@crusoe.crusoe.net>

[posted & mailed]

On Apr 5, k_k@planet.nl said:

>Is it possible to change variables in a package and reuse the changed
>values without having to recompile that particular package.

>XXX.pm
>------------------------
>package variables;
>
>$var1 = 0x00;
>$var2 = 0x01;
>$var3 = 0x02;

These variables, although they exist in XXX.pm, are in the namespace
variables::.  Therefore, when you say:

>$XXX::var1 = 0x04;
>$XXX::var2 = 0x05;
>$XXX::var3 = 0x06;

you're not getting THEM.  You need to do:

  $variables::var1 = ...;

Like so.

As for your dynamic array question, I suggest not using an array at
all.  You could use a function instead:

  package variables;

  ($x,$y,$z) = (0x01, 0x02, 0x03);

  sub MESSAGE () { return ($x, $y, $z) }

Which you would then use as:

  Send( [ variables::MESSAGE() ] )

-- 
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: Thu, 5 Apr 2001 21:30:15 +0100
From: "Milliwave" <milliwave@rfengineering.freeserve.co.uk>
Subject: ftell() an fseek()
Message-Id: <9aikgh$e79$1@news7.svr.pol.co.uk>

Hello,

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?

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?

file.txt contents

one
tow
ther
five
two
three
four
end of file

cheers
Ken





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

Date: Thu, 5 Apr 2001 21:22:55 +0100
From: "Milliwave" <milliwave@rfengineering.freeserve.co.uk>
Subject: ftell() and fseek() with perl
Message-Id: <9aik2p$dr4$1@news7.svr.pol.co.uk>

Hello,

I have spent some of my time trying to find how to use the functions ftell()
and fseek(),
mainly using he perl cammel book. But have found no examples showing how to
use the above
with perl? Can you provide me with an example?

Say for example you have the following file name
file.txt   #containing the following lines

One
two
Three
4
five
twelve
moon
six

if I want to have a pointer pointing towards  "five" how would I achieve
this using the above functions?
And I want to read everything below "five" in sequence and write it out to
another_file_.txt

Cheers







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

Date: Thu, 05 Apr 2001 14:07:09 -0400
From: OOooooH Yeah <F8864@jingting.edu>
Subject: HELP NEEDED!!!!!
Message-Id: <3ACCB44D.4BFEAB97@jingting.edu>

Hi guys!

     I am new to this ...just having a little bit of problem with this
code...when executed it prints out  not just the HTML code but also
displays the perl code which it isn't suppose to.  I can't figure out
why it is showing perl code....Any help would be greatly appreciated....

here is the code..

#!/usr/bin/perl

use CGI;

print "Content-type: text/html \n\n";

#read (STDIN, $query_string, $ENV{'CONTENT_LENGTH'});

print "<html><body
background=http://www.blah.com/~cgi/csc5750/bground1.jpg>";

if ($ENV {REQUEST_METHOD} eq 'GET')
{
 $user_input = $ENV{QUERY_STRING};
}
else
{
#$user_input = $query_string;
#chomp($user_input);
 chomp($user_input=<STDIN>);
}


%input;
$delim = ";";

$remote_host = $ENV{'REMOTE_HOST'};
#$order_file_name ="orders/orders.txt"; # "orders/".$remote_host;
$order_file_name ="orders/".$remote_host;

if($user_input eq 'd=cart'){
 if(-e $order_file_name){

  &view_cart();

  exit;
 } else {

  print "<center><h2>Your Shopping Cart is empty .
<BR><BR>";
         print '<table><tr><td valign="top"
align=center>&nbsp;<p><big>search books</big></p>
  <form method="POST"
action="http://www.blah.edu/~cgi/user-cgi/book.pl">
  <strong>Search:</strong><input type="text" name="string"
size="20"><input type="submit" value="Search" name="search">
  </form>

  </td></tr></table>

  ';

print '<table><tr><td valign="top" align=center>&nbsp;
  <form method="POST"
action="http://www.blah.edu/~cgi/user-cgi/empty_cart.pl">
  <p align=center><input type="submit" value="Empty Cart" name="B1"></p>

<p align=center><a href
="http://www.blah.edu/~cgi/csc5750/project/search.html"><input
type="button" value="Buy more" name="buy"></a></p>
</form>

  </td></tr></table>
  ';
print "<p><a href=http://www.blah.edu/~cgi/project/main.html><img
SRC=http://www.cs.wayne.edu/~hassan/csc5750/email2.gif ALIGN=\"center\"
> </A>";
  exit;
 }
}

&parsedata();

&appendtofile();
&view_cart();




sub parsedata(){
 @key_value_pairs = split(/&/, $user_input);
 foreach $key_value(@key_value_pairs){
  ($key,$value)=split(/=/, $key_value);
  $value =~ tr/+/ /;
  $input{$key}=$value;

 }
}

sub appendtofile(){

if (-e $order_file_name) {
 open(order_file, $order_file_name)|| die "Cannot open $order_file_name
for reading\n" ;

 while (<order_file>) {
  chop;
  ($item_id, $item_name, $item_price, $item_qty) = split(/$delim/,$_);


 }
 close (order_file);
}
else
{
 open (order_file, ">> $order_file_name")  || die "CAN'T CREATE
FILE $order_file_name";
 close (order_file);
}



open(order_file, ">>$order_file_name") || die "Cannot open
$order_file_name for writing\n";


if ($input{'ITEM_QTY'} > 0)
{
 print order_file
$input{'ITEM_ID'}.$delim.$input{'ITEM_NAME'}.$delim.$input{'ITEM_PRICE'}.$delim.$input{'ITEM_QTY'};

 print order_file "\n";
}
else
{
 print "<center><h3>Quantity entered was 0, Please go back and enter a
valid ";
 print "quantity for at the item</h3></center>";

 exit;
}
close (order_file);
}

sub  view_cart(){

if (-e $order_file_name) {
open(order_file, "$order_file_name") || die "Cannot open
$order_file_name for reading\n";

$sub_total = 0;
print "<body
background=http://www.blah.edu/~cgi/csc5750/project/bground1.jpg>";
 print "<form method=post
action=\"http://www.cs.wayne.edu/~hassan/csc5750/register.html\">";
 print "<center><table border=0 cellspacing=0
cellpadding=0><caption><font SIZE=+1>INVOICE<\/font><\/caption>";
 print '<tr><td align=center><B><H3>ISBN NO<BR></td><TD
align=center><B><H3>Book Title</TD><TD><B><H3>Qty</TD>';
 print '<TD align=center><B><H3>Unit Price</TD><TD><B><H3>Item
Total</TD></tr>';
while(<order_file>){
chop;
($item_id,$item_name,$price,$quantity) = split(/$delim/, $_);
 print "<tr>";
 $item_total = $price * $quantity;
 $sub_total = $sub_total + $item_total;
 print "<td align=center>$item_id<\/td><td align=left>$item_name<\/td>";

 $item_total = &Currency ($item_total);
 $price = &Currency($price);
 print "<td align=right>$quantity<\/td><td align=right>$price<\/td><td
align=right>$item_total<\/td><\/tr>";
}
 $tax = $sub_total * 0.06;
 $shipping = ($sub_total < 50)? 0 : $sub_total * 0.1;
 $total = $sub_total + $tax + $shipping;
 $sub_total = &Currency($sub_total);
 $total = &Currency($total);
 $shipping = &Currency($shipping);
 $tax = &Currency($tax);
 print '<TR><TD colspan=5>&nbsp;</TD>';
 print "<tr align=left><td colspan=3>&nbsp;<\/td><td align=left><B>Sub
Total: <\/td><td       align=right>$sub_total<\/td><\/tr>";
 print "<tr align=left><td colspan=3>&nbsp;<\/td><td align=left><B>State
Tax 6\%: <\/td><td align=right>$tax<\/td><\/tr>";
 print "<tr align=left><td colspan=3>&nbsp;<\/td><td
align=left><B>Shipping:<\/td><td align=right>$shipping<\/td><\/tr>";
 print "<tr align=left><td colspan=3>&nbsp;<\/td><td
align=left><B>Total:<\/td><td align=right>$total<\/td><\/tr>";
 print "<\/table></center>";

# print "<br><br><center><input type=submit value=\"CHECKOUT\">";
print "<center><A
href=http://www.blah.edu/~cgi/csc5750/project/register.html><img
SRC=http://www.blah.edu/~cgi/csc5750/project/book4.gif ALIGN=\"center\"
";

print "<FONT COLOR=yellow><CENTER><A
HREF='http://www.cs.wayne.edu/~hassan/csc5750/project/register.html'>CHECKOUT</CENTER></FONT></A>";

print '</form></center>';




print '
<form method="POST"
action="http://www.blahblah.com/~cgi/user-cgi/empty_cart.pl">
  <center><input type="submit" value="EMPTY Cart" name="B1"></center>
</form>';

}
close (order_file);
}



sub  Currency {
 my $price = $_[0];
 $price = sprintf("%.2f", $price);
 $price = "\$".$price;
 return $price;
}
print "</body></html>";


Thank You




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

Date: 5 Apr 2001 18:49:37 GMT
From: steve@zeropps.uklinux.net (Steve)
Subject: Re: HELP NEEDED!!!!!
Message-Id: <slrn9cpf77.b55.steve@zero-pps.localdomain>

On Thu, 05 Apr 2001 14:07:09 -0400, OOooooH Yeah wrote:
>Hi guys!

Hi 

The subject line isn't very helpful is it?  Presumably if you're
posting here you're asking for help. 

>
>     I am new to this ...just having a little bit of problem with this
>code...when executed it prints out  not just the HTML code but also
>displays the perl code which it isn't suppose to.  I can't figure out
>why it is showing perl code....Any help would be greatly appreciated....

This is a frequently asked question so is probably answered in the perl
FAQ or in the CGI FAQ (specifically the perl CGI FAQ Q4.16). 


>here is the code..
>
>#!/usr/bin/perl

Usually advisable to run with -wT 

>use CGI;

Why load the module if you're not going to use the shorcuts it provides. 

I won't go on because it just looks asthough I'm being picky. 

It's a good idea to read the CGI documentation that comes with perl and
the various FAQs that are around. "perldoc CGI" should get you going.   

-- 
Cheers
Steve              email mailto:steve@zeropps.uklinux.net

%HAV-A-NICEDAY Error not enough coffee  0 pps. 

web http://www.zeropps.uklinux.net/

or  http://start.at/zero-pps

  7:26pm  up 62 days, 20:10,  2 users,  load average: 1.04, 1.02, 1.00


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

Date: 5 Apr 2001 18:35:06 GMT
From: Nicholas <nickysantoro@yahoo.com>
Subject: Re: How to do Quasi search engine in Perl?
Message-Id: <9aidsq$a2g$1@agate.berkeley.edu>

Thanks for the suggestions. I think that building a regexp to match
at runtime is probably what I want to do. First, one of the features
I want is to be able tos how similar results, i.e., if I search
for Horror movies 60-90 minutes long, it returns all five in that
category, but secondarily it returns the 90-120 min movies next.
I haven't reaaly used databases that much and don't know how
hard that is to do. At least in Perl, I have an idea of how to build 
a range to match.
Thanks,



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

Date: Thu, 05 Apr 2001 16:46:14 -0500
From: Dan Berger <djberge@uswest.com>
Subject: Re: maximum value of a list
Message-Id: <3ACCE7A6.84ABB2C8@uswest.com>

<question regarding most efficient approach to finding maximum element
of array>

I used four different approaches and benchmarked them.  Here's the code:

#!/bin/perl

use Benchmark;
use List::Util qw(max);

@nums = qw(5 7 3 2 9 12 44 55 66 77 -4);
$x = 0;

timethese(100000,{
   map => q{
      map{ $x = $_ if $_ > $x } @nums;
   },

   max => q{
      max(@nums);
   },

   sort => q{
      @sorted = sort{ $a <=> $b } @nums;
   },

   foreach => q{
      foreach $i(@nums){ $max = $i if $i > $max};
   },
});

Here were the results:

Benchmark: timing 100000 iterations of foreach, map, max, sort...

foreach:  4 wallclock secs ( 3.14 usr +  0.00 sys =  3.14 CPU)
map:  9 wallclock secs ( 8.54 usr +  0.00 sys =  8.54 CPU)
max: 21 wallclock secs (21.04 usr +  0.00 sys = 21.04 CPU)
sort:  8 wallclock secs ( 9.11 usr +  0.00 sys =  9.11 CPU)

Machine was a Sun Microsystems Sunray.

Regards,

Dan



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

Date: 5 Apr 2001 21:56:40 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Most efficient way to extract unique array elements?
Message-Id: <986506855.4376@itz.pp.sci.fi>

In article <3ACBF22D.B080211C@earthlink.net>, Benjamin Goldberg wrote:
>
>Since the problem is to remove duplicates, giving a list which *has* no
>duplicates isn't necessarily the best way to go.

Using the same code but replacing "1 .. 1024" with "(1 .. 256) x 4", I
get the following results:

Benchmark: timing 1024 iterations of for, map, slice, undef...
       for:  4 wallclock secs ( 4.05 usr +  0.09 sys =  4.14 CPU)
       map: 28 wallclock secs (25.95 usr +  0.07 sys = 26.02 CPU)
     slice:  3 wallclock secs ( 2.61 usr +  0.04 sys =  2.65 CPU)
     undef:  3 wallclock secs ( 2.24 usr +  0.02 sys =  2.26 CPU)

It seems the time for "map" is almost unchanged, "for" gets noticeably
faster, but "slice" and "undef" gain even more than "for".  Removing the
"map" entry and running more iterations shows clearly that using a slice
is now almost twice as fast as a for loop.

Benchmark: timing 4096 iterations of for, slice, undef...
       for: 17 wallclock secs (16.08 usr +  0.02 sys = 16.10 CPU)
     slice: 10 wallclock secs ( 8.88 usr +  0.03 sys =  8.91 CPU)
     undef:  8 wallclock secs ( 7.86 usr + -0.01 sys =  7.85 CPU)

Just to check, I also tried a list of "(1) x 1024", which as expected
only made the above differences even more pronounced:

Benchmark: timing 8192 iterations of for, slice, undef...
       for: 20 wallclock secs (18.59 usr +  0.00 sys = 18.59 CPU)
     slice:  7 wallclock secs ( 6.65 usr +  0.02 sys =  6.67 CPU)
     undef:  5 wallclock secs ( 4.69 usr +  0.00 sys =  4.69 CPU)

Of course, any or none of these benchmarks might be realistic for any
given real world application.  When I've had to do something like this,
I usually _haven't_ expected a significant number of duplicates, but I
can well imagine situations where the opposite would be true.

Anyway, "undef @hash{@list};" seems to be fastest in all cases.

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla / Kira -- do not feed the troll.


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

Date: Thu, 5 Apr 2001 14:29:48 -0700
From: "Brandon Thornburg" <centreman_19@NOSPAMyahoo.com>
Subject: Re: Newbies welcome
Message-Id: <9aiobj$jvs$1@fremont.ohsu.edu>

If there was ever something that needed saying, this is It.
"A_Geekette" <moiraine{NOSPAM}@qwest.net> wrote in message
news:3ACB0843.24346AEE@qwest.net...
> Do you know what a newsgroup is for?  It's for communication.  It's for
people
> who have common interests to discuss them.  One of the topics of
conversation is
> a problem that someone is having.  A lot of times, people just need an
alternate
> perspective, because they've been working on a problem for a week straight
> without any real social contact so are going insane not to mention
berrating
> themselves for not figuring out something they're sure is a simple problem
and
> have to get it done now because they have an arrogant know-it-all slimball
of a
> boss breathing down their neck telling them how to do their job when the
boss
> knows next to nothing about the subject matter the boss is telling you
about
> ..................
> So, kindly take your arrogant, superior, freaking attitude and shove it
somewhere
> mildly to extremely uncomfortable...prefereably your prosterior, but any
orifice
> will do.
> --
> Geekette




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

Date: Thu, 05 Apr 2001 20:03:04 GMT
From: "George Hardisty" <ghardisty@asia-net.com>
Subject: opening several Sendmail processes with Perl
Message-Id: <Yb4z6.29623$8y.8216549@typhoon.austin.rr.com>

I maintain a list of about 95K users who want job information.  I keep the
list very clean of old addresses, etc.  I have a program in Perl that calls
a function to merge user data (for the dynamic url to unsubscribe, etc.)
into the message for the day and send.  I run through a loop of each iser
(95K of them) and each time call the function MailMerge (below) that call
the FieldSub routine.

I am using Redhat with the most recent version of sendmail.  For each user I
am basically starting a sendmail instance with "|/usr/lib/sendmail
$address".   The program gets sluggish and I am thinking there has to be a
less expensive way to do this ... like write out the files and start
sendmail separately or something ... but I am not sure.  Any advice for me?
I would just like this to run faster.  I understand qmail is a better MTA
for this type of job, but besides that is there a better way?

George
george@tapestry.net

sub MailMerge {
  my ($templatefile, $info, $address, $homedir);
  ($templatefile, $info, $address) = @_;
  #TEMPLATE is the text file with which data is merged
  open(TEMPLATE, "$templatefile") or die "Could not open
$homedir/$templatefile";
  open(MAILPIPE, "|/usr/lib/sendmail $address") or die "Could not run
sendmail.";
  while(<TEMPLATE>) {
    print MAILPIPE FieldSub($_, $info);
  }
  close(MAILPIPE);
  close(TEMPLATE);
}

sub FieldSub {
  my($string, $data) = @_;
  if ($string) {
    while ($string =~ /(<!--\[)(\w+)(\]-->)/) {
      if (defined $data->{$2}) {
        $string =~ s/(<!--\[)(\w+)(]-->)/$data->{$2}/;
      } else {
        $string =~ s/(<!--\[)(\w+)(]-->)/"<strong>Undefined field in
template:$2<\/strong>"/;
      }
    }
    return $string;
  } else {
    return "ERROR: empty template string???\n";
  }




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

Date: 5 Apr 2001 19:02:42 GMT
From: steve@zeropps.uklinux.net (Steve)
Subject: Re: Perl script causing Apache to hang under MS Win 2000 Pro
Message-Id: <slrn9cpg8s.bc1.steve@zero-pps.localdomain>

On Thu, 05 Apr 2001 14:43:57 GMT, Mark Warnes wrote:

>Has anyone else come across this problem and are there any
>solutions/suggestions as to what to do?

Will it serve ordinary HTML pages without problems, will it
serve other CGI scripts without problems.  Will the CGI run
from the command line on that machine etc.  Will other perl
scrits run on that machine (without CGI)?

-- 
Cheers
Steve              email mailto:steve@zeropps.uklinux.net

%HAV-A-NICEDAY Error not enough coffee  0 pps. 

web http://www.zeropps.uklinux.net/

or  http://start.at/zero-pps

  7:49pm  up 62 days, 20:33,  2 users,  load average: 1.19, 1.10, 1.05


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

Date: Thu, 05 Apr 2001 11:07:24 -0700
From: Dan Brown <datm@qwest.net>
Subject: Re: Please Help
Message-Id: <3ACCB45C.C6015F0@qwest.net>

If no mode is given for open, it is assumed that you are opening the
file for input (reading).  The print clearly shows that you want to open
the file for output (writing or appending).

From "perldoc -f open"

              If MODE is `'<'' or nothing, the file is opened
               for input.  If MODE is `'>'', the file is

If you change the open line to

   open (THEFILE,">/data1/hm/makers/bezoekers/$remote2");

for open write or

   open (THEFILE,">>/data1/hm/makers/bezoekers/$remote2");

for open append you should be good to go.

Dan

Waarddebon wrote:
> 
> Why doesn't this work ?
> 
> $remote2="today";
> open (THEFILE,"/data1/hm/makers/bezoekers/$remote2");
> print THEFILE "hi";
> close THEFILE;


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

Date: Thu, 05 Apr 2001 16:02:14 -0400
From: Robert Rothenburg <wlkngowl@unix.asb.com>
Subject: Q: Units of Measurement in Convert-Units
Message-Id: <3ACCCF46.94AA6311@unix.asb.com>


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.

The purpose of the module is to allow one to choose an appropriate
measurement system but to let one convert to the different measurement
systems as needed. So if you only need some basic length conversions,
Convert::Units::Length is fine. If for some reason you need to work with
traditional English units of measurement (converting cubits or furlongs
to kilometers for some reason) them Convert::Units::Length::English is
what you'd use.

One of the reasons I'm setting this up for different systems is that
units aren't always consistent: a "chain" or "link" has different
meaningins depending on "Gunther" of "Engineer's" suverying lengths you
are referring to; also, in older English systems a "point" is 1/120th of
an inch, not the PostScript 1/72 of an inch. Likewise, why not a plug-in
module to convert from meters to "li" for Chinese measurement systems.

What I need advice on is how to connect these different systems. I have
a base module where ratios are defined and a conversion matrix is built.
But I'd like to be able to tie other systems. Two general ideas:

One system inherits from another. So if you specify "kilometers" as a
unit for Convert::Units::Length::English, it looks in it's parent for
how convert that into something it understands (like "yards").

A parent system that looks for specified children. So you'd say
something like:

  use Convert::Units::Length qw(English Metric);

and it would load in the ratios for units of measurement it needs.

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?

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

Comments? Ideas? Advice?


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

Date: Thu, 5 Apr 2001 21:30:02 +0000 (UTC)
From: abigail@foad.org (Abigail)
Subject: Re: Q: Units of Measurement in Convert-Units
Message-Id: <slrn9cpoup.o7h.abigail@tsathoggua.rlyeh.net>

Robert Rothenburg (wlkngowl@unix.asb.com) wrote on MMDCCLXXIV September
MCMXCIII in <URL:news:3ACCCF46.94AA6311@unix.asb.com>:
,, 
,, 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.

Did you check out the units tools in the Perl Power Tools?

,, The purpose of the module is to allow one to choose an appropriate
,, measurement system but to let one convert to the different measurement
,, systems as needed. So if you only need some basic length conversions,
,, Convert::Units::Length is fine. If for some reason you need to work with
,, traditional English units of measurement (converting cubits or furlongs
,, to kilometers for some reason) them Convert::Units::Length::English is
,, what you'd use.
,, 
,, One of the reasons I'm setting this up for different systems is that
,, units aren't always consistent: a "chain" or "link" has different
,, meaningins depending on "Gunther" of "Engineer's" suverying lengths you
,, are referring to; also, in older English systems a "point" is 1/120th of
,, an inch, not the PostScript 1/72 of an inch. Likewise, why not a plug-in
,, module to convert from meters to "li" for Chinese measurement systems.
,, 
,, What I need advice on is how to connect these different systems. I have
,, a base module where ratios are defined and a conversion matrix is built.
,, But I'd like to be able to tie other systems. Two general ideas:
,, 
,, One system inherits from another. So if you specify "kilometers" as a
,, unit for Convert::Units::Length::English, it looks in it's parent for
,, how convert that into something it understands (like "yards").

Frankly, I fail to see why you want one system inherit the other. I
wouldn't say that for instance the centimeter refines the meter, so
the centimeter class should inherit from the metre class.

Having the programmer have to inherit Convert::Units::Length::English
before a user can use yards seems like pointless red tape just for the
sake of red tape to me.

,, A parent system that looks for specified children. So you'd say
,, something like:
,, 
,,   use Convert::Units::Length qw(English Metric);
,, 
,, and it would load in the ratios for units of measurement it needs.
,, 
,, 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

Typically, implementations of the units program use datafiles containing
lines like:

     foot     =  12 inches
     yard     =   3 foot
     feet     =     foot

A possibility is that you have a few "base" measurements (say, metre,
kilogram, second, etc). From that, you can make a topological sort
of the definitions and quickly map everything to standard units.
The reverse is trivial.

,, 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'd say set up base measurements, prefixes (kilo, mega, centi, etc),
then make a topological sort of the definitions so that each one is
defined in terms of things already defined, and then make a hash
that maps a unit to a set consisting of a ratio and a (possibly
empty) product of base measurements.

,, 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".
,, 
,, Comments? Ideas? Advice?


The naming issues have been solved by previous implementations of 'units'
before. I suggest looking at them.

But that has little to do with Perl.



Abigail
-- 
sub _ {$_ = shift and y/b-yB-Y/a-yB-Y/                xor      !@ _?
       exit print                                                  :
            print and push @_ => shift and goto &{(caller (0)) [3]}}
            split // => "KsvQtbuf fbsodpmu\ni flsI "  xor       & _


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

Date: 05 Apr 2001 11:12:58 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Regular Expression Help (Easy Question) - Another One
Message-Id: <m1zodvi5at.fsf@halfdome.holdit.com>

>>>>> "Max" == Max Gravitt <magrav@wnt.sas.com> writes:

Max> Thanks for the response!
Max> How about if I want to match a combination of letters where order
Max> doesn't matter and each letter can only be used 0 or 1 times?

Max> For example, I want to match "FJT", "JFT", "TJF", "T", "TJ", "JT",
Max> "FJ", "F", etc. 

Max> [FJT]* is close, but it allows "FFJT", "FFFFFJJJJJTTTT", etc.

Well, this'll get you there, but not quickly. :)

  /^(?=[FJT]*\z)(?!.*(.).*\1)/

First, make sure the string is entirely [FJT]*, then ensure that no
character is repeated (that's the expensive part, but for short strings,
probably no big whoop).

print "Just another Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Thu, 05 Apr 2001 18:13:24 GMT
From: sweth+perl@gwu.edu (Sweth Chandramouli)
Subject: Re: Regular Expression Help (Easy Question) - Another One
Message-Id: <8B2z6.25815$iU.4825096@news1.rdc1.md.home.com>

In article <u9vgojqmet.fsf@wcl-l.bham.ac.uk>,  <nobull@mail.com> wrote:
>Regular expressions are not good at matching things that _don't_
>contain something!
	Yes, but Perl's regular expressions aren't.  (Regular
Expressions, that is.)  Extensions like lookaround make this sort of 
thing very easy.

	-- Sweth.

-- 
Sweth Chandramouli ; <sweth+perl@gwu.edu>


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

Date: Thu, 05 Apr 2001 14:30:34 -0400
From: Max Gravitt <magrav@wnt.sas.com>
Subject: Re: Regular Expression Help (Easy Question) - Another One
Message-Id: <cdepctk4co7s6mslmrrp3avmbh4uq0i7ch@4ax.com>

On Thu, 05 Apr 2001 16:45:56 GMT, sweth+perl@gwu.edu (Sweth
Chandramouli) wrote:

>In article <2m2pctk1l1361n2v8m0ik41sfr6es65hbe@4ax.com>,
>Max Gravitt  <magrav@unx.sas.com> wrote:
>>How about if I want to match a combination of letters where order
>>doesn't matter and each letter can only be used 0 or 1 times?
>>
>>For example, I want to match "FJT", "JFT", "TJF", "T", "TJ", "JT",
>>"FJ", "F", etc. 
>	Should the empty string "" be considered a match,
>or not?  Technically, your description above allows it.

Yes, an empty string is a match.


>
>	-- Sweth.



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

Date: Thu, 05 Apr 2001 14:49:50 -0400
From: Max Gravitt <magrav@wnt.sas.com>
Subject: Re: Regular Expression Help (Easy Question) - Another One
Message-Id: <v9fpct818g3migfareo8vd951kkc839rms@4ax.com>

On Thu, 05 Apr 2001 17:32:14 GMT, sweth+perl@gwu.edu (Sweth
Chandramouli) wrote:

>In article <m3n19ve1wx.fsf@dhcp9-175.support.tivoli.com>,
>Ren Maddox  <ren@tivoli.com> wrote:
>>> For example, I want to match "FJT", "JFT", "TJF", "T", "TJ", "JT",
>>> "FJ", "F", etc. 
>[snip]
>>But neither of this is likely to help you in Java.  How about this:
>>
>>  /^[FJT]*$/ && /^[^F]*F?[^F]*$/ && /^[^J]*J?[^J]*$/ && /^[^T]*T?[^T]*$/
>	Well, since Java apps can use ORO and get the full Perl
>regex set, why not just use lookahead?  /x(?!.*x)/ matches any
>instance of x not followed at any point by another instance of x, or
>more colloquially, any unique instance of x.  Toss in a backreference
>and a character class, and (assuming as you did that an empty string
>is a valid match) /^(([TFJ])(?!.*\2))*$/ should work, and be easily
>extendable to any length set of valid characters.  (Replace the * with
>a + if the intended use should disallow empty strings.)

I hate to complicate things but ...
(?=...) positive lookahead operator (Perl5)
(?!...) negative lookahead operator (Perl5)
 ... are unsupported syntax in the "gnu.regexp" java package.

I didn't know until I tried to run with what Sweth and Ren came up
with.

Any way to do it without the lookahead operators?

>
>	-- Sweth.



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

Date: Thu, 05 Apr 2001 19:57:39 GMT
From: sweth+perl@gwu.edu (Sweth Chandramouli)
Subject: Re: Regular Expression Help (Easy Question) - Another One
Message-Id: <T64z6.25858$iU.4845967@news1.rdc1.md.home.com>

In article <v9fpct818g3migfareo8vd951kkc839rms@4ax.com>,
Max Gravitt  <magrav@unx.sas.com> wrote:
>I hate to complicate things but ...
>(?=...) positive lookahead operator (Perl5)
>(?!...) negative lookahead operator (Perl5)
>... are unsupported syntax in the "gnu.regexp" java package.
	Well, yes.  That's why I suggested using ORO instead.  If
you can't switch, you're stuck with basic regex capabilities, which
makes things much harder; Ren's final solution is one of the better
solutions in that case, but it doesn't scale well as the number of
characters increases.  That said, why do you need to use a regex for
validation?  Something like


%valid_char_hash = (
   F => 1,
   T => 1,
   J => 1
);
@chars = split //, $input;
for $char (@chars) {
   2 == ++$valid_char_hash{$char} 
     or die "Invalid or repeated char";
};

	can do what you seem to need, procedurally, in a very 
scalable manner.

-- 
Sweth Chandramouli ; <sweth+perl@gwu.edu>


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

Date: 05 Apr 2001 13:57:54 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Regular Expression Help (Easy Question) - Another One
Message-Id: <m3y9tfcgy5.fsf@dhcp9-175.support.tivoli.com>

On Thu, 05 Apr 2001, magrav@wnt.sas.com wrote:

> Any way to do it without the lookahead operators?

I did post a method that did it without lookahead, and I believe other
have now as well.  I think the one I actually liked best was something
like:

  /^[FJT]*$/ && ! /(.).*\1/

-- 
Ren Maddox
ren@tivoli.com


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

Date: Thu, 5 Apr 2001 21:33:02 +0100
From: "Milliwave" <milliwave@rfengineering.freeserve.co.uk>
Subject: Using ftell() and fseek()
Message-Id: <9aiklo$dvj$1@news5.svr.pol.co.uk>

Hello,

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

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?

file.txt contents

one
tow
ther
five
two
three
four
end of file

cheers
Ken






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

Date: Thu, 05 Apr 2001 19:21:04 GMT
From: David Bakhash <cadet@alum.mit.edu>
Subject: Want Lisp-like state machine impl.
Message-Id: <m3g0fn8vpr.fsf@alum.mit.edu>

Hi,

I'm writing because I'm implementing something in Perl now, and I'd
*really* like it to look Lispy.

I'm not too sure that Perl isn't capable, but it's certainly not as
straight-forward as if done in Common Lisp.

I'm writing a program for a system which, if it had it's own
custom-made language, would look like the following.  I'll try to
provide some background.

A "state" is a uniquely named entity (i.e. a name is provided,
e.g. `Q1').  It contains a list of required fields (parameters) that
must all be provided in order to enter this state, and potentially
some optional types of these fields.  Each state must list all of the
states it might possibly seek, as well as exception states it can
throw into (which are also just states, like any other).

In Common Lisp, I'd just write a macro:

(defstate Q1 (:throws (E0 E2 E4)
              :seeks (P2 P3))
  "This is Q1's description."
  ;; following is a list of parameter specifications
  (param-1
   param-2
   ;; ...
   person-id
   (person-name :type string) ; also a param, but with more type info
   ;; ...
   ) ; end of parameters
  ;; now begin implementation of the state
  (if (= param-1 ...)
      ;; then:
      (do-this person-id)
    ;; else:
    (goto-state P3 :first-param (+ param-2 3)
                   :second-param person-id
                   ;; ...
                   )
  ;; ...
  )

This is really beautiful.  I wish I could do this in Perl the way I
can in CL.  In CL, I'd make the macro so smart that it'd do all the
right things such that it would do error-checking and validation at
compile-time.

I'd really appreciate something elegant.  I do realize that Perl is
NOT Common Lisp, but I've noticed that people have been able to do
cool things with Perl.

One thing to note about my `defstate' macro above is that its
implementation handles the complexity, and the global ``state'' that's 
affected by each `defstate' definition.

thanks,
dave


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

Date: Thu, 05 Apr 2001 10:37:14 -0700
From: Gary W <gary@db.stanford.edu>
Subject: Re: What level of Perl needed for my system() call to work?
Message-Id: <3ACCAD4A.299D7D3C@db.stanford.edu>

Ren,
Thanks for tying. It seems to be that my Linux 6.2/Perl 5.005
combo necessitates me using the . command version, as in:
cd ../handlers
 ./process net://Eh:9613 90000000 > /dev/null

Which works for Linux 7.0/Perl 5.6 as well.
I still don't know if it is Perl limitation or not,
suspect not...
It looks like it was running tcsh, even though the
prompt was $ ! :(

Gary



 Maddox wrote:
> 
> On Wed, 04 Apr 2001, gary@db.stanford.edu wrote:
> 
> > From the console:
> >
> > Connecting on 171.64.75.93:9613 issuing command:
> > ../handlers/process net://Eh:9613 90000000 > /dev/null
> > at Wed Apr  4 09:54:41 2001
> >
> > (There is no carriage return in the actual command)
> 
> So the actual command being run is:
> 
> ../handlers/process net://Eh:9613 90000000 > /dev/null
> 
> right?
> 
> The only things I can think of are:
> 
> * Current directory isn't what's expected so the relative path isn't
> working.
> 
> * Something in the environment is different and that's leading to a
> failure of some kind.
> 
> Wish I could offer more insight....
> 
> --
> Ren Maddox
> ren@tivoli.com

-- 

Gary Wesley
Stanford       
"Life without music would be a mistake." F. Nietzsche


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

Date: Thu, 05 Apr 2001 13:59:33 -0700
From: Bryan Coon <bcoon@sequenom.com>
Subject: Re: Where to find Register script ?
Message-Id: <3ACCDCB4.4F00E75B@sequenom.com>

hugo botha wrote:

> Hi all.
>
> I am looking for a perl script that allows members to signup to become a
> member and auto receive a username and password.
>
> Any help ?
>
> hugo.b@derivs.com
>
> Thanks

Check out AMLite (Account Manager Lite).  It's pretty cool and free.

http://cgi.elitehost.com/acctlite/

Or you could just roll your own.

Bryan



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

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


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