[18997] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1192 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 25 18:11:37 2001

Date: Mon, 25 Jun 2001 15:10:14 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <993507014-v10-i1192@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 25 Jun 2001     Volume: 10 Number: 1192

Today's topics:
    Re: perl script worked on redhat 6 but not 7.x (Anno Siegel)
    Re: perl script worked on redhat 6 but not 7.x <Laszlo.G.Szijarto@grc.nasa.gov>
        Problem with Archive::Tar <djberge@uswest.com>
        Problems verifying numerical data (Ted)
    Re: Problems verifying numerical data (Mark Jason Dominus)
    Re: Problems verifying numerical data (Geoffrey Kinnel)
    Re: Problems verifying numerical data <yanoff@yahoo.com>
    Re: puzzled over fork() doing something different to bo <buggs-clpm@splashground.de>
    Re: puzzled over fork() doing something different to bo <m.grimshaw@salford.ac.uk>
    Re: puzzled over fork() doing something different to bo <m.grimshaw@salford.ac.uk>
        right symbol? <min_c_lee@yahoo.com>
    Re: right symbol? <buggs-clpm@splashground.de>
        Script stops on multiple question marks (Darren Spidell)
    Re: simulating multi-thread <dan@tuatha.sidhe.org>
    Re: THE fastest way to count lines in a file (Craig Berry)
        Trouble with CGI.PM <dbusby3@slb.com>
    Re: Trouble with CGI.PM <m.grimshaw@salford.ac.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 25 Jun 2001 18:50:06 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: perl script worked on redhat 6 but not 7.x
Message-Id: <9h814u$f8s$1@mamenchi.zrz.TU-Berlin.DE>

According to Michael M. <m_musgrove@yahoo.com>:
> This script is not working on RedHat 7.x. It worked fine on version
> 6.x.
> The error I am receiving when running it at the command prompt is:
> Missing braces on \N{} at ./chatplace2backup.cgi line 85, within
> string
> Execution of ./chatplace2backup.cgi aborted due to compilation errors.
> 
> If anyone could help me out I would really appreciate it. I am
> unfortunately not a programmer. :(

[code snipped]

Apparently the new version came with a different version of Perl.
("perl -v" checks the version, that is the first thing you should do
when a Perl program inexplicably starts giving you errors.)

You should check your code (including chat-vars.lib) for the
appearance of "\N" inside strings.  In older Perls the backslash
was ignored; these days the combination has a meaning and *must*
be followed by something enclosed in {}.

Most commonly "\N" is a mis-typing of "\n", the line terminator.
In that case, there was a bug in the program before, and you should
have seen some over-long lines with an unmotivated "N" in the middle.

Anno


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

Date: Mon, 25 Jun 2001 16:21:04 -0400
From: "Laszlo G. Szijarto" <Laszlo.G.Szijarto@grc.nasa.gov>
Subject: Re: perl script worked on redhat 6 but not 7.x
Message-Id: <9h86i6$jrv$1@sulawesi-fi.lerc.nasa.gov>

I don't know if you just forgot to include it, BUT ..
toward the bottom of your script, you have some messed up quotation mark
stuff ...





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

Date: Mon, 25 Jun 2001 15:32:36 -0500
From: "Mr. Sunray" <djberge@uswest.com>
Subject: Problem with Archive::Tar
Message-Id: <3B379FE4.2E272EA@uswest.com>


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

Hi all,

Bughat 6.2, Perl 5.6.1, Archive::Tar 0.22

I must be having a bad day, because I don't seem to be able to create a
tar archive within Perl.  I've used Archive::Zip with no problems, so I
don't know what my deal is.

I'm reading through a directory, creating a separate tar file for each
group of files with similar basenames.  I am able to create the tar file
with no errors.  However, when I try and extract the tar file on the
command line, all I get is: "tar: Record size = 2 blocks", presumably
because there were 2 files in my test (though I'm guessing).

Here is the script in its entirety.  You may wish to skip to the bottom
for the 'Archive::Tar' portion.  It's the last thing that gets done.

Thanks in advance for any help.

Regards,

Mr. Sunray


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

#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

# Archiver.pl
#
# Author(s):
#   Mr. Sunray
#
# Date:
#   25-Jun-2001
#
# Purpose:
#   Archives any zip files that were generated for MyProgram by placing
#   them in the 'Archive' directory.  Every two weeks all of the files
in
#   the Archive directory will be tar'd and gzip'd, grouped by filename.

#   Any non-zipped (.xls) files will be deleted.
#
#   The script will run on the 15th (archiving all files from the 1st to

#   the 15th) and the last day of the month (archiving all files from
the
#   16th to the last day of the month).
#
# Notes:
#   Technically, the 'last day of the month' is midnight + 1 second of
the
#   first day of the next month.  This is done to get around the fact
that
#   'cron' doesn't have any way of specifying a 'last day of month'
within
#   the crontab (that I know of).
#
# Log:
#   1.0 - Initial release
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


use strict;
use File::Basename;
use Time::localtime;
use Date::Manip qw(Date_DaysInMonth);
use Archive::Tar;

use constant HOME       => '/home/database/Run';
use constant ARCHIVEDIR => '/home/database/Run/Archive';

my($hour,$month,$year,$dim,$dateString);

#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

# Because the cron runs at midnight of the first day of the next month
in
# lieu of the last day of the current month, we want to lie a bit
# and assign the last day of the previous month if we detect that we're
# running at midnight (the zero hour).
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

$year = localtime->year() + 1900;
$month = localtime->mon();

$dim = Date_DaysInMonth($month,$year);

if( localtime->mday() == 1){
   $dateString = "$year-$month-16-$dim";
}
elsif( localtime->mday() == 15){
   $month += 1;
$dateString = "$year-$month-1-15";
}
else{
   $month += 1;
   $dateString = "$year-$month-TEMP";  # Testing or error occurred
}

opendir(DH, HOME) or die "Unable to open home directory: $!\n";

my @files = readdir(DH);

foreach my $file(@files){
   if($file =~ /^.*?\.xls$/i){
      system("rm","$file");           # Remove any .xls files
   }
   if($file =~ /^.*?\.zip$/i){
      system("mv","$file","Archive"); # Move .zip files
   }
}

closedir(DH) or die "Unable to close home directory: $!\n";

#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# Within the 'Archive' directory, tar and gzip each group of files.
# The script will be run bi-monthly via 'cron', so we'll use the
# date range as the basis of the tar filename.
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
opendir(DH,ARCHIVEDIR) or die "Unable to open archive directory: $!\n";

@files = readdir(DH);

my %filehash;
foreach my $file(@files){
   next unless($file =~ /zip/i);
   my $name = basename($file,'.zip');
   $name =~ s/^(.*?)-.*?$/$1/;
   $filehash{$name} = 1;
}

# Tried putting this as the last statement as well, with no effect.
closedir(DH) or die "Unable to close 'Archive' directory: $!\n";

#+++++++++++++++++++++++++++++++++++++++++++++++++++++
# I also tried creating a filehandle and passing it to the
'create_archive'
# method, with different, but equally strange results.
#+++++++++++++++++++++++++++++++++++++++++++++++++++++
foreach my $basename(keys %filehash){

   my $tarfilename = "$basename-$dateString" . ".tar";

   my $tar = Archive::Tar->new();
   die "Unable to create tar archive: $!\n" unless defined $tar;

   foreach my $file(@files){
      $tar->add_files($file) if $file =~ /$basename/;
   }
   $tar->write("Archive/$tarfilename")
      or die "Couldn't write to tarfile: $!\n";

}

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

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<font size=+1>Hi all,</font><font size=+1></font>
<p><font size=+1>Bughat 6.2, Perl 5.6.1, Archive::Tar 0.22</font><font size=+1></font>
<p><font size=+1>I must be having a bad day, because I don't seem to be
able to create a tar archive within Perl.&nbsp; I've used Archive::Zip
with no problems, so I don't know what my deal is.</font><font size=+1></font>
<p><font size=+1>I'm reading through a directory, creating a separate tar
file for each group of files with similar basenames.&nbsp; I am able to
create the tar file with no errors.&nbsp; However, when I try and extract
the tar file on the command line, all I get is: "tar: Record size = 2 blocks",
presumably because there were 2 files in my test (though I'm guessing).</font><font size=+1></font>
<p><font size=+1>Here is the script in its entirety.&nbsp; You may wish
to skip to the bottom for the 'Archive::Tar' portion.&nbsp; It's the last
thing that gets done.</font><font size=+1></font>
<p><font size=+1>Thanks in advance for any help.</font><font size=+1></font>
<p><font size=+1>Regards,</font><font size=+1></font>
<p><font size=+1>Mr. Sunray</font>
<br><font size=+1></font>&nbsp;<font size=+1></font>
<p><font size=+1>#!/usr/local/bin/perl -w</font>
<br><font size=+1>&nbsp;</font>
<br><font size=+1>#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</font>
<br><font size=+1># Archiver.pl</font>
<br><font size=+1>#</font>
<br><font size=+1># Author(s):</font>
<br><font size=+1>#&nbsp;&nbsp; Mr. Sunray</font>
<br><font size=+1>#</font>
<br><font size=+1># Date:</font>
<br><font size=+1>#&nbsp;&nbsp; 25-Jun-2001</font>
<br><font size=+1>#</font>
<br><font size=+1># Purpose:</font>
<br><font size=+1>#&nbsp;&nbsp; Archives any zip files that were generated
for MyProgram by placing</font>
<br><font size=+1>#&nbsp;&nbsp; them in the 'Archive' directory.&nbsp;
Every two weeks all of the files in</font>
<br><font size=+1>#&nbsp;&nbsp; the Archive directory will be tar'd and
gzip'd, grouped by filename.</font>
<br><font size=+1>#&nbsp;&nbsp; Any non-zipped (.xls) files will be deleted.</font>
<br><font size=+1>#</font>
<br><font size=+1>#&nbsp;&nbsp; The script will run on the 15th (archiving
all files from the 1st to</font>
<br><font size=+1>#&nbsp;&nbsp; the 15th) and the last day of the month
(archiving all files from the</font>
<br><font size=+1>#&nbsp;&nbsp; 16th to the last day of the month).</font>
<br><font size=+1>#</font>
<br><font size=+1># Notes:</font>
<br><font size=+1>#&nbsp;&nbsp; Technically, the 'last day of the month'
is midnight + 1 second of the</font>
<br><font size=+1>#&nbsp;&nbsp; first day of the next month.&nbsp; This
is done to get around the fact that</font>
<br><font size=+1>#&nbsp;&nbsp; 'cron' doesn't have any way of specifying
a 'last day of month' within</font>
<br><font size=+1>#&nbsp;&nbsp; the crontab (that I know of).</font>
<br><font size=+1>#</font>
<br><font size=+1># Log:</font>
<br><font size=+1>#&nbsp;&nbsp; 1.0 - Initial release</font>
<br><font size=+1>#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</font>
<br><font size=+1>&nbsp;</font>
<br><font size=+1>use strict;</font>
<br><font size=+1>use <A HREF="File::Basename">File::Basename</A>;</font>
<br><font size=+1>use Time::localtime;</font>
<br><font size=+1>use Date::Manip qw(Date_DaysInMonth);</font>
<br><font size=+1>use Archive::Tar;</font>
<br><font size=+1>&nbsp;</font>
<br><font size=+1>use constant HOME&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
=> '/home/database/Run';</font>
<br><font size=+1>use constant ARCHIVEDIR => '/home/database/Run/Archive';</font>
<br><font size=+1>&nbsp;</font>
<br><font size=+1>my($hour,$month,$year,$dim,$dateString);</font>
<br><font size=+1>&nbsp;</font>
<br><font size=+1>#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</font>
<br><font size=+1># Because the cron runs at midnight of the first day
of the next month in</font>
<br><font size=+1># lieu of the last day of the current month, we want
to lie a bit</font>
<br><font size=+1># and assign the last day of the previous month if we
detect that we're</font>
<br><font size=+1># running at midnight (the zero hour).</font>
<br><font size=+1>#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</font>
<br><font size=+1>$year = localtime->year() + 1900;</font>
<br><font size=+1>$month = localtime->mon();</font>
<br><font size=+1>&nbsp;</font>
<br><font size=+1>$dim = Date_DaysInMonth($month,$year);</font>
<br><font size=+1>&nbsp;</font>
<br><font size=+1>if( localtime->mday() == 1){</font>
<br><font size=+1>&nbsp;&nbsp; $dateString = "$year-$month-16-$dim";</font>
<br><font size=+1>}</font>
<br><font size=+1>elsif( localtime->mday() == 15){</font>
<br><font size=+1>&nbsp;&nbsp; $month += 1;</font>
<br><font size=+1>$dateString = "$year-$month-1-15";</font>
<br><font size=+1>}</font>
<br><font size=+1>else{</font>
<br><font size=+1>&nbsp;&nbsp; $month += 1;</font>
<br><font size=+1>&nbsp;&nbsp; $dateString = "$year-$month-TEMP";&nbsp;
# Testing or error occurred</font>
<br><font size=+1>}</font>
<br><font size=+1>&nbsp;</font>
<br><font size=+1>opendir(DH, HOME) or die "Unable to open home directory:
$!\n";</font>
<br><font size=+1>&nbsp;</font>
<br><font size=+1>my @files = readdir(DH);</font>
<br><font size=+1>&nbsp;</font>
<br><font size=+1>foreach my $file(@files){</font>
<br><font size=+1>&nbsp;&nbsp; if($file =~ /^.*?\.xls$/i){</font>
<br><font size=+1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; system("rm","$file");&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
# Remove any .xls files</font>
<br><font size=+1>&nbsp;&nbsp; }</font>
<br><font size=+1>&nbsp;&nbsp; if($file =~ /^.*?\.zip$/i){</font>
<br><font size=+1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; system("mv","$file","Archive");
# Move .zip files</font>
<br><font size=+1>&nbsp;&nbsp; }</font>
<br><font size=+1>}</font>
<br><font size=+1>&nbsp;</font>
<br><font size=+1>closedir(DH) or die "Unable to close home directory:
$!\n";</font>
<br><font size=+1>&nbsp;</font>
<br><font size=+1>#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</font>
<br><font size=+1># Within the 'Archive' directory, tar and gzip each group
of files.</font>
<br><font size=+1># The script will be run bi-monthly via 'cron', so we'll
use the</font>
<br><font size=+1># date range as the basis of the tar filename.</font>
<br><font size=+1>#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++</font>
<br><font size=+1>opendir(DH,ARCHIVEDIR) or die "Unable to open archive
directory: $!\n";</font>
<br><font size=+1>&nbsp;</font>
<br><font size=+1>@files = readdir(DH);</font>
<br><font size=+1>&nbsp;</font>
<br><font size=+1>my %filehash;</font>
<br><font size=+1>foreach my $file(@files){</font>
<br><font size=+1>&nbsp;&nbsp; next unless($file =~ /zip/i);</font>
<br><font size=+1>&nbsp;&nbsp; my $name = basename($file,'.zip');</font>
<br><font size=+1>&nbsp;&nbsp; $name =~ s/^(.*?)-.*?$/$1/;</font>
<br><font size=+1>&nbsp;&nbsp; $filehash{$name} = 1;</font>
<br><font size=+1>}</font>
<br><font size=+1>&nbsp;</font>
<br><font size=+1># Tried putting this as the last statement as well, with
no effect.</font>
<br><font size=+1>closedir(DH) or die "Unable to close 'Archive' directory:
$!\n";</font>
<br><font size=+1>&nbsp;</font>
<br><font size=+1>#+++++++++++++++++++++++++++++++++++++++++++++++++++++</font>
<br><font size=+1># I also tried creating a filehandle and passing it to
the 'create_archive'</font>
<br><font size=+1># method, with different, but equally strange results.</font>
<br><font size=+1>#+++++++++++++++++++++++++++++++++++++++++++++++++++++</font>
<br><font size=+1>foreach my $basename(keys %filehash){</font>
<br><font size=+1>&nbsp;</font>
<br><font size=+1>&nbsp;&nbsp; my $tarfilename = "$basename-$dateString"
 . ".tar";</font>
<br><font size=+1>&nbsp;</font>
<br><font size=+1>&nbsp;&nbsp; my $tar = Archive::Tar->new();</font>
<br><font size=+1>&nbsp;&nbsp; die "Unable to create tar archive: $!\n"
unless defined $tar;</font>
<br><font size=+1>&nbsp;</font>
<br><font size=+1>&nbsp;&nbsp; foreach my $file(@files){</font>
<br><font size=+1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $tar->add_files($file)
if $file =~ /$basename/;</font>
<br><font size=+1>&nbsp;&nbsp; }</font>
<br><font size=+1>&nbsp;&nbsp; $tar->write("Archive/$tarfilename")</font>
<br><font size=+1>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; or die "Couldn't write
to tarfile: $!\n";</font><font size=+1></font>
<p><font size=+1>}</font></html>

--------------42C34EEDDACF0E2BE765FFDF--



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

Date: 25 Jun 2001 12:07:41 -0700
From: ted9669@yahoo.com (Ted)
Subject: Problems verifying numerical data
Message-Id: <c9cff006.0106251107.38a1920f@posting.google.com>

Alright, so I'm trying to force a check that a number is *exactly* 4
digits. In regexes, I always thought that the \d was the same as
[0-9], and I'm using the general multiplier to ensure the exact length
of 4 digits, so what is wrong here? This prints Yes, though I assumed
it would print No. Any help would be a great deed.
 .ted
 
#!/usr/bin/perl -w

$mynum = 12345;
print "$mynum\n";

if ($mynum =~ /\d{4}/) {
	print "Yes\n";
} else {
	print "No\n";
}


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

Date: Mon, 25 Jun 2001 19:36:02 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Problems verifying numerical data
Message-Id: <3b3792a1.715c$34@news.op.net>

In article <c9cff006.0106251107.38a1920f@posting.google.com>,
Ted <ted9669@yahoo.com> wrote:
>Alright, so I'm trying to force a check that a number is *exactly* 4
>digits. In regexes, I always thought that the \d was the same as
>[0-9],

Right.

> and I'm using the general multiplier to ensure the exact length
>of 4 digits,

Right.

> so what is wrong here?

By default, regexes search for *substrings*.  For example,

        "A string that mentions doggies" =~ /dog/;

this *will* match.  The regex /dog/ matches any string that *contains* "dog".

Your regex /\d{4}/ will match any string that *contains* four
consecutive digits, including "9999", "Pay me that $1000 you owe me",
and "12738123123".

You probably want

        /^\d{4}$/

instead.

-- 
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print


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

Date: 25 Jun 2001 19:41:38 GMT
From: gk@d2465-hp4m.lvl.pri.bms.com (Geoffrey Kinnel)
Subject: Re: Problems verifying numerical data
Message-Id: <slrn9jf4vi.blo.gk@d2465-hp4m.lvl.pri.bms.com>

On 25 Jun 2001 12:07:41 -0700, Ted <ted9669@yahoo.com> wrote:
>Alright, so I'm trying to force a check that a number is *exactly* 4
>digits. 

>#!/usr/bin/perl -w
>
>$mynum = 12345;
>print "$mynum\n";
>
>if ($mynum =~ /\d{4}/) {
>	print "Yes\n";
>} else {
>	print "No\n";
>}

You are checking for exactly 4 digits anywhere within the variable. You 
need to anchor the regex like so:

if ($mynum =~ /^\d{4}$/) {
  
Your regex would return Yes for "iuriwiwe8888wierwi".

Hope that helps.

Geoff



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

Date: Mon, 25 Jun 2001 15:11:57 -0500
From: Scott Yanoff <yanoff@yahoo.com>
To: Ted <ted9669@yahoo.com>
Subject: Re: Problems verifying numerical data
Message-Id: <3B379B0D.BA19ED7D@yahoo.com>

Ted wrote:
> 
> Alright, so I'm trying to force a check that a number is *exactly* 4
> digits. In regexes, I always thought that the \d was the same as
> [0-9], and I'm using the general multiplier to ensure the exact length
> of 4 digits, so what is wrong here? This prints Yes, though I assumed
> it would print No. Any help would be a great deed.
> .ted
> 
> #!/usr/bin/perl -w
> 
> $mynum = 12345;
> print "$mynum\n";
> 
> if ($mynum =~ /\d{4}/) {
>         print "Yes\n";
> } else {
>         print "No\n";
> }

There may be better methods, but try chaging the pattern match to:
if ($mynum =~ /^\d{4}$/) {

(add the caret at the front and the dollar sign at the end to signify
that you want to match on only 4 characters)

Good luck,

-- 
-Scott
yanoff@yahoo.com | http://www.yanoff.org | AOL IM: SAY KJY


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

Date: Mon, 25 Jun 2001 20:07:48 +0200
From: Buggs <buggs-clpm@splashground.de>
Subject: Re: puzzled over fork() doing something different to book example
Message-Id: <9h7ufe$gkm$02$1@news.t-online.com>

Mark Grimshaw wrote:

> <snip>
>> 
>> Is reading docu an option? :)
>> 
>> This is not an easy topic.
>> 
> 
> <snip>
> 
> Makes sense now.
> 
> I think this is my first post here where I've been told to go read the
> documentation!  I thought I'd been doing pretty well until then.... :)
>
> Of course I read documentation and all my perl books on fork()!  If I
> was a UNIXhead or perl guru, I wouldn't be asking questions here would I
> now?  man fork is pretty impenetrable stuff (to me) as, to a lesser
> extent, is perldoc perlipc.  perldoc -q fork talks about daemon
> processes.  perldoc -f fork is very short and mainly seems to state the
> need to use wait() which doesn't seem to be the whole truth when I
> combine it with pipes.  The following works perfectly well, does what I
> expect it to do and creates no zombies - and not a wait() in sight (it
> sits there looping away until I CTRL-C):

--snip--

> As you say, 'this is not an easy topic' and a combination of books, man,
> perldoc, my own experimentation and, as a final resort, answers from
> here usually leads me to the solution by collating some understanding
> from each.  What throws me off my stride is when the example from a book
> does not do exactly what that book says it will do (I'll grant that the
> -l switch was a leftover from previous scripts that I didn't take out -
> the order of execution was still different without it), nor does the
> book state that the order of execution of processes may not be exactly
> that given.  Perhaps I'm _too_ trusting of the documentation ;)

Marc, there was no offense meant when pointing to the docu :)
You also migth have noticed that I did not point
to perldoc -f fork ;-). You just seemed to need some
general context.
Without the context I've seen no way to discuss this topic.

Never trust docu.
There are no debugging switches for docu :(
But it should give you enough context to start thinking.

Have fun,
Buggs


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

Date: Mon, 25 Jun 2001 19:34:19 +0100
From: Mark Grimshaw <m.grimshaw@salford.ac.uk>
Subject: Re: puzzled over fork() doing something different to book example
Message-Id: <3B37842B.BE87107@salford.ac.uk>

<snip>
> 
> Marc, there was no offense meant when pointing to the docu :)
> You also migth have noticed that I did not point
> to perldoc -f fork ;-). You just seemed to need some
> general context.
> Without the context I've seen no way to discuss this topic.
> 
> Never trust docu.
> There are no debugging switches for docu :(
> But it should give you enough context to start thinking.

No offense taken - I just thought it amusing that for a non-easy subject
it was suggested I read the documentation ;)


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

Date: Mon, 25 Jun 2001 19:51:05 +0100
From: Mark Grimshaw <m.grimshaw@salford.ac.uk>
Subject: Re: puzzled over fork() doing something different to book example
Message-Id: <3B378819.19F4B022@salford.ac.uk>

Mark Jason Dominus wrote:
> 
> In article <3B3774B8.4646B824@salford.ac.uk>,
> Mark Grimshaw  <m.grimshaw@salford.ac.uk> wrote:
> >The following creates no zombies - and not a wait() in sight
> 
> When the child exits, it becomes a zombie.  The reason you don't see
> this is that the parent exits at almost the same time, and the zombie
> is automatically adopted by the 'init' process.  Init runs a program
> that looks something like this:
> 
>               while (1) {
>                 wait;
>               }
> 
> which cleans up the zombie immediately.
> 

aah - an ephemeral zombie.  man zombie doesn't mention these!
For the type of seesawing I'm doing in my test script, should I be
bothered about such 'zombies'?


> I suggest you get the Richard W. Stevens book about Advanced
> Programming in the Unix Environment.  Sooner or later you are going to
> run into a problem you can't solve without an understanding of what is
> really going on.

Thanks for the tip.  I may just do that but I was bored and thought I'd
have a look into fork() to while away the time.

> 
> >nor does the book state that the order of execution of processes may
> >not be exactly that given.
> 
> Get a better book.

In addition to the book mentioned in my OP (which goes into fork() in
the greatest detail), I have the lama and camel books neither of which
(to my knowledge) relate process precedence to fork().


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

Date: Mon, 25 Jun 2001 21:32:32 GMT
From: "Michael" <min_c_lee@yahoo.com>
Subject: right symbol?
Message-Id: <Q5OZ6.9863$Up.293458@sea-read.news.verio.net>

Trying to print out the following query string:
http://somewhere/abc.asp?param1=$var1&param2=$var2

it should be like:
print "http://somewhere/abc.asp\?param1=$var1\&param2=$var2";

However, $var2 needs to be formatted using a subroutine:
$var2 = &format_string($var2)";

How can I combine these two commands in one line (as follow)
without confusing the ampersand sign as the start of the next parameter?

print
"http://somewhere/abc.asp\?param1=$var1\&param2=&format_string($var2)";




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

Date: Mon, 25 Jun 2001 23:46:23 +0200
From: Buggs <buggs-clpm@splashground.de>
Subject: Re: right symbol?
Message-Id: <9h8b97$pm3$07$1@news.t-online.com>

Michael wrote:

> Trying to print out the following query string:
> http://somewhere/abc.asp?param1=$var1&param2=$var2
> 
> it should be like:
> print "http://somewhere/abc.asp\?param1=$var1\&param2=$var2";
> 
> However, $var2 needs to be formatted using a subroutine:
> $var2 = &format_string($var2)";
> 
> How can I combine these two commands in one line (as follow)
> without confusing the ampersand sign as the start of the next parameter?
> 
> print
> "http://somewhere/abc.asp\?param1=$var1\&param2=&format_string($var2)";

print   q(http://somewhere/abc.asp?param1=), $var1,
        q(&param2=),format_string($var2);

print "http://bla/foo.asp\?param1=$var1\&param2=${&format_string($var2)}";


Buggs


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

Date: 25 Jun 2001 11:19:00 -0700
From: dspidell@mta.ca (Darren Spidell)
Subject: Script stops on multiple question marks
Message-Id: <f5d27ac9.0106251019.5a9ce62c@posting.google.com>

I have a Perl script that compares feilds in Mysql tables for correct
responses using a regular expresion (part of a French assessment). One
table contains the user responses, the other contains possible correct
answers. If there is a match a variable gets incremented. The user's
response gets printed as HTML whether correct or not, so the evaluator
can see all student responses.

The problem is: If a response contains a string of 3 or more question
marks, the script simply stops. The section of code is below.

if (($i > $start_value+$part_1_num)&($i <= $start_value+$part_2_num))
#Checks to see which part of the assessment the current question is in
  {
    print "$response[$i], ";
    my $temp_answer = $answers[$i-$start_value];
    $temp_response = $response[$i];
    if ($temp_answer =~ /< *$temp_response *>/)
    {
      $part_2++;
    }
  }

If the response is "etre???", the script prints "etre???," then quits.
It seems to stop when it hits the regular expression.


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

Date: Mon, 25 Jun 2001 18:14:23 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: simulating multi-thread
Message-Id: <3cLZ6.112199$v5.8510314@news1.rdc1.ct.home.com>

Rafael Garcia-Suarez <rgarciasuarez@free.fr> wrote:
> My suggestion would be not to use parallel processing when you don't
> have to. This will not improve performance unless you have multiple
> processors, and your OS is built to take advantage of them. Even in this
> case, parallelizing a loop only makes sense when the operations inside
> the loop take a long time to complete.

That turns out not to be the case. Parallelizing a program can offer
rather significant speed benefits if your program doesn't already
peg a CPU. Processes that are I/O bound can often see a big boost
in performance when rewritten properly, as threading can be used
to simulate an asynchronous I/O system on those platforms that either
don't have one or have a poor one.

> If you want to learn about multi-threaded programming, I suggest to use
> the Java language, because it's API is simple and pedagogical.

I'd not recommend Java as the language to learn to write threaded
code with. A number of folks with significant threading experience
(including Dave Butenhof, who's judgement I trust in these things)
have a lot of unpleasant things to say about Java's threading
model. See the archives of comp.programming.threads for details.

					Dan


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

Date: Mon, 25 Jun 2001 18:24:01 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: THE fastest way to count lines in a file
Message-Id: <tjf0e1rp907d5c@corp.supernews.com>

toreLG (torelg@hotmail.com) wrote:
: The fastest way to count lines,  is:
: 
: $count += tr/\n/\n/ while sysread(FILE, $_, 2 ** 16);

No need to repeat \n on the subsitution side.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Magick is the art and science of causing change in conformity
   |   with Will."  - Aleister Crowley


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

Date: Mon, 25 Jun 2001 14:28:34 -0500
From: David Busby <dbusby3@slb.com>
Subject: Trouble with CGI.PM
Message-Id: <3B3790E1.84CB27B2@slb.com>


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

First forgive my ignorance.

I need to read a local text file and send the results back to the users
browser.

I thought I could use the CGI.PM but I can seem to figure out what I am
doing wrong.

My code, below, will only process the lines in BOLD.  For some reason it
prints the data from the command line correctly but does not send that
back to the browser.  If anyone could give me a few tips it would be
great.  If I can just get a test working then I can work on the rest of
the program.

Thanks in advance to anyone.  Please respond via email to
dbusby@houston.geoquest.slb.com


use CGI;
$query = new CGI;

print $query->header;
print $query->start_html(-title=>'Sybase Interface');

print "<H2>Trying to talk to SWIFT</H2>\n";
print "<h1>hello</h1>";


if(open(SMR,"smr.data")){
 $line = <SMR>;
 while ($line ne ""){
  if($line =~ /Schlum/){
   print "<li>$line</li>";
  }
   $count++;
  $line = <SMR>;
 }
}

print "End of Result Set!";
print $query->end_html;

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

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
First forgive my ignorance.
<p>I need to read a local text file and send the results back to the users
browser.
<p>I thought I could use the CGI.PM but I can seem to figure out what I
am doing wrong.
<p>My code, below, will only process the lines in BOLD.&nbsp; For some
reason it prints the data from the command line correctly but does not
send that back to the browser.&nbsp; If anyone could give me a few tips
it would be great.&nbsp; If I can just get a test working then I can work
on the rest of the program.
<p>Thanks in advance to anyone.&nbsp; Please respond via email to dbusby@houston.geoquest.slb.com
<br>&nbsp;
<p>use CGI;
<br>$query = new CGI;
<p>print $query->header;
<br>print $query->start_html(-title=>'Sybase Interface');
<p><b>print "&lt;H2>Trying to talk to SWIFT&lt;/H2>\n";</b>
<br><b>print "&lt;h1>hello&lt;/h1>";</b>
<br>&nbsp;
<p>if(open(SMR,"smr.data")){
<br>&nbsp;$line = &lt;SMR>;
<br>&nbsp;while ($line ne ""){
<br>&nbsp; if($line =~ /Schlum/){
<br>&nbsp;&nbsp; print "&lt;li>$line&lt;/li>";
<br>&nbsp; }
<br>&nbsp;&nbsp; $count++;
<br>&nbsp; $line = &lt;SMR>;
<br>&nbsp;}
<br>}
<p><b>print "End of Result Set!";</b>
<br>print $query->end_html;</html>

--------------57321E21F4FFBF777F238838--



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

Date: Mon, 25 Jun 2001 20:49:01 +0100
From: Mark Grimshaw <m.grimshaw@salford.ac.uk>
Subject: Re: Trouble with CGI.PM
Message-Id: <3B3795AD.E7731D9D@salford.ac.uk>

David Busby wrote:
> 
> First forgive my ignorance.
> 
> I need to read a local text file and send the results back to the
> users browser.
> 
> I thought I could use the CGI.PM but I can seem to figure out what I
> am doing wrong.
> 
> My code, below, will only process the lines in BOLD.  For some reason
> it prints the data from the command line correctly but does not send
> that back to the browser.  If anyone could give me a few tips it would
> be great.  If I can just get a test working then I can work on the
> rest of the program.
> 
> Thanks in advance to anyone.  Please respond via email to
> dbusby@houston.geoquest.slb.com
> 
> 
> use CGI;
> $query = new CGI;
> 
> print $query->header;
> print $query->start_html(-title=>'Sybase Interface');
> 
> print "<H2>Trying to talk to SWIFT</H2>\n";
> print "<h1>hello</h1>";
> 
> 
> if(open(SMR,"smr.data")){
>  $line = <SMR>;
>  while ($line ne ""){
>   if($line =~ /Schlum/){
>    print "<li>$line</li>";
>   }
>    $count++;
>   $line = <SMR>;
>  }
> }
> 
> print "End of Result Set!";
> print $query->end_html;

one reason may be that it can't open smr.data (you're not checking for
errors on opening) so it obviously won't print the next.


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.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 1192
***************************************


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