[6292] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 914 Volume: 7

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 7 23:13:21 1997

Date: Fri, 7 Feb 97 20:00:23 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 7 Feb 1997     Volume: 7 Number: 914

Today's topics:
     4-arg select() and buffered I/O question (Ric Steinberger)
     Re: Commercial success stories using perl. (Paul D. Smith)
     Re: Fast list search (Charles DeRykus)
     format print produces blank pages <charliew@atlml1.attmail.com>
     Re: Frivilous request for new Perl function (Charles DeRykus)
     Re: Gregorian to Julain date conversion (Patrick Duff)
     Re: Help: $| does not flush stream (Dave Thomas)
     Re: How do child processes talk to each other? [Q] (Ric Steinberger)
     How to handle a "@" (not "\@") in a string ? <klcho5@student.monash.edu.au>
     Re: How to handle a "@" (not "\@") in a string ? (Dave Thomas)
     Re: How to peek at next line of STDIN? (repost) <merlyn@stonehenge.com>
     Matt's Script: SSI Random Banner Generator (Thomas J. Forbes)
     Re: negative zero???? (Patrick Duff)
     OLE adds a byte at end of string? (Patrick Duff)
     Re: Perl vs Korn Shell (Ilya Zakharevich)
     Re: perl? (Clay Irving)
     program to recognize and respond to FAQ questions <fawcett@nynexst.com>
     Re: Removing extra spaces (Dave Thomas)
     Re: Removing extra spaces (Tad McClellan)
     Re: Rounding decimal numbers (Patrick Duff)
     Search Engine in Perl <senthil@ece.vill.edu>
     Re: Sending results to two frames at once (Roger Lewau)
     Slightly Nifty, but possibly dangerous perl. <bignell@netcom.ca>
     Timing perl with granularity less than .1 seconds <dprice@healthdesk.com>
     Re: Timing perl with granularity less than .1 seconds (Dave Thomas)
     Re: turn 1,2,3,5 into 1-3,5 ? (Patrick Duff)
     Re: why can't "system" return a long? <guenther@lunen.gac.edu>
     Digest Administrivia (Last modified: 8 Jan 97) (Perl-Users-Digest Admin)

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

Date: 7 Feb 1997 23:58:49 GMT
From: ric@isl.sri.com (Ric Steinberger)
Subject: 4-arg select() and buffered I/O question
Message-Id: <5dgfjp$lim@unix.sri.com>

The Camel book warns: "Mixing buffered I/O (like read or
<HANDLE>) with four-argument select is asking for trouble.  Use
sysread instead."

Could someone explain exactly why?  I have been using select()
for sometime to tell me when I can read a socket or pipe handle.
When select() indicates that the filehandle can be read without
blocking, I have been using the while(defined($line = <HANDLE>))
style to read it, with no [known] ill effects.  
	Using sysread() would be somewhat inconvenient, as I need
to be able to read newline-terminated lines of varying length.
What sort of things should I be worryting about?  A short answer
or pointer to a man page or other document would be much
appreciated.  Thanks so much.....

-- 
Ric Steinberger                 Email: ric@sri.com
SRI Consulting                  Phone: 415.859.4300
333 Ravenswood Ave  AH301       Pager: 415.907.4598
Menlo Park CA 94025             FAX:   415.859.2986


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

Date: 07 Feb 1997 19:00:45 -0500
From: psmith@baynetworks.com (Paul D. Smith)
To: Steve Vanechanos <stevev@dynamicweb.com>
Subject: Re: Commercial success stories using perl.
Message-Id: <p5hgjoupxu.fsf@baynetworks.com>

Check out PureAtria's new ClearGuide product.

PureAtria (the recently merged companies of Pure Software and Atria
Software) is arguably the leading company for software development tools
(source control management, testing, benchmarking, etc.) for UNIX
platforms.

Atria did extensive work with Perl5 and are integrating it into both
their baseline product (ClearCase) and their new flagship process
management product (ClearGuide).  They embed a perl interpreter in their
product and use it as their scripting language: all their triggers,
etc. can be written in perl and run directly.  On a lesser note, they've
been using Perl as an installation/patch/etc. scripting language for a
while (they ship perl with their product).

Check out http://www.pureatria.com/ for more details on ClearGuide, etc.

-- 
-------------------------------------------------------------------------------
 Paul D. Smith <psmith@baynetworks.com>         Network Management Development
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
-------------------------------------------------------------------------------
     These are my opinions--Bay Networks takes no responsibility for them.


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

Date: Sat, 8 Feb 1997 01:20:15 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Fast list search
Message-Id: <E59Fpt.CM5@bcstec.ca.boeing.com>

In article <qumu3np7xpc.fsf@cyclone.stanford.edu>,
Russ Allbery  <rra@cs.stanford.edu> wrote:
>Tom Christiansen <tchrist@mox.perl.com> writes:
>
>> I think we should add a new perl built-in called faq().  For example,
>> faq("string in list") might return:
>
>>   5.5) How can I tell whether an array contains a certain element?
>
>You know, that might not be that bad of an idea, actually.  use FAQ
>anyone?
>
>-- 
 
It'd probably be totally FAQotten.

(Ducking again,)

--
Charles DeRykus
ced@carios2.ca.boeing.com


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

Date: Tue, 04 Feb 1997 15:45:44 -0500
From: Charlie Wu <charliew@atlml1.attmail.com>
Subject: format print produces blank pages
Message-Id: <32F79FF8.362E@atlml1.attmail.com>

hi dear perl gurus:

i am preparing a report generated by database isql queries ... and i
use the "format tool" provided by perl, it prints the header on each
page, and formats the data correctly... however, there's a ^L at the
end of every page - causing the printer to spit out a blank page every
other page ... very annoying - of course i can write this to a file
and then filter out the ^Ls but can someone enlighten me how that
^L got in there - a perl bug??? or is the printer stupid...

thanks. email reply greatly appreciated ... since it's hard to go thru
hundreds of posts every day here - i use netscape news reader which has
NO search capability :(

thanks!!!

Charlie Wu
charliew@atfppc.ppc.att.com


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

Date: Sat, 8 Feb 1997 01:16:09 GMT
From: ced@bcstec.ca.boeing.com (Charles DeRykus)
Subject: Re: Frivilous request for new Perl function
Message-Id: <E59FIy.CFB@bcstec.ca.boeing.com>

In article <5de36h$42i@nntp1.u.washington.edu>,
William R. Somsky <somsky@dirac.phys.washington.edu> wrote:
 >After Chris Schoenfeld <chris@ixlabs.com> wrote:
   >>>
   >>> It would be great, and a little more Perlish, if there were a chop that
   >>> returned the truncated string, rather than what was chopped off. It
   >>> could be called chew, or perhaps masticate.
   >>> 
   >>> That way you could plop the chew call right in the print LIST. No Perl
   >>> programmer wants a sorry line like plain 'ol:
   >>> chop $scaler;
 >
 >
 >Randal Schwartz <merlyn@stonehenge.com> replied:
   >> 
   >> sub chew {
   >> 	substr($_[0],0,-1);
   >> }
 >
 >Hmm... I've often wished for such a thing, and was just asleep at the
 >wheel not to think of just writing a simple little subroutine like this.
 >I feel embarrased.  :-)
 >
 >But I probably would have done it like this:
 >
 > sub chew { my $t = shift ; chop $t ; return $t ; }
 >
 >I see the 'substr' version would be more efficient.
 >
 >But what I've usually wanted more often is a "chew" variant of "chomp",
 >rather than "chop", -- let's call it "chaw".  :-)  My above result would
 >easily give:
 >
 >sub chaw { my $t = shift ; chomp $t ; return $t ; }
 >
 >But is there a better/more efficient way to do it?  Or what about being
 >able to act on arrays?
 >
 >I suppose if we don't worry about trying to make it a pure function
 >w/out side effects, and let "chew" modify it's argument(s) just like
 >"chomp", but just to return the "what's left" part instead of "what's
 >been chomped", we might be able to do:
 >
 >sub chaw { chomp @_ ; return @_ ; }
 >
 >Or is there still something better?
 >(Or is this perhaps broken, I didn't test it...)


sub chaw { chomp @_; @_ };   # spit out some of the chaw 


(Ducking,)

--
Charles DeRykus
ced@carios2.ca.boeing.com


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

Date: Sat, 08 Feb 1997 03:35:16 GMT
From: pduff@airmail.net (Patrick Duff)
Subject: Re: Gregorian to Julain date conversion
Message-Id: <3300f355.169636379@news.airmail.net>

On Thu, 30 Jan 1997 15:18:48 -0800, Tom Phoenix
<rootbeer@teleport.com> wrote:

>On 30 Jan 1997, Robert McGraw wrote:
>
>> I am look for a perl function that will convert
>> a Gregorian date to a Julain day number.
>> 
>> Can someone send me the code or point me to a archive of
>> functions.
>
>   http://www.perl.com/CPAN/
>
>If you discover something that you need is not in CPAN, please code it up
>and submit it. :-)  Hope this helps!
>
>-- Tom Phoenix        http://www.teleport.com/~rootbeer/
>rootbeer@teleport.com   PGP  Skribu al mi per Esperanto!
>Randal Schwartz Case:     http://www.lightlink.com/fors/
>

Here's one.

-- 
regards, Patrick Duff (pduff@airmail.net)


###########################################################################

sub Week_Day {
   #Finds the day of the week for any date A. D..

   #Arg0 is the Month number, Arg1 is the Day number, and Arg2 is the
year
   #number.  Or Arg0 is a string in the format YYMMDD or YYYYMMDD.
   #Also $Date_String in the format "Www DD Mmm YYYY", where Www is
the day
   #(e.g. "Tue") and Mmm is the month (e.g. "Sep").

   #Sets $Bad_Date if an illegal date is given.  Returns $Bad_Date.

   #The day is returned as a number from 0 to 6, with 0 = Sunday.
   #Note:  In the ANSI and COBOL II standards, day numbers are 1 to 7,
   #with 7 = Sunday.  In the IBM CICS standard, day numbers are 0 to
6,
   #with 0 = Sunday.  Another common usage is day numbers 1 to 7, but
1 =
   #Sunday.

   #As side-effects, sets $Leap_Year to 1 if year is a leap-year, and
   #$Day_Num to the number of days since the beginning of the year (1
Jan
   #is day number 001, 1 Feb is day number 032, etc.).

   #Example dates for testing:
   #   29 May 1453 = Tue
   #    9 Apr 1957 = Tue
   #    1 Mar 1990 = Thu
   #    1 Mar 1991 = Fri  #Not Leap year:  Day Number = 60
   #    1 Mar 1992 = Sun  #Leap year:  Day Number = 61
   #    1 Jan 1994 = Sat
   #   17 Jul 1994 = Sun
   #   28 Feb 2000 = Mon
   #   29 Feb 2000 = Tue
   #    1 Mar 2000 = Wed
   #Use &Week_Day() if you want the current date.

   #Note:  The correspondence between date-of-month and day-of-week
repeats
   #exactly every 28 years, unless one of those years is a
non-leap-year
   #century-year (the whole pattern repeats every 400 years).  So the
year
   #2000 is equivalent to the years 1972 and 2028.

   if ("@_" eq "") {
      ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime();
      $Month = $mon + 1;
      $Day = $mday;
      $Year = $year;
   } else {
      if ($#_ == 0) {
         if (length($_[0]) == 8) {  #YYYYMMDD format
            $Month = substr($_[0],4,2);
            $Day = substr($_[0],6,2);
            $Year = substr($_[0],0,4);
         } else {  #YYMMDD format
            $Month = substr($_[0],2,2);
            $Day = substr($_[0],4,2);
            $Year = substr($_[0],0,2);
      }  } else {
         $Month = $_[0];
         $Day = $_[1];
         $Year = $_[2];
   }  };

   if (length($Year) == 2) {
      if ($Year > $Century_Threshold) {
         $Year = $Base_Century . $Year;
      } else {
         $Year = ($Base_Century+1) . $Year;
   }  };

   $Gregorian = (   ($Year > $Gregorian_Year)
                 || (   ($Year == $Gregorian_Year)
                     && (   (   ($Month == $Gregorian_Month)
                             && ($Day >= $Gregorian_Day)
                            )
                         || ($Month > $Gregorian_Month)
                )   )   );

   &Leap_Year($Year);

   #Check for an illegal date:
   $Month_Days[2] += $Leap_Year;  #Temporary adjustment
   if (   ($Year == 0)
       || (   ($Year == $Gregorian_Year)
           && ($Month == $Gregorian_Month)
           && ($Day > $Julian_Day)
           && ($Day < $Gregorian_Day)
          )
       || ($Month < 1)
       || ($Month > 12)
       || ($Day < 1)
       || ($Day > $Month_Days[$Month])
      ) {
      $Month_Days[2] -= $Leap_Year;  #Return to default state
      #print "Bad_Date = $Month/$Day/$Year $Leap_Year \n"; #For
debugging purposes
      return $Bad_Date = 1;
   } else {
      $Month_Days[2] -= $Leap_Year;  #Return to default state
      $Bad_Date = 0;
   };

   $Day_Num =
      (  (($Month > 1) * 31)
       + (($Month > 2) * 28)
       + (   ($Month > 2)
          && $Leap_Year
         )
       + (($Month > 3) * 31)
       + (($Month > 4) * 30)
       + (($Month > 5) * 31)
       + (($Month > 6) * 30)
       + (($Month > 7) * 31)
       + (($Month > 8) * 31)
       + (($Month > 9) * 30)
       + (($Month > 10) * 31)
       + (($Month > 11) * 30)
       + $Day
      );

   while (length($Day_Num) < 3) {
      $Day_Num = "0$Day_Num";
   };

   #Begin Day-of-Week calculation:

   local($Century) = substr($Year,0,2);

   #Determine the offset for the date's century:
   if ($Gregorian) {
      $Century_Offset = 5 if (($Century % 4) == 0);
      $Century_Offset = 3 if (($Century % 4) == 1);
      $Century_Offset = 1 if (($Century % 4) == 2);
      $Century_Offset = 6 if (($Century % 4) == 3);
   } else {
      $Century_Offset = 3 if (($Century % 7) == 0);
      $Century_Offset = 2 if (($Century % 7) == 1);
      $Century_Offset = 1 if (($Century % 7) == 2);
      $Century_Offset = 0 if (($Century % 7) == 3);
      $Century_Offset = 6 if (($Century % 7) == 4);
      $Century_Offset = 5 if (($Century % 7) == 5);
      $Century_Offset = 4 if (($Century % 7) == 6);
   };

   #Determine the offset for the date's month:
   $Month_Offset = (1 - $Leap_Year) if ($Month == 1);
   $Month_Offset = (4 - $Leap_Year) if ($Month == 2);
   $Month_Offset = 4 if ($Month ==  3);
   $Month_Offset = 0 if ($Month ==  4);
   $Month_Offset = 2 if ($Month ==  5);
   $Month_Offset = 5 if ($Month ==  6);
   $Month_Offset = 0 if ($Month ==  7);
   $Month_Offset = 3 if ($Month ==  8);
   $Month_Offset = 6 if ($Month ==  9);
   $Month_Offset = 1 if ($Month == 10);
   $Month_Offset = 4 if ($Month == 11);
   $Month_Offset = 6 if ($Month == 12);

   $YY = substr($Year,-2,2);

   $Www = (  (  $Century_Offset
              + $YY
              + $YY / 4
              + $Month_Offset
              + $Day
             )
           % 7
          );

   #For debugging:
   #print "$Century_Offset ", (($YY + ($YY / 4)) % 7), " $Month_Offset
$Day $Www\n";

   $Day_String = substr($Day_Name[$Www],0,3);
   $Month_String = substr($Month_Name[$Month],0,3);

   $Date_String = "$Day_String $Day $Month_String $Year";

   return $Bad_Date;
};

#Example calls for test purposes:

#&Week_Day(5,29,1453);
#   &Week_Day_Print;
#&Week_Day(4,9,1957);
#   &Week_Day_Print;
#&Week_Day(3,1,1991);  #Not a leap year
#   &Week_Day_Print;
#&Week_Day(3,1,1992);  #Leap year
#   &Week_Day_Print;
#&Week_Day(1,1,1994);
#   &Week_Day_Print;
#&Week_Day(7,17,1994);
#   &Week_Day_Print;
#&Week_Day();          #Current date
#   &Week_Day_Print;
#&Week_Day(1,34,1995); #Bad date
#   &Week_Day_Print;
#&Week_Day(450622);
#   &Week_Day_Print;
#&Week_Day(550622);
#   &Week_Day_Print;
#&Week_Day(950622);
#   &Week_Day_Print;
#&Week_Day(19950622);
#   &Week_Day_Print;
#&Week_Day("090622");
#   &Week_Day_Print;
#&Week_Day(20000228);  #Should be a Monday
#   &Week_Day_Print;
#&Week_Day(20000229);  #Should be a Tuesday
#   &Week_Day_Print;
#&Week_Day(20000301);  #Should be a Wednesday
#   &Week_Day_Print;
#&Week_Day(19810622);   #28 year test
#   &Week_Day_Print;
#&Week_Day(20090622);   #28 year test
#   &Week_Day_Print;
#&Week_Day(20370622);   #28 year test
#   &Week_Day_Print;

###########################################################################

1;  #Return true if this file is "required" by some other script



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

Date: 8 Feb 1997 00:10:25 GMT
From: dave@fast.thomases.com (Dave Thomas)
Subject: Re: Help: $| does not flush stream
Message-Id: <slrn5fngv5.3pq.dave@fast.thomases.com>

On 7 Feb 1997 18:23:25 -0500, swapna ganashyam samant <samant@badlands.cis.ohio-state.edu> wrote:
>     print QUERY "select Name from hierarchy\n"; print QUERRY "go\n";
                                                        ^^^^^^
                         _________________________________|
		        |
			Might this be the original problem?
			
'cat' only gets an EOF on its input when you close the FIFO, so if your
cat buffers output that itsn't going to a terminal, you'd get the
result you're seeing.

You could experiment more easily by writing a simple Perl client and server
and running them independendly - that should be able to duplicate the
behaviour you're seeing and gives you better control over the debugging.

Just a thought.

Dave


-- 

 _________________________________________________________________________
| Dave Thomas - Dave@Thomases.com - Unix and systems consultancy - Dallas |
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


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

Date: 7 Feb 1997 21:43:58 GMT
From: ric@isl.sri.com (Ric Steinberger)
To: peers@rintintin.Colorado.EDU (Eric J Peers)
Subject: Re: How do child processes talk to each other? [Q]
Message-Id: <5dg7mu$lim@unix.sri.com>

[Posted and mailed]

In article <5darsp$et6@lace.colorado.edu>,
	peers@rintintin.Colorado.EDU (Eric J Peers) writes:
> How can I get two child processes to talk to each other/
> pass strings back and forth. I'm using the simple
> client/server code as detailed in the perl book and I'd like
> to be able to pass a string from one forked process in the
> server to another forked process...

One strategy would be to create a pipe (see IO::Pipe) prior
to creating either child.  Then create both children.
Then one child can read the pipe and the other can write it.
(The IO::Pipe man page has details on this).  
	If each child needs to read from and write to the other,
you could either use two pipes, or use socketpair().  

	This will be easier to debug if you just create one
pipe first.

-- 
Ric Steinberger                 Email: ric@sri.com
SRI Consulting                  Phone: 415.859.4300
333 Ravenswood Ave  AH301       Pager: 415.907.4598
Menlo Park CA 94025             FAX:   415.859.2986


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

Date: Sat, 08 Feb 1997 12:33:35 -0800
From: Edmund Chow <klcho5@student.monash.edu.au>
Subject: How to handle a "@" (not "\@") in a string ?
Message-Id: <32FCE31F.598F@student.monash.edu.au>

Hi everyone ...
               I am currently doing a web database for my school project
and I need to remove the @ sign in a string. When perl read this text,
it sees the @ as an array and not as a character.How do I  remove the @
? here is the source listing.  

------------------------------------
#! /usr/local/bin/perl

 $x = "/";
 $y = "~";
 $z = "+";
 $a = "=";
 $b = "//";
 $c = "\@";
 $d = "@";

# $txt = $ENV{QUERY_STRING};

 $txt
="http://user:password@abc.ct.monash.edu.au/~cvc/sdc.html?hidval=test";
 $txt =~ s/$d/$c/g;

 print $txt;
 print "\n";
 @str1 = split(/$b/,$txt);

#get user name
 print "\n";
 $txt1 = $str1[1];
 @str2 = split(/:/,$txt1);
 print "user name :";print $str2[0];

# get password and data
 $txt2 = $str2[1];
 @str3 = split(/$c/,$txt2);
 print "\npassword :";print $str3[0];
 print "\nfrom server :";print $str3[1];
 print "\nfrom user :";print $str3[2];
 print "\ndata:"; print $str~3[3];
--------------------------------------------


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

Date: 8 Feb 1997 02:44:15 GMT
From: dave@fast.thomases.com (Dave Thomas)
Subject: Re: How to handle a "@" (not "\@") in a string ?
Message-Id: <slrn5fnpvj.4ag.dave@fast.thomases.com>

On Sat, 08 Feb 1997 12:33:35 -0800, Edmund Chow <klcho5@student.monash.edu.au> wrote:
> Hi everyone ...
>                I am currently doing a web database for my school project
> and I need to remove the @ sign in a string. When perl read this text,
> it sees the @ as an array and not as a character.How do I  remove the @
> ? here is the source listing.  
> 
> ------------------------------------
> #! /usr/local/bin/perl
> 
>  $x = "/";
>  $y = "~";
>  $z = "+";
>  $a = "=";
>  $b = "//";
>  $c = "\@";
>  $d = "@";
> 
> # $txt = $ENV{QUERY_STRING};
> 
>  $txt
> ="http://user:password@abc.ct.monash.edu.au/~cvc/sdc.html?hidval=test";
>  $txt =~ s/$d/$c/g;
> 
>  print $txt;
>  print "\n";
>  @str1 = split(/$b/,$txt);
> 
> #get user name
>  print "\n";
>  $txt1 = $str1[1];
>  @str2 = split(/:/,$txt1);
>  print "user name :";print $str2[0];
> 
> # get password and data
>  $txt2 = $str2[1];
>  @str3 = split(/$c/,$txt2);
>  print "\npassword :";print $str3[0];
>  print "\nfrom server :";print $str3[1];
>  print "\nfrom user :";print $str3[2];
>  print "\ndata:"; print $str~3[3];
> --------------------------------------------

You escape it with a '\'- just like you did for $c.
Now, I'm not one for brevity - I'm often the first to get into arguments
with people who write obscure 1 liners. However, I can't let an obscure 35
liner go by!

How about something simpler like:


$txt ="http://user:password\@abc.ct.monash.edu.au/~cvc/sdc.html?hidval=test";
($user, $pw, $server, $from_user, $data) = 
    ($txt =~ m!http://(\w+):(\w+)@(.+?)/~(.+?)/.*\?(.*)!);
    
print "User: $user\nPassword: $pw\nfrom: $from_user\nData: $data\n";

You don't need to remove the '@' sign in regular expression patterns.

Dave

-- 

 _________________________________________________________________________
| Dave Thomas - Dave@Thomases.com - Unix and systems consultancy - Dallas |
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


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

Date: 07 Feb 1997 18:36:36 -0700
From: Randal Schwartz <merlyn@stonehenge.com>
To: tchrist@mox.perl.com (Tom Christiansen      		tchrist@perl.com)
Subject: Re: How to peek at next line of STDIN? (repost)
Message-Id: <8cenesgjtn.fsf@gadget.cscaper.com>

>>>>> "Tom" == Tom Christiansen tchrist@perl com <tchrist@mox.perl.com> writes:

Tom>  [courtesy cc of this posting sent to cited author via email]
Tom> In comp.lang.perl.misc, Randal Schwartz <merlyn@stonehenge.com> writes:
Tom> :H> In other words I want to use the angle operator to read in a line and 
Tom> :H> then put that  line back so I can use the angle operator to read it in 
Tom> :H> again. How can this effect be achieved?

Tom> :It can't be done transparently

Tom> Sure it can: TIEHANDLE

No, I thought of that.  ARGV (the filehandle in <>) cannot be
sufficiently "smartened" using TIEHANDLE, as it would make the
underlying magic @ARGV open-sequence disappear.

Unless there's even MORE special magic about overloading ARGV.  That
would be scary.

print "Just another Perl hacker," # but not what the media calls "hacker!" :-)
## legal fund: $20,495.69 collected, $182,159.85 spent; just 570 more days
## before I go to *prison* for 90 days; email fund@stonehenge.com for details

-- 
Name: Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
Keywords: Perl training, UNIX[tm] consulting, video production, skiing, flying
Email: <merlyn@stonehenge.com> Snail: (Call) PGP-Key: (finger merlyn@ora.com)
Web: <A HREF="http://www.stonehenge.com/merlyn/">My Home Page!</A>
Quote: "I'm telling you, if I could have five lines in my .sig, I would!" -- me


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

Date: Sat, 08 Feb 1997 01:36:20 GMT
From: tforbes@ix.netcom.com (Thomas J. Forbes)
Subject: Matt's Script: SSI Random Banner Generator
Message-Id: <32fbd60b.157118468@nntp.ix.netcom.com>

I am trying to get Matt's Random Banner Generator with Server Side
Includes running. This is my first attempt at SSI, I get the message:
[an error occurred while processing this directive]. The line in my
shtml file reads <!--#exec cgi="ssi_rand_image.cgi"--> and is located
at http://www.medstore.com/ads2/forsalead.shtml.

The banner images are in ads2/banners and the cgi file is in the ads2
directory. Here is the script, with the modified variables:

#!/usr/bin/perl
##############################################################################
# SSI Random Image Displayer    Version 1.2
# 
# Copyright 1996 Matt Wright    mattw@worldwidemart.com
#
# Created 7/1/95                Last Modified 11/4/95
#
# Scripts Archive at:           http://www.worldwidemart.com/scripts/
#
##############################################################################
# COPYRIGHT NOTICE
#
# Copyright 1996 Matthew M. Wright  All Rights Reserved.
#
#
#
# SSI Random Image may be used and modified free of charge by anyone
so      #
# long as this copyright notice and the comments above remain intact.
By    #
# using this this code you agree to indemnify Matthew M. Wright from
any     #
# liability that might arise from it's use.
#  
#
#
# Selling the code for this program without prior written consent is
#
# expressly forbidden.  In other words, please ask first before you
try and  #
# make money off of my program.
#
#
#
# Obtain permission before redistributing this software over the
Internet or #
# in any other medium.  In all cases copyright and header must remain
intact.#
##############################################################################
# Define Variables

$basedir = "http://www.medstore.com/ads2/banners/";

@images =
("ama.gif","cai.gif","gms.gif","labquip.gif","meddepot.gif","mee.gif","mis.gif","mmr.gif","open.gif","tfsrehab.gif");

@urls = ("http://www.medstore.com/assetmgmt/",
         "http://www.medstore.com/cai/",
         "http://www.medstore.com/gms/",
         "http://www.medstore.com/labquip/",
         "http://www.medstore.com/meddepot/",
         "http://www.medstore.com/mee/",
         "http://www.medstore.com/mis/",
         "http://www.medstore.com/mmr/",
         "http://www.medstore.com/join.htm",
         "http://www.medstore.com/tfsrehab/");

@alt = ("Your MedStore or MedMart Web site includes your company
banner HERE!",
        "Your MedStore or MedMart Web site includes your company
banner HERE!",
        "Your MedStore or MedMart Web site includes your company
banner HERE!",
        "Your MedStore or MedMart Web site includes your company
banner HERE!",
        "Your MedStore or MedMart Web site includes your company
banner HERE!",
        "Your MedStore or MedMart Web site includes your company
banner HERE!",
        "Your MedStore or MedMart Web site includes your company
banner HERE!",
        "Your MedStore or MedMart Web site includes your company
banner HERE!",
        "Your MedStore or MedMart Web site includes your company
banner HERE!",
        "Your MedStore or MedMart Web site includes your company
banner HERE!");

##############################################################################
# Options
$uselog = "0";            # 1 = YES; 0 = NO
   $logfile = "/path/to/log/file";
   $date = `/usr/bin/date`; chop($date);

$link_image = "1";        # 1 = YES; 0 = NO
$align = "middle";
$border = "2";

# Done
##############################################################################

srand(time ^ $$);
$num = rand(@images); # Pick a Random Number

# Print Out Header With Random Filename and Base Directory
print "Content-type: text/html\n\n";
if ($link_image eq '1' && $urls[$num] ne "") {
   print "<a href=\"$urls[$num]\">";
}

print "<img src=\"$basedir$images[$num]\"";
if ($border ne "") {
   print " border=$border";
}
if ($align ne "") {
   print " align=$align";
}
if ($alt[$num] ne "") {
   print " alt=\"$alt[$num]\"";
}
print ">";

if ($link_image eq '1' && $urls[$num] ne "") {
   print "</a>";
}

print "\n";

# If You want a log, we add to it here.
if ($uselog eq '1') {
   open(LOG, ">>$logfile");
   print LOG "$images[$num] - $date - $ENV{'REMOTE_HOST'}\n";
   close(LOG);
}

I'm stuck. I have not modified the script in any way, and I checked
the syntax with perl -c, all checked OK.

I set the permissions as follows:

perl script - chmod 755
forsalead.shtml - chmod 777
ads2 and ads2/banners directories - chmod 777

Anyone have an idea? I can't seem to figure this one out.

Thanks for looking,

TOM FORBES


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

Date: Sat, 08 Feb 1997 03:13:27 GMT
From: pduff@airmail.net (Patrick Duff)
Subject: Re: negative zero????
Message-Id: <32ffeed3.168482646@news.airmail.net>

On Tue, 28 Jan 1997 08:29:28 -0600, tadmc@flash.net (Tad McClellan)
wrote:

>Craig Berry (cberry@cinenet.net) wrote:
>: Randal Schwartz (merlyn@stonehenge.com) wrote:
>: : >>>>> "Ilya" == Ilya Zakharevich <ilya@math.ohio-state.edu> writes:
>: : Ilya> P.S. In older Solaris's answerbooks there was a remarkable document
>: : Ilya> with reasons for IEEE decisions. I've heard it is no more :-(...
>: : 
>: : Which is no more?  Solaris, answerbooks, a remarkable document,
>: : the reasons, the IEEE or decisions they make?
>: : 
>: : P.S. Isn't English remarkably wonderfully ambiguous?  And if you think
>: : that's bad, try this real life example:
>: : 
>: : 	We Only Serve Lunch On Fridays
>: : 
>: : and just when you think you *know* what it means, *another* meaning
>: : pops into your head.  Gaaaaah!  (hint: bind "only" to each of the
>: : other four major words, and then for a real kicker, imagine a guy
>: : named Lunch. :-)
>
>: My favorite of these is "Time flies like an arrow."
>
>: ....which may be parsed as...
>
>:   "Time, the measure of duration, travels similarly to an arrow."
>:   "Use this stopwatch to time these housefiles in the same way you would an 
>: arrow."
>:   "There is this odd subspecies of housefiles, called time flies, and 
>: they enjoy a particular arrow."
>:   A simile comparing a group of the aforementioned time flies to an arrow. 
>
>: I've often seen this sentence paired with "fruit flies like a banana."
>
>
>What about:
>
>"Not available in all stores"
>
>Where the heck do you buy it then?
>
>
>s/all/some/  seems to be what they really mean.
>
>
>--
>    Tad McClellan                          SGML Consulting
>    tadmc@flash.net                        Perl programming

Try saying each of the following sentences out loud:

     It's hard to recognize speech.

     It's hard to wreck a nice beach.

     It's hard to wreck a nice beech.

-- 
regards, Patrick Duff (pduff@airmail.net)



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

Date: Sat, 08 Feb 1997 02:30:55 GMT
From: pduff@airmail.net (Patrick Duff)
Subject: OLE adds a byte at end of string?
Message-Id: <32fbe164.165042225@news.airmail.net>

WinNT PERL 5.003 build 302.

I've found another weird behavior while interacting with an OLE
application using PERL.

Say I've used PERL to build an MS Access database with a table named
"Table1", which has a field named "Field1" and some of the rows have
the value "String1".  To get just these rows in Visual Basic, I do:

OpenRecordset("SELECT * FROM Table1 WHERE Field1 = 'String1' ")

But when I do this from PERL, it fails to select any rows.  Instead,
to get the intended result I have to do the following:

OpenRecordset("SELECT * FROM Table1 WHERE Field1 LIKE 'String1?' ")

Somehow in the handshaking from PERL to OLE to Access, either in the
original insertion of values into the database when PERL built it, or
now when I'm selecting the rows I want, an extra byte has been added
to String1.

If I start MS Access and look at the rows which have value String1,
there does not appear to be an extra byte stored at the end of String1
(if I range the value with the mouse, only the characters in String1
get highlighted -- it doesn't show an extra character at the end).

So does anyone know what's going on?

-- 
regards, Patrick Duff (pduff@airmail.net)



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

Date: 8 Feb 1997 02:06:01 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Perl vs Korn Shell
Message-Id: <5dgn29$lo2$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Nathan Wagner 
<nw@hydaspes.if.org>],
who wrote in article <32FB95DE.3E2D@hydaspes.if.org>:
> Abigail wrote:
> 
> > I agree perl is "better" than sed or awk. Yet I still use awk for
> > two reasons:
> > 
> > - Sometimes awk is less typing (or less thinking) than perl.
> >   I just can't beat "| awk '{print $2}'" in perl.
> 
> I suppose you realize this, but how about
> | perl -pe '(split)[1]'

Did you try this before posting? Please do the next time.

Meanwhile what about
	| perl -lane 'print $F[2]'
(not tested ;-)?

Ilya


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

Date: 7 Feb 1997 19:10:26 -0500
From: clay@panix.com (Clay Irving)
Subject: Re: perl?
Message-Id: <5dgg9i$q8g@panix.com>

In <Pine.GSO.3.95.970207075501.3726H-100000@linda.teleport.com> Tom Phoenix <rootbeer@teleport.com> writes:
>On Thu, 6 Feb 1997, ehsan zarrabi wrote:

>> How do I run this Perl Script.

>[ Entire script snipped. ]

>You can run it the same way you would run this much shorter one.

>    #!/usr/bin/perl

>    print "The Perl docs will help you out.\n";

May I suggest an improvement?

     print "The Perl docs will help you out.\n" x 100; 

-- 
See the happy moron,                             
He doesn't give a damn,                                    Clay Irving N2VKG  
I wish I were a moron,                                        clay@panix.com
My God! Perhaps I am!                             http://www.panix.com/~clay


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

Date: 07 Feb 1997 22:08:29 -0500
From: Tom Fawcett <fawcett@nynexst.com>
Subject: program to recognize and respond to FAQ questions
Message-Id: <8jvi840zbm.fsf@nynexst.com>


About six months ago in a fit of idleness I started coding a Perl script to
respond to FAQ postings.  It would scan comp.lang.perl.misc postings,
recognize FAQ questions and mail out the answers.  I put it aside because
(I dimly recall) someone with a real IR background was working on the same
project.

I haven't heard anything since.  Is anyone working on such a thing?  If
not, I might resurrect my code just to see if it's feasible.

-Tom


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

Date: 7 Feb 1997 23:51:35 GMT
From: dave@fast.thomases.com (Dave Thomas)
Subject: Re: Removing extra spaces
Message-Id: <slrn5fnfrs.3pq.dave@fast.thomases.com>

On 7 Feb 1997 21:54:07 GMT, Lynn Wilson <lynn@swcp.com> wrote:
> I want to remove extra spaces in a piece of text as part of
> a normalization process.  I know how to remove leading and
> trailing spaces using seperate regular expressions.  How do
> I remove a variable number of spaces embedded in the middle
> of the text?
> 
> $input_text = "  big   long line     of text with leading+trailing+middle  ";

  $input_text =~ s/\s{2,}/ /g;
  
Replaces two or more spaces with a single space.

Its marginal, but you'll probably want to do this _after_ stripping the
leading and trailing spaces (as the anchored searches are faster).

So, maybe something like:

  $input_text =~ s/\s+$//;
  $input_text =~ s/^\s+//;
  $input_text =~ s/\s{2,}/ /g;

Regards

Dave

-- 

 _________________________________________________________________________
| Dave Thomas - Dave@Thomases.com - Unix and systems consultancy - Dallas |
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


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

Date: Fri, 7 Feb 1997 17:16:59 -0600
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Removing extra spaces
Message-Id: <b5dgd5.tt.ln@localhost>

Lynn Wilson (lynn@swcp.com) wrote:
: I want to remove extra spaces in a piece of text as part of
: a normalization process.  I know how to remove leading and
: trailing spaces using seperate regular expressions.  How do
: I remove a variable number of spaces embedded in the middle
: of the text?

: $input_text = "  big   long line     of text with leading+trailing+middle  ";

: $output = "big long line of text with leading+trailing+middle";

: I want to retain a single internal space where called for.

: Is there a nice perlish way of doing this?


Of course there is a perlish way ;-)


---------
#! /usr/bin/perl -w

$input_text = "  big   long line     of text with leading+trailing+middle  ";

$output = $input_text;
$output =~ s/\s\s+/ /g;     # interior (replace two or more with one)
$output =~ s/^\s+//;        # leading
$output =~ s/\s+$//;        # trailing

print "'$output'\n";
---------


: I'm going to use this as a key to an assocative array hoping to locate
: duplicate records.  In reality the input strings will contain
: business names (ie; "Sam's Club"  "Super Hardware Stores" );

: Thanks.

You're welcome.


--
    Tad McClellan                          SGML Consulting
    Tag And Document Consulting            Perl programming
    tadmc@flash.net


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

Date: Sat, 08 Feb 1997 03:09:11 GMT
From: pduff@airmail.net (Patrick Duff)
Subject: Re: Rounding decimal numbers
Message-Id: <32feedcc.168218730@news.airmail.net>

On Mon, 27 Jan 1997 19:21:49 -0600, tadmc@flash.net (Tad McClellan)
wrote:

>Bruce W. Mohler (bruce.w.mohler@cpmx.saic.com) wrote:
>: I'm avoiding using the integer module and am finding some divisions
>: producing numbers with nice long numbers to the right of the decimal
>: point, precision that I really don't need and was wondering, having
>: checked the Blue Camel book, how to specify (for example) round to the
>: nearest 2 decimal places.
>
>
>$num = 123.12789000314159;
>
>printf("%5.2f\n", $num);
>
>
>--
>    Tad McClellan                          SGML Consulting
>    tadmc@flash.net                        Perl programming

Here's a fancier version you might like.

-- 
regards, Patrick Duff (pduff@airmail.net)

###########################################################################

sub Round {
   #Returns $Arg0 number rounded to $Arg1 decimal places.

   #Some machines are subject to floating-point precision errors which
may
   #cause PERL to store a number like 2.535 as 2.53499999999999991,
which
   #when rounded via sprintf %4.2 returns "2.53" instead of "2.54".
This
   #function detects such borderline cases and handles them properly.

   #When the number to be rounded is exactly halfway between rounding
up or
   #rounding down (e.g. 2.525 rounded to 2 decimal places) always
rounding
   #up or always rounding down would skew the average results.
Instead the
   #choice to round up or down is balanced by always rounding to an
even
   #last digit.  So 2.515 rounds to 2.52, 2.525 rounds to 2.52, 2.535
rounds
   #to 2.54, and 2.545 rounds to 2.54.  When rounding lots of numbers
this
   #averages out to 0.

   my($Result,$Diff);
   $Result = sprintf("%.$_[1]f",$_[0]);
   $Diff = ($_[0] - $Result) * (10 ** $_[1]);
   if (($Diff =~ /^-?0.5$|^-?4999999999/) && (substr($Result,-1) % 2))
{
      my($Adjustment) = (10 ** (($_[1] + 1) * -1));
      $Adjustment *= -1 if ($Result > 0);
      $Result = sprintf("%.$_[1]f",($_[0] + $Adjustment));
   };
   return $Result;
};

#For test purposes:
#print '-2.514 @ 2 >> ' .  Round(-2.514,2) . " Should be -2.51\n";
#print '-2.515 @ 2 >> ' .  Round(-2.515,2) . " Should be -2.52\n";
#print '-2.516 @ 2 >> ' .  Round(-2.516,2) . " Should be -2.52\n";
#print ' 2.514 @ 2 >>  ' . Round( 2.514,2) . " Should be  2.51\n";
#print ' 2.515 @ 2 >>  ' . Round( 2.515,2) . " Should be  2.52\n";
#print ' 2.516 @ 2 >>  ' . Round( 2.516,2) . " Should be  2.52\n";

#print '-2.524 @ 2 >> ' .  Round(-2.524,2) . " Should be -2.52\n";
#print '-2.525 @ 2 >> ' .  Round(-2.525,2) . " Should be -2.52\n";
#print '-2.526 @ 2 >> ' .  Round(-2.526,2) . " Should be -2.53\n";
#print ' 2.524 @ 2 >>  ' . Round( 2.524,2) . " Should be  2.52\n";
#print ' 2.525 @ 2 >>  ' . Round( 2.525,2) . " Should be  2.52\n";
#print ' 2.526 @ 2 >>  ' . Round( 2.526,2) . " Should be  2.53\n";

#print '-0.5   @ . >> ' .  Round(-0.5  ,0) . " Should be  -0\n";
#print '-1.5   @ . >> ' .  Round(-1.5  ,0) . " Should be  -2\n";
#print '-2.5   @ . >> ' .  Round(-2.5  ,0) . " Should be  -2\n";
#print '-3.5   @ . >> ' .  Round(-3.5  ,0) . " Should be  -4\n";
#print '-4.5   @ . >> ' .  Round(-4.5  ,0) . " Should be  -4\n";
#print '-5.5   @ . >> ' .  Round(-5.5  ,0) . " Should be  -6\n";
#print '-6.5   @ . >> ' .  Round(-6.5  ,0) . " Should be  -6\n";
#print '-7.5   @ . >> ' .  Round(-7.5  ,0) . " Should be  -8\n";
#print '-8.5   @ . >> ' .  Round(-8.5  ,0) . " Should be  -8\n";
#print '-9.5   @ . >> ' .  Round(-9.5  ,0) . " Should be -10\n";

#print ' 0.5   @ . >> ' .  Round( 0.5  ,0) . " Should be   0\n";
#print ' 1.5   @ . >> ' .  Round( 1.5  ,0) . " Should be   2\n";
#print ' 2.5   @ . >> ' .  Round( 2.5  ,0) . " Should be   2\n";
#print ' 3.5   @ . >> ' .  Round( 3.5  ,0) . " Should be   4\n";
#print ' 4.5   @ . >> ' .  Round( 4.5  ,0) . " Should be   4\n";
#print ' 5.5   @ . >> ' .  Round( 5.5  ,0) . " Should be   6\n";
#print ' 6.5   @ . >> ' .  Round( 6.5  ,0) . " Should be   6\n";
#print ' 7.5   @ . >> ' .  Round( 7.5  ,0) . " Should be   8\n";
#print ' 8.5   @ . >> ' .  Round( 8.5  ,0) . " Should be   8\n";
#print ' 9.5   @ . >> ' .  Round( 9.5  ,0) . " Should be  10\n";

1;  #Return true if this file is "required" by some other script



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

Date: Fri, 7 Feb 1997 10:47:16 -0500
From: Senthilvel Rangaswamy <senthil@ece.vill.edu>
Subject: Search Engine in Perl
Message-Id: <Pine.SV4.3.95.970207104601.1742A-100000@vu-vlsi.ee.vill.edu>


Hi All:

Does anybody know where I can find a search engine written in Perl.

Thanks,

 ..Senthil

"Out the 10Base-T, through the router, down the T1, over the leased line,
 off the bridge, past the firewall.... nothing but Net."
						       - Todd Postma



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

Date: Sat, 08 Feb 97 01:29:26 GMT
From: lewau@belsebub.ics.lu.se (Roger Lewau)
Subject: Re: Sending results to two frames at once
Message-Id: <5dgku1$8ne@news.lth.se>

In article <32FB2E37.5E38@bbn.hp.com>, Christoph Marquardt <Christoph_Marquardt@bbn.hp.com> wrote:
>you might want to insert a sub frame-layout-document into your document 
>to make this work
>
>(e.g. have one file with 3 frames where the middle frame might have the 
>name "middle_frame" and then load a 2 frame document to target 
>"middle_frame", then you just need to replace this "middle_frame" frame 
>with another 2 frame document by targetin the according output)

>does that help?

No ;) The problem _was_ to get the result of one script into two frames at 
once. I have an orderform in one frame and a shopping bag in another. The 
shoppingform is editable and when sending the edited form to the server the 
result should be a new editable form _and_ an update of the shopping bagwindow 
as well. The problem is now fixed.

//Roger  
But thanks anyway


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

Date: Fri, 07 Feb 1997 19:12:37 -0500
From: Graham Bignell <bignell@netcom.ca>
Subject: Slightly Nifty, but possibly dangerous perl.
Message-Id: <32FBC4F5.38D8@netcom.ca>

I was seeking a solution to my need for scalars 
that were defined externally but only interpolated/parsed
when used, and with the help of someone in #perl came up
with this:

in conf.cf

	sub foo {
	"
	This is just a bit of text \
	that will span lines. $bar \
	blahblahblahblah
	";
	}

in foo.pl

	require "conf.cf";

	$bar = "BAR";
	print &foo;

Can anyone think of any dangers involved with using functions like this?
I was wondering what sort of stuff would screw it up, or break the
script.

Also, I am assuming this works because perl is returning the last
assignment
to $_ instead of a return code or nothing at all, will this work in
future
versions of perl?

---
Graham


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

Date: Fri, 07 Feb 1997 15:43:57 -0800
From: Dave Price <dprice@healthdesk.com>
Subject: Timing perl with granularity less than .1 seconds
Message-Id: <32FBBE3D.67EB@healthdesk.com>

Howdy

	I'm trying to time several portions of my perl script.  The code would
look something like this:

$start1 = time;
# a bunch of code
$end1 = time;
$start2 = time;
#another block of code
$end2 = time;

print "Time for block 1 is " . $end1 - $start1 . " seconds\n";
print "Time for block 2 is " . $end2 - $start2 . " seconds\n"; 

	Unfortunately time only returns the current time in seconds, which is
not nearly accurate enough for my purposes.  What I would like is
something similar to the gettimeofday() function in C.  In that case I
get a timeval struct back which returns both seconds and microseconds.
I have looked at both times() and timeit(), but neither is a good fit
for my needs.  

	Please email responses to dprice@healthdesk.com

Thanks for your time
Dave


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

Date: 8 Feb 1997 02:28:23 GMT
From: dave@fast.thomases.com (Dave Thomas)
Subject: Re: Timing perl with granularity less than .1 seconds
Message-Id: <slrn5fnp1q.48t.dave@fast.thomases.com>

On Fri, 07 Feb 1997 15:43:57 -0800, Dave Price <dprice@healthdesk.com> wrote:
> Howdy

Hi - did you know your 'reply-to' address is missing a shift key?

> 	I'm trying to time several portions of my perl script.  The code would
> look something like this:

Even if you had a high resolution timer, doing single samples like that is
going to be inaccurate - the chances of some external event (the system
flushing buffers to disk, a burst of comms activity etc) affecting your
results is high.

However, all is not lost. Have you looked at the Benchmark module that comes
with Perl. It lets you run blocks of code repetitively, and gives you a time
breakdown. For the documentation:

       timethis - run a chunk of code several times
       
       timethese - run several chunks of code several times
	      
       timeit - run a chunk of code and see how long it goes
		     
    SYNOPSIS
       timethis ($count, "code");
			
       timethese($count, {
                         'Name1' => '...code1...',
                         'Name2' => '...code2...',
           });
	   
       $t = timeit($count, '...other code...')
      print "$count loops of other code took:",timestr($t),"\n";
				 
Dave


-- 

 _________________________________________________________________________
| Dave Thomas - Dave@Thomases.com - Unix and systems consultancy - Dallas |
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


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

Date: Sat, 08 Feb 1997 02:58:18 GMT
From: pduff@airmail.net (Patrick Duff)
Subject: Re: turn 1,2,3,5 into 1-3,5 ?
Message-Id: <32fdea21.167279761@news.airmail.net>

On 26 Jan 1997 21:17:08 GMT, andyr@rmi.net (Andy Rabagliati) wrote:

>Devin Ben-Hur <dbenhur@emarket.com> wrote:
>
>:Well, CPAN may be our friend, but sometimes one can go overboard
>:looking for existing implementations of trivial algorithms.
>
>One reason to do so is that hopefully the CPAN one does not have
>bugs in it ?
>
>I can write one, but I might have problems testing all the
>weird conditions that might crop up.
>
>Long lines ?
>
>Non-monotonic sequences ?
>
>Negative numbers ?
>
>Well, they will never happen in my case :-)
>
>Cheers,      Andy!
>
>
This isn't what you asked for;  it actually does the inverse
operation.  I'm sending it just in case you might find it useful.  At
the very least, you can use it to generate test cases for the function
you asked for!

-- 
regards, Patrick Duff (pduff@airmail.net)

###########################################################################

sub Expand_Range {
   #Expands first argument from something like "9-12" into
"9,10,11,12",
   #where each "," is taken from the value of $Separator.  For
example,
   #$Separator could be set to ", " or "|" or "\n" instead.
   #Understands cases where first number is greater than second
number,
   #such as "21-5", "99-1", "100-9" or "100-99".
   #Returns result as a string in $Range;  also returns $From and $To.
   #Usage note: To process the elements from range one at a time, use
something
   #like:  ($First,$Rest) = split(/[ ,]+/,$Range,2);

   ($_[0] =~ /^[0-9]+$/) && return $Range = $From = $To = $_[0];
#Single number argument

   ($_[0] =~ /^[0-9]+-[0-9]+$/) || die "Bad range syntax in argument
$_[0]";

   ($From,$To) = $_[0] =~ /^([0-9]+)-([0-9]+)$/;

   $Separator = "," unless defined($Separator);

   $Length = (length($To));

   $Range = $From;

   local($Current) = $From;

   while (substr($Current,0-$Length) != $To) {
      $Range .= $Separator . ++$Current;
   };

   return $Range;
};

###########################################################################

sub Numerical {
   $a <=> $b;
};

###########################################################################

sub Normalize_Number_List {
   #Given a string containing a list of numbers and ranges, expands
ranges,
   #sorts list, and removes duplicates.  Returns @Normalized array of
numbers.

   local(@UnNormalized) = split(/[ ,]+/,$_[0]);
   local(@UnRanged);

   foreach (@UnNormalized) {
      push(@UnRanged,split(/[ ,]+/,Expand_Range($_)));
   };

   @UnRanged = sort Numerical @UnRanged;

   undef(@Normalized);

   foreach (@UnRanged) {
      if ($_ != $Normalized[$#Normalized]) {
         push(@Normalized,$_);
   }; };

   return @Normalized;
};

#For test purposes:

#Expand_Range("12");       print("$From-$To:  $Range\n");
#Expand_Range("12-");      print("$From-$To:  $Range\n");
#Expand_Range("9-12");     print("$From-$To:  $Range\n");
#Expand_Range("21-5");     print("$From-$To:  $Range\n");
#Expand_Range("99-1");     print("$From-$To:  $Range\n");
#Expand_Range("100-9");    print("$From-$To:  $Range\n");
#Expand_Range("100-11");   print("$From-$To:  $Range\n");
#Expand_Range("100-111");  print("$From-$To:  $Range\n");
#Normalize_Number_List("101-6,9,9-12,101-7,100");  print(join('
',@Normalized),"\n");

1;  #Return true if this file is "required" by some other script



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

Date: 07 Feb 1997 19:08:03 -0600
From: Philip Guenther <guenther@lunen.gac.edu>
Subject: Re: why can't "system" return a long?
Message-Id: <e6920asrtos.fsf@lunen.gac.edu>

epaik@deans.umd.edu (Ellen Paik) writes:

> Can someone clarify what I need to do in order to get a call to a 
> C program using the "system" function to return a value of type long?
> Whenever the program returns an integer larger than type int, the 
> return value gets messed up.

Exit codes in UNIX must fit within one byte, period.  This is due to how
the exit status is returned to the parent process doing a wait(), and for
backwards compatibility, no one has dared change it.  Typically, wait*()
stores 2 bytes of status info in some location, with one byte determining
whether the child exited normally, was killed by a signal, or was stopped
by a signal.  The other byte then either gives the exit status or the
number of the signal involved (though that may be stored in the former
byte instead).

Anyway, if you need to return more than eight bits of information, you'll
need to open a pipe and have the program write the desired value down the
pipe before exiting, so that you perl code will run along the lines of:

open(PIPE, "foo|")		or die "Unable to fork: $!";
$value = <PIPE>;			# get the written value
close(PIPE);
$return_value = $?			# you can still get the return value


Philip Guenther

----------------------------------------------------------------
Philip Guenther			UNIX Systems and Network Administrator
Internet: guenther@gac.edu	Voicenet: (507) 933-7596
Gustavus Adolphus College       St. Peter, MN 56082-1498


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

Date: 8 Jan 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Jan 97)
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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

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 V7 Issue 914
*************************************

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