[7430] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1055 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Sep 21 02:17:30 1997

Date: Sat, 20 Sep 97 23:00:21 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 20 Sep 1997     Volume: 8 Number: 1055

Today's topics:
     "here document" method of print erroring <jds02@ix.netcom.comNoSpam>
     Any Recommendations for portable signal processing? (Adrian Pepper)
     Re: Any Recommendations for portable signal processing? (Andrew M. Langmead)
     Re: Capitalizing the first letter via regex (Jason Gloudon)
     Re: Capitalizing the first letter via regex (Tad McClellan)
     Re: Capitalizing the first letter via regex (Jason Gloudon)
     Re: chop/chomp, take 2 (Gerben Vos)
     Re: Does Perl Have C's fflush function? (dave)
     Re: Getting next array element in a foreach (Dave Schenet)
     Re: Getting next array element in a foreach (Daniel E. Macks)
     HELP: Unable to reference package variables <brannon@surf.usc.edu>
     Re: looping through an sql query using win32::odbc <madebeer@igc.apc.org>
     mathematical calculation varies greatly between call an <brannon@surf.usc.edu>
     mon-0.37d - Service Monitoring Daemon (Jim Trocki)
     Question about pattern matching! <tam1@uwindsor.ca>
     Redirecting stderr to stdout (Justin Greer)
     Re: Redirecting stderr to stdout (Andrew M. Langmead)
     setgid bit on GNU make? <h.b.furuseth@usit.uio.no>
     Re: SQL program that works both in Win'95 and Linux (Danny Aldham)
     Re: To delete a file <dankogai@dan.co.jp>
     Tricky Sort Command - sorting a list (Ravi Agarwal)
     Re: Tricky Sort Command - sorting a list (Jason Gloudon)
     Re: Tricky Sort Command - sorting a list <doug@tc.net>
     Re: Value within range? <dankogai@dan.co.jp>
     Week of the Year [Was: Re: Calculating the week number] <dankogai@dan.co.jp>
     Week of the Year [Was: Re: Calculating the week number] <dankogai@dan.co.jp>
     what's wrong in this function? <tam1@uwindsor.ca>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Sat, 20 Sep 1997 22:15:15 -0500
From: Ben Scott <jds02@ix.netcom.comNoSpam>
Subject: "here document" method of print erroring
Message-Id: <34249143.7531@ix.netcom.comNoSpam>

hi-

I am using the "here document" style of the print command and it is not
working correctly for me.  please lemme know if I'm doing everything
right or am completely off in some way.  code and error follow:

code____________________________
    print <<END_OF_TEXT;
        a bunch of text
	with quotes "and other stuff"
END_OF_TEXT

error___________________________
Can't find string terminator "END_OF_TEXT" anywhere before EOF at
mycgi.cgi line 68.

thanx
-ben
thorgram@hotmail.com


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

Date: Fri, 19 Sep 1997 19:43:56 GMT
From: arpepper@math.uwaterloo.ca (Adrian Pepper)
Subject: Any Recommendations for portable signal processing?
Message-Id: <EGrtH8.Dy8@undergrad.math.uwaterloo.ca>

I have to do a moderate amount of signal catching in a perl application
which I would like to remain the same across 5 or so different UNIX and
UNIX-like (AIX) architectures.  (5 or so depending how you define
"different").  I also need to keep the application compatible with
Perl-4.0, since /usr/local/bin/taintperl seems to be perl 4, and
/usr/local/bin/perl -t is not guaranteed to work on all of them.

Now, one thing which surprises me is that

keys %SIG

is not initialized to anything.  Nor is there a built-in "kill -l".
One particularly horrible problem (although it doesn't concern me
in this application actually) is the ALM versus ALRM discrepancy.

<<<In the midst of this rambling, following paragraph is real question>>>
Since keys %SIG is not initialized, the initial state of the
signals cannot be determined through the SIG hash, can it?  (No,
apparently no magic takes place there; they have no value until you
give them one).  I.e. if I decide to temporarily catch something for
some reasons, how do I decide whether to put it back to DEFAULT or
IGNORE?

(Yes, if I look hard enough I find in the perl-4 man page for "perl";
"The SIG array only contains values for the signals actually set within
the perl script."   Side question: is a perl program really a script?
Why?  Discuss.  For full marks present at least ten good arguments on
both sides.  Also, I don't think that statement appears in the Perl 5
camel book, hey can I grep the book from the web site?  Hmm.  No, not
quite.  I suspect our proxy web-server must have cached the full
documentation manual 8-) and yes, that statement does seem to appear
there, but that's not the camel book, is it?--1535 50-line lynx pages
rather than 600 or so paper pages; not sure which is longer.  I suppose
publishers take a dim view of selling something on paper which can
be downloaded from the Web--Hey, can the version 4 camel book go on
the Web now?).

<<<another implied real question>>>
It's not clear to me whether the signal.ph and sys/signal.ph files
co-operate or compete with the internal signal mechanism.

Having to call `kill -l` to get a list of valid signal entries
(maybe; or have they been "standardized", esp wrt ALRM?) seems
really kludgey and possibly unreliable.  Oh well, I know which
ones I really care about, and restoring DEFAULT or IGNORE is
not an issue either.  I guess if I could guarantee perl 5 then
I would use the Config module as documented.  It incorporates
some improvements.  I suppose one problem with having an
initialized %SIG would be the pseudo-signal functions should
perhaps not be treated like other signals.

Now to see when that nifty list of perl resources arrives, and
how useful it is.


Adrian Pepper
Math Faculty Computing Facility
University of Waterloo, Ontario, Canada
arpepper@math.uwaterloo.ca


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

Date: Sun, 21 Sep 1997 05:19:07 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Any Recommendations for portable signal processing?
Message-Id: <EGuErw.F55@world.std.com>

arpepper@math.uwaterloo.ca (Adrian Pepper) writes:

>I have to do a moderate amount of signal catching in a perl application
>which I would like to remain the same across 5 or so different UNIX and
>UNIX-like (AIX) architectures.

Thats too bad. Have you seen the patches the Chip Salzenberg made for
perl5porters that make signals safe in perl? There seem to still be
some discussions about performance and backwards compatibility, but if
you're depending on signals working (and not causing a core dump.) you
probably want to take a look.

>Now, one thing which surprises me is that

>keys %SIG

>is not initialized to anything.  Nor is there a built-in "kill -l".
>One particularly horrible problem (although it doesn't concern me
>in this application actually) is the ALM versus ALRM discrepancy.

If you could use perl 5, you can get the signal names from the Config
module.

use Config;
@signames = split " ", $Config{sig_names};

>if I decide to temporarily catch something for
>some reasons, how do I decide whether to put it back to DEFAULT or
>IGNORE?

You can do something like this:

  {
     local($SIG{$signame}) = 'sig_catcher';
     # do something
  }  # end of block, localized va is gone, sig is reset to its original state.


><<<another implied real question>>>
>It's not clear to me whether the signal.ph and sys/signal.ph files
>co-operate or compete with the internal signal mechanism.

Well, it would be tough to get the names by requiring signal.ph (I
guess you could load it in a certain package, and then go through the
package and see which variables in the package match /^SIG/.)

Since .ph files are just mechanical conversions of their C headers
counterpart. I'd describe them as being oblivious to perl's signal
mechanism.

-- 
Andrew Langmead


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

Date: 20 Sep 1997 17:00:35 GMT
From: jgloudon@bbn.com (Jason Gloudon)
Subject: Re: Capitalizing the first letter via regex
Message-Id: <600vfj$553$1@daily.bbnplanet.com>

In article <slrn6274mm.fgi.tom@mitra.phys.uit.no>,
Tom Grydeland <tom@mitra.phys.uit.no> wrote:
>On Mon, 15 Sep 1997 12:25:56 -0700,
>Christopher Zukowski <czukowski@qualcomm.com> wrote:
>> To all,
>> 
>>     I am trying to figure out how to capitalize the first character of
>> an otherwise all lower case string.
                ^^^^^^^^^
You've missed quite a few replies to this. And you didn't answer his
question anyhow.

>
>$capstring = "\u$string";
>
>> Any suggestions?
>
>Read the FAQ.
>
>> Thank
>
>Yeah, right.
>
>> Christopher Zukowski
>
>-- 
>//Tom Grydeland <Tom.Grydeland@phys.uit.no>

Jason Gloudon


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

Date: Sat, 20 Sep 1997 12:26:14 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Capitalizing the first letter via regex
Message-Id: <mv0106.732.ln@localhost>

Jason Gloudon (jgloudon@bbn.com) wrote:
: In article <slrn6274mm.fgi.tom@mitra.phys.uit.no>,
: Tom Grydeland <tom@mitra.phys.uit.no> wrote:
: >On Mon, 15 Sep 1997 12:25:56 -0700,
: >Christopher Zukowski <czukowski@qualcomm.com> wrote:
: >> To all,
: >> 
: >>     I am trying to figure out how to capitalize the first character of
: >> an otherwise all lower case string.
:                 ^^^^^^^^^
: You've missed quite a few replies to this. 


What do you see that makes you think he has missed some replies?

Maybe his newsfeed is slow.

Just because you can see them does not mean that he can see them (yet).


: And you didn't answer his
: question anyhow.


What do you mean by that?

Tom's answer does indeed show how to capitalize the first character of
an otherwise all lower case string.


I can make no sense of either of your comments.

Please explain what you meant.


: >
: >$capstring = "\u$string";
: >
: >> Any suggestions?
: >
: >Read the FAQ.
: >
: >> Thank
: >
: >Yeah, right.
: >
: >> Christopher Zukowski
: >
: >-- 
: >//Tom Grydeland <Tom.Grydeland@phys.uit.no>

: Jason Gloudon


--
    Tad McClellan                          SGML Consulting
    tadmc@flash.net                        Perl programming
    Fort Worth, Texas


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

Date: 20 Sep 1997 21:11:14 GMT
From: jgloudon@bbn.com (Jason Gloudon)
Subject: Re: Capitalizing the first letter via regex
Message-Id: <601e5i$2i9$1@daily.bbnplanet.com>

In article <mv0106.732.ln@localhost>, Tad McClellan <tadmc@flash.net> wrote:
>Jason Gloudon (jgloudon@bbn.com) wrote:
>: In article <slrn6274mm.fgi.tom@mitra.phys.uit.no>,
>: Tom Grydeland <tom@mitra.phys.uit.no> wrote:
>: >On Mon, 15 Sep 1997 12:25:56 -0700,
>: >Christopher Zukowski <czukowski@qualcomm.com> wrote:
>: >> To all,
>: >> 
>: >>     I am trying to figure out how to capitalize the first character of
>: >> an otherwise all lower case string.
>:                 ^^^^^^^^^
>: You've missed quite a few replies to this. 
>
>
>What do you see that makes you think he has missed some replies?
>
>Maybe his newsfeed is slow.
>
>Just because you can see them does not mean that he can see them (yet).

Thought I saw several other replies to the question over the last few days.
trn dimensia perhaps ?
>
>
>: And you didn't answer his
>: question anyhow.
>
>
>What do you mean by that?
>
>Tom's answer does indeed show how to capitalize the first character of
>an otherwise all lower case string.

My read was that he wants to take words like allonecaselow and capitalize
the first letter, while leaving things like RAM or even i86 unmodified. 
However may brain may have been polluted as I did something similar to this
fairly recently. Sorry for reading like a lawyer.

Jason Gloudon


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

Date: 21 Sep 1997 01:44:45 GMT
From: gerben@cs.vu.nl (Gerben Vos)
Subject: Re: chop/chomp, take 2
Message-Id: <601u6d$dej$1@star.cs.vu.nl>

Steve Lamb writes:

>    I've been also loogging to a file now so I can use joe to look at the
>files and see any hidden characters.  Sad that the console cannot display
>these characters.

``cat -v'' can, at least on the systems i've been on.

g e r b e n @ c s . v u . n l . . . . . . . . . . . . G e r b e n   V o s   <><
Join the Coalition Against Unsolicited Commercial Email!  http://www.cauce.org/
The three principal virtues of a programmer are Laziness, Impatience,
and Hubris.                             -- Larry Wall


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

Date: Sat, 20 Sep 1997 21:11:43 GMT
From: over@the.net (dave)
Subject: Re: Does Perl Have C's fflush function?
Message-Id: <34243b17.18019574@news.one.net>

Jonathan Nichols <Jonathan.O.Nichols@ast.lmco.com> wrote:

>The subject says it all.  Can I flush an output buffer like I can in C
>with the fflush function?
>
>
>jon

I think your simple question deserves a simple answer.

There are two methods of setting stdout or any other file handle so
they are automatically flushed, so you don't need an fflush.  The one
I use is provided with the FileHandle package.  You simply say:

STDOUT->autoflush;

or substitute another filehandle for STDOUT.

The FileHandle package provides a lot of other nice functions.

Dave

|
| Please visit me at http://w3.one.net/~dlripber
|
| For reply by email, use:
| dlripber@one.net
|________


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

Date: 20 Sep 1997 21:25:15 GMT
From: shodan@shodan.erols.com (Dave Schenet)
Subject: Re: Getting next array element in a foreach
Message-Id: <601evr$4m4@winter.news.erols.com>

Gip (nospam.gibsonc@aztec.asu.edu) wrote:
: How would one go about getting the next element after finding an element
: in an array, using a foreach:

: # assume for this ex that the @array contains   b d h t
: foreach $item (@array) {

:   if ($item eq "d") {

:     # the next line is where my problem is; I want the next item 'h'!
:     $next_item = ??? ; # I've tried shift unshift pop push
:     $last;
:   }

: } 


You could also try:
foreach $item (@array) {
  if ($item eq "d") { next; }
}

And that will start the next iteration of the foreach loop.

--Dave


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

Date: 20 Sep 1997 21:05:35 GMT
From: dmacks@sas.upenn.edu (Daniel E. Macks)
Subject: Re: Getting next array element in a foreach
Message-Id: <601dqv$f2e$3@netnews.upenn.edu>

Since it sounds like the array itself is disposable (you were willing
to shift, etc.), just loop through it by shifting. Then you can get
the next element by doing a shift within the loop:

  while ($item = shift @array) {  # perhaps need a more robust test if
    if ($item eq 'd') {           # a value might be logically false
      $next_item = shift @array;
      unshift @array, $next_item; # only needed if you care to continue
      $last;      # dunno what this is, but hey--it's your code...
      last;       # perhaps you meant this instead?
    };
  };

If you're gonna need @array intact later, just run on a copy of it.

dan

Gip (nospam.gibsonc@aztec.asu.edu) said:
: How would one go about getting the next element after finding an element
: in an array, using a foreach:
: 
: # assume for this ex that the @array contains   b d h t
: foreach $item (@array) {
:   if ($item eq "d") {
:     # the next line is where my problem is; I want the next item 'h'!
:     $next_item = ??? ; # I've tried shift unshift pop push
:     $last;
:   }
: } 
: 
[ snip...wants to avoid a for() and subscripts of @array ]

-- 
Daniel Macks
dmacks@a.chem.upenn.edu
dmacks@netspace.org
http://www.netspace.org/~dmacks




-- 
Daniel Macks
dmacks@a.chem.upenn.edu
dmacks@netspace.org
http://www.netspace.org/~dmacks



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

Date: 20 Sep 1997 19:20:03 -0700
From: Terrence Brannon <brannon@surf.usc.edu>
Subject: HELP: Unable to reference package variables
Message-Id: <lb202jh0h8.fsf@surf.usc.edu>

  DB<6> brannon@surf /export/freeway/brannon/nuweb/workspace : perl -de 42
  DB<1> use lib '/export/freeway/brannon/nuweb/workspace'
  DB<2> $HH::voltage = 20;
  DB<5> use HH
  DB<6> HH::calculate_rate_constants;
voltage: n: -0.1d: -0.632120558828558
^^^^^^^^ there is no voltage printed, even though defined in debugger.
alpha_h::::> 49963425.6382427

======================== here is the Module:

package HH;
use Exporter;

@ISA = qw(Exporter);
@EXPORT = qw(voltage calculate_rate_constants alpha beta);

use strict;

sub calculate_rate_constants {

    my ($pn, $pm);

    printf "voltage: ", $HH::voltage, $/;

    if ($HH::voltage == 10) {
	$HH::alpha{'n'} = $pn;
    } else {
	my $n = (0.01*(-$HH::voltage + 10));
	my $d = (exp((-$HH::voltage + 10)/10) - 1);
	print "n: ", $n, "d: ", $d, $/;
	$HH::alpha{'n'} = $n / $d;
#	    (0.01*(-$HH::voltage + 10)) / (exp((-$HH::voltage + 10)/10) - 1);
    }
    $pn = $HH::alpha{'n'};
    $HH::beta{'n'} = 0.125 * exp(-$HH::voltage/80);

    if ($HH::voltage == 25) {
	$HH::alpha{'m'} = $pm;
    } else {
	my $n = 0.1*(-$HH::voltage + 25.0);
	my $d = (exp( (-$HH::voltage + 25.0)/10 ) - 1.0);
	$HH::alpha{'m'} = $n / $d ;
    }
    $pm = $HH::alpha{'m'};
    $HH::beta{'m'} = 4 * exp(-$HH::voltage/ 18.0);

    $HH::alpha{'h'} = \
	0.07*exp(-$HH::voltage/20);
    print "alpha_h::::> ", $HH::alpha{'h'}, $/;
    $HH::beta{'h'} = \
	1.0 / (exp((-$HH::voltage + 30)/10) + 1);
}


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

Date: Sat, 20 Sep 1997 00:04:27 -0700 (PDT)
From: Michael de Beer <madebeer@igc.apc.org>
Subject: Re: looping through an sql query using win32::odbc
Message-Id: <APC&1'0'50775d8b'11b@igc.apc.org>

Each time you run this code you overwrite @ok.  I don't think this is 
what you want.

# separates each line of the file and breaks each line up into an array
foreach $line (@file){
   $_ = $line;
   @ok = split(/ /,   $line);
}

-mike de beer
madebeer@igc.org


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

Date: 20 Sep 1997 19:43:42 -0700
From: Terrence Brannon <brannon@surf.usc.edu>
Subject: mathematical calculation varies greatly between call and debugger
Message-Id: <lbzpp7fktd.fsf@surf.usc.edu>


when called with a value of 0 from a test script or debugger, I get a
completely erroneous value for $alpha{'h'} from my function
calculate_rate_constants. However simply calculating the exponential
of 0 and multiplying by 0.07 gives the right answer. I dont know why
this script would bomb.

==============test script
#!/usr/bin/perl

use lib '/export/freeway/brannon/nuweb/workspace';
use PGPLOT;
use HH;

use strict;



$HH::voltage = 0;
HH::calculate_rate_constants($HH::voltage);

    printf "-----", $/;
    print "voltage, ", $HH::voltage, $/;
    print "alpha_n ", $HH::alpha{'n'}, $/;
    print "beta_n ", $HH::beta{'n'}, $/;
    print "alpha_m ", $HH::alpha{'m'}, $/;
    print "HH::beta_m ", $HH::beta{'m'}, $/;
    print "alpha_h ", $HH::alpha{'h'}, $/;
    print "HH::beta_h ", $HH::beta{'h'}, $/;

    ++$HH::point_count;
    push(@HH::x, $HH::voltage);
    push(@HH::y, HH::tau('n'));


print join ':', @HH::y;
print $/;

PGPLOT::pgbegin(0,"?",1,1);
PGPLOT::pgenv(-70,60,0,0.6,0,0);
PGPLOT::pgline($HH::point_count,\@HH::x,\@HH::y);
PGPLOT::pgend;



============== package

package HH;
require Exporter;
use strict;
#@Exporter::ISA = qw(Exporter);
#@Exporter::EXPORT = qw($voltage calculate_rate_constants %alpha %beta);



sub calculate_rate_constants {

    my ($pn, $pm);

    $HH::voltage = $_[0];

#    print "got: ", $_[0];
    print "voltage: ", $HH::voltage, $/;

    if ($HH::voltage == 10) {
	$HH::alpha{'n'} = $pn;
    } else {
	my $n = (0.01*(-$HH::voltage + 10));
	my $d = (exp((-$HH::voltage + 10)/10) - 1);
	print "n: ", $n, "d: ", $d, $/;
	$HH::alpha{'n'} = $n / $d;
#	    (0.01*(-$HH::voltage + 10)) / (exp((-$HH::voltage + 10)/10) - 1);
    }
    $pn = $HH::alpha{'n'};
    $HH::beta{'n'} = 0.125 * exp(-$HH::voltage/80);

    if ($HH::voltage == 25) {
	$HH::alpha{'m'} = $pm;
    } else {
	my $n = 0.1*(-$HH::voltage + 25.0);
	my $d = (exp( (-$HH::voltage + 25.0)/10 ) - 1.0);
	$HH::alpha{'m'} = $n / $d ;
    }
    $pm = $HH::alpha{'m'};
    $HH::beta{'m'} = 4 * exp(-$HH::voltage/ 18.0);

    $HH::alpha{'h'} = \
	0.07*exp(-$HH::voltage/20);
    print "alpha_h::::> ", $HH::alpha{'h'}, $/;
    $HH::beta{'h'} = \
	1.0 / (exp((-$HH::voltage + 30)/10) + 1);
}

sub tau {
    my $state_var = $_[0];

#    print "state_var ", $state_var, $/;

    1.0 / ( $HH::alpha{$state_var} + $HH::beta{$state_var} ) ;
}

sub infty {
    my $state_var = $_[0];

    print "state_var ", $state_var, $/;

    $HH::alpha{$state_var} / ( $HH::alpha{$state_var} + $HH::beta{$state_var} ) ;
}



1;

-- 
o============o  Sending unsolicited commercial e-mail (UCE)  to this address
 Legal Notice   is indication of your consent to pay me $120/hour for 1 hour
o============o  minimum for professional proofreading & technical assessment.
  Terrence Brannon * brannon@surf.usc.edu * http://quake.usc.edu/~brannon


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

Date: 20 Sep 1997 18:27:10 GMT
From: trockij@transmeta.com (Jim Trocki)
Subject: mon-0.37d - Service Monitoring Daemon
Message-Id: <6014hu$gsb$1@palladium.transmeta.com>

Mon version 0.37d

INTRODUCTION
------------

"mon" is a tool for monitoring the availability of services. Services
may be network-related, environmental conditions, or nearly anything
that can be tested with software.  It is extremely useful for system
administrators, but not limited to use by them. It was designed to
separate the tasks of monitoring a service for availability and sending
out alerts when things fail. To achieve this, "mon" is implemented as a
scheduler which runs the programs which do the testing, and triggering
alert programs when these scripts detect failure.  None of the actual
service testing or reporting is actually handled by "mon". These functions
are handled by auxillary programs.

This model was chosen because it is very extensible, and does not require
changing the code of the scheduler to add new tests and alert types. For
example, an alphanumeric paging alert can be added simply by writing a
new alert script, and referencing the alert script in the configuration
file. Monitoring the temperature in a room can be done by adding a script
that gathers data from a thermistor via a serial port.  Often these
monitoring scripts can just be wrappers for pre-existing software.

The "mon" scheduler also can communicate with network clients, allowing
manipulation of run-time parameters, disabling and enabling of alerts
and tests, listing failure and alert history, and reporting of current
states of all monitors.

AVAILABILITY
------------

The latest version of mon is available at:

http://consult.ml.org/~trockij/mon


REQUIREMENTS
------------

"mon" uses Perl 5.n, where n >= 003.

You'll need the Time::Period module, available from your local
CPAN archive (http://www.perl.com/perl).

"mon" uses the Sys::Syslog module that comes with Perl 5. If you're
running this under Linux, you must patch "Syslog.pm" with one of the
supplied patches written by Sean Robinson (robinson_s@sc.maricopa.edu).
These patches can be found in the patches/ directory.

You need the "File::Df" module from CPAN for freespace.monitor
to operate.

To use "telnet.monitor", "tcp.monitor", and "fping.monitor" (which all
come with the mon distribution), you need the "fping" and "tcp_scan"
utilities from Wietse Venema and Dan Farmer's Satan package to make
monitoring easier and more efficient. If you're building under Linux,
you'll need the 4.4BSD netinet headers (distributed separately), and a
patch to tcp_scan.c that fixes arguments to select(2).

----------
Jim Trocki
Computer System and Network Engineer
Transmeta Corporation
Santa Clara, CA
trockij@transmeta.com


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

Date: Sun, 21 Sep 1997 05:15:12 GMT
From: "Tam, Kai Fai" <tam1@uwindsor.ca>
Subject: Question about pattern matching!
Message-Id: <3424AD60.266C@uwindsor.ca>

Hi! Everyone,

Do you guys have any clue about what the subroutine below
is doing?



while ($buf =~ /^^(.*)\n\r?([\000-\377]*)$/) 
{
     $_ = $1;
     $buf = $2;
}




Thanks!


Ken


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

Date: Sat, 20 Sep 1997 11:00:01 -0700
From: see@sig.line (Justin Greer)
Subject: Redirecting stderr to stdout
Message-Id: <MPG.e8daefc2cf0b44d989680@nntp.ix.netcom.com>


How might I make the stderr and stdout both print to stdout?  I have a 
little prog to run telnet commands over the web, and even with a 

open(STDERR,">&STDOUT");

it doesn't seem to give me the errors...


Thanks,
  Justin Greer
-- 
#!/usr/local/bin/perl
$email = 'khsffs@ufdiopmphjtu.dpn';
$email =~ tr/b-z/a-z/;
print "$email\n";


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

Date: Sun, 21 Sep 1997 05:23:34 GMT
From: aml@world.std.com (Andrew M. Langmead)
Subject: Re: Redirecting stderr to stdout
Message-Id: <EGuEzA.G89@world.std.com>

see@sig.line (Justin Greer) writes:

>How might I make the stderr and stdout both print to stdout?  I have a 
>little prog to run telnet commands over the web, and even with a 

>open(STDERR,">&STDOUT");

>it doesn't seem to give me the errors...

I'd explain it, but Tom Christiansen already has in the FAQ:

>  How can I capture STDERR from an external command?
>
>    There are three basic ways of running external commands:
>
>        system $cmd;                # using system()
>        $output = `$cmd`;           # using backticks (``)
>        open (PIPE, "cmd |");       # using open()
>
>    With system(), both STDOUT and STDERR will go the same place as the
>    script's versions of these, unless the command redirects them.
>    Backticks and open() read only the STDOUT of your command.
>
>    With any of these, you can change file descriptors before the call:
>
>        open(STDOUT, ">logfile");
>        system("ls");
>
>    or you can use Bourne shell file-descriptor redirection:
>
>        $output = `$cmd 2>some_file`;
>        open (PIPE, "cmd 2>some_file |");
>
>    You can also use file-descriptor redirection to make STDERR a
>    duplicate of STDOUT:
>
>        $output = `$cmd 2>&1`;
>        open (PIPE, "cmd 2>&1 |");
>
>    Note that you *cannot* simply open STDERR to be a dup of STDOUT in
>    your Perl program and avoid calling the shell to do the redirection.
>    This doesn't work:
>
>        open(STDERR, ">&STDOUT");
>        $alloutput = `cmd args`;  # stderr still escapes
>
>    This fails because the open() makes STDERR go to where STDOUT was
>    going at the time of the open(). The backticks then make STDOUT go to
>    a string, but don't change STDERR (which still goes to the old
>    STDOUT).
>
>    Note that you *must* use Bourne shell (sh(1)) redirection syntax in
>    backticks, not csh(1)! Details on why Perl's system() and backtick and
>    pipe opens all use the Bourne shell are in
>    http://www.perl.com/CPAN/doc/FMTEYEWTK/versus/csh.whynot .
>
>    You may also use the IPC::Open3 module (part of the standard perl
>    distribution), but be warned that it has a different order of
>    arguments from IPC::Open2 (see the IPC::Open3 manpage).
-- 
Andrew Langmead


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

Date: 21 Sep 1997 05:59:20 +0200
From: Hallvard B Furuseth <h.b.furuseth@usit.uio.no>
Subject: setgid bit on GNU make?
Message-Id: <HBF.970921owfy@bombur2.uio.no>

hints/solaris_2.sh says:

 NOTE: Your PATH points to GNU make, and your GNU make has the set-group-id
 bit set.  You must either rearrange your PATH to put /usr/ccs/bin before the
 GNU utilities or you must ask your system administrator to disable the
 set-group-id bit on GNU make.

Why is this?  For that matter, why would anyone *set* the setgid bit?

-- 
Hallvard


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

Date: 20 Sep 1997 20:36:08 -0700
From: danny@lennon.postino.com (Danny Aldham)
Subject: Re: SQL program that works both in Win'95 and Linux
Message-Id: <6024n8$ogi$1@lennon.postino.com>

kiet (kiet@uclink2.berkeley.edu) wrote:

: Hi people of the world:

: Anyone know of a SQL program that works both in Win'95 and Linux.  The
: only thing that I found are exclusive for Win'95 or Linux.  Such programs
: for Win'95 are Access, MS-SQL, Fox Pro.  For Linux they are mSQL, Oracle.
: I just want a mini-SQL that works in both environment.  

Since most MS programs are commercial, I wouldn't look for Windows
programs running on Linux. Best to look for unix/Linux stuff ported
to Win32. Start at www.cygnus.com , where they are heading a gnu-win32
project. If it has been ported to win32 from unix, you should find a
pointer there.

--
Danny Aldham           SCO Ace , MCSE , JAPH , DAD
I wak'd, she fled, and day brought back my night. jm


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

Date: Sun, 21 Sep 1997 01:37:49 +0900
From: Dan Kogai <dankogai@dan.co.jp>
Subject: Re: To delete a file
Message-Id: <3423FBAF.1E4CCBF6@dan.co.jp>

RobStone wrote:
> How do I delete a file - or in general - how do I perform disk
> operations in Perl ?

unlink $afile;

# perldoc -f unlink

Dan the Camel Abuser


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

Date: Sat, 20 Sep 1997 23:21:27 GMT
From: RaviA@CommerceToday.com (Ravi Agarwal)
Subject: Tricky Sort Command - sorting a list
Message-Id: <342459c7.4542490@news2.ibm.net>

Problem: How do you sort a hash of arrays?

For example,

%abc = (
	"7" => [ "dog", "cat", "rat" ],
	"3" => [ "computer", "mouse", "drive" ],
	"9" => [ "phone", "fax", "tele" ]
);

I want to sort %abc by the key, so that when I do:
foreach $key (keys %abc) {
	print "$key = @{ $abc{$key}}";
}

I want:
3 = computer mouse drive
7 = dog cat rat
9 = phone fax tele

The key holds an order id and I need to sort by this field.

Can anyone PLEASE help me with this tricky sort command??

Thanks.

-Ravi Agarwal
http://www.CommerceToday.com
RaviA@CommercToday.com
"Secure Electronic Commerce at an Affordable Price"
(800) 505-5484	


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

Date: 20 Sep 1997 23:52:09 GMT
From: jgloudon@bbn.com (Jason Gloudon)
Subject: Re: Tricky Sort Command - sorting a list
Message-Id: <601nj9$jkb$1@daily.bbnplanet.com>

In article <342459c7.4542490@news2.ibm.net>,
Ravi Agarwal <RaviA@CommerceToday.com> wrote:
>Problem: How do you sort a hash of arrays?
>
>For example,
>
>%abc = (
>	"7" => [ "dog", "cat", "rat" ],
>	"3" => [ "computer", "mouse", "drive" ],
>	"9" => [ "phone", "fax", "tele" ]
>);
>
>I want to sort %abc by the key, so that when I do:
>foreach $key (keys %abc) {

The 'trick' for this is in the perlfunc manpage, in the documentation for 
sort as 

   # sort numerically ascending
   @articles = sort {$a <=> $b} @files;

What you are looking for looks like 
   foreach $key (sort {$a <=> $b} keys %abc)

It isn't tricky, once you understand what keys returns and what sort does.

Jason Gloudon


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

Date: 20 Sep 1997 20:08:06 -0400
From: Douglas McNaught <doug@tc.net>
To: RaviA@CommerceToday.com
Subject: Re: Tricky Sort Command - sorting a list
Message-Id: <m2zpp7plzt.fsf@ono.tc.net>

[mailed and posted]

RaviA@CommerceToday.com (Ravi Agarwal) writes:

> Problem: How do you sort a hash of arrays?
> 
> For example,
> 
> %abc = (
> 	"7" => [ "dog", "cat", "rat" ],
> 	"3" => [ "computer", "mouse", "drive" ],
> 	"9" => [ "phone", "fax", "tele" ]
> );
> 
> I want to sort %abc by the key, so that when I do:
> foreach $key (keys %abc) {
> 	print "$key = @{ $abc{$key}}";
> }

You can't sort a hash, but you can iterate through it in sorted
order.  Your code is actually very close.  Try this:

foreach $key (sort {$a <=> $b} keys %abc) {
	print "$key = @{ $abc{$key}}";
}

I've put a numeric comparison function in there since it looks like
your keys are numeric--if they're alpha, you can leave it out since
sort defaults to alpha ordering.

-Doug
-- 
sub g{my$i=index$t,$_[0];($i%5,int$i/5)}sub h{substr$t,5*$_[1]+$_[0],1}sub n{(
$_[0]+4)%5}$t='encryptabdfghjklmoqsuvwxz';$c='fxmdwbcmagnyubnyquohyhny';while(
$c=~s/(.)(.)//){($w,$x)=g$1;($y,$z)=g$2;$w==$y&&($p.=h($w,n$x).h($y,n$z))or$x==
$z&&($p.=h(n$w,$x).h(n$y,$z))or($p.=h($y,$x).h($w,$z))}$p=~y/x/ /;print$p,"\n";


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

Date: Sun, 21 Sep 1997 01:44:17 +0900
From: Dan Kogai <dankogai@dan.co.jp>
Subject: Re: Value within range?
Message-Id: <3423FD33.D2FCAFE2@dan.co.jp>

Craig M. Votava wrote:
> I trying to understand the best way to check if a value is within a
> given range.

sub within_range{my($n,$min,$max) = @_; return ($min <= $n and $n <= $max);}
# change <= to < if excluding the boundary

Dan the Camel Abuser


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

Date: Sun, 21 Sep 1997 12:32:11 +0900
From: Dan Kogai <dankogai@dan.co.jp>
To: Bjorn <bjorn@earthcorp.nn.se>
Subject: Week of the Year [Was: Re: Calculating the week number]
Message-Id: <34249521.9ED47E96@dan.co.jp>

Bjorn wrote me back via mail;
> > > I need a piece of code for calculating the current week. I checked the
> > > perl FAQ, but the formula there doesn't work (unless you're on a year
> > > that starts with monday and don't care about the last week being
> > > correct). Any help would be greatly appreciated...
> > 
> > $thisweek = (localtime())[6];
> > 
> This only tells him the day of the week.  Not the week of the year.

  Ah!  I was mistaken.  Still a trivial prob to me....

sub weekofyear($$$){	# weekofyear(21, 8, 97) for today.  It was 37.
    my($dd, $mm, $yy) = @_;
    use Time::Local;
    my $thedate = timelocal(0,0,0,$dd, $mm, $yy);
    my $jan1st  = timelocal(0,0,0,  1,   0, $yy);
    my $weeklen = 60 * 60 * 24 * 7;	# take this out of the function if
									# you use this function frequently.
    return int(($thedate - $jan1st) / $weeklen);
}

And all you need is &weekofyear((localtime())[3..5]);.

> I also have a feeling that I made this calculation more complex than 
> I needed to.

  Your feeling was correct.  It doesn't matter what day of the week Jan 1st
is.  All it counts is the difference of time.
  Rule of the thumb for time conversion;  Convert it to seconds first.

Dan the Camel Abuser


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

Date: Sun, 21 Sep 1997 13:25:50 +0900
From: Dan Kogai <dankogai@dan.co.jp>
Subject: Week of the Year [Was: Re: Calculating the week number]
Message-Id: <3424A1AF.575F3D4E@dan.co.jp>

Dan Kogai wrote:
>   Ah!  I was mistaken.  Still a trivial prob to me....

  Not so fast, Dan!  The function is supposed to yield;

1997/01/01 = week 0 (Wed)
1997/01/02 = week 0 (Thu)
1997/01/03 = week 0 (Fri)
1997/01/04 = week 0 (Sat)
1997/01/05 = week 1 (Sun)
1997/01/06 = week 1 (Mon)
1997/01/07 = week 1 (Tue)

  But yours go;

1997/01/01 = week 0 (Wed)
1997/01/02 = week 0 (Thu)
1997/01/03 = week 0 (Fri)
1997/01/04 = week 0 (Sat)
1997/01/05 = week 0 (Sun)
1997/01/06 = week 0 (Mon)
1997/01/07 = week 0 (Tue)

  Remember a week starts on Sunday, not an arbitrary day
of the week like Wednesdey?   Here is a correct and inproved
version;

sub weekofyear($$$){
    my($dd, $mm, $yy) = @_;
    use Time::Local;
    use integer;
    my $daylen      = 86400;
    my $thedate     = timelocal(0,0,0,$dd, $mm, $yy);
    my $jan1st      = timelocal(0,0,0,1,   0,   $yy);
    my $magic       = (localtime($jan1st))[6] * $daylen;
    my $theweek     = ($thedate + $magic - $jan1st) / ($daylen * 7);
}

  See the usage of $magic?  That way we can always start the week on
Sundays.

Dan the Camel Abuser


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

Date: Sun, 21 Sep 1997 02:12:53 GMT
From: "Tam, Kai Fai" <tam1@uwindsor.ca>
Subject: what's wrong in this function?
Message-Id: <342482A5.6FF7@uwindsor.ca>

Hi! Everyone,

Do you have any idea about what's wrong in the function below,
no matter syntax or style?


sub award
{
  local ($tmpflags);

  $tmpflags=$flags; $flags="g"; &matchaction; $flags=$tmpflags;
}


Thanks!

Ken


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

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

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed 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 V8 Issue 1055
**************************************

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