[11625] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5225 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 25 13:07:40 1999

Date: Thu, 25 Mar 99 10:00:24 -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           Thu, 25 Mar 1999     Volume: 8 Number: 5225

Today's topics:
    Re: "seeding" the time function (Bill Moseley)
    Re: "seeding" the time function (Mark Leighton Fisher)
    Re: "seeding" the time function <Philip.Newton@datenrevision.de>
    Re: @INC Problem (Tad McClellan)
        Big or Little endian-ness? tslusser@bigfoot.com
    Re: Big or Little endian-ness? (Bart Lateur)
    Re: Calculating the current time in London or GMT+x <neil.johnson@soton.sc.philips.com>
    Re: Deep Recursion error in a tie'd variable (Kelly E Jones)
        exclusively create a new file over nfs? <sidi@angband.org>
    Re: Help a rookie please tslusser@bigfoot.com
    Re: Help a rookie please <dave@mag-sol.com>
        Input Password <hlee@ccserv2.ee.ntu.edu.tw>
    Re: Is there a statement to activate a setenv command (Larry Rosler)
    Re: Is this a perl problem or am I missing somehting... <jeromeo@atrieva.com>
        Looking For a Module? <Steven.Arnott@soton.sc.philips.com>
        need help getting started! <stiwar1@gl.umbc.edu>
    Re: Need Help with Simple Program <Philip.Newton@datenrevision.de>
    Re: New Bee Alert <sternji@mail.northgrum.com>
    Re: New Bee Alert <aqumsieh@matrox.com>
    Re: Parsing text file <Philip.Newton@datenrevision.de>
    Re: Premature end of script headers (Mark P.)
    Re: Quicksort won't work (Mark Leighton Fisher)
    Re: Quicksort won't work <Philip.Newton@datenrevision.de>
    Re: Quicksort won't work <Philip.Newton@datenrevision.de>
        S/MIME messages with perl? (Reiner Buehl)
        SENDMAIL not allowing Content-Type: multipart/mixed hea <julian.madle@mcmail.com>
    Re: STDOUT to HTML <dave@mag-sol.com>
        String Limit in IE? <jsilver@multisoft.com>
        Try This, please - was Re: open3 and flushing STDOUT (Bill Moseley)
        Urgent: Document contains no data <sjenifer@geo.census.gov>
    Re: Urgent: Document contains no data (Mark P.)
    Re: Urgent: Document contains no data (Bill Moseley)
    Re: Urgent: Document contains no data (Mark Leighton Fisher)
    Re: Values of 'true' and 'false'? (Rob Greenbank)
    Re: Values of 'true' and 'false'? (Bart Lateur)
    Re: Values of 'true' and 'false'? <Philip.Newton@datenrevision.de>
    Re: Values of 'true' and 'false'? <Philip.Newton@datenrevision.de>
    Re: WHY: open (HPIPE, "| notexistfile") or die "..."; D <jeromeo@atrieva.com>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Thu, 25 Mar 1999 08:52:12 -0800
From: moseley@best.com (Bill Moseley)
Subject: Re: "seeding" the time function
Message-Id: <MPG.1164099ad76dbe6d9896ef@206.184.139.132>

In article <36FA5A69.9A19CFA2@peon.oit.umass.edu>, 
dave@peon.oit.umass.edu says...
> Is there a function in Perl that can take a month, day, year, time set
> of arguments, and return the number of seconds from the epoch to that
> time?  Or am I off to write my own?  If it's not actually part of Perl,
> but someone else has it out there, it would be great if I could take a
> look at it.  My version's not very efficient, and it's off by 5 hrs...

Just add:
my $corrected_time = $your_time + 5 * 3600;
or
my $corrected_time = $your_time - 5 * 3600;

The entry in Programming Perl under localtime talks about using 
timelocal.

Also,

"How can I take a string and turn it into epoch seconds?" is a FAQ 
question.  You might want to spend some time and read the FAQs again.

Or dejanews since this is such a common question it gets asked quite 
often.




-- 
Bill Moseley mailto:moseley@best.com


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

Date: Thu, 25 Mar 1999 12:11:24 -0500
From: fisherm@tce.com (Mark Leighton Fisher)
Subject: Re: "seeding" the time function
Message-Id: <MPG.11643845b7d2ad679896b4@news-indy.indy.tce.com>

In article <36FA5A69.9A19CFA2@peon.oit.umass.edu>, 
dave@peon.oit.umass.edu says...
> Is there a function in Perl that can take a month, day, year, time set
> of arguments, and return the number of seconds from the epoch to that
> time?  Or am I off to write my own?

No.  Look at CPAN (http://www.perl.com/CPAN/) -- CPAN is
your friend. 
==========================================================
Mark Leighton Fisher          Thomson Consumer Electronics
fisherm@.tce.com              Indianapolis, IN
"Browser Torture Specialist, First Class"


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

Date: Thu, 25 Mar 1999 18:24:08 +0100
From: Philip Newton <Philip.Newton@datenrevision.de>
Subject: Re: "seeding" the time function
Message-Id: <36FA7138.3ED88721@datenrevision.de>

Dave Heaney wrote:
> 
> Is there a function in Perl that can take a month, day, year, time set
> of arguments, and return the number of seconds from the epoch to that
> time?

Time::Local ist your friend.

Cheers,
Philip


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

Date: Thu, 25 Mar 1999 05:17:30 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: @INC Problem
Message-Id: <qf2dd7.6i4.ln@magna.metronet.com>

Jens Engelbrecht (engelbrecht@t-online.de) wrote:

: I wrote a cgi script using the modul LWP::Simple.
                                            ^
                                            ^

: "Can't locate LWP/simple.pm in @INC (@INC contains:
                    ^
                    ^

--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Thu, 25 Mar 1999 16:11:23 GMT
From: tslusser@bigfoot.com
Subject: Big or Little endian-ness?
Message-Id: <7ddn70$kkj$1@nnrp1.dejanews.com>

Does anyone know a *quick* way to tell if a file is big or little endian?  I
can shell out a 'file' command and read the output from it, but I am afraid
that will be too slow since I need to check about 10,000 files.  I checked the
- file operators, (-e, -x, etc) and the stat function.  Any ideas?

Thanks in advance.

Ted Slusser
tslusser@bigfoot.com

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


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

Date: Thu, 25 Mar 1999 16:46:54 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Big or Little endian-ness?
Message-Id: <36fa67c6.145386@news.skynet.be>

tslusser@bigfoot.com wrote:

>Does anyone know a *quick* way to tell if a file is big or little endian?  I
>can shell out a 'file' command and read the output from it, but I am afraid
>that will be too slow since I need to check about 10,000 files.  I checked the
>- file operators, (-e, -x, etc) and the stat function.  Any ideas?

What kind a file? Text files don't *have* an endian-ness. In TIFF-files,
the endian-ness is marked inside the file. Most other files are always
either big-endian or little-endian, depending on the file type.

There's no other way than to read apart of the file, and interpret the
data. What exactly do you want?

	Bart.


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

Date: Thu, 25 Mar 1999 15:48:33 GMT
From: Neil Johnson <neil.johnson@soton.sc.philips.com>
Subject: Re: Calculating the current time in London or GMT+x
Message-Id: <36FA5AD1.3EEE2C9@soton.sc.philips.com>

The element [8] of the the array returned by local time will indicate if daylight
saving is in action where the server is situated. However this will not help with
the time in London.

Californian daylight saving , I believe is very similar to British and European
daylight saving. The only difference is that in Britain and Europe the clocks go
forward a week earlier than California (28th March). The clocks go back on the
same date.

yours
NJ



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

Date: 25 Mar 1999 18:37:57 GMT
From: kejones@ptdcs2.intel.com (Kelly E Jones)
Subject: Re: Deep Recursion error in a tie'd variable
Message-Id: <7ddvq5$209@news.or.intel.com>

Thanks for your reply!

In article <36F9C034.E698F5A1@home.com>,
Rick Delaney  <rick.delaney@home.com> wrote:
>  It's hard
>to tell what the problem is exactly without a snippet that I can run
>that produces the error.  

My apologies, I've appended a complete piece of code that reproduces
the error.

I didn't know about the 'closure' construct.  This is useful (I
learned something!), but I'm not sure it's what I want here: If I
understand correctly, this will always use the value from the @a array
which existed when @b was tied?
 But if @a changes after the tie, then I want @b to change as well. (I
wasn't able to get your code to run yet, due to syntax problems).

I guess what I really want is to be able to look up the value of a
variable without triggering the call to FETCH.  For a scalar, I was
able to do this by dereferencing a reference to the scalar ($$xref1).  This
seems not to call FETCH.  But for an array element, dereferencing the
reference ( $$xref1[$subscript] ) DOES call FETCH, leaving me with
recursion.  To quote the camel:

"A Perl variable lives in a symbol table and holds one hard reference
to it's underlying thingy. There may be other hard references to the
same thingy, but if so, the variable doesn't know or care about them."

I extrapolate this to mean that if I create a hard reference to a
value, that reference is completely independant of the original
variable name, and thus accessing the thingy through the reference
should not involve a FETCH on the original variable name.  What am I
missing?

Thanks again for your help,

Kelly

#!/usr/bin/perl -w
use strict;

my $y; my $x;
tie $y, 'ScalarTie', \$x, \$y;
$y = 3; $x = 5;
print "x: $x y: $y\n";

my @xarray; my @yarray;
tie @yarray, 'ArrayTie', \@xarray, \@yarray;

@yarray[2] = 3;
@xarray[2] = 5;
print"x element: $xarray[2], y element: $yarray[2]\n";

sub function {
    my($a, $b) = @_;
    return($a + $b);
}
package ScalarTie;
 
sub TIESCALAR {
    my ($pkg, $xref1, $xref2) = @_;
    return(bless [$xref1,$xref2], $pkg);
}
sub STORE {
    my ($obj, $val) = @_;
    return $val;
}
sub FETCH {
    my ($obj) = @_;
    my ($xref1, $xref2) = @$obj;
    my $x1 = $$xref1;
# Is this a recursive reference?
    my $x2 = $$xref2;
    return(main::function($x, $y));
}

package ArrayTie;
sub TIEARRAY {
    my ($pkg, $ref1, $ref2) = @_;
    return(bless [$ref1, $ref2], $pkg);
}
sub FETCH {
    my ($obj, $subscript) = @_;
    my ($xref1, $xref2) = @{$obj};
    my $x1 = $$xref1[$subscript]; #This is line 49

    my $x2 = $$xref2[$subscript];
    return(main::function($x1, $x2));

}

sub STORE {
    my ($obj, $val) = @_;
    return $val;
}


>x: 5 y: 8
>Deep recursion on subroutine "FETCH" at line 49.



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

Date: 25 Mar 1999 09:23:31 GMT
From: Chris Sidi <sidi@angband.org>
Subject: exclusively create a new file over nfs?
Message-Id: <7dcvaj$jm6$1@news-int.gatech.edu>

If I was hellbent on attempting to create a new file on nfs mount, and
want to at least be sure I wasn't overwriting a plain file that had
information (i.e. wasn't zero bytes), would this work?: 

  use Fcntl qw(:DEFAULT :flock);

  #This is pretty unique to begin with.
  my $filename = "/some/nfsdir/myappdir/foo." . time() . ".$$";

  #Could it hurt to use O_EXCL on a nfs file?
  #Could it potentially truncate/mess up a file created between here and
  #the flock?
  sysopen(FH, $filename, O_WRONLY|O_EXCL|O_CREAT) 
      or die "Can't sysopen  $filename: $!\n";

  #If we just created the file, we should able to flock immediately,
  #right?  (flock doesn't have a fatal error on nfs on my system)
  flock(FH, LOCK_EX|LOCK_NB)
      or die "Can't noblock flock $filename: $!\n";

  #Don't overwrite a non-zero byte file
  (-z FH)
   or die "File $filename isn't zero bytes - won't overwrite.\n";

  #use FH
  print FH "some important info I wouldn't want to lose\n";

  close FH;


Do I need to autoflush above?

The reason I'm looking at writing to an nfs mount instead of the local fs
is the only local directories I can write in are /tmp and /var/tmp and I'm
worried my files might get deleted (I'll need them for up to 5 days, when
they'll either be moved or deleted).

I've read perlfaq5 and perlopentut and I know that creation of files isn't
guaranteed to be an atomic operation over NFS.  I know flock doesn't alway
work over network file systems, but it appears to work fine on our HP-UX
10.20 system.

Thanks,
Chris Sidi

-- 
"What's your favorite Jingle?"
"By Men-nen"
                     - _Dill Scallion_ (http://www.dillscallion.com)


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

Date: Thu, 25 Mar 1999 16:07:44 GMT
From: tslusser@bigfoot.com
Subject: Re: Help a rookie please
Message-Id: <7ddn06$k7p$1@nnrp1.dejanews.com>

Why not use a tell() to write the bytecount you were last at in the file. 
Then use seek() next time you want to read the log file.  It will pickup from
the last line you previously read.  I would probably write the byte count
into a separate file and read it the next time you invoke your script.

Good luck!



In article <36fa4248.70640479@news.supernews.com>,
  jeffery_jones@mtlusa.com wrote:
> I'm working on a perl script (my first) that summarizes a log file for
> me. With
> some pretty horrible code I've gotten it to do what I want except for
> one
> thing. I'd like the script to run as a cron job. But I don't want the
> entire
> log file analyzed every time...only what are new entries since the
> last
> analysis. I've thought of using DateManip to only examine entries by
> time...but
> that seemed like a clunky solution.
>
> What I'd like to do is place a string like 'analyzed' in the log file
> and only
> read from the last instance on into an array for analysis. I've pored
> over the
> NGs and man pages and I know this has to be easy for a seasoned perl
> coder. Any
> help?
>
> Regards,
> Jeff
>

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


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

Date: Thu, 25 Mar 1999 16:35:45 GMT
From: Dave Cross <dave@mag-sol.com>
Subject: Re: Help a rookie please
Message-Id: <7ddol0$ltr$1@nnrp1.dejanews.com>

In article <36fb42b5.70748978@news.supernews.com>,
  jeffery_jones@mtlusa.com wrote:
> I'm working on a perl script (my first) that summarizes a log file for
> me. With
> some pretty horrible code I've gotten it to do what I want except for
> one
> thing. I'd like the script to run as a cron job. But I don't want the
> entire
> log file analyzed every time...only what are new entries since the
> last
> analysis. I've thought of using DateManip to only examine entries by
> time...but
> that seemed like a clunky solution.
>
> What I'd like to do is place a string like 'analyzed' in the log file
> and only
> read from the last instance on into an array for analysis. I've pored
> over the
> NGs and man pages and I know this has to be easy for a seasoned perl
> coder. Any
> help?

One lateral thinking solution springs to mind. When you've finished processing
the log file, rename it to 'logfile.[date].[time]'. Then the next time you go
back to look at the original file, it will only have new stuff in it.

Stops the log file getting too big as well.

--
Dave Cross
Magnum Solutions Ltd: <http://www.mag-sol.com/>
London Perl M[ou]ngers: <http://london.pm.org/>

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


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

Date: 25 Mar 1999 17:42:06 GMT
From: Huang Lee <hlee@ccserv2.ee.ntu.edu.tw>
Subject: Input Password
Message-Id: <7ddshe$596$2@gemini.ntu.edu.tw>



hello,
I want to write a server which can listen requests and folk
other programs for clients.

My problem is that the program need users to input password,
but when users input password,I can not "hide" the password for users.
Users can see their own password when they key-in password.

How can I make the input invisiable for client terminal?
Thanks.

Here is the program.
--------------------------------------------------------------
$|=1;

BEGIN { $ENV{PATH} = '/usr/ucb:/bin' }
use strict;
use Socket;
use Carp;

sub spawn; # forward declaration
sub logmsg { print "$0 $$: @_ at ", scalar localtime , "\n" }

my $port = shift || 4444;
my $proto = getprotobyname('tcp');

socket(SERVER, PF_INET, SOCK_STREAM, $proto)        || die "socket: $!";
setsockopt(SERVER, SOL_SOCKET, SO_REUSEADDR, 1)     || die "setsockopt: $!";
bind(SERVER, sockaddr_in($port, INADDR_ANY))        || die "bind: $!";
listen(SERVER,SOMAXCONN)                            || die "listen: $!";

my $waitedpid = 0;

my $paddr;

sub REAPER {
    $SIG{CHLD} = \&REAPER;       # loathe sysV
    $waitedpid = wait;
    logmsg "Reaped $waitedpid" . ($? ? " with exit $?" : '');
}

$SIG{CHLD} = \&REAPER;

for ( $waitedpid = 0;
      ($paddr = accept(CLIENT,SERVER)) || $waitedpid;
      $waitedpid = 0, close CLIENT)
{
    next if $waitedpid;
    my($port,$iaddr) = sockaddr_in($paddr);
    my $name = gethostbyaddr($iaddr,AF_INET);

    spawn sub {

        print "Welcome\n";

        exec "./program.pl" or confess "Can't exec : $!";

    };

sub spawn {

    my $coderef = shift;
    unless (@_ == 0 && $coderef && ref($coderef) eq 'CODE') {
        confess "Usage: spawn CODEREF";
    }

    my $pid;
    if (!defined($pid = fork)) {
        logmsg "Cannot fork: $!";
        return;
    } elsif ($pid) {
        logmsg "Begat $pid";
        return;  # i'm the parent
    }

    # else i'm the child -- go spawn

    open(STDIN,  "<&CLIENT")    || die "Can't dup client to stdin";
    open(STDOUT, ">&CLIENT")    || die "Can't dup client to stdout";

    open(STDERR, ">&STDOUT")    || die "Can't dup stdout to stderr";

    exit &$coderef();

}


-- 
My HomePage URL:http://www.ee.ntu.edu.tw/~hlee/


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

Date: Thu, 25 Mar 1999 07:58:44 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Is there a statement to activate a setenv command
Message-Id: <MPG.1163fd0efcb348cf9897c6@nntp.hpl.hp.com>

[Posted and a courtesy copy sent.]

In article <36FA526A.E49A5EC5@cs.ucc.ie> on Thu, 25 Mar 1999 15:12:42 
+0000, sean O'Connor <oconnors@cs.ucc.ie >says...
> I'm running a perl program to access an oracle database using oraperl.
> To make the program run I have to type in the command
> 'setenv LD_LIBRARY_PATH ${ORACLE_HOME}/lib', before I run it. I now have
> to run the program straight from the net using cgi so I can't type the
> setenv command and I was wondering if there is any command in perl that
> will run the setenv statement for me.

$ENV{LD_LIBRARY_PATH} = "$ORACLE_HOME/lib";

will set the environment variable for the Perl program itself and for 
its children.

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


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

Date: Thu, 25 Mar 1999 08:15:19 -0800
From: Jerome O'Neil <jeromeo@atrieva.com>
To: Griffith <j.jenkins@gu.edu.au>
Subject: Re: Is this a perl problem or am I missing somehting...
Message-Id: <36FA6117.6273E854@atrieva.com>

Griffith wrote:
> If I run this script (as me) from the command line
> it works just fine. However when I run the script
> from the webserver (as nobody) it crashes. In debugging
> the scrip the last info dumped is (I open STDOUT ">dump");
> 
> open (FILE, ">>datbase.csv);
> 
> Ther perl script stops here with no error messages.

I think you're missing something.

If that is directly from your code, you're missing a close quote.

Also, we don't know if there are errors because you don't check for
them.

open (FILE, ">>databas.csv") or die "Unable to open database $!\n";

You might also consider:

use CGI::Carp qw{fatalsToBrowser};

I'm sure one of these will tell you what is wrong.

Good Luck!


-- 
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947 
The Atrieva Service: Safe and Easy Online Backup  http://www.atrieva.com


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

Date: Thu, 25 Mar 1999 17:39:34 GMT
From: Steven Arnott <Steven.Arnott@soton.sc.philips.com>
Subject: Looking For a Module?
Message-Id: <36FA74D6.9D7962FC@soton.sc.philips.com>

Hi,
  I'm looking for a module that would give my program to ability to read
and write simple option files. Anyone know of such a module?

Thanks

Steven
--
Steven Arnott - CoReUse - DTC
Steven.Arnott@soton.sc.philips.com
Philips Semiconductors, Southampton
+44-(0)1703 316444


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

Date: Thu, 25 Mar 1999 12:19:57 -0500
From: sheela tiwary <stiwar1@gl.umbc.edu>
Subject: need help getting started!
Message-Id: <Pine.SGI.3.96A.990325121629.503064A-100000@umbc9.umbc.edu>

Hi,

I have a simple perl script that works fine when I run it in the UNIX
environment.  However it won't run on the web-page, the web page just
displays the contents of the file instead of the results.

I would appreciate any suggestions on how to fix this problem.

Sheela



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

Date: Thu, 25 Mar 1999 18:11:33 +0100
From: Philip Newton <Philip.Newton@datenrevision.de>
Subject: Re: Need Help with Simple Program
Message-Id: <36FA6E45.2898CDBA@datenrevision.de>

Ophir Marko wrote:
> 
> #! /local/perl/bin/perl -w

OK, you've got -w on. That's good.

> $index=0;
> while(<>){
>  $i=0;
>  while ($i <= $#_){
>   ++$i;
>  }
> $index=$index+$#_+1;
> }

This appears to be a loop over either (1) all the lines of STDIN, or (2)
all the lines of all the files named on the command line. For each line,
$i is first set to 0. Then $i is increased until it's larger than the
index of the last element in @_. But @_ isn't set anywhere, so $#_ is
-1. Therefore, $i is always 0. Then $index gets $#_ (again, -1) and 1
added to it. Net result: $i and $index get set to 0 over and over again.

> $t=0;
> $a=123;
> open(FILE2, ">file");

You forgot to check whether the open succeeded:

    open(FILE2, ">file") or die "Cannot open file: $!";

> if ($index eq $a){
>  print FILE2 $index, "\n";
>  ++$t;
> }

Hmm, up above $index was treated as a number (we added stuff to it,
though we didn't ever change its value). Now you're using eq, which is a
string compare. '0' is not the same as '123', so the stuff inside the if
is never executed. If it were, it would print "0\n" to FILE2 and then
increment $t.

> close(FILE2);

Again, you forget to check whether the close succeeded:

    close(FILE2) or die "Error closing file: $!";

> Please note that there are some relics of a previous script in here.
> Disregard them

I couldn't see any. Except if you mean "what I have posted here are
relics of a previous script".

Is this the "simple program" you need help with? What help do you need
with it? What is it supposed to do?

Cheers,
Philip


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

Date: Thu, 25 Mar 1999 17:31:58 GMT
From: "James M. Stern" <sternji@mail.northgrum.com>
Subject: Re: New Bee Alert
Message-Id: <36FA730E.C087A9AA@mail.northgrum.com>

Gabriel Richards wrote:

> [...]
> 
> while (<THREAD>) {
>     #if...etc
>     elsif ($_ eq "\n") { print "<br>"}
>     else { print "$_ \n"}
> }
> 
> [...] So, I want to make up
> for that by printing the <br> tag where the originating text file has a
> blank line. For some reason this isn't working and I'm not chopping or
> chomping anything. The originating text file looks as follows:
> 
> This is a line of text followed by a blank line then more text.
> 
> This is the second line of text (paragraph).

By "isn't working," I assume you mean it doesn't print "<br>".  Perhaps
the blank line contains whitespace before the "\n".  Try

	elsif (! /\S/) { print "<br>"}

-- 
James M. Stern                Northrop Grumman Corp.  Hawthorne, CA
Opinions expressed above are not necessarily my employer's.


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

Date: Thu, 25 Mar 1999 10:44:08 -0500
From: Ala Qumsieh <aqumsieh@matrox.com>
Subject: Re: New Bee Alert
Message-Id: <x3ysoatvak7.fsf@tigre.matrox.com>


"Gabriel Richards" <grichard@uci.edu> writes:

>     elsif ($_ eq "\n") { print "<br>"}

If you want to test if $_ is a blank line, it is better to do
something like:

	elsif (/^\s*$/) { print "<br>" }

or maybe:

	elsif (/\S/) { print "<br>" }

both of these will identify blank lines as lines that contain any
combination of whitespace only.

HTH,
Ala



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

Date: Thu, 25 Mar 1999 18:26:06 +0100
From: Philip Newton <Philip.Newton@datenrevision.de>
Subject: Re: Parsing text file
Message-Id: <36FA71AE.ED35CA81@datenrevision.de>

Alan Scott wrote:
> 
> I need to read a test file into an array so I can then write it out as
> a different file. How would I do this????

    open FILE, "<filename.ext" or die "Error opening filename.ext: $!";
    @contents = <FILE>;
    close FILE or die "Error closing filename.ext: $!";

Cheers,
Philip


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

Date: Thu, 25 Mar 1999 16:23:45 GMT
From: mag@imchat.com (Mark P.)
Subject: Re: Premature end of script headers
Message-Id: <36fa628c.64350040@news.ionet.net>

Now thats hilarious!! <G>

On Thu, 25 Mar 1999 12:28:16 GMT, gellyfish@gellyfish.com (Jonathan
Stowe) wrote:


>No we have no clue what you're really doing either - Unfortunately
>we've had to curtail our research into remote debugging after the
>government withdrew our funding - apparently they were concerned about
>one particular experiment where subjects were locked in a darkened
>room without a computer and attempted to alter hundreds of CGI
>programs to use CGI.pm by the power of their minds alone.
>
>/J\



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

Date: Thu, 25 Mar 1999 12:04:29 -0500
From: fisherm@tce.com (Mark Leighton Fisher)
Subject: Re: Quicksort won't work
Message-Id: <MPG.116436abce3d63329896b2@news-indy.indy.tce.com>

In article <36fa56fa.604315079@news>, darrenNO.SPAMsmurthwaite@unn.ac.uk 
says...
> I have just started using PERL and am trying to convert some old C++
> routines.  Can anyone tell me what is wrong with the following code?
> It is trying to read a file then quicksort the array but it doesn't
> sort anything.  Is it something to do with the way the variables work?

1) Yes, your subroutines only pass the values, so after
swap() is called, the array reverts to the old values.
You should look at references ("perldoc perlref").

2) Unless you have some special requirement you haven't
mentioned, Perl's sort() function will probably be OK for
this sorting task. 
==========================================================
Mark Leighton Fisher          Thomson Consumer Electronics
fisherm@.tce.com              Indianapolis, IN
"Browser Torture Specialist, First Class"


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

Date: Thu, 25 Mar 1999 18:15:21 +0100
From: Philip Newton <Philip.Newton@datenrevision.de>
Subject: Re: Quicksort won't work
Message-Id: <36FA6F29.377F3A63@datenrevision.de>

Darren Smurthwaite wrote:
> 
> I have just started using PERL and am trying to convert some old C++
> routines.  Can anyone tell me what is wrong with the following code?
> It is trying to read a file then quicksort the array but it doesn't
> sort anything.  Is it something to do with the way the variables work?

Do you really need to port quicksort to Perl? Perl already has a
perfectly good sort function which you can call. `perldoc -f sort` will
tell you more about it.

Cheers,
Philip


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

Date: Thu, 25 Mar 1999 18:19:47 +0100
From: Philip Newton <Philip.Newton@datenrevision.de>
Subject: Re: Quicksort won't work
Message-Id: <36FA7033.413D400@datenrevision.de>

Darren Smurthwaite wrote:
> 
>         $temp=@list[i];

$list[$i] not @list[i]. Similarly in other parts of your program.

(At the expense of confusing you: you can also swap two array elements
directly: @list[$i,$j] = @list[$j,$i] -- here you need the @ because
you're working with what's called an *array slice*. But if you're just
referencing a single element, you need $.)

>                 if(@list[$r]<@list[$r-1])

$l, not l -- you can't leave off the "funny character" in Perl.

Cheers,
Philip


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

Date: Thu, 25 Mar 1999 16:41:50 GMT
From: reiner@asta4.rz.fh-ulm.de (Reiner Buehl)
Subject: S/MIME messages with perl?
Message-Id: <36fa6690.82134372@tmbbwmc.bbn.hp.com>

Hi,

is there a module for creating S/MIME encrypted mails with perl or a
easy way to create such mails using the MIME and encryption modules
from CPAN?

Reiner Buehl.



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

Date: Thu, 25 Mar 1999 16:34:42 +0000
From: Julian Madle <julian.madle@mcmail.com>
Subject: SENDMAIL not allowing Content-Type: multipart/mixed header
Message-Id: <36FA65A2.FF7F960F@mcmail.com>

I have written a Perl4 compliant multipurpose formmail script that
handles attachments, I have re-writtrn the base64 encoder module
to be Perl4 compatible and the Mail is sending out. However I do
not know much about SENDMAIL and I cannot manage to get the 
multipart/mixed stuff in the email header, therefore my mail client
(Netscape Messenger) does not recognize the attachment, instead
leaving the base64 encoded file in the message contents (which I
have to save out and decode with Winzip). The code is below, any
ideas much appreciated to julian.madle@mcmail.com.


$bound = "------------6B797646304";
$attach = qq{$bound\nContent-Type: $contentType;
name="$newfilename"\nContent-Transfer-Encoding: };
$attach .= qq{base64\nContent-Disposition: inline;
filename="$newfilename"\n\n$upfile64\n$bound};

# SEND MAIL
open(MAIL,"|$mailprog -t");
print MAIL "To: $in{'recipient'}\n";
print MAIL "From: $in{'email'}\n";
print MAIL "MIME-Version: 1.0\n";
print MAIL "Subject: $in{'subject'}\n";
print MAIL qq{Content-Type: multipart/mixed; boundary="$bound"\n\n};
print MAIL qq{\n$bound\nContent-Type: text/plain; charset=us-ascii;
name="message.txt"\n};
print MAIL "Content-Transfer-Encoding: 7bit\n\n";
print MAIL $main_message; # THE FORM CONTENT
print MAIL $attach; # BASE64 ENCODED STRING
close (MAIL);
}


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

Date: Thu, 25 Mar 1999 16:32:20 GMT
From: Dave Cross <dave@mag-sol.com>
Subject: Re: STDOUT to HTML
Message-Id: <7ddoek$lp8$1@nnrp1.dejanews.com>

In article <7ddj21$gju$1@nnrp1.dejanews.com>,
  domat6905@my-dejanews.com wrote:
> I want to execute a system command (e.g. "ls directory") and show otput on the
> Web page. What would be the proper way to to this?
> I'm trying following code but it doesn't appear in the browser:
>
> #!/usr/bin/perl
>
> require "cgi-lib/cgi-lib.pl";
>
> @pag = 'radlist';
> ...
> print &PrintHeader;
> print "<html><body>@pag</body></html>";
> ...

I haven't used cgi-lib.pl, but isn't there a way to change the content type
header text/plain rather than text/html. Then you wouldn't need to put all the
HTML stuff around your text.

Oh... and you need backticks (`) not quotes (') around the command.

Dave...

--
Dave Cross
Magnum Solutions Ltd: <http://www.mag-sol.com/>
London Perl M[ou]ngers: <http://london.pm.org/>

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


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

Date: Thu, 25 Mar 1999 16:32:43 GMT
From: "Justin M. Silver" <jsilver@multisoft.com>
Subject: String Limit in IE?
Message-Id: <LytK2.4379$my.9052@monger.newsread.com>

I have a perl script that passes user input from web page to webpage and
eventually writes a file based on this information. The problem is with a
<textarea> input. All of the information goes through fine in Netscape, but
in IE, the variable is cut in half, with the data  at the end replaced with
a "%". This only happens with large amounts of data (IE seems to cut it off
at about 1800 characters). I dont think this is the scripts fault, as it is
rather simple, and it work in NS. Does anyone else have any ideas, or know
if IE has a limit on the length of strings it will pass?

Thanks

Justin
--
--------------------------------------------------------
MultiSoft Incorporated         Phone: 770-612-8411 X1417
http://www.multisoft.com       Pager: 404-743-7488
Email: jsilver@multisoft.com   Fax:   770-612-1978
--------------------------------------------------------





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

Date: Thu, 25 Mar 1999 08:45:29 -0800
From: moseley@best.com (Bill Moseley)
Subject: Try This, please - was Re: open3 and flushing STDOUT
Message-Id: <MPG.11640801c12a90ce9896ee@206.184.139.132>

Ok, What's happening here?

A few days ago I posted a problem using open3 to send mail within a CGI 
script.  I was receiving STDOUT multiple times on the browser.
(The reason for open3 was to capture STDOUT and STDERR to check for any 
output from sendmail that might indicate an error that wasn't reported in 
a failed open, print, or close.)

Seems that redirecting STDOUT (as with a web server) causes the problem:

So try this (hacked up version of my code):

#!/usr/local/bin/perl5.005 -w
use strict;

print "\nTesting 123 - ", scalar localtime(),"\n";

my $ret = send_mail_via_sendmail( 'cat', 'hello there' );



use FileHandle;
use IPC::Open3;

sub send_mail_via_sendmail {

    my ($sendmail, $body) = @_;

    my $params = $sendmail;

    my $in  = new FileHandle;
    my $out = new FileHandle;
    my $err = new FileHandle;


    open3( $in, $out, $err, $params )
        or return "Failed open of sendmail:$sendmail:$!";

    ## the $in->print() & $in->close() stuff removed to simplify here.

    0;
}


152) ~/cgi-bin/moseley %./dup1.pl

Testing 123 - Thu Mar 25 08:31:23 1999  <- One line output

153) ~/cgi-bin/moseley %./dup1.pl > x   <- now redirect
154) ~/cgi-bin/moseley %cat x

Testing 123 - Thu Mar 25 08:31:28 1999

Testing 123 - Thu Mar 25 08:31:28 1999  <- two copies!

158) ~/cgi-bin/moseley %perl -v

This is perl, version 5.005 built for sun4-solaris


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

Date: Thu, 25 Mar 1999 10:40:55 -0500
From: "Shade L. Jenifer" <sjenifer@geo.census.gov>
Subject: Urgent: Document contains no data
Message-Id: <36FA5907.1095FE2D@geo.census.gov>

Hello developers,

I have a problem that needs immediate attention and
our resources here (ie books) are scarce.  I have
a CGI perl script that causes my browser (Netscape
4.0 running on an SGI/IRIX OS) to pop up an
alert window saying:

Document contains no data.

Normally, this tells me that I have a syntax error in
my script.  However, when I run the script from the
command line, I get no errors.  Are there any other
reasons why such an alert is generated?

Quick response is greatly appreciated.

-shade l. jenifer
--





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

Date: Thu, 25 Mar 1999 16:31:32 GMT
From: mag@imchat.com (Mark P.)
Subject: Re: Urgent: Document contains no data
Message-Id: <36fa644b.64797323@news.ionet.net>

	It might help if you post the script. A lot of scripts do this
especially if you don't send errors to the browser to let you know
where the script is dying. Whats probably happening is a file handle
isn't opening, but then you haven't posted the script so its
impossible to tell.

On Thu, 25 Mar 1999 10:40:55 -0500, "Shade L. Jenifer"
<sjenifer@geo.census.gov> wrote:

>Hello developers,
>
>I have a problem that needs immediate attention and
>our resources here (ie books) are scarce.  I have
>a CGI perl script that causes my browser (Netscape
>4.0 running on an SGI/IRIX OS) to pop up an
>alert window saying:
>
>Document contains no data.
>
>Normally, this tells me that I have a syntax error in
>my script.  However, when I run the script from the
>command line, I get no errors.  Are there any other
>reasons why such an alert is generated?
>
>Quick response is greatly appreciated.
>
>-shade l. jenifer
>--
>
>
>



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

Date: Thu, 25 Mar 1999 08:58:24 -0800
From: moseley@best.com (Bill Moseley)
Subject: Re: Urgent: Document contains no data
Message-Id: <MPG.11640b09bcf99dfa9896f0@206.184.139.132>

In article <36FA5907.1095FE2D@geo.census.gov>, sjenifer@geo.census.gov 
says...
> I have a problem that needs immediate attention and
> our resources here (ie books) are scarce.  I have
> a CGI perl script that causes my browser (Netscape
> 4.0 running on an SGI/IRIX OS) to pop up an
> alert window saying:
> 
> Document contains no data.
> 
> Normally, this tells me that I have a syntax error in
> my script.  However, when I run the script from the
> command line, I get no errors.

What do you get?  Nothing?  No Data, perhaps?

Normally, you returned proper headers, but nothing else.


> Are there any other
> reasons why such an alert is generated?

Might take a look at some of the FAQs:
http://www.smithrenaud.com/public/CGI_MetaFAQ.html


> Quick response is greatly appreciated.

Quick responses cost extra.



-- 
Bill Moseley mailto:moseley@best.com


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

Date: Thu, 25 Mar 1999 12:08:00 -0500
From: fisherm@tce.com (Mark Leighton Fisher)
Subject: Re: Urgent: Document contains no data
Message-Id: <MPG.1164377fa4fd3e0a9896b3@news-indy.indy.tce.com>

In article <36FA5907.1095FE2D@geo.census.gov>, sjenifer@geo.census.gov 
says...
> I have> a CGI perl script that causes my browser (Netscape
> 4.0 running on an SGI/IRIX OS) to pop up an
> alert window saying:
> 
> Document contains no data.

You should make sure that the script is running under an
appropriate user ID and with the appropriate environment
variables, as the Web server is probably running under a
different user ID and likely passes fewer environment
variables to your script.

Also, you should have asked this on
comp.infosystems.www.authoring.cgi... 
==========================================================
Mark Leighton Fisher          Thomson Consumer Electronics
fisherm@.tce.com              Indianapolis, IN
"Browser Torture Specialist, First Class"


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

Date: Thu, 25 Mar 1999 16:07:23 GMT
From: rob@frii.com (Rob Greenbank)
Subject: Re: Values of 'true' and 'false'?
Message-Id: <36fa5bca.60932953@news.frii.com>

On Wed, 24 Mar 1999 23:04:46 -0800, lr@hpl.hp.com (Larry Rosler)
wrote:

>In article <1dp73pa.rr27hc1i8f31qN@p74.block2.tc1.state.ma.tiac.com> on 
>Thu, 25 Mar 1999 00:04:37 -0500, Ronald J Kimball 
><rjk@linguist.dartmouth.edu >says...
>> Larry Rosler <lr@hpl.hp.com> wrote:
>...
>> > Can you point in the docs to a statement of the values of TRUE and FALSE
>> > as returned by a Boolean operator?  I can't remember where I read it.
>> 
>> Boolean operators return the special values SV_YES for true and SV_NO
>> for false.  SV_YES comprises a string value of '1' and a numeric value
>> of 1.  SV_NO comprises a string value of '' and a numeric value of 0.
>> 
>> (This came up on the MacPerl list a while ago.  I figured it out with a
>> perl compiled for DEBUGGING.)
>
>I figured it out by experiment.  But I still don't know if it is in 'the 
>docs' for any of the usual values of 'the docs'.

OK, let's really make this fun.  Helping someone figure out a problem
I came across the following behavior:
	$val = 8 && 1;		# $val is 1
	$val = 8 and 1;		# $val is 8
	$val = 8 && 4;		# $val is 4
	$val = 8 and 4;		# $val is 8

On the surface, it appears like "&&" and "and" evaluate differently.
The real problem (and the problem with my friend's program) is
precedence, as the "=" is evaluated before the "and".  Add parens and
"$val = (8 and 4)" gives the expected result.  

What did strike me as odd at first, and what makes it relevant to the
current thread, is the logical and operation will yield the value of
the last operand.  Chaining a bunch, as in "( 32 && 16 && 4 && 8 )"
will yield the value 8.  Logical and could care less what it actually
returns for true (as long as it's EXACTLY non-zero :^).

By the way, logical or will allways return the first operand.

There's probably some use for this in an algorithm for something, but
I'm not sure it's safe.  It definitely could be confusing.

	Rob Greenbank


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

Date: Thu, 25 Mar 1999 16:48:53 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Values of 'true' and 'false'?
Message-Id: <36fb6899.356353@news.skynet.be>

Rob Greenbank wrote:

>I came across the following behavior:
>	$val = 8 && 1;		# $val is 1
>	$val = 8 and 1;		# $val is 8
>	$val = 8 && 4;		# $val is 4
>	$val = 8 and 4;		# $val is 8
>
>On the surface, it appears like "&&" and "and" evaluate differently.

No, it's a matter of precencence. I must take care to say it right this
time ;-). { $val = 8 and 1; } means the same as { ($val = 8) and 1; },
therefore the "and 1" part is useless.

	Bart.


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

Date: Thu, 25 Mar 1999 17:58:44 +0100
From: Philip Newton <Philip.Newton@datenrevision.de>
Subject: Re: Values of 'true' and 'false'?
Message-Id: <36FA6B44.67497BE8@datenrevision.de>

Rob Greenbank wrote:
> 
> [T]he logical and operation will yield the value of the last operand.

Only if there's no false value in between - then it returns the first
false value found.

> By the way, logical or will allways return the first operand.

first *non-zero* operand.

Cheers,
Philip


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

Date: Thu, 25 Mar 1999 17:59:29 +0100
From: Philip Newton <Philip.Newton@datenrevision.de>
Subject: Re: Values of 'true' and 'false'?
Message-Id: <36FA6B71.F0DAC1AB@datenrevision.de>

Philip Newton wrote:
> 
> first *non-zero* operand.

make that: first false operand ('' or '0' or 0).

Cheers,
Philip


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

Date: Thu, 25 Mar 1999 08:22:31 -0800
From: Jerome O'Neil <jeromeo@atrieva.com>
To: "Patrice M.I. Parmentier" <ppa@itmasters.com>
Subject: Re: WHY: open (HPIPE, "| notexistfile") or die "..."; DOES NOT DIE ???
Message-Id: <36FA62C7.C40B194F@atrieva.com>

Patrice M.I. Parmentier wrote:
> 
> I want to open a pipe for writing to the stdin of a program:
> 
> open (HPIPE, "| xxxx") or die "...";
> 
> !!! The open never fails, even when xxxx does not exist !!!
> WHY???

Because it knows you didn't read the documentation for open, which
references perlipc, which explains in POE:

__QUOTE__
Be careful to check both the open() and the close() return values. If
you're writing to a pipe, you should also trap SIGPIPE. Otherwise, think
of what happens
when you start up a pipe to a command that doesn't exist: the open()
will in all likelihood succeed (it only reflects the fork()'s success),
but then your
output will fail--spectacularly. 
__/QUOTE__

Good Luck!

-- 
Jerome O'Neil, Operations and Information Services
Atrieva Corporation, 600 University St., Ste. 911, Seattle, WA 98101
jeromeo@atrieva.com - Voice:206/749-2947 
The Atrieva Service: Safe and Easy Online Backup  http://www.atrieva.com


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

Date: 12 Dec 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 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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

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