[10763] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4364 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Dec 5 11:07:21 1998

Date: Sat, 5 Dec 98 08:00:22 -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           Sat, 5 Dec 1998     Volume: 8 Number: 4364

Today's topics:
    Re: @INC... (Bart Lateur)
        Animals and Perl (was Re: newbie file open question) <gellyfish@btinternet.com>
    Re: Animals and Perl (was Re: newbie file open question (Fluffy)
    Re: ARP? or How to get MAC address? <gellyfish@btinternet.com>
    Re: can match $n times be done? (Larry Rosler)
    Re: can match $n times be done? (David Alan Black)
    Re: clean up html tags <gellyfish@btinternet.com>
    Re: clearing the screen in perl? <gellyfish@btinternet.com>
    Re: Convert $seconds to $hours:$min:$sec (Bart Lateur)
    Re: Convert $seconds to $hours:$min:$sec <tchrist@mox.perl.com>
    Re: Creating a key field for writing relational databas taktisk_semantik@my-dejanews.com
        file locking <wongk@ug.eds.com>
    Re: File with Sendmail <gellyfish@btinternet.com>
        Installing Win32 Perl (was Re: Seeking Win32::DES.pm) <gellyfish@btinternet.com>
    Re: Merge Files <group95@allied.demon.co.uk>
    Re: Missing warning on '23foo'++ (Ilya Zakharevich)
    Re: Missing warning on '23foo'++ <dgris@moiraine.dimensional.com>
    Re: newbie file open question <dgris@moiraine.dimensional.com>
    Re: newbie question searching string with =~ <perlguy@technologist.com>
        Newbie: Secure directories?? <webmaster@bluegalaxy.hypermart.net>
        Problem printing with CGI.pm (Glen)
    Re: Problem printing with CGI.pm <Tony.Curtis+usenet@vcpc.univie.ac.at>
    Re: Problem printing with CGI.pm <gellyfish@btinternet.com>
    Re: Problem with seek..... (Bart Lateur)
    Re: Recipe Database for Unix <gellyfish@btinternet.com>
    Re: signals on Windows nt <gellyfish@btinternet.com>
    Re: system commands in WinNT <gellyfish@btinternet.com>
    Re: Tool to reverse engineer perl code <gellyfish@btinternet.com>
    Re: using exec cmd <Tony.Curtis+usenet@vcpc.univie.ac.at>
    Re: Using glob() w/WinNT vs. glob() w/Win95 (Randy Kobes)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Sat, 05 Dec 1998 14:26:52 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: @INC...
Message-Id: <36703cb8.3234752@news.skynet.be>

Brad Whitaker wrote:

>I'm running Perl Win32 and I need to add /apache/cgi-bin to the @INC
>directory.  How do I do this permanently?  Do I have to compile the
>source with my dir added in???

Check if your distribution honnors the PERLLIB or PERL5LIB environment
variables.

	Bart.


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

Date: 5 Dec 1998 15:09:40 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Animals and Perl (was Re: newbie file open question)
Message-Id: <74bibk$qp$1@gellyfish.btinternet.com>

On Fri, 04 Dec 1998 15:10:12 +0000 23_skidoo <nospam23_skidoo@geocities.com> wrote:
<snip>
> thing? (newbie perl hacker but i've been reading the word crufty a lot
> round here, never felt the need to ask what it meant as it seemed pretty
> self evident :)

I always thought that it was something to do with dogs but I guess thats
not appropriate in a Perl context. This gives rise to another thought
regarding an earlier thread - would a dog walking on the keyboard
produce better Perl than a cat ?  To this end I simulated the canine
perambulations with a Portmerion vase ....

<dragged off sighing 'whoever you are I've always relied on the kindness of
strangers'>

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: 5 Dec 1998 15:32:47 GMT
From: gerglery@usa.net (Fluffy)
Subject: Re: Animals and Perl (was Re: newbie file open question)
Message-Id: <slrn76ikgv.icn.gerglery@meowhost.meow.invalid>

Jonathan Stowe <gellyfish@btinternet.com> wrote:
> This gives rise to another thought regarding an earlier thread -
> would a dog walking on the keyboard produce better Perl than a cat ?

Ha!  Dogs can't program for beans.



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

Date: 5 Dec 1998 14:16:46 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: ARP? or How to get MAC address?
Message-Id: <74bf8e$od$1@gellyfish.btinternet.com>

On Fri, 04 Dec 1998 15:11:24 GMT Scott Steeves <steevess@shore.net> wrote:
>    I really hope that I've done enough searching and haven't missed
> something stupid, but...
>    
>    Is there any module that has a routine that I can use to determine
> the MAC address of a remote system? I'm looking for ARP, basically.
> 
>    I did find a couple routines that shell to run a system command,
> but I was hoping to do it entirely within Perl.
> 

There doesnt appear to be such a module available from CPAN (but perhaps I
wasnt looking hard enough).  If you wanted to implement one yourself you
would want to seek out the the specification for the ARP.  On some unix
systems you might have a /proc/net/arp file that can be read to divulge
this information - you could try something like this:


#!/usr/bin/perl

open(ARP,"/proc/net/arp") || die "Cant open arp - $!\n";

while(<ARP>)
  {
    next if /^IP/;
    chomp;
    my ($ip,$type,$flags,$mac,$mask,$device) = split ' ';

    print "MAC address for $ip is $mac\n";
  }
close ARP


You could of course make this a little more sophisticated with a
gethostbyaddr() to obtain the hostname associated with each MAC. I would
have done this myself but I havent get an NIC in this machine and am not
currently online.

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Sat, 5 Dec 1998 06:45:50 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: can match $n times be done?
Message-Id: <MPG.10d2e6f41de3597f989941@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and copy mailed.]

In article <ebohlmanF3HG4G.DJK@netcom.com> on Sat, 5 Dec 1998 08:12:16 
GMT, Eric Bohlman <ebohlman@netcom.com> says...
> Paul J. Lucas <pjl@be-NOSPAM-st.com> wrote:
> : 	I have a string of words I want to truncate after the nth word
> : 	where $n is a variable:
> 
> : 		$_ = "now is the time for all good men";
> 
> $_ = join '', split (/(\W+)/, $_, 2*$n-1);

That is wrong as it stands, because the result is identical to the 
input.  I doubt that you tested it before posting it.

  $_ = join '', split (/(\W+)/, $_, 2*$n-1)[0 .. 2*$n-1];

I benchmarked this correct version against the regex, and chose not to 
post it.

It has two disadvantages compared to the regex:

1.  It is almost two times slower as it stands. 

2.  It is not '-w'-silent if the operand string is too short.  Fixing 
it:
  $_ = join '', map defined $_ && $_, (split /(\W+)/)[ 0 .. 2*$n-1];
makes it *three* times slower!

#!/usr/local/bin/perl -w
use Benchmark;

$x = "now is the time for all good men";
$n = 5;

timethese ( (1 << (shift || 0) ), {
  Regex => sub {
    my $pat = "((?:\\S+\\s+){$n}).*"; ($y = $x) =~ s/$pat/$1/ },
  Split0 => sub {
    $y = join "", split /(\S+)/, $x, 2*$n-1 },        # Wrong.
  Split1 => sub {
    $y = join "", (split /(\S+)/, $x)[0 .. 2*$n-1] }, # Noisy.
  Split2 => sub { $y = join "", map defined $_ && $_,
                  (split /(\S+)/, $x)[0 .. 2*$n-1] }, # OK.
  Split3 => sub { $y = join "", map defined $_ && $_,
        (s  plit /(\S+)/, $x, 2*$n-1)[0 .. 2*$n-1] }, # No better.
} );
__END__

Benchmark: timing 16384 iterations of Regex, Split0, Split1, Split2, 
Split3...
     Regex:  2 wallclock secs ( 1.37 usr +  0.00 sys =  1.37 CPU)
    Split0:  2 wallclock secs ( 2.64 usr +  0.00 sys =  2.64 CPU)
    Split1:  3 wallclock secs ( 3.03 usr +  0.00 sys =  3.03 CPU)
    Split2:  4 wallclock secs ( 4.39 usr +  0.00 sys =  4.39 CPU)
    Split3:  5 wallclock secs ( 4.57 usr +  0.00 sys =  4.57 CPU)

But thank *you* for posting it, so my attempt wasn't in vain. :-)

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 5 Dec 1998 10:27:04 -0500
From: dblack@pilot.njin.net (David Alan Black)
Subject: Re: can match $n times be done?
Message-Id: <74bjc8$6e9$1@pilot.njin.net>

Hello -

lr@hpl.hp.com (Larry Rosler) writes:

>timethese ( (1 << (shift || 0) ), {
>  Regex => sub {
>    my $pat = "((?:\\S+\\s+){$n}).*"; ($y = $x) =~ s/$pat/$1/ },
>  Split0 => sub {
>    $y = join "", split /(\S+)/, $x, 2*$n-1 },        # Wrong.
>  Split1 => sub {
>    $y = join "", (split /(\S+)/, $x)[0 .. 2*$n-1] }, # Noisy.
>  Split2 => sub { $y = join "", map defined $_ && $_,
>                  (split /(\S+)/, $x)[0 .. 2*$n-1] }, # OK.
>  Split3 => sub { $y = join "", map defined $_ && $_,
>        (s  plit /(\S+)/, $x, 2*$n-1)[0 .. 2*$n-1] }, # No better.
>} );
>__END__

>Benchmark: timing 16384 iterations of Regex, Split0, Split1, Split2, 
>Split3...
>     Regex:  2 wallclock secs ( 1.37 usr +  0.00 sys =  1.37 CPU)
>    Split0:  2 wallclock secs ( 2.64 usr +  0.00 sys =  2.64 CPU)
>    Split1:  3 wallclock secs ( 3.03 usr +  0.00 sys =  3.03 CPU)
>    Split2:  4 wallclock secs ( 4.39 usr +  0.00 sys =  4.39 CPU)
>    Split3:  5 wallclock secs ( 4.57 usr +  0.00 sys =  4.57 CPU)


Another sort of hybrid approach:

join '', ($x =~ /\S+\s*/g)[0..$n-1]

which comes about the same as 'Regex', above.


David Black
dblack@pilot.njin.net


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

Date: 5 Dec 1998 14:38:10 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: clean up html tags
Message-Id: <74bggi$ot$1@gellyfish.btinternet.com>

On Fri, 04 Dec 1998 04:20:32 -0800 Xah <xah@best.com> wrote:
> 
> I have about a hundred html files that I want to eliminate all the style tags 
> such as <font>, bgcolor, etc. I can easily write a simple-minded script 
> to do it but I want correctness. I can also try to download 
> HTML::Parser and spend time to learn to use it, but it seems overkill.
> 
> Are there utilities or the like that strips non-essential html tags? 
> This seems  to me a common task.

It all depends on what you are calling non-essential html tags of course.

You really *do* want to use HTML::Parser to do this job though - if you
go to : <URL:http://www.btinternet.com/~gellyfish/resources/htbeauty.htm>
you will find an example of the use of HTML::Parser and you can hack it
around to not print the tags and attributes you want to get rid of.

/J\

-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: 5 Dec 1998 14:27:46 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: clearing the screen in perl?
Message-Id: <74bft2$op$1@gellyfish.btinternet.com>

On 4 Dec 1998 17:07:39 -0800 Jim Matzdorff <syran@shell1.ncal.verio.com> wrote:
> So, I have looked around at perl.com, couldn't find an answer.
> 
> SO... :)
> 
> Is there a way to clear the screen in perl?  Such as "clear" in a shell?  I
> can't backtick it and run clear, since that clears the shell's screen, not the current
> screen.  Am I (and I know I am) missing something simple here?
> 

You want to use the Term::Cap module :


#!/usr/bin/perl

require Term::Cap;


my $terminal = Tgetent Term::Cap { TERM => undef, OSPEED => 9600};

print $terminal->Tputs('cl',1);
__END__
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Sat, 05 Dec 1998 14:26:44 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Convert $seconds to $hours:$min:$sec
Message-Id: <366f3c49.3124298@news.skynet.be>

Bryce Pursley wrote:

>To be honest, I'm not doing real well with my kludge.
>
>$deltatime is the difference between the "occur" time and "clear" time
>of an alarm in my alarm system in "seconds."
>
>$deltasec = ($deltatime % 3600);
># this can still be over 59 so it's not finished yet
>
>$deltamin = ($deltasec / 60);
># I can use printf to make this "look" right but I can't use it in
>other operations real well.  I want just the quotient and drop the
>fraction.
 ....

Perl doesn't have an integer division operator (or has it?), so you
better use int() to round the numbers *down*.

	$deltahour = int($deltatime / 3600); 
	$deltatime %= 3600; # drop the hours
	# only minutes and seconds left
	$deltasec = $deltatime % 60; # seconds only
	$deltamin = int($deltatime / 60); # minutes only

Now that you have all of the seconds, minutes and hours, combine them
using 2 digits per number:

      $time = sprintf ("%2d:%02d:%02d", $deltahour,$deltamin,$deltasec);

   HTH,
   Bart.


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

Date: 5 Dec 1998 15:04:47 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Convert $seconds to $hours:$min:$sec
Message-Id: <74bi2f$2hb$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    bart.lateur@skynet.be (Bart Lateur) writes:
:Perl doesn't have an integer division operator (or has it?), so you
:better use int() to round the numbers *down*.

int() doesn't round numbers `down'.  It performs integer truncation.
This is virtually unrelated.

  for ($i = $sum = 0; $i < 19; $sum += -1/19, $i++) {}
  printf "%.20g", $sum                                
-0.99999999999999955591
  print int $sum
0

I would hardly call that rounding, or down.

  for ($i = $sum = 0; $i < 19; $sum += 5/19, $i++) {} 
  printf "%.20g", $sum
5.0000000000000008882
  print int $sum
5

You want to be using printf, sprintf, or the POSIX floor or ceiling
functions. Any of these games with int($n + 0.5) or what not are really
goint to screw up.  Floats aren't what you think they are.  Computers
don't do math.  And they barely do arithmetic, at least, on floats.

--tom
-- 
pos += screamnext[pos]  /* does this goof up anywhere? */
    --Larry Wall, from util.c in the v5.0 perl distribution


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

Date: Sat, 05 Dec 1998 11:11:16 GMT
From: taktisk_semantik@my-dejanews.com
Subject: Re: Creating a key field for writing relational databases
Message-Id: <74b4ck$44h$1@nnrp1.dejanews.com>


> Obviously to link them I need a unique key field.

You will have seen a lot of ppl in this thread who say
that you should be using identity values or similar
features of your db. Now, having done a bit of data
manipulation in envs where there is *a lot* going on
in the db simultaneously all I have to say is that you
are probably well advised to stay clear of those features
and roll your own id values. The trick is to make sure
that you *really* roll unique values.

Here is what I do (conceptually, a bit cleaner in real
code of course):

In a CGI environment

$host_id=system("/bin/hostid"); # actually, I export this as an
                                # Apache env variable

Generated key, used in main program
($key,$time_used,$counter)=generate_key(time(),$host_id,$time_used,$counter);

sub generate_key {
    my $newtime=shift;
    my $host_id=shift;
    my $oldtime=shift;
    my $in_second=shift;

    if ($newtime == $oldtime) {
       $in_second++;
    } else {
       $in_second=0;
    }

    my $proc_id=$$;

    my $key="$newtime$host_id$in_second$proc_id";
    return ($key,$newtime,$in_second);
}

If used in a threaded environment, you should probably throw
in the thread-id in the key as well.

Also, this is quite a long key, so I usually do a MIME::64
on it before I store it.

The advantage of this is that the keys are guaranteed to
be unique, that it is fast (can generate 1kKey/s+ :-)
and that you don't depend on db features that *will* break
down if you have a heavily normalized db with a heavy
work load.

Hope this helps,
/Gurra

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Fri, 04 Dec 1998 14:12:29 -0800
From: Kevin Wong <wongk@ug.eds.com>
Subject: file locking
Message-Id: <36685E4D.167E@ug.eds.com>

I currently have a process with distributed runs on 10 machines, when
it's done each one will write the result to the same file that located 
at the central machine. Unfortunately, they tend to get 
mucked up, even if you supposedly do non-buffered IO and all
that.

So what I have to do is pass back results to the "master"
distribution engine. I can only think of dumping the results in a file,
named with the name of  the machine that was running the job, and then
having the central server do the append to the results file.

Actually, that does sound pretty good. Anybody else know any tricks for
allowing multiple people to write to a file from all kinds of platforms
& stuff & avoiding interleaved output? Locking via perl doesn't seem to
work (I believe NFS is the problem).


Thanks!


Kevin Wong


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

Date: 5 Dec 1998 14:50:18 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: File with Sendmail
Message-Id: <74bh7a$qb$1@gellyfish.btinternet.com>

On Fri, 4 Dec 1998 09:03:00 +0100 Daniel Boksjv <daniel@boksjo.com> wrote:
> You might be right about the two parameters, but I was told to do it this
> way (obviously it wasn't correct information!). Anyway, I'll try it your
> way.
> 
> Another problem to me is that I would like to have the file as an
> attachment. For now, I'm reading the contents of the file into a variable
> that I put in the attachment part of the message. It works (since the file
> isn't that big), but it gives me the notion that there should be an easier
> way...
> 

If you want to have the file as an attachment then you will probably want to
use one of the MIME::* modules available from CPAN 
<URL:http://www.perl.com/CPAN>

There have been suggestions posted here in the past as to how to achieve
this without using a module - if you are interested you can search DejaNews.

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: 5 Dec 1998 12:26:41 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Installing Win32 Perl (was Re: Seeking Win32::DES.pm)
Message-Id: <74b8q1$e2$1@gellyfish.btinternet.com>

On Fri, 04 Dec 1998 16:32:23 -0800 David L. Painter <dpainter@lightspeed.net> wrote:
> Andrew,
> This is not really in response to your module problem, but I thought
> that you might know something about how
> to build/install/configure Perl for Win95. I've 
> downloaded the latest port (5.005) but don't have
> any clear idea of how to proceed with the installation.
> 
> Any help, suggestions, or references would help.
> 

You should have downloaded a file called APi506.exe or something like that
and all it requires is for you to run it.  The install program is pretty
simple but will ask you some questions and just so long as you can give an
intelligent answer to them then everything should be just swell - infact
you are probably safe just accepting the defaults for everything.  However
don not be tempted to install into a directory with a space in the name as
this has been reported to cause problems in some cases.

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Sat, 5 Dec 1998 10:26:57 -0000
From: "Bruce Davidson" <group95@allied.demon.co.uk>
Subject: Re: Merge Files
Message-Id: <912853418.17201.0.nnrp-06.9e982204@news.demon.co.uk>


Eric Bohlman wrote in message ...

Have that ok but need to know how to create an array of up to 300 files
without having to name in e.g., @names.  Would like script to look see if
files exist and if so pass the array to the copy ($arrayfile, newfile.db).





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

Date: 5 Dec 1998 09:34:10 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Missing warning on '23foo'++
Message-Id: <74aumi$qrj$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Daniel Grisinger 
<dgris@moiraine.dimensional.com>],
who wrote in article <m3af1354dh.fsf@moiraine.dimensional.com>:
>        The auto-increment operator has a little extra builtin magic to
>        it.  If you increment a variable that is numeric, or that has
 ...

> This is one of those silly things that useful sometimes (in fact I
> actually have a lot of code that uses this), but that is somewhat
> surprising.  I'd guess that it belongs on your list of perl gotchas
> and Ilya's list of things that use pedantic will fix.

What should it fix?

     >perl -wle "$a='23foo'; $a++; print $a"
     24

Should produce a warning without any additional pragma.

Ilya


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

Date: 05 Dec 1998 02:54:53 -0700
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: Missing warning on '23foo'++
Message-Id: <m3iufq52xe.fsf@moiraine.dimensional.com>

[posted to comp.lang.perl.misc and mailed to the cited author]

ilya@math.ohio-state.edu (Ilya Zakharevich) writes:

> What should it fix?
> 
>      >perl -wle "$a='23foo'; $a++; print $a"
>      24
> 
> Should produce a warning without any additional pragma.

Yes, of course it should.  I misunderstood what I was reading.

dgris
-- 
Daniel Grisinger          dgris@moiraine.dimensional.com
Supporter of grumpiness where grumpiness is due on clpm.
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print 
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'


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

Date: 05 Dec 1998 02:23:38 -0700
From: Daniel Grisinger <dgris@moiraine.dimensional.com>
Subject: Re: newbie file open question
Message-Id: <m3af1354dh.fsf@moiraine.dimensional.com>

lr@hpl.hp.com (Larry Rosler) writes:

> If one replaces '$a++;' by its semantic equivalent, '$a += 1;', one gets 
> a warning about non-numeric in 'add' -- properly, I believe.  Yet 
> '$a++;' is silent.  How peculiar!
> 
> Can anyone explain or justify the absence of a warning for '$a++;'?

>From perlop:

       The auto-increment operator has a little extra builtin magic to
       it.  If you increment a variable that is numeric, or that has
       ever been used in a numeric context, you get a normal
       increment.  If, however, the variable has been used in only
       string contexts since it was set, and has a value that is not
       the empty string and matches the pattern /^[a- zA-Z]*[0-9]*$/,
       the increment is done as a string, preserving each character
       within its range, with carry

This is one of those silly things that useful sometimes (in fact I
actually have a lot of code that uses this), but that is somewhat
surprising.  I'd guess that it belongs on your list of perl gotchas
and Ilya's list of things that use pedantic will fix.

dgris
-- 
Daniel Grisinger          dgris@moiraine.dimensional.com
Supporter of grumpiness where grumpiness is due on clpm.
perl -Mre=eval -e'$_=shift;;@[=split//;;$,=qq;\n;;;print 
m;(.{$-}(?{$-++}));,q;;while$-<=@[;;' 'Just Another Perl Hacker'


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

Date: Sat, 05 Dec 1998 09:07:19 -0600
From: Brent Michalski <perlguy@technologist.com>
Subject: Re: newbie question searching string with =~
Message-Id: <36694C27.975E10A0@technologist.com>

jlhughes@pobox.com wrote:
 ..SNIP..
> # open the log for reading
> open (LOGFILE, "d:/perl5/samples/dec4log");
> # each line becomes variable
> @fileinput = <LOGFILE>;
> #close the log file
> close (LOGFILE);
> 
> #count the lines in the file
> print "There are $#fileinput lines in the log.\n";
> 
> #get search term
> print "Enter search term: ";
> $FindThis = <STDIN>;
> 
> #read line by line through logfile for search term
>  for ($i = 0; $i <= $#fileinput; $i++) {
>     if ($fileinput[$i] =~ $FindThis) {
>         print "$fileinput[$i]\n";
>     }
>  }

I'd do this a little different.  Try this:

#get search term
print "Enter search term: ";
$FindThis = <STDIN>;
chomp $FindThis;

#read line by line through logfile for search term
 foreach (@fileinput) {
   print "$fileinput[$i]\n" if(/$FindThis/i);
 }

The "i" will also make the match case-INsensitive so BRENT would match
BrEnt, etc...

Good luck!
Brent
-- 
Java?  I've heard of it, it is what I drink while hacking Perl! -me
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$            Brent Michalski             $
$         -- Perl Evangelist --          $
$    E-Mail: perlguy@technologist.com    $
$ Resume: http://www.inlink.com/~perlguy $
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$


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

Date: Sat, 05 Dec 1998 12:52:02 GMT
From: "Christian H. Knudsen" <webmaster@bluegalaxy.hypermart.net>
Subject: Newbie: Secure directories??
Message-Id: <36692D7A.2547E515@bluegalaxy.hypermart.net>

I have a directory with a 700 permission. I would like a script
to be able to change the permission to 777 (for example),
write some files in the dir and the chmod back to 700. The
reason for this is that I would like the files in the dir to be
hidden from any users, as it will contain secret info like
passwords and user names.

My problem is that the script (naturally) isn't able to chmod
the dir to 777 because of the 700 permission!

Any ideas?

-- Christian H. Knudsen



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

Date: Sat, 05 Dec 1998 13:19:11 GMT
From: glen@bah.net (Glen)
Subject: Problem printing with CGI.pm
Message-Id: <366931c3.568710925@news.enter.net>

I'm trying to use CGI.pm to make dynamic web pages and use it to
display things like text files, but I'm loosing all normal text
formating.  It seems to be stripping charage returns, tabs and more
than one space gets squished to one space. The output looks like crap!

Is there a way to fix this?

Thanks,

-Glen

Please also respond to this email address:  glen@bah.net


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

Date: 05 Dec 1998 15:19:07 +0100
From: Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at>
Subject: Re: Problem printing with CGI.pm
Message-Id: <83u2zazn6s.fsf@vcpc.univie.ac.at>

Re: Problem printing with CGI.pm, Glen
<glen@bah.net> said:

Glen> I'm trying to use CGI.pm to make dynamic web
Glen> pages and use it to display things like text
Glen> files, but I'm loosing all normal text
Glen> formating.  It seems to be stripping charage
Glen> returns, tabs and more than one space gets
Glen> squished to one space. The output looks like
Glen> crap!

No, it looks like rendered HTML.  Which is what
you're telling it to do, no?

If you need to force it, you could enclose it in a
<pre></pre>.

hth
tony
-- 
Tony Curtis, Systems Manager, VCPC,    | Tel +43 1 310 93 96 - 12; Fax - 13
Liechtensteinstrasse 22, A-1090 Wien,  | <URI:http://www.vcpc.univie.ac.at/>
"You see? You see? Your stupid minds!  | private email:
    Stupid! Stupid!" ~ Eros, Plan9 fOS.| <URI:mailto:tony_curtis32@hotmail.com>


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

Date: 5 Dec 1998 14:25:08 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Problem printing with CGI.pm
Message-Id: <74bfo4$ok$1@gellyfish.btinternet.com>

On Sat, 05 Dec 1998 13:19:11 GMT Glen <glen@bah.net> wrote:
> I'm trying to use CGI.pm to make dynamic web pages and use it to
> display things like text files, but I'm loosing all normal text
> formating.  It seems to be stripping charage returns, tabs and more
> than one space gets squished to one space. The output looks like crap!
> 
> Is there a way to fix this?
> 

Yeah learn HTML ;-}

You can do one of two things :

A) if the entire output is plaintext then you could set the content type
to "text/plain"  with $query->header("text/plain")

B) if the text file is mingled amongst other HTML you can wrap it in 
<PRE> </PRE> tags to preserve the formatting.

This really isnt a perl issue though - you probably want to ask further
questions of this type in one of the 
comp.infosystems.www.authoring.* groups .

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Sat, 05 Dec 1998 14:26:54 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Problem with seek.....
Message-Id: <36713d3f.3370033@news.skynet.be>

bravo wrote:

>Everything's working fun but the problem is my stuff gets appended to the
>bottom(as normal).
>
>What I want to do is append it to the top so the most recent info is on top.
>
>I am using the following code in my script.
>
>  open(OUTF,">>data.txt");
>  flock(OUTF, 8) or die "cannot unlock file: $!";
>  seek(OUTF,0,0);
>
>But it still appends to the bottom.....

Good thing that it does that, or you would be overwriting what was in
the file.

You cretae a new file, print to that, and copy everything that was in
there after that. Finally, copy the new file over the old one.

But that would be slow. Especially if the file gets large, and you do
this a lot.

So, my advice: don't do it. Keep it as it is. Only when you need a
report, let the reporting software reverse the order of the lines in the
file. Something along these lines:

	open(IN,'logfile');
	@line = reverse <IN>;

	Bart.


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

Date: 5 Dec 1998 14:59:04 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Recipe Database for Unix
Message-Id: <74bhno$qj$1@gellyfish.btinternet.com>

On Thu, 3 Dec 1998 07:40:12 -0800 JBreit <ips@damd.net> wrote:
> Has anyone seen a good recipe database which allows adds, mods, and
> searches?  Ive been looking for days.... I want to use a flat file.
> 

I have heard of someone using unix manpages to store recipes - that way
you can do 'man -k advocado'  and you will get all a list of all the
recipes with advocado in them:

$ man -k advocado
Guacamole (R)         - Mexican advocado salad
AdvocadoGratin (R)    - Baked advocado with cheese and chestnut


The manpages can be constructed in pod format and then converted using
pod2man - you will also need to run makewhatis in order for man -k to work.

;-?

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: 5 Dec 1998 15:31:58 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: signals on Windows nt
Message-Id: <74bjle$qv$1@gellyfish.btinternet.com>

On Thu, 3 Dec 1998 10:46:50 +0100 Fernando Nunez Benito <fnunez@mail.cern.ch> wrote:
> Hi all,
> I finished implemented a monitoring program for different unix platforms
> and when I tried to port it to Winndows NT, I realised "frok()" function
> was not implemented (surprising) and signals didn't work.
> 

frok() sounds like it causes your script to put on thigh-high stilleto boots
and mince down to Madame Jo-Jo's ;-}

Alternatively if you mean fork() and want to use it then you might try out
compiling a perl with Cygwin32 (which is definitely not for you if you cant
eat three Shredded Wheat :) I think that it also implements alarm but dont
quote me on that ...

It is available from http://www.cygnus.com/

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: 5 Dec 1998 15:20:25 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: system commands in WinNT
Message-Id: <74bivp$qs$1@gellyfish.btinternet.com>

On Wed, 02 Dec 1998 17:44:46 -0600 darmawan <darmawan@scic.org> wrote:
> I am trying to get a script to work on NT but when run through a Web
> page it doeesn't seem to return anything for system calls.
> 
> Let's say I have the lines
> 
> $version = `ver`;
> print "Version: $version";
> 
> somewhere in my script.  When run from the command line I get
> 
> Version: Window NT Version 4.0
> 
> But when run from a browser I get
> 
> Version:
> 
> What is the deal?  Is there something, somewhere that needs to be set so
> that the default Web user can reference system commands through scripts?
> 

Really this is not a Perl problem at all but one with the envronment a CGI
program runs in on the server.

If you have a problem with the configuration of a server you should really
ask in a group that is interested in such matters.

You most probably will want to use an explicit path to an external command
under these circumstances or perhaps alter $ENV{'PATH'} to reflect the
location of the executables (though not having an NT server here I cant
check whether this latter will work but intuitively [if anything about
NT can be said to be intuitive] it seems that it should).

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: 5 Dec 1998 11:42:26 -0000
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Tool to reverse engineer perl code
Message-Id: <74b672$ds$1@gellyfish.btinternet.com>

On Fri, 04 Dec 1998 18:52:46 GMT drkeith@bway.net wrote:
> I was just searching for the same thing -- a tool for analyzing perl
> application -- required files, sub-routines & data members, inputs, outputs,
> etc & generating HTML documentation a la javadoc. Anything exist already?
> I've seen debuggers, but I'm wanting to document working apps.
> 

I tend to use vi to do the documenting ;-}

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: 05 Dec 1998 15:20:39 +0100
From: Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at>
Subject: Re: using exec cmd
Message-Id: <83soeuzn48.fsf@vcpc.univie.ac.at>

Re: using exec cmd, geekman <pinoy@w-link.net> said:

geekman> Cheers: does anyone know if it's possible
geekman> to use <!--#exec cmd --> in a perl
geekman> script.. I've used the \ esc char to make
geekman> the script read this line.  but no ouput
geekman> from the cmd.. any help appredicated

It is not possible.  What you are actually
describing is server-parsed HTML, not perl.

Try asking again in a more relevant group, like:

    comp.infosystems.www.authoring.html

or the group that addresses the HTTP server you are
using.

hth
tony
-- 
Tony Curtis, Systems Manager, VCPC,    | Tel +43 1 310 93 96 - 12; Fax - 13
Liechtensteinstrasse 22, A-1090 Wien,  | <URI:http://www.vcpc.univie.ac.at/>
"You see? You see? Your stupid minds!  | private email:
    Stupid! Stupid!" ~ Eros, Plan9 fOS.| <URI:mailto:tony_curtis32@hotmail.com>


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

Date: 5 Dec 1998 15:24:05 GMT
From: randy@theory.uwinnipeg.ca (Randy Kobes)
Subject: Re: Using glob() w/WinNT vs. glob() w/Win95
Message-Id: <slrn76ikhu.ms8.randy@theory.uwinnipeg.ca>

On 4 Dec 1998 22:42:04 GMT, 
	Charles Wilt <charles.0272@worldnet.no.spam.att.net> wrote:
>The following is a short code snippet:
>
>#!perl -w
>
>while (glob("*.tst")){
>     print "$_\n";
>}
>
>which on a WinNT box correctly prints a list of all files with a tst 
>extension.  But on a Win95 box, I get a message saying 
>"Read on closed filehandle <_GEN_0> at mytest line 6."

Hi,
   Is this the entire code? The line numbers don't seem to match
up (which doesn't necessarily mean anything ...) I checked this 
out on my Windows 98 perl, and it ran fine, though. Which perl are 
you using? Is it fine otherwise? You might want to read the README
files in the perl source distribution concerning the use of
glob in Win32 - there's some things you can change to alter the
glob behaviour.

-- 
		Best regards,
		Randy Kobes

Physics Department		Phone: 	   (204) 786-9399
University of Winnipeg		Fax: 	   (204) 774-4134
Winnipeg, Manitoba R3B 2E9	e-mail:	   randy@theory.uwinnipeg.ca
Canada				http://theory.uwinnipeg.ca/


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

Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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

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