[18037] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 197 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 2 00:05:31 2001

Date: Thu, 1 Feb 2001 21:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <981090309-v10-i197@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 1 Feb 2001     Volume: 10 Number: 197

Today's topics:
    Re: [OT] how to split *gz file <peter.sundstrom@eds.com>
    Re: capture e-mail in script <taboo@comcen.com.au>
        CGI Script Error - Premature end of script headers <louieyk@pc.jaring.my>
        error: requires explict package/callback subroutine <projectobjects@earthlink.net>
    Re: error: requires explict package/callback subroutine <joe+usenet@sunstarsys.com>
    Re: error: requires explict package/callback subroutine <projectobjects@earthlink.net>
    Re: error: requires explict package/callback subroutine <joe+usenet@sunstarsys.com>
    Re: FAQ 3.0:   What is perl.com? Perl Mongers? pm.org?  <elaine@chaos.wustl.edu>
        first real PERL script . . . <smart73@NOSPAM.mediaone.net>
    Re: first real PERL script . . . <bwalton@rochester.rr.com>
    Re: I have the weirdest problem !!! (die, and exit don' <bwalton@rochester.rr.com>
        Looking for perl script... <nik@casarta.com>
    Re: Problem running perl scripts on Netscape server (Rob - Rock13.com)
    Re: race condition or lock problem <johnm@acadiacom.net>
    Re: replace a matched string <jdf@pobox.com>
    Re: replace a matched string (Damian James)
    Re: replace a matched string (Damian James)
    Re: replace a matched string (Garry Williams)
    Re: replace a matched string (Garry Williams)
    Re: replace a matched string (Garry Williams)
    Re: replace a matched string (Damian James)
    Re: Running shell comands from Perl? <yosikim@lgeds.lg.co.kr>
        undef question <taboo@comcen.com.au>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 2 Feb 2001 14:40:46 +1300
From: "Peter Sundstrom" <peter.sundstrom@eds.com>
Subject: Re: [OT] how to split *gz file
Message-Id: <95d36v$dj6$1@hermes.nz.eds.com>


"Chris W" <chrisw@dynamite.com.au> wrote in message
news:50ne6.23$bi2.5153@news0.optus.net.au...
> "Peter Sundstrom" <peter.sundstrom@eds.com> wrote in message
> news:95cm20$nlk$1@hermes.nz.eds.com...
> > What's wrong with the split command?
>
> It doesn't produce n gzip files each containing some of the files from the
> original, each useful on its own.

The OP didn't mention anything about multiple files (and it would have to be
a tar archive or similar for it to contain multiple files).  They just said
they had a gzip file and wanted to split it into smaller files.  That being
the case split would work just fine.

However, the intent of the OP is not clear.  So I'm just guessing as to what
they really want to do.  I suppose I might need some more training with the
PSI::ESP module.

>
> Of course, that doesn't make this any more a Perl question.

Very true, but many people seem to want to go down the wrong track of
finding a Perl solution to a problem that can be very easily and efficiently
solved with existing tools.





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

Date: 2 Feb 2001 12:34:45 +1100
From: "Kiel R Stirling" <taboo@comcen.com.au>
Subject: Re: capture e-mail in script
Message-Id: <3a7a0eb5$1@nexus.comcen.com.au>


Andrew McGregor <andy@misk.co.uk> wrote:
>I can get normal command line arguments, but I'm at a loss on how to>capture an entire e-mail if it were to be piped in (?) from sendmail.
>
>I'm trying to write a small majordomo style script.
>
>Regards
>
>andy

When you pipe to a script use a while loop and the <STDIN> filehandel
to read the input.
Something like, 

while (<STDIN>) {
	# Do something the data it's in $_ 
}



Regards,

Kiel R Stirling.

>



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

Date: Fri, 02 Feb 2001 12:52:30 +0800
From: Snow Wolf <louieyk@pc.jaring.my>
Subject: CGI Script Error - Premature end of script headers
Message-Id: <3A7A3D0E.CDF99844@pc.jaring.my>


--------------CD374C738A583788C26DD66C
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hi,

I am new to Perl script and willing to learn more.
Presently I am coding some Perl script but have been
completely frustrated ~>.<~

Initially I didn't get the permission to view/invoke my CGI script,
but then I'd changed the user permission by logging into Telnet
subsequently,
changed the user permission of my cgi-bin directory and my CGI script to

readable & executable.
Then I called my CGI script again, but this time the server returned
error with a message, the message was that "Internal Server Error...The
server
encountered an internal error or misconfiguration and was unable to
complete your request."

It seems like something's wrong with my perl languarge, right ?
but I don't have any problem when I run this script on my
local machine (I'm using Apache Web Server).

I checked my server error log file and obtained the error message :
Premature end of script headers:
/home/mydomainname/www/cgi-bin/myscript.cgi

I have been spending a day to work on my CGI script
but I still keep on getting this error message.....

No other error messages appear, only this !
I even logged into Unix command line to compile my script by using -cwT
switch and I am
replied that : myscript.cgi Syntax OK.

I refer back to my book and was told that this catchall error message
describes any situation
in which my script in run, and the Content-Type header -- printed by the
CGI module's header
function is not the first thing emitted by the script, sometimes a
secondary message appears
in the log file, immediately before or after this.

This is a problem known as output buffering, isn't it ?

And the reference book proposed me a solution is that to tell Perl not
to buffer my output,
and to force Perl to flush the standard output stream buffers after
every write
by turning buffering off $| = 1;

Then I tested my script again from command line, an expected result was
generated.
I could see that the Content_Type : text/html was printed first.

I won't get any error if I test my script from command line, but the
same error appear when I
call my script from server to my web broowser.

I even copied down (well, you may say "stealing" ^.~ ) a CGI script from
the reference book
and tried it,still getting the same error.....
Premature end of script headers:
/home/mydomainname/www/cgi-bin/myscript.cgi

I hope you could help me on this.

Thanks in advance


--------------CD374C738A583788C26DD66C
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
Hi,
<p>I am new to Perl script and willing to learn more.
<br>Presently I am coding some Perl script but have been
<br>completely frustrated ~>.&lt;~
<p>Initially I didn't get the permission to view/invoke my CGI script,
<br>but then I'd changed the user permission by logging into Telnet subsequently,
<br>changed the user permission of my cgi-bin directory and my CGI script
to
<br>readable &amp; executable.
<br>Then I called my CGI script again, but this time the server returned
<br>error with a message, the message was that "Internal Server Error...The
server
<br>encountered an internal error or misconfiguration and was unable to
complete your request."
<br>&nbsp;
<br>It seems like something's wrong with my perl languarge, right ?
<br>but I don't have any problem when I run this script on my
<br>local machine (I'm using Apache Web Server).
<p>I checked my server error log file and obtained the error message :
<br><i><font color="#FF0000">Premature end of script headers: /home/mydomainname/www/cgi-bin/myscript.cgi</font></i>
<p>I have been spending a day to work on my CGI script
<br>but I still keep on getting this error message.....
<br>&nbsp;
<br>No other error messages appear, only this !
<br>I even logged into Unix command line to compile my script by using
<i><font color="#FF0000">-cwT</font></i> switch and I am
<br>replied that : myscript.cgi Syntax OK.
<p>I refer back to my book and was told that this catchall error message
describes any situation
<br>in which my script in run, and the Content-Type header -- printed by
the CGI module's header
<br>function is not the first thing emitted by the script, sometimes a
secondary message appears
<br>in the log file, immediately before or after this.
<br>&nbsp;
<br>This is a problem known as output buffering, isn't it ?
<br>&nbsp;
<br>And the reference book proposed me a solution is that to tell Perl
not to buffer my output,
<br>and to force Perl to flush the standard output stream buffers after
every write
<br>by turning buffering off <b><font color="#FF0000">$| = 1</font></b>;
<p>Then I tested my script again from command line, an expected result
was generated.
<br>I could see that the Content_Type : text/html was printed first.
<p>I won't get any error if I test my script from command line, but the
same error appear when I
<br>call my script from server to my web broowser.
<br>&nbsp;
<br>I even copied down (well, you may say "stealing" ^.~ ) a CGI script
from the reference book
<br>and tried it,still getting the same error.....
<br><i><font color="#FF0000">Premature end of script headers: /home/mydomainname/www/cgi-bin/myscript.cgi</font></i>
<br>&nbsp;
<br>I hope you could help me on this.
<br>&nbsp;
<br>Thanks in advance
<br>&nbsp;</html>

--------------CD374C738A583788C26DD66C--



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

Date: Fri, 02 Feb 2001 03:29:50 GMT
From: "dkh" <projectobjects@earthlink.net>
Subject: error: requires explict package/callback subroutine
Message-Id: <OQpe6.758$gv3.81285@newsread2.prod.itd.earthlink.net>

I am trying to run a test script using a module HTML::Pager that has 'use
strict'.
It does not like the callback subroutine although it is declared
The error msg with the script after:

syntax error at testPager2.pl line 25, near "my "
Global symbol "$get_data_sub" requires explicit package name at
testPager2.pl line 25.  Execution of testPager2.pl aborted due to
compilation errors.



#!/usr/bin/perl -w
 use HTML::Pager;
 use CGI;
use strict;
local $SIG{__WARN__} = \&Carp::cluck;

my $pager;
# my $get_data_sub;
 # get CGI query object
 my $query = CGI->new();

# create a callback subroutine to generate the data to be paged
 my $get_data_sub = sub {
    my ($offset, $rows) = @_;
    my @return_array;

    for (my $x = 0; $x < $rows; $x++) {
       push(@return_array, [ time() ]);
    }
    return \@return_array;
 }


 # create a Pager object
 my $pager = HTML::Pager->new( query => $query, get_data_callback =>
$get_data_sub, rows => 100, page_size => 10, debug => 1);


  # make it go - send the results to the browser.
  print $pager->output;







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

Date: 01 Feb 2001 22:37:41 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: error: requires explict package/callback subroutine
Message-Id: <m3elxh7o1m.fsf@mumonkan.sunstarsys.com>

"dkh" <projectobjects@earthlink.net> writes:

> # create a callback subroutine to generate the data to be paged
>  my $get_data_sub = sub {
>     my ($offset, $rows) = @_;
>     my @return_array;
> 
>     for (my $x = 0; $x < $rows; $x++) {
>        push(@return_array, [ time() ]);
>     }
>     return \@return_array;
>  }
    ^^^^
 
Aren't you forgetting something;
a statement separator perhaps?

>  # create a Pager object
>  my $pager = HTML::Pager->new( query => $query, get_data_callback =>
> $get_data_sub, rows => 100, page_size => 10, debug => 1);
> 
> 
>   # make it go - send the results to the browser.
>   print $pager->output;
> 

-- 
Joe Schaefer


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

Date: Fri, 02 Feb 2001 04:11:59 GMT
From: "dkh" <projectobjects@earthlink.net>
Subject: Re: error: requires explict package/callback subroutine
Message-Id: <jsqe6.956$gv3.100906@newsread2.prod.itd.earthlink.net>

You are right Joe, it was a semicolon missing. I copied directly from the
Perldoc...hahahah

What about the next error for the same script?
It relates to Term::Readline.pm:

Unable to get Terminal Size. The TIOCGWINSZ ioctl didn't work. The COLUMNS
and LINES environment


>
> > # create a callback subroutine to generate the data to be paged
> >  my $get_data_sub = sub {
> >     my ($offset, $rows) = @_;
> >     my @return_array;
> >
> >     for (my $x = 0; $x < $rows; $x++) {
> >        push(@return_array, [ time() ]);
> >     }
> >     return \@return_array;
> >  }
>     ^^^^
>
> Aren't you forgetting something;
> a statement separator perhaps?
>
> >  # create a Pager object
> >  my $pager = HTML::Pager->new( query => $query, get_data_callback =>
> > $get_data_sub, rows => 100, page_size => 10, debug => 1);
> >
> >
> >   # make it go - send the results to the browser.
> >   print $pager->output;
> >
>
> --
> Joe Schaefer
>



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

Date: 01 Feb 2001 23:27:24 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: error: requires explict package/callback subroutine
Message-Id: <m3ae857lqr.fsf@mumonkan.sunstarsys.com>

"dkh" <projectobjects@earthlink.net> writes:

> You are right Joe, it was a semicolon missing. I copied directly 
> from the Perldoc...hahahah

If that was part of the module's documentation, 
you should report it to the author so s/he can
fix it.

> What about the next error for the same script?
> It relates to Term::Readline.pm:
> 
> Unable to get Terminal Size. The TIOCGWINSZ ioctl didn't work. The 
> COLUMNS and LINES environment
> 

You're not trying to use Term::Readline in a CGI 
script, are you? If HTML::Pager requires it, and 
it is a CGI script, then I think you're SOL.  If 
it is a CGI script, try another package with similar 
functionality that doesn't require Term::Readline.

I'm not familiar with HTML::Pager, sorry.  You could 
try clp.modules for this if noone here helps you.

-- 
Joe Schaefer



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

Date: Fri, 02 Feb 2001 03:45:25 GMT
From: Elaine Ashton <elaine@chaos.wustl.edu>
Subject: Re: FAQ 3.0:   What is perl.com? Perl Mongers? pm.org? perl.org?
Message-Id: <B69F978E.926F%elaine@chaos.wustl.edu>

in article slrn97j9cn.d5s.dha@panix2.panix.com, David H. Adler at
dha@panix2.panix.com quoth:
> On Thu, 01 Feb 2001 02:57:34 -0500, brian d foy <comdog@panix.com> wrote:
>>> Perl Mongers is an advocacy organization for the Perl language. For
>>> details, see the Perl Mongers web site at http://www.perlmongers.org/.
>> 
>> that should be www.perl.org.
>> 
>> [dha - what's up with that ;) ]
> 
> I forget when this was last patched.  Also, there has been some
> indication lately that the FAQ autoposter may not be posting the most
> up to date entries...  I'll have to take a look.

This has been changed/corrected in the 5.6.1 faq. :)
 
>>> AUTHOR AND COPYRIGHT
>> 
>> there's a problem here.  i think dha wrote the most (if not all)
>> of the content of that answer.
> 
> Interesting point.  :-)  Actually, I'll have to check this as
> well... (I think I may have just patched some existing stuff - but
> maybe I'm just being modest again... :-).

Well, if you look at the bottom of

http://www.perl.com/pub/CPAN/misc/cpan-faq.html

ORA has a 'compilation copyright' though they didn't compile anything.

I suspect if everyone who offered patches and such to the FAQs over the
years got a name in the copyright that the doc would be twice as long. :)

You can copyright anything, defending it is another story.

e.



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

Date: Fri, 02 Feb 2001 02:17:17 GMT
From: Stephen S. <smart73@NOSPAM.mediaone.net>
Subject: first real PERL script . . .
Message-Id: <2r5k7t4t97459n2agntpumht5pha0gt415@4ax.com>

Hey,

	This is a copy of my first real PERL script.  I was wondering
if someone would take a look at it and make any suggetions about it.
The scripts works and run with no forseeable problems but I would like
to see if there was a different way of doing all or any of this.
Basically it takes a list of files with nul extentions (files.new
created  by a dir /b *. >> files.new) and creates a DBf file readable
by a certain program.  TIA

Stephen

#A listing of the files to be imported into Companion . . .
#Plain text, no extentions between 5 and 8 characters . . .
$filename ="files.new";
$out_file = "> btch_clm.dbf";
open (FILE, $out_file) || die "[NEW MAIL]Can't open new mail list.
Aborting . .";
print "\nOpened output file sucsssfully . . .\n";


#assigning "Top of file" to an array for later printing
@top = (
"\x03\x65\x01\x1c\xff\x00\x00\x00\xc1\x00\x4b\x00\x00\x00\x00\x00",
"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
"\x44\x41\x54\x45\x00\x00\x00\x00\x00\x00\x00\x44\x00\x00\x00\x00",
"\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
"\x54\x49\x4d\x45\x00\x00\x00\x00\x00\x00\x00\x43\x00\x00\x00\x00",
"\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
"\x44\x45\x53\x43\x52\x49\x50\x54\x00\x00\x00\x43\x00\x00\x00\x00",
"\x2d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
"\x46\x49\x4c\x45\x5f\x4e\x41\x4d\x45\x00\x00\x43\x00\x00\x00\x00",
"\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
"\x44\x45\x4c\x45\x54\x45\x00\x00\x00\x00\x00\x43\x00\x00\x00\x00",
"\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
"END"
);


#assigning "End of Record" to an array for later printing
@EOR = (
"\x0d"
);

#assigning "End of file" to an array for later printing
@EOF = (
"\x0a"
);


#Printing the top of the file . . .
#Followed by an EOR Flag (seperator) . . .
$i = 0;
$done = "no";

while ($done eq "no") {
        if ($top[$i] eq "END") {
             $done = "yes";
           } else {
                print FILE $top[$i];
                $i = ++$i;               
           }            
 }
print FILE $EOR[0];
print "Sucessfully printed TOP of file . . .\n";


open (FILELIST, $filename) || die "[OLD MAIL]Can't open old mail list.
Aborting . .";

while ($file = <FILELIST>) {
 chomp $file;
 $file_length = length($file);

 if ($file_length > 8) {die "\n\n[OLD MAIL]File names are too long.
Aborting . .";}

 if ($file_length eq 8) {
   date_time_stamp();
   print FILE "$file.   N";
  } elsif ($file_length eq 7) {
   date_time_stamp();
   print FILE "$file .   N";
  } elsif ($file_length eq 6) {
   date_time_stamp();
   print FILE "$file  .   N";
  } elsif ($file_length eq 5) {
   date_time_stamp();
   print FILE "$file   .   N";
  } else {
   die "[OLD MAIL]File names are too short.\nThere may also be a
problem with the FILES.NEW.  Aborting  . .";
  }
 }
print "Sucessfully printed mail records to file . . .\n";


#Printing corect end of file flag
print FILE $EOF[0];
print "Sucessfully printed EOF flag . . .\n";
close FILE;
close FILELIST;


sub date_time_stamp {
#Dealing with Time and Date . . .

#load variable with localetime values
($sec,$min,$hour,$dayofmonth,$month,$year,$wday,$yday,$isdst) =
localtime(time);

#year and month start at 0 due to perl being unix native

$year = ($year +1900);
$month = ($month + 1);

#print out date correctly

if ($month >= 10 && $dayofmonth >= 10) {
        print FILE " $year$month$dayofmonth";
 } elsif ($month >= 10 && $dayofmonth <= 9) {
        print FILE " $year$month","0","$dayofmonth";
 } elsif ($month <= 9 && $dayofmonth >= 10) {
        print FILE " ";
        print FILE (($year),"0",($month),$dayofmonth);
 } elsif ($month <= 9 && $dayofmonth <= 9) {
        print FILE " ";
        print FILE (($year),"0",($month),"0","$dayofmonth");
 }

#String 1 date & time stamp and report name
#Basically fills in a leading ")" for minutes and hours less than 10
if ($min >= 10 && $hour >= 10) {
        print FILE ($hour);
        print FILE ":",($min)," AMBATCH REPORT (OLD)
";
 } elsif ($min <= 9 && $hour >= 10) {
        print FILE ($hour);
        print FILE ":","0",($min)," AMBATCH REPORT (OLD)
";
 } elsif ($min >= 10 && $hour <= 9) {
        print FILE "0",($hour);
        print FILE ":",($min)," AMBATCH REPORT (OLD)
";
 } elsif ($min >= 10 && $hour <= 9) {
        print FILE "0",($hour);
        print FILE ":","0",($min)," AMBATCH REPORT (OLD)
";
 }
}



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

Date: Fri, 02 Feb 2001 03:47:03 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: first real PERL script . . .
Message-Id: <3A7A2E67.40D2C3CE@rochester.rr.com>

"Stephen S." wrote:
 ...
>         This is a copy of my first real PERL script.  I was wondering
> if someone would take a look at it and make any suggetions about it.
> The scripts works and run with no forseeable problems but I would like
> to see if there was a different way of doing all or any of this.
> Basically it takes a list of files with nul extentions (files.new
> created  by a dir /b *. >> files.new) and creates a DBf file readable
> by a certain program.  TIA
> 
> Stephen
>

warning:  my suggestions below are UNTESTED

use strict;
use warnings qw(all);
> #A listing of the files to be imported into Companion . . .
> #Plain text, no extentions between 5 and 8 characters . . .
> $filename ="files.new";
> $out_file = "> btch_clm.dbf";
> open (FILE, $out_file) || die "[NEW MAIL]Can't open new mail list.
> Aborting . .";
> print "\nOpened output file sucsssfully . . .\n";
> 
> #assigning "Top of file" to an array for later printing
> @top = (
> "\x03\x65\x01\x1c\xff\x00\x00\x00\xc1\x00\x4b\x00\x00\x00\x00\x00",
> "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
> "\x44\x41\x54\x45\x00\x00\x00\x00\x00\x00\x00\x44\x00\x00\x00\x00",
> "\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
> "\x54\x49\x4d\x45\x00\x00\x00\x00\x00\x00\x00\x43\x00\x00\x00\x00",
> "\x08\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
> "\x44\x45\x53\x43\x52\x49\x50\x54\x00\x00\x00\x43\x00\x00\x00\x00",
> "\x2d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
> "\x46\x49\x4c\x45\x5f\x4e\x41\x4d\x45\x00\x00\x43\x00\x00\x00\x00",
> "\x0c\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
> "\x44\x45\x4c\x45\x54\x45\x00\x00\x00\x00\x00\x43\x00\x00\x00\x00",
> "\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00",
> "END"
> );
> 
> #assigning "End of Record" to an array for later printing
> @EOR = (
> "\x0d"
> );
> 
> #assigning "End of file" to an array for later printing
> @EOF = (
> "\x0a"
> );
> 
> #Printing the top of the file . . .
> #Followed by an EOR Flag (seperator) . . .
> $i = 0;
> $done = "no";
> 
> while ($done eq "no") {
>         if ($top[$i] eq "END") {
>              $done = "yes";
>            } else {
>                 print FILE $top[$i];
>                 $i = ++$i;
you mean just $i++ or ++$i -- no assignment needed
>            }
>  }
for the above, eliminate the "END" entry in @top and use:
  print FILE for(@top);
eliminating everything after the last comment above
> print FILE $EOR[0];
> print "Sucessfully printed TOP of file . . .\n";
> 
> open (FILELIST, $filename) || die "[OLD MAIL]Can't open old mail list.
> Aborting . .";
> 
> while ($file = <FILELIST>) {
>  chomp $file;
>  $file_length = length($file);
> 
>  if ($file_length > 8) {die "\n\n[OLD MAIL]File names are too long.
> Aborting . .";}
add:  if($file_length<5){die "[OLD MAIL]File names are two short..."}
> 
>  if ($file_length eq 8) {
>    date_time_stamp();
>    print FILE "$file.   N";
>   } elsif ($file_length eq 7) {
>    date_time_stamp();
>    print FILE "$file .   N";
>   } elsif ($file_length eq 6) {
>    date_time_stamp();
>    print FILE "$file  .   N";
>   } elsif ($file_length eq 5) {
>    date_time_stamp();
>    print FILE "$file   .   N";
>   } else {
>    die "[OLD MAIL]File names are too short.\nThere may also be a
> problem with the FILES.NEW.  Aborting  . .";
>   }
replace the entire if above with:
    date_time_stamp();
    printf FILE "%-8s.   N",$file;
>  }
> print "Sucessfully printed mail records to file . . .\n";
> 
> #Printing corect end of file flag
> print FILE $EOF[0];
> print "Sucessfully printed EOF flag . . .\n";
> close FILE;
> close FILELIST;
> 
> sub date_time_stamp {
> #Dealing with Time and Date . . .
> 
> #load variable with localetime values
> ($sec,$min,$hour,$dayofmonth,$month,$year,$wday,$yday,$isdst) =
> localtime(time);
> 
> #year and month start at 0 due to perl being unix native
> 
> $year = ($year +1900);
> $month = ($month + 1);
> 
> #print out date correctly
> 
> if ($month >= 10 && $dayofmonth >= 10) {
>         print FILE " $year$month$dayofmonth";
>  } elsif ($month >= 10 && $dayofmonth <= 9) {
>         print FILE " $year$month","0","$dayofmonth";
>  } elsif ($month <= 9 && $dayofmonth >= 10) {
>         print FILE " ";
>         print FILE (($year),"0",($month),$dayofmonth);
>  } elsif ($month <= 9 && $dayofmonth <= 9) {
>         print FILE " ";
>         print FILE (($year),"0",($month),"0","$dayofmonth");
>  }
replace entire if above with:
   printf FILE "%4d%02d%02d",$year,$month,$dayofmonth;
> 
> #String 1 date & time stamp and report name
> #Basically fills in a leading ")" for minutes and hours less than 10
you mean leading 0??
> if ($min >= 10 && $hour >= 10) {
>         print FILE ($hour);
>         print FILE ":",($min)," AMBATCH REPORT (OLD)
> ";
>  } elsif ($min <= 9 && $hour >= 10) {
>         print FILE ($hour);
>         print FILE ":","0",($min)," AMBATCH REPORT (OLD)
> ";
>  } elsif ($min >= 10 && $hour <= 9) {
>         print FILE "0",($hour);
>         print FILE ":",($min)," AMBATCH REPORT (OLD)
> ";
>  } elsif ($min >= 10 && $hour <= 9) {
>         print FILE "0",($hour);
>         print FILE ":","0",($min)," AMBATCH REPORT (OLD)
> ";
>  }
replace entire if above with:
   printf FILE "%02d:%02d AMBATCH REPORT (OLD)",$hour,$min;
> }
-- 
Bob Walton


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

Date: Fri, 02 Feb 2001 03:16:28 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: I have the weirdest problem !!! (die, and exit don't work)
Message-Id: <3A7A273D.72B56BC4@rochester.rr.com>

pape_98@my-deja.com wrote:
 ...
> I have an if statement written below, and when it finds the variable
> $name, the script is supposed to print some stuff out, and then die.
> But for some reason it doesn't. It actually excecutes the commands
> written after the else. This is what i don't understand.
> I have asked co-workers to look at this, and they tell me that it
> shouls work. So now i'm left pondering why it doesn't work.
> Do any of you guys see something wrong with what I have written???
> 
> Thanks,
> Pape
> 
> This is what the script looks like:
> 
> # Opens the file animal and stores contents into an array.
> open (file, "/applications/apache/cgi-bin/animal-schedule-
> list/animal1.txt");
> @lines = <file>;
> close (file);
> 
> # If the name that was imputed is already in the list, then the program
> exits.
> for ($i=0; $i <= $#lines; $i++) {
>  if ($lines[$i] =~ s/$email/$email/){
>     print header(), start_html("USER ALREADY EXISTS");
>     print "<center> The user $name is already in the list<br>";
>     print end_html;
>     }
>  if ($lines[$i] =~ s/$email/$email/){
>     die ;
>     exit(0);
>     print "i still c u <br>";
>     }
>  else{
> 
> # Otherwise, it opens the file for writing and prints the updated array.
>     open (file, ">/applications/apache/cgi-bin/animal-schedule-
> list/animal1.txt");
>     print file @lines;
>     print file "$name,$email\n";
>     close (file);
>     }
> }
 ...
Well, you don't say what is in $email, but I'll bet it contains some
regexp metacharacters.  When you do the first substitute, some of the
metacharacters match something other than themselves, and then get
substituted in, making the string different than it was before.  Then
with the second match, the match fails, causing your else branch to be
executed.  Here are a couple of items:

1.  You shouldn't be using substitutions when what you really want is
just a match.  Check out m// in perlop.  If you want to avoid having
metacharacters in $email treated as metacharacters during the match, try
m/\Q$email\E/.  Also, if you want to ensure that only an exact match
succeeds, try m/^\Q$email\E$/.  Of course, then you'd better chomp
@lines also.

2.  There is no need to do the test twice anyway.  Just combine the two
if blocks and eliminate the second if (but keep the else).

3.  Learn to use perl -d.  You can step through your program and observe
exactly what is in each variable as you go.

4.  You've got some really bad logic problems even if the if statement
were corrected.  For example, you will open for write, write (with one
extra line), and close the file once for each line in the original file,
providing $email is not matched.  Whatever you are trying to do, I doubt
that is actually it.

5.  You're missing the or die "Oops, $!" clause after your open
statements.

6.  You're missing the -w flag and use strict;.
-- 
Bob Walton


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

Date: Fri, 02 Feb 2001 02:52:23 GMT
From: Casarta <nik@casarta.com>
Subject: Looking for perl script...
Message-Id: <B69F7D06.1B91%nik@casarta.com>

I'm need to create a site that will do the following and am looking for a
perl script to accomplish the task. Willing to pay if necessary.

The site is a simple form, however, we want it to fill in some of the blanks
automatically if a repeat user/regular user opens the form. The purpose is
that the regular users do not have to type in their personal information
each item (i.e. company name, address, phone, etc..) and can go directly to
the fields which are unique (job order info).

We don't expect a large number of customers, so it doesn't need to be too
scalable.

Anyone have something like this or willing to write a script to do this?

Can email me directly at nik@casarta.com if interested.




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

Date: 2 Feb 2001 04:16:38 GMT
From: rob_13@excite.com (Rob - Rock13.com)
Subject: Re: Problem running perl scripts on Netscape server
Message-Id: <903BE48A3rock13com@207.91.5.10>

Sanjay Krishna <krishnasanjay@hotmail.com>:

>I am trying to run a perl script wrapped in a .bat file. So the
>contents of the bat file are
>
>c:\perl\bin\perl script.pl

Why the .bat ? And if Perl is in your path you can just say:
perl script.pl

>script.pl contains
>.....
>print "Location: $url\n\n";#$url contains the url where it has to
>be redirected to.
>
>when I execute the perl script using...
>
>http://mymachine.domain.com/cgi/test.bat
>
>I get this message in the browser
>Location : url_itself
>in short redirection is not working.

I believe the file is simply being executed by the browser/OS not the 
server. It would need to get executed by the server so the browser is 
passed the Location header. In other words as a CGI script.

>Also if I add @echo off as
>the first line in the .bat file the perl script doesn't execute.
>
>I am using Active state Perl/Windows NT/Netscape FastTrack 2.01
>Server 

-- 

Rob - http://rock13.com/
Web Stuff: http://rock13.com/webhelp/


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

Date: 02 Feb 2001 02:35:30 GMT
From: "John Michael" <johnm@acadiacom.net>
Subject: Re: race condition or lock problem
Message-Id: <95d6di$gga@dispatch.concentric.net>

I am getting the impression that I did not give you enough info.
The script keeps information as to number of guesses. After 15 incorrect
guesses, it updates the .htaccess file to block the ip.

The script keeps up with this info in a seperate file.

Since I have had this problem, I have added some things to the script in an
attempt to prevent the problem from occuring.

For instance, if an ip is already listed, do not send an email notice.

ALso, since the ip is added to the .htaccess file, no additional hits should
even be allowed into the protected area.  And no more attempts would then be
made at guessing user info.  And the script should not run, because no
errorhandler would be called because the ip would be blocked.  However, I
usually receive multiply notices after the limit condition is reached.

This tells me that the scripts or threads were already running before the ip
was blocked by the first thread that ran the script.

The ip is getting blocked and logged as blocked.  The .htaccess file is
being updated.

I have the limit set to 15.  The script sends the email notifying that it
has made the block and number of occurances.  However, I will recive email
notices for 16, 17, 18, 19, 20, and sometimes more.

John Michael




"Jonathan Feinberg" <jdf@pobox.com> wrote in message
news:zog5n9g4.fsf@pobox.com...
> "John Michael" <johnm@acadiacom.net> writes:
>
> > The script is run buy an apache errordoc handler
> >
> > ErrorDocument 401 /cgi-bin/myscript.pl
> > Therefore,  a bot script running on another server can make a lot of
request
> > in just few seconds.
>
> Well, so one script is finished by the time another starts up, so why
> shouldn't they both send an email?
>
> --
> Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
> http://pobox.com/~jdf




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

Date: 01 Feb 2001 21:06:37 -0500
From: Jonathan Feinberg <jdf@pobox.com>
Subject: Re: replace a matched string
Message-Id: <r91hn8ia.fsf@pobox.com>

cleng1@my-deja.com writes:


> s/(book_.*)/$1_buff/g;

Your regex says

   (        # capture
   book_    # the literal expression "book_"
   .*       # followed by 0 or more of any kind of character
   )

> book_yellow, book_green, book_red
  ^^^^^
    |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^  
    |               |
  book_   0 or more of any character

> my output should be like
> book_yellow_buff, book_green_buff, book_red_buff

Remember that the * is "greedy"; it eats as many characters as it can,
not the fewest possible.  What you want is to match "book_" followed
by any number of alphabetic characters, right?  So say so!

   s/(book_[a-z]*)/$1_buff/gi;

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
http://pobox.com/~jdf


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

Date: 2 Feb 2001 02:25:10 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: replace a matched string
Message-Id: <slrn97k6g1.mcu.damian@puma.qimr.edu.au>

Thus spake cleng1@my-deja.com on Fri, 02 Feb 2001 00:55:31 GMT:
>I have a string like this:
>book_yellow, book_green, book_red
>
>after I did
>s/(book_.*)/$1_buff/g;
>
>my output should be like
>book_yellow_buff, book_green_buff, book_red_buff
>
>How come my output is like
>book_yellow, book_green, book_red_buff
>
>How to fix, so I can replace all string? intead one?
>

You are forgetting that the .* in your regex is greedy - it is matching 
the whole string, merely appending "_buff" to the end. See the perlre man 
page for details.

You probably want something like:

s/(book_.*?)/$1_buff/g;

or:

s/(book_\w*)/$1_buff/g;

HTH

Cheers,
Damian
-- 
$;=ord$%,$:=$;-ord q,.,,$_=q 13346:3366:3276:3326:3386:546:566:966:3396:3376:1.
q 73386:546:;96:3326:3336:3386:3266:3236:3366:546::26:3236:3366:32:6:546:32667.
q,:;96:;;6:3296:3236:3366:326:56,,s,.,ord($&)-$:-$;;;;;;,eg,s,$;,;chr$&-$:;,eg,
eval eval;               #requires 5.6.0 ## my first attempt at one of these...


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

Date: 2 Feb 2001 02:52:21 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: replace a matched string
Message-Id: <slrn97k87h.mcu.damian@puma.qimr.edu.au>

Thus spake Damian James on 2 Feb 2001 02:25:10 GMT:
>
>You probably want something like:
>
>s/(book_.*?)/$1_buff/g;
>         ^^^
>or:
>
>s/(book_\w*)/$1_buff/g;
>

Sorry -- that should be:

s/(book_.*?),/$1_buff,/g;

mea culpa

Cheers,
Damian


-- 
$;=ord$%,$:=$;-ord q,.,,$_=q 13346:3366:3276:3326:3386:546:566:966:3396:3376:1.
q 73386:546:;96:3326:3336:3386:3266:3236:3366:546::26:3236:3366:32:6:546:32667.
q,:;96:;;6:3296:3236:3366:326:56,,s,.,ord($&)-$:-$;;;;;;,eg,s,$;,;chr$&-$:;,eg,
eval eval;               #requires 5.6.0 ## my first attempt at one of these...


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

Date: Fri, 02 Feb 2001 03:01:12 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: replace a matched string
Message-Id: <Yppe6.411$Sn3.15609@eagle.america.net>

On Fri, 02 Feb 2001 00:55:31 GMT, cleng1@my-deja.com <cleng1@my-deja.com> wrote:
>I have a string like this:
>book_yellow, book_green, book_red

I assume you mean: 

  $_ = "book_yellow, book_green, book_red";

Right?  

>after I did
>s/(book_.*)/$1_buff/g;

Okay, let's take that apart.  

The match part will match the string "book_" followed by any character
occurring zero or more times (the `.*' bit).  This last part (the `.*'
bit) will consume the entire string.  That match will be captured in
$1 as: 

  book_yellow, book_green, book_red
  ^^^^^
    |  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    |             |
    |             |
 s/(book_        .*)

Now that we have satisfied the match, the substitute will be
performed.  

There will be no more possibilities to match the string again using
the /g option.  So the statement is finished.  The result will be the
string you report below.  

This behavior is called `greediness'.  The quantifier `*' will consume
as much of the string as it can before yielding to the next part of
the regular expression.  Since `.' will match anything (except \n
except when /s is used), this will consume the entire string.  Now,
since there is nothing left in the regular expression, the match is
successful and the substitution is done.  (If there was more to the
regular expression, the regular expression engine would back-track one
character and try to match again.  This would repeat until a match was
found or until there was no possible previous choice-point to
back-track to, in which case the match would fail.)  

>my output should be like
>book_yellow_buff, book_green_buff, book_red_buff
>
>How come my output is like
>book_yellow, book_green, book_red_buff
>
>How to fix, so I can replace all string? intead one?

Use a different match that explicitly matches *only* the part that you
want replaced instead of the whole string: 

  s/(book_.*?)\b/$1_buff/g;

The *? quantifier will be `non-greedy' in that it will consume the
*minimum* characters necessary to allow the rest of the regular
expression to match.  The \b (word boundary) will cause a match before
the commas and before the end of the string.  

Check out the perlre and perlop manual pages for lots more on how
regular expressions and s/// operate.  

-- 
Garry Williams


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

Date: Fri, 02 Feb 2001 03:09:16 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: replace a matched string
Message-Id: <wxpe6.412$Sn3.15609@eagle.america.net>

On 2 Feb 2001 02:25:10 GMT, Damian James <damian@qimr.edu.au> wrote:
>Thus spake cleng1@my-deja.com on Fri, 02 Feb 2001 00:55:31 GMT:
>>I have a string like this:
>>book_yellow, book_green, book_red
>>
>>after I did
>>s/(book_.*)/$1_buff/g;
>>
>>my output should be like
>>book_yellow_buff, book_green_buff, book_red_buff
>>
>>How come my output is like
>>book_yellow, book_green, book_red_buff

[snip]

>You probably want something like:
>
>s/(book_.*?)/$1_buff/g;

  $ perl -wle '$_="book_yellow, book_green, book_red";\
      s/(book_.*?)/$1_buff/g;print'
  book__buffyellow, book__buffgreen, book__buffred
  $ 

>or:
>
>s/(book_\w*)/$1_buff/g;

  $ perl -wle '$_="book_yellow, book_green, book_red";\
      s/(book_\w*)/$1_buff/g;print'
  book_yellow_buff, book_green_buff, book_red_buff
  $ 

-- 
Garry Williams


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

Date: Fri, 02 Feb 2001 03:11:44 GMT
From: garry@zvolve.com (Garry Williams)
Subject: Re: replace a matched string
Message-Id: <Qzpe6.413$Sn3.15609@eagle.america.net>

On 2 Feb 2001 02:52:21 GMT, Damian James <damian@qimr.edu.au> wrote:
>Thus spake Damian James on 2 Feb 2001 02:25:10 GMT:
>>
>>You probably want something like:
>>
>>s/(book_.*?)/$1_buff/g;
>>         ^^^
>>or:
>>
>>s/(book_\w*)/$1_buff/g;
>>
>
>Sorry -- that should be:
>
>s/(book_.*?),/$1_buff,/g;

  $ perl -wle '$_="book_yellow, book_green, book_red";\
      s/(book_.*?),/$1_buff,/g;print'
  book_yellow_buff, book_green_buff, book_red
  $ 

-- 
Garry Williams


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

Date: 2 Feb 2001 03:32:53 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: replace a matched string
Message-Id: <slrn97kajh.spn.damian@puma.qimr.edu.au>

Thus spake Garry Williams on Fri, 02 Feb 2001 03:11:44 GMT:
>On 2 Feb 2001 02:52:21 GMT, Damian James <damian@qimr.edu.au> wrote:
>>Thus spake Damian James on 2 Feb 2001 02:25:10 GMT:
>>>
>>>You probably want something like:
>>>
>>>s/(book_.*?)/$1_buff/g;
[snip]         ^^^
>>Sorry -- that should be:
>>
>>s/(book_.*?),/$1_buff,/g;
>
>  $ perl -wle '$_="book_yellow, book_green, book_red";\
>      s/(book_.*?),/$1_buff,/g;print'
>  book_yellow_buff, book_green_buff, book_red
>  $ 
>

OK -- I was off my tree posting the first example without testing it. Of
course, what I meant was:

%perl -wle '$_="book_yellow, book_green, book_red";\
	s/(book_.*?)\b/$1_buff/g;print'
				^^
book_yellow_buff, book_green_buff, book_red_buff
%

I had thought of the word boundary first time, but had forgotten when I
spotted the mistake. Serves me right for not testing. mea culpa magna

Cheers,
Damian
-- 
$;=ord$%,$:=$;-ord q,.,,$_=q 13346:3366:3276:3326:3386:546:566:966:3396:3376:1.
q 73386:546:;96:3326:3336:3386:3266:3236:3366:546::26:3236:3366:32:6:546:32667.
q,:;96:;;6:3296:3236:3366:326:56,,s,.,;ord($&)-$:-$;;;;;,eg,s,$;,;chr$&-$:;,eg,
eval eval;               #requires 5.6.0 ## my first attempt at one of these...


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

Date: Fri, 02 Feb 2001 12:50:55 +0900
From: Yongsik Kim <yosikim@lgeds.lg.co.kr>
Subject: Re: Running shell comands from Perl?
Message-Id: <3A7A2E9F.D564CD82@lgeds.lg.co.kr>

perldoc -f system

Graham Daniell wrote:
> 
> How can I run a shell command from Perl?
> 
> What I want to do is run "/sbin/ifconfig ppp0' and test what is
> returned, to see whether ppp0 is running.
> 
> Something like:
> 
> # test ppp0
> if ( "sbin/ifconfig ppp0" )
>     do ...
> fi
> #
> 
> Thanks,
> Graham Daniell
> gdaniell@wt.com.au


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

Date: 2 Feb 2001 12:26:52 +1100
From: "Kiel R Stirling" <taboo@comcen.com.au>
Subject: undef question
Message-Id: <3a7a0cdc@nexus.comcen.com.au>


Hi all,

Quick question about the undef function.
Programing Perl seems to say this function undefines a EXPR.
If I had data in a variable and I wanted it to go away 
I would do something like $data = ""; which would, I think, undefine
$data.

Which leads me to my question: 
Can I just use the undef function and why should I? 

Regards,

Kiel R Stirling.


   


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 197
**************************************


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