[18509] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 677 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 11 14:16:19 2001

Date: Wed, 11 Apr 2001 11:15:32 -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: <987012931-v10-i677@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Wed, 11 Apr 2001     Volume: 10 Number: 677

Today's topics:
        path name of script executed ? <Alain.Braun@meteo.fr>
    Re: path name of script executed ? (Craig Berry)
    Re: path name of script executed ? <Alain.Braun@meteo.fr>
    Re: Private subroutine inside subroutine (Tad McClellan)
        Q : Why out of memory? <gregory.deal@unisys.com>
    Re: Q : Why out of memory? (Mark Jason Dominus)
    Re: Q : Why out of memory? <gregory.deal@unisys.com>
    Re: reference , 2-dimensional array <uri@sysarch.com>
    Re: Regex: Finding multiple targets <rick.delaney@home.com>
        running totals with exception <nospam@nospam.com>
        Stripping non standard control characters from a file <ronda@panix.com>
    Re: Stripping non standard control characters from a fi (Logan Shaw)
    Re: Stripping non standard control characters from a fi <iltzu@sci.invalid>
        syntax error help- newbie <ssanders@chicago.avenew.com>
    Re: syntax error help- newbie <peter.s@tjgroup.dk>
    Re: syntax error help- newbie (Tad McClellan)
    Re: syntax error help- newbie <ssanders@avenew.com>
        Testing open ports <mikecook@cigarpool.com>
    Re: Testing open ports nobull@mail.com
    Re: We have 'use strict' and 'my', and now 'our', but n <ariels@compugen.co.il>
    Re: Whats is the best Perl book to tech "How to use Per <dbenson@ifxcorp.com>
    Re: Why does DynaLoader fail? (Steve K. Brown)
    Re: Why does DynaLoader fail? (Logan Shaw)
    Re: Why is finish() necessary here with DBI? Bug in DBD <webmuse@my-deja.com>
    Re: Why is finish() necessary here with DBI? Bug in DBD (Logan Shaw)
    Re: Why is finish() necessary here with DBI? Bug in DBD <bart.lateur@skynet.be>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 11 Apr 2001 18:31:12 +0200
From: Braun <Alain.Braun@meteo.fr>
Subject: path name of script executed ?
Message-Id: <3AD486D0.D15ACDA3@meteo.fr>

Hi,

Is there a direct method to catch the complete path name of the script
currently executed ? $0 is the program name, okay, but I didn't find the
information for the path, neither in the variables names, nor in the FAQ
I read. I am working in an Unix environment.

The aim is to use, at the beginning of the script, a require() for
reading a configuration file, this to be found normally at the same
place that the script file.

Many thanks in advance,
Alain


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

Date: Wed, 11 Apr 2001 17:00:21 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: path name of script executed ?
Message-Id: <td93d5dmrkkmf4@corp.supernews.com>

Braun (Alain.Braun@meteo.fr) wrote:
: Is there a direct method to catch the complete path name of the script
: currently executed ? $0 is the program name, okay, but I didn't find the
: information for the path, neither in the variables names, nor in the FAQ
: I read. I am working in an Unix environment.

perldoc FindBin

: The aim is to use, at the beginning of the script, a require() for
: reading a configuration file, this to be found normally at the same
: place that the script file.

I often find it useful to use FindBin to locate the app directory, then
chdir to that directory to access require'd and open'd files.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "When the going gets weird, the weird turn pro."
   |               - Hunter S. Thompson


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

Date: Wed, 11 Apr 2001 19:06:29 +0200
From: Braun <Alain.Braun@meteo.fr>
To: Braun <Alain.Braun@meteo.fr>
Subject: Re: path name of script executed ?
Message-Id: <3AD48F15.1DB92657@meteo.fr>

Hi,

Waiting for some help coming from the forum, I made more efforts to find
the solution and I found it (!) and it is quite simple since a standard
module is existing !

use FindBin qw($RealBin);
print "$RealBin\n";

Hope this information will be useful to others.

Regards,
Alain


I wrote :
> 
> Hi,
> 
> Is there a direct method to catch the complete path name of the script
> currently executed ? $0 is the program name, okay, but I didn't find the
> information for the path, neither in the variables names, nor in the FAQ
> I read. I am working in an Unix environment.
> 
> The aim is to use, at the beginning of the script, a require() for
> reading a configuration file, this to be found normally at the same
> place that the script file.
> 
> Many thanks in advance,
> Alain


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

Date: Wed, 11 Apr 2001 08:02:25 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Private subroutine inside subroutine
Message-Id: <slrn9d8huh.7r1.tadmc@tadmc26.august.net>

Gwyn Judd <tjla@guvfybir.qlaqaf.bet> wrote:
>I was shocked! How could Brian E. Lavender <brian@brie.com>
>say such a terrible thing:
>>
>>I created a private subroutine inside another subroutine.  Rather than
>>pass the variables to the private subroutine, I made them visible to
>>the private subroutine using local. Is this good coding practice? I am
>>still don't completely understand local, but it appears it is making
>>$arg2 visible to any block inside outer. Here's my sample chunk of code.
>
>I would say not. If you have to ask what local() does, you shouldn't be
>using it. It honestly doesn't do what you think it does. 


For those who are wondering what local() _does_ do, it may  be
helpful (in addition to seeing the applicable FAQ) to know:


   If you think that local() has something to do with the visibility
   (scope) of a variable, then you do not know what it does.

   local() has something to do with the visibility of the *value*
   of a variable. It does not affect the scope of the variable
   itself.


>You probably
>want to use my(). 


Right, because my() _does_ have something to do with the visibility
of variables, which is what most people want when they make the
mistake of using local().


The general rule to use is:

   Always prefer my() over local() (unless you can't).

More accurately:

   Always prefer lexical variables over dynamic variables.


The most common cases where "you can't" use lexical variables:

   Perl's builtin variables

   If the variable's scope is to cross file boundaries


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Wed, 11 Apr 2001 11:00:32 -0400
From: "Gregory K. Deal" <gregory.deal@unisys.com>
Subject: Q : Why out of memory?
Message-Id: <9b1rfa$a8u$1@trsvr.tr.unisys.com>

I'm running perl 5.5 on an HP J5000 with 4GB real memory and 6GB swap. I get
an "out of memory" error. Yet, the memory image of the program right before
dying is ~960MB. At this point, there was 1500MB real memory and 2080MB
virtual memory in use. We've run programs that have a larger memory image
successfully (at least to 2GB or so). Is there something I need to bump up?
Any interesting debug modes when running? Need a newer perl? More info
below. Thanks for any help or guidance.

trj5000c  (ip3pd) 10:27am ~/scripts [266] % /opt/perl5/bin/perl -v

This is perl, version 5.005_03 built for PA-RISC2.0

Copyright 1987-1999, Larry Wall


Program output :
Read 1720000 lines
Read 1730000 lines
Read 1740000 lines
Read 1750000 lines
Read 1760000 lines
Out of memory!

Result of setting PERL_DEBUG_MSTATS to 2 before running :

Read 1750000 lines
Read 1760000 lines
Out of memory!
Memory allocation statistics after execution:   (buckets
4(4)..8392696(8388608)
    8816 free:    42    81     1    13     5   2   2     0   0 0 0 0 0 0 0 0
0 0 0 0 0
              249    41    57    10    11
975742312 used: 877668 1285921 3356891 693457 107611 1710 4790 420028   3 1
1 3 0 0 0 0 0 1 1 0 1
            1281339 6824269 285968 4420196 452264
Total sbrk(): 987946208/313:460. Odd ends: pad+heads+chain+tail:
1248+12193832+0+0.





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

Date: Wed, 11 Apr 2001 16:32:32 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: Q : Why out of memory?
Message-Id: <3ad48720.6d8b$80@news.op.net>


In article <9b1rfa$a8u$1@trsvr.tr.unisys.com>,
Gregory K. Deal <gregory.deal@unisys.com> wrote:
>I'm running perl 5.5 on an HP J5000 with 4GB real memory and 6GB swap. I get
>an "out of memory" error. Yet, the memory image of the program right before
>dying is ~960MB. At this point, there was 1500MB real memory and 2080MB
>virtual memory in use.

Many systems have a per-process memory limit enforced by the system.  
Look into the 'limit' or 'ulimit' command in your shell.
-- 
@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: Wed, 11 Apr 2001 13:03:45 -0400
From: "Gregory K. Deal" <gregory.deal@unisys.com>
Subject: Re: Q : Why out of memory?
Message-Id: <9b22mb$e0u$1@trsvr.tr.unisys.com>

Thanks. I checked out the limit commands and get the info below. Do I need
to worry about the stacksize?

trj5000c  (ip3pd) 12:06pm /etc [277] % limit
cputime         unlimited
filesize        unlimited
datasize        unlimited
stacksize       81612 kbytes     <<<<<<<<<<<<<< bump up???????????
coredumpsize    2097151 kbytes
memoryuse       unlimited
descriptors     1024
trj5000c  (ip3pd) 12:45pm /etc [278] % ulimit
unlimited

Mark Jason Dominus wrote in message <3ad48720.6d8b$80@news.op.net>...
>
>In article <9b1rfa$a8u$1@trsvr.tr.unisys.com>,
>Gregory K. Deal <gregory.deal@unisys.com> wrote:
>>I'm running perl 5.5 on an HP J5000 with 4GB real memory and 6GB swap. I
get
>>an "out of memory" error. Yet, the memory image of the program right
before
>>dying is ~960MB. At this point, there was 1500MB real memory and 2080MB
>>virtual memory in use.
>
>Many systems have a per-process memory limit enforced by the system.
>Look into the 'limit' or 'ulimit' command in your shell.





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

Date: Wed, 11 Apr 2001 17:40:44 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: reference , 2-dimensional array
Message-Id: <x7r8yznxlv.fsf@home.sysarch.com>

>>>>> "BL" == Bart Lateur <bart.lateur@skynet.be> writes:

  BL> 	my $fields;
  BL> 	while($fields = $sth->fetchrow_arrayref){
  BL> 	    push @list, [ @$fields ];
  BL> 	}

  BL> Unfortunately, fetchrow_arrayref returns the same reference every time
  BL> (for speed reasons).

then call:

	$ary_ref  = $sth->fetchall_arrayref;

why build up your own LOL? DBI can do it for you.

so having $sth->fetchrow_arrayref() return the same ref each time is
okay as this is meant to be used in row by row processing. if you want
all the rows at once, use the fetchall call.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Learn Advanced Object Oriented Perl from Damian Conway - Boston, July 10-11
Class and Registration info:     http://www.sysarch.com/perl/OOP_class.html


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

Date: Wed, 11 Apr 2001 17:53:03 GMT
From: Rick Delaney <rick.delaney@home.com>
Subject: Re: Regex: Finding multiple targets
Message-Id: <3AD49D3C.8163653D@home.com>

Ilmari Karonen wrote:
> 
> Well, you could at least replace $` with pos():

or @-.

> 
>   print map "$$_[1]\n", sort {$a->[0] <=> $b->[0]} map {
>       my @rv = $string =~ /($_)/g ? [pos($string) - length($1), $_] : ();

    my @rv = $string =~ /($_)/ ? [$-[1], $1] : ();

I'm guessing Patrick wants to print the text found rather than the
pattern that matched.  Or 

    my @rv = $string =~ /$_/ ? [$-[0], $&] : ();

I don't *think* the warnings against $& apply anymore.

>       pos($string) = 0;  # reset position for next match

You only need this because you're using /g in scalar context.  Why are
you using /g?

>       @rv;
>   } @search_rexeps;


-- 
Rick Delaney
rick.delaney@home.com


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

Date: Wed, 11 Apr 2001 14:49:40 GMT
From: Borgy <nospam@nospam.com>
Subject: running totals with exception
Message-Id: <3AD46EF3.435C649F@nospam.com>

What I am trying to do here is split up the cookie and get the total for
all items selected plus their applicable taxes. The problem I am having
is some
items contain the word book. These items should not have TAX1 applied to
them.
Therefore the total taxes at the bottom should reflect this. ie books
are exempt from TAX1. Any
help would be greatly appreciated. Thanks, Borgy

########
sub ViewCart {

if (&GetCookies('cart')) {

print "Content-type: text/html\n";

$viewcookie = "$Cookies{'cart'}";
$tobeadded = $viewcookie;
@cooky = split(/\|/, $viewcookie);

print "Price  Quantity  Item\n";

 $RemoveNumber=0;
 foreach $cooky (@cooky) {
 
 ($quantity, $price, $item) = split(/:/ , $cooky);
 
 if ($item =~(book)) {			### this part is incorrect
    $price2=$price*1.08;
    $price2=sprintf("%.2f", $price);
   }
 else {
   $price2=$price*.1;
   $price2=sprintf("%.2f", $price);
   }
 
 $RemoveNumber++;
  }
 
print "Total(before taxes): $Total\n";
print "Total Tax1:          $TAX1\n";
print "Total TAX2:          $TAX2\n";
print "GrandTotal:          $GrandTotal\n";


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

Date: 11 Apr 2001 15:31:36 GMT
From: Ronda Hauben <ronda@panix.com>
Subject: Stripping non standard control characters from a file
Message-Id: <9b1tco$d6i$1@news.panix.com>

I am writing a program to strip old wordstar files of the non standard 
control characters. I found the function ord (expr) which converts text 
to the numeric ascii value of the first character of (expr).

I am working on using ord in a loop to convert each character of a file 
and test to see whether the character is in the range of standard ascii 
characters of 32-127

I wondered if there is some other function or a module in
perl that would be a better one to use for my program to strip
wordstar control characters from files.

Thanks for any help on this.

Best wishes

Ronda
ronda@panix.com
http://www.columbia.edu/~rh120/other/birth_internet.txt


             Netizens: On the History and Impact
               of Usenet and the Internet
          http://www.columbia.edu/~hauben/netbook/
            in print edition ISBN 0-8186-7706-6 




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

Date: 11 Apr 2001 10:49:00 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Stripping non standard control characters from a file
Message-Id: <9b1udc$sjs$1@charity.cs.utexas.edu>

In article <9b1tco$d6i$1@news.panix.com>,
Ronda Hauben  <ronda@panix.com> wrote:
>I am writing a program to strip old wordstar files of the non standard 
>control characters. I found the function ord (expr) which converts text 
>to the numeric ascii value of the first character of (expr).
>
>I am working on using ord in a loop to convert each character of a file 
>and test to see whether the character is in the range of standard ascii 
>characters of 32-127
>
>I wondered if there is some other function or a module in
>perl that would be a better one to use for my program to strip
>wordstar control characters from files.

Sure, you can strip all such characters out like this:

	perl -pe 'tr/^\x20-\x7F//dc' foo.wordstar > foo.txt

But surely you don't want to do that, because a newline is a control
character and a very useful one.  So maybe this:

	perl -pe 'tr/^\x20-\x7F\n//dc' foo.wordstar > foo.txt

The "tr" operator is a lot like the Unix "tr" command.  If that
doesn't mean anything to you, think of "tr" as being a lot like
the substitution operator ("s").

For more information, do "perldoc perlop"; the description of "tr" is
in the "Regexp Quote-Like Operators" section.

  - Logan
-- 
my  your   his  her   our   their   _its_
I'm you're he's she's we're they're _it's_


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

Date: 11 Apr 2001 16:00:00 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Stripping non standard control characters from a file
Message-Id: <987004373.25644@itz.pp.sci.fi>

In article <9b1tco$d6i$1@news.panix.com>, Ronda Hauben wrote:
>I am working on using ord in a loop to convert each character of a file 
>and test to see whether the character is in the range of standard ascii 
>characters of 32-127
>
>I wondered if there is some other function or a module in
>perl that would be a better one to use for my program to strip
>wordstar control characters from files.

Use tr///.  Perl also provides some handy command line options that make
such tasks very simple:

  perl -lpe 'tr/ -~//cd' <inputfile >outputfile

The tr/ -~//cd removes any characters not in the range ' ' to '~'.  The
syntax is documented in the perlop manual page, in the section titled
"Quote and Quote-like Operators".  The -p switch makes perl loop over
each line of the input, printing each line after it has been processed.
The -l switch chomps and reinserts the trailing newline, to avoid it
getting removed by the tr///.  Both switches are documented in perlrun.

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla / Kira -- do not feed the troll.


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

Date: Wed, 11 Apr 2001 08:09:24 -0500
From: Stan Sanderson <ssanders@chicago.avenew.com>
Subject: syntax error help- newbie
Message-Id: <ssanders-9C43A2.08092411042001@news.avenew.com>

I'm trying to learn linux (RH 6.2); good book (Alan Simpson & John Ray, 
_Using Red hat Linux_) but it has some typos. 

A perl script is included to automate updating. I've included it below. 
When I run it as shown in the book, I get three syntax errors (messages 
have been shortened):

line 50- near "0;"
line 50- near "++ )"
line 54- near "}"

(entire script is included at the end of this post)

49:   $rpmout=`rpm -q $packagename`
50:   for ($y=0;$y<@filters;$y++) {
51:      if ($packagename=~/$filters[$y]/i) {
52:         $rpmout="filtered";
53:      }
54:   }

Adding a ";" to the end of line 49 (after $packagename`) results in a 
single error reported, line 50- near "++ )".

I'd be grateful for some help- TIA!

Stan
-----

#!/usr/bin/perl
#
# (c) 2000 by John Ray
# This software may be modified, distributed, etc. as long as the 
original
# author's name remains somewhere in the code listing.
#
# $filter contains a comma separated list of package names that need to 
be
# filtered from the installation. Kernel updates are best installed 
manually!

$filter="kernel,kde";

print "\nJohn's little update helper v.1\n";
$|=1;
@filters=split(/\,/,$filter);

if (!(-f ".updateinfo")) {
   print "Enter your update mirror hostname: ";
   $hostname=<STDIN>;
   print "Enter your update mirror path: ";
   $path=<STDIN>;
   open UPDATEINFO, "> .updateinfo";
   print UPDATEINFO $hostname,$path;
   close UPDATEINFO;
} else {
   open UPDATEINFO, ".updateinfo";
   $hostname=<UPDATEINFO>;
   $path=<UPDATEINFO>;
   close UPDATEINFO;
}
chomp($hostname,$path);

# Fix paths missing "/"s on the ends.
if ($path=~/^[^\/]/) { $path="/".$path; }
if ($path=~/[^\/]$/) { $path=$path."/"; }

# Get the file listing using Lynx.
print "Retrieving listing from ftp://$hostname$path...";
$filelist=`lynx -source "ftp://$hostname$path"`;
print "Done!\n";
while ($filelist=~s/([^\/]*?\.rpm)\"//i) {
   $filelist[$x++]=$1;
}

# Cycle through the available files and check to see if they are 
installed
# or filtered.
for ($x=0;$x<@filelist;$x++) {
   $packagename=$filelist[$x];
   $packagename=~s/\.[^\.]*\.rpm//gi;
   $rpmout=`rpm -q $packagename`
   for ($y=0;$y<@filters;$y++) {
      if ($packagename=~/$filters[$y]/i) {
         $rpmout="filtered";
      }
   }
   
   if (!($rpmout=~/not installed/i)) {
      print $packagename," not installed. Install now? (Y/N): ";
      $install=<STDIN>;
      if ($install=~/y/i) {
         $packagepath="ftp://$hostname$path$filelist[$x]";
         $rpmout=`rpm -Uvh $packagepath`;
         print $rpmout;
      }
   }
}

print "Done processing!\n";

-- 
Stan Sanderson 
http://www.chicago.avenew.com/personal/ssanders


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

Date: Wed, 11 Apr 2001 15:32:41 +0200
From: "Peter Søgaard" <peter.s@tjgroup.dk>
Subject: Re: syntax error help- newbie
Message-Id: <9b1md2$jca$1@news.inet.tele.dk>

Corrected a few errors - this seems to run without problems:

#!/usr/bin/perl
#
# (c) 2000 by John Ray
# This software may be modified, distributed, etc. as long as the original
# author's name remains somewhere in the code listing.
#
# $filter contains a comma separated list of package names that need to be
# filtered from the installation. Kernel updates are best installed
manually!

$filter="kernel,kde";

print "\nJohn's little update helper v.1\n";
$|=1;
@filters=split(/\,/,$filter);

if (!(-f ".updateinfo")) {
   print "Enter your update mirror hostname: ";
   $hostname=<STDIN>;
   print "Enter your update mirror path: ";
   $path=<STDIN>;
   open UPDATEINFO, "> .updateinfo";
   print UPDATEINFO $hostname,$path;
   close UPDATEINFO;
} else {
   open UPDATEINFO, ".updateinfo";
   $hostname=<UPDATEINFO>;
   $path=<UPDATEINFO>;
   close UPDATEINFO;
}
chomp($hostname,$path);

# Fix paths missing "/"s on the ends.
if ($path=~/^[^\/]/) { $path="/".$path; }
if ($path=~/[^\/]$/) { $path=$path."/"; }

# Get the file listing using Lynx.
print "Retrieving listing from ftp://$hostname$path...";
$filelist=`lynx -source "ftp://$hostname$path"`;
print "Done!\n";
while ($filelist=~s/([^\/]*?\.rpm)\"//i) {
   $filelist[$x++]=$1;
}

# Cycle through the available files and check to see if they are installed
# or filtered.
for ($x=0;$x<@filelist;$x++) {
   $packagename=$filelist[$x];
   $packagename=~s/\.[^\.]*\.rpm//gi;
   $rpmout=`rpm -q $packagename`;
   for ($y=0;$y<@filters;$y++) {
      if ($packagename=~/$filters[$y]/i) {
         $rpmout="filtered";
      }
   }

   if (!($rpmout=~/not installed/i)) {
      print $packagename," not installed. Install now? (Y/N): ";
      $install=<STDIN>;
      if ($install=~/y/i) {
         $packagepath="ftp://$hostname$path$filelist[$x]";
         $rpmout=`rpm -Uvh $packagepath`;
         print $rpmout;
      }
   }
}

print "Done processing!\n";





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

Date: Wed, 11 Apr 2001 08:57:13 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: syntax error help- newbie
Message-Id: <slrn9d8l59.7ut.tadmc@tadmc26.august.net>

Stan Sanderson <ssanders@chicago.avenew.com> wrote:
>I'm trying to learn linux (RH 6.2); good book (Alan Simpson & John Ray, 
>_Using Red hat Linux_) but it has some typos. 


Typos are the least of its problems.

I would not trust this code for anything other than a 
"learning experience". In fact, I doubt that I would even
let it execute on my system.

It probably works, but there is a large pile of "indicators" that
this wasn't written by a fully competent Perl programmer.

You can check the syntax without executing the program:

   perl -cw my_prog


>A perl script is included to automate updating. I've included it below. 
>When I run it as shown in the book, I get three syntax errors (messages 
>have been shortened):
>
>line 50- near "0;"
>line 50- near "++ )"
>line 54- near "}"
>
>(entire script is included at the end of this post)
>
>49:   $rpmout=`rpm -q $packagename`
>50:   for ($y=0;$y<@filters;$y++) {


That is "C code" written in Perl. The Perlish way would be:

   foreach my $y ( 0 .. $#filters ) {

or, even better, avoid explicit indexing altogether:

   foreach my $regex ( @filters ) {
      if ($packagename =~ /$regex/i) {
         ...


Space characters are not a scarse resource. Feel free to use them
to make your code easier to read and understand.


>51:      if ($packagename=~/$filters[$y]/i) {
>52:         $rpmout="filtered";
>53:      }
>54:   }
>
>Adding a ";" to the end of line 49 (after $packagename`) results in a 
>single error reported, line 50- near "++ )".


I cannot duplicate your problem. I get "syntax OK" after adding
the semicolon.

Show us the code with the added semicolon, and the error message text.


>I'd be grateful for some help- TIA!


Sorry. Cannot duplicate.


>#!/usr/bin/perl


No warnings.

No strictures.

No thanks.

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


>if (!(-f ".updateinfo")) {

   unless ( -f '.updateinfo') {


>   open UPDATEINFO, "> .updateinfo";

You should always, yes *always*, check the return value from open():

   open UPDATEINFO, '> .updateinfo' or die "could not open '.updateinfo' $!";


># Fix paths missing "/"s on the ends.
>if ($path=~/^[^\/]/) { $path="/".$path; }

   $path =~ s/^([^\/])/\/$1/;

or, even better:

   $path =~ s#^([^/])#/$1#;   # look Ma! No backslashes!


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Wed, 11 Apr 2001 09:32:37 -0500
From: ssanders <ssanders@avenew.com>
Subject: Re: syntax error help- newbie
Message-Id: <ssanders-C67CAC.09321911042001@news.avenew.com>

Thanks for the responses- now to the hard part...digesting them!


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

Date: Wed, 11 Apr 2001 08:01:03 -0700
From: "Michael Cook" <mikecook@cigarpool.com>
Subject: Testing open ports
Message-Id: <yl_A6.708$8R6.189154@news.uswest.net>

Hello,
    I am trying to write a Perl script to test whether certain ports on
other servers are listening. I have searched CPAN, but can find nothing -
can someone point me in the right direction?
        Thanks!
            Michael
--
== CigarPool ==
http://www.cigarpool.com




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

Date: 11 Apr 2001 17:58:52 +0100
From: nobull@mail.com
Subject: Re: Testing open ports
Message-Id: <u9bsq38jar.fsf@wcl-l.bham.ac.uk>

"Michael Cook" <mikecook@cigarpool.com> writes:

>     I am trying to write a Perl script to test whether certain ports on
> other servers are listening. I have searched CPAN, but can find nothing -
> can someone point me in the right direction?

use IO::Socket;
print "$host is listening on $port\n" 
  if IO::Socket::INET->new( -PeerAddr => $host, -PeerPort => $port );

Or are you trying to abort the TCP setup handshake part way?

If so then you are looking in the wrong place.  The details of
bypassing the OS IP stack are likely to be far more OS dependant than
language dependant.  Once you've figured out how to persuade your OS to
let you do this sort of thing then come back here if you need help
coding it in Perl.

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: 11 Apr 2001 15:59:16 +0200
From: Ariel Scolnicov <ariels@compugen.co.il>
Subject: Re: We have 'use strict' and 'my', and now 'our', but no 'use  local-scope' - why?
Message-Id: <yzqn19nv8p7.fsf@orion.compugen.co.il>

Ian Phillipps <dont.reply@myself.com> writes:

> Mark Jason Dominus wrote:
> 
> > In article <3AD2864E.68F8FBCF@nowhere.com>,
> > Phil Voris  <pvoris@nekophile.com> wrote:
> > >I've long been baffled that there is no pragma to automatically declare
> > >all variables as default locally-scoped.
> > 
> > Because nobody knows what that would mean.
> > 
> > >This way, rather than typing 'my' everywhere, one could just type the
> > >ocassional 'our' and assume everything else is local (er, my'd).
> 
> > But local to what?  The file? The innermost block in which it appears?
> > Neither of those are sensible.
> 
> If the pragma is the equivalent of inserting an implicit "my" at the
> first appearance of each variable name which is not 'local' or given an
> explicit package), then I'd vote it as fairly sensible.

This was done to death on perl6-language, I think.  The problem is
that code like

  sub sum {
    for $x (@_) {
      $sum += $x
    }
    $sum
  }

would return 0 (they're 2 different C<$sum>s!).


And of course adopting *any* implicit `my' proposal means you can't
catch variable name mistakes, because when you mention $Fo0 in some
inner scope it assumes you really didn't want $FOO.  So why bother?

[...]

-- 
Ariel Scolnicov        |"GCAAGAATTGAACTGTAG"            | ariels@compugen.co.il
Compugen Ltd.          |Tel: +972-2-5713025 (Jerusalem)	\ We recycle all our Hz
72 Pinhas Rosen St.    |Tel: +972-3-7658117 (Main office)`---------------------
Tel-Aviv 69512, ISRAEL |Fax: +972-3-7658555    http://3w.compugen.co.il/~ariels


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

Date: Wed, 11 Apr 2001 14:44:23 GMT
From: Dean Benson <dbenson@ifxcorp.com>
Subject: Re: Whats is the best Perl book to tech "How to use Perl With SQL servers"?
Message-Id: <b5_A6.155$Jd.48201@news2.mia>

I've found that the MySQL / MSQL book from O'reilly press covers the perl 
correllation very well and gives great examples.  Check it out -- it's the 
pink cover with the 2 birds ...



"Perl Programmer" <the_programmer@arabicteam.com> wrote:
> [-- text/plain, encoding quoted-printable, 10 lines --]

> Hi guys
> I am an new perl programmer
> I bought book : Tech yourself Perl in 24 hours (SAMS) .
> And it was very good . 
> now I need book to tech me how to use Perl with MySql and MsSql and PgSql .
> Regards

> < Perl Programmer >



--
Dean Benson
bensode@ifxcorp.com



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

Date: 11 Apr 2001 17:40:53 GMT
From: skbrown@vcd.hp.com (Steve K. Brown)
Subject: Re: Why does DynaLoader fail?
Message-Id: <9b24v5$hgp$1@news.vcd.hp.com>

Bjoern Hoehrmann (bjoern@hoehrmann.de) wrote:
:" "* Steve K. Brown wrote in comp.lang.perl.misc:
:" ">I received the following error:
:" ">
:" ">Can't load '/usr/local/bin/perl5/lib/5.00503/PA-RISC1.1/auto/IO/IO.sl'
:" ">for module IO: Permission denied at 

:" ">So the question is why?

:" "What isn't clear about that?
:" "-- 
Why is permission denied?  I am root and I can't load a module?  
Unless this command is trying to write to a file I should be able
to perform this action.  Why not?

Steven K Brown


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

Date: 11 Apr 2001 12:18:45 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Why does DynaLoader fail?
Message-Id: <9b23ll$t4j$1@charity.cs.utexas.edu>

In article <9b24v5$hgp$1@news.vcd.hp.com>,
Steve K. Brown <skbrown@vcd.hp.com> wrote:
>Bjoern Hoehrmann (bjoern@hoehrmann.de) wrote:
>:" "* Steve K. Brown wrote in comp.lang.perl.misc:
>:" ">I received the following error:
>:" ">
>:" ">Can't load '/usr/local/bin/perl5/lib/5.00503/PA-RISC1.1/auto/IO/IO.sl'
>:" ">for module IO: Permission denied at 
>
>:" ">So the question is why?
>
>:" "What isn't clear about that?
>:" "-- 
>Why is permission denied?  I am root and I can't load a module?  
>Unless this command is trying to write to a file I should be able
>to perform this action.  Why not?

Forgetting for a moment that this is a Unix question and not a Perl
question, a few possible reasons come to mind:

  * The file's mode doesn't include read permissions, i.e.
    someone did something like "chmod a-r foo".

  * The file is located on an NFS-mounted filesystem, and you're
    root, and root is getting translated to the user "nobody"
    as is the default with NFS, and "nobody" doesn't have the
    required access.

  * You're loading a module that has some native code, and its execute
    permissions aren't set, i.e. someone did something like
    "chmod a-x foo".

Here is where I insert my standard statement about making sure you
really need to be running this as root, and how it's best not to run
things as root that don't need to be run as root.

  - Logan
-- 
my  your   his  her   our   their   _its_
I'm you're he's she's we're they're _it's_


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

Date: Wed, 11 Apr 2001 12:14:53 -0400
From: "Thomas" <webmuse@my-deja.com>
Subject: Re: Why is finish() necessary here with DBI? Bug in DBD::ODBC?
Message-Id: <1q%A6.174$R27.21536@news4.mco>

Hi Richard,

Thank you for the link with the detailed description of finish(),
but I guess my real question is why am I needing to use finish()
even in circumstances where only one row is returned, and I've
fetched the row. Shouldn't DBD::ODBC be calling finish() for me
at that point? Has anyone else experienced this problem?

Regards,
Thomas


> http://const.icm.re.kr/Oracle-perl/DBI-Ref/finish.txt






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

Date: 11 Apr 2001 11:33:35 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Why is finish() necessary here with DBI? Bug in DBD::ODBC?
Message-Id: <9b210v$su2$1@charity.cs.utexas.edu>

In article <1q%A6.174$R27.21536@news4.mco>, Thomas <webmuse@my-deja.com> wrote:
>Thank you for the link with the detailed description of finish(),
>but I guess my real question is why am I needing to use finish()
>even in circumstances where only one row is returned, and I've
>fetched the row. Shouldn't DBD::ODBC be calling finish() for me
>at that point? Has anyone else experienced this problem?

How do you know that it knows that there aren't any more rows to
fetch?  When I type this

	select * from foo where bar = "blahblahblah"

I could get back any number of rows.  Sure, if I type

	select 2+2

then the driver might be able to infer that I'll only get one row back,
but that's not its job.

Or maybe you're saying that part of the ODBC rules are that after you
read a row, the driver must check with the server and find out whether
that was the last row.  That's possible, I suppose, but it would be
unnecessarily complicated.  Is that what you're saying?

  - Logan
-- 
my  your   his  her   our   their   _its_
I'm you're he's she's we're they're _it's_


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

Date: Wed, 11 Apr 2001 17:00:45 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Why is finish() necessary here with DBI? Bug in DBD::ODBC?
Message-Id: <oe39dts3jd3aidlbjqrfghnradqvn35vam@4ax.com>

Thomas wrote:

>I guess my real question is why am I needing to use finish()
>even in circumstances where only one row is returned, and I've
>fetched the row. Shouldn't DBD::ODBC be calling finish() for me
>at that point?

I wrote about that in my other post: unless the db itself sees that
there are no more rows to fetch, it will not call finish().

-- 
	Bart.


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

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


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