[19995] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2190 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 23 09:15:49 2001

Date: Fri, 23 Nov 2001 06:15:18 -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: <1006524918-v10-i2190@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 23 Nov 2001     Volume: 10 Number: 2190

Today's topics:
        stat($file) help <raggmopp@NOSPAMix.netcom.com>
    Re: stat($file) help <wyzelli@yahoo.com>
    Re: stat($file) help <uri@stemsystems.com>
    Re: stat($file) help <krahnj@acm.org>
    Re: stat($file) help (Sara)
    Re: Using CGI.pm to obtain a list of params (Wiliam Stephens)
    Re: Using CGI.pm to obtain a list of params (Helgi Briem)
    Re: Using CGI.pm to obtain a list of params <flavell@mail.cern.ch>
    Re: Using CGI.pm to obtain a list of params news@roaima.freeserve.co.uk
    Re: variable scope <joe+usenet@sunstarsys.com>
    Re: variable scope <bart.lateur@pandora.be>
    Re: win32::ole - change excel worksheet name <jimbo@soundimages.co.uk>
    Re: XML::Parser, DBI and unicode <nat@DONTSPAMPLEASEc2i.net>
    Re: XML::Parser, DBI and unicode <bart.lateur@pandora.be>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 23 Nov 2001 00:52:21 -0700
From: "Rick" <raggmopp@NOSPAMix.netcom.com>
Subject: stat($file) help
Message-Id: <9tkvg6$926$1@slb3.atl.mindspring.net>

Hi all:

Doing some work with lpstat and trying my hand at perl. Got perl 5.6.0 on
hpux 11.00.

Trying to work the script listed below:
===============================================================
#!/bin/perl -w

use constant VARLPDIR => "/var/spool/lp/request";
$dirname = VARLPDIR;

opendir(VARLP, "$dirname") || die "Can't open the directory\n";
@filelist = grep (!/^\./, grep (!/^PDR/, grep (!/\./, readdir(VARLP))));
closedir(VARLP);
foreach $file (@filelist) {
  opendir(PRTLST, "$dirname/$file") || die "Can't open\n";
  @prts = grep (!/^\./, grep (!/^d/, readdir(PRTLST)));
  closedir(PRTLST);
  foreach $prt (@prts) {
    ($Dev,$Ino,$Mode,$Nlink,$Uid,$Gid,$Rdev,$Size,$Atime,$Mtime,$Ctime) =
stat($prt);
      print "$file,$prt,$Mtime\n";
  }
  print ("\n");
}
=================================================================
I am getting the following errors:
  Name "main :Size" used only once: possible typo at ./test line 14
  (Same error for Ino, Gid, Mode, etc...)

I can go directly to the directory and without the variable and array
assignments, it works.

I can print the $file and the $prt as listed above, but not (stat($prt))
which is what I am looking for.

Any ideas?




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

Date: Fri, 23 Nov 2001 18:06:33 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: stat($file) help
Message-Id: <lTnL7.1$SP2.254@vicpull1.telstra.net>

"Rick" <raggmopp@NOSPAMix.netcom.com> wrote in message
news:9tkvg6$926$1@slb3.atl.mindspring.net...
> Hi all:
>
> Doing some work with lpstat and trying my hand at perl. Got perl 5.6.0 on
> hpux 11.00.
>
> Trying to work the script listed below:
> ===============================================================
> #!/bin/perl -w
>
> use constant VARLPDIR => "/var/spool/lp/request";
> $dirname = VARLPDIR;
>
> opendir(VARLP, "$dirname") || die "Can't open the directory\n";
> @filelist = grep (!/^\./, grep (!/^PDR/, grep (!/\./, readdir(VARLP))));
> closedir(VARLP);
> foreach $file (@filelist) {
>   opendir(PRTLST, "$dirname/$file") || die "Can't open\n";
>   @prts = grep (!/^\./, grep (!/^d/, readdir(PRTLST)));
>   closedir(PRTLST);
>   foreach $prt (@prts) {
>     ($Dev,$Ino,$Mode,$Nlink,$Uid,$Gid,$Rdev,$Size,$Atime,$Mtime,$Ctime) =
> stat($prt);
>       print "$file,$prt,$Mtime\n";
>   }
>   print ("\n");
> }
> =================================================================
> I am getting the following errors:
>   Name "main :Size" used only once: possible typo at ./test line 14
>   (Same error for Ino, Gid, Mode, etc...)

Well, you assign things to them all, and then never use them.  That is what
the warning is telling you.  If you aren't going to use them, why assign to
them?

$Mtime = (stat($prt))[9];

Wyzelli
--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass it
around');
$d='$_$a$s$b$w';$e='$_$a$s$b';sub d{$h=shift;$h=~s/\$(\w+)/${$1}/g;return$h}
sub
e{return(shift!=1)?'s':''}for(reverse(1..100)){$s=e($_);$f=d($d);$g=d($e);
$c.="$f\n$g\n$t\n";$_--;$s=e($_);$e=d($d);$c.="$e\n\n";}print"$c*hic*";




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

Date: Fri, 23 Nov 2001 08:45:00 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: stat($file) help
Message-Id: <x78zcxc1th.fsf@home.sysarch.com>

>>>>> "R" == Rick  <raggmopp@NOSPAMix.netcom.com> writes:

someone else answered your warning bug.

  R> opendir(VARLP, "$dirname") || die "Can't open the directory\n";
  R> @filelist = grep (!/^\./, grep (!/^PDR/, grep (!/\./, readdir(VARLP))));

one, why is !/^\./ grepped twice?

two, do you know that you can use any expression in grep including 2
regexes?

	@filelist = grep (!/^\./ && !/^PDR/, readdir(VARLP) ) ;

  R> foreach $file (@filelist) {
  R>   opendir(PRTLST, "$dirname/$file") || die "Can't open\n";
  R>   @prts = grep (!/^\./, grep (!/^d/, readdir(PRTLST)));

same here.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Fri, 23 Nov 2001 12:46:42 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: stat($file) help
Message-Id: <3BFE45EE.18318869@acm.org>

Rick wrote:
> 
> Doing some work with lpstat and trying my hand at perl. Got perl 5.6.0 on
> hpux 11.00.
> 
> Trying to work the script listed below:
> ===============================================================
> #!/bin/perl -w

use strict;


> use constant VARLPDIR => "/var/spool/lp/request";
> $dirname = VARLPDIR;

my $dirname = '/var/spool/lp/request';


> opendir(VARLP, "$dirname") || die "Can't open the directory\n";
                 ^        ^
perldoc -q quoting
Also, you should include the file name and the $! variable in the error
message.

opendir VARLP, $dirname or die "Can't open $dirname: $!";


> @filelist = grep (!/^\./, grep (!/^PDR/, grep (!/\./, readdir(VARLP))));

my @filelist = grep !/\./ and !/^PDR/, readdir VARLP;


> closedir(VARLP);
> foreach $file (@filelist) {

foreach my $file ( @filelist ) {


>   opendir(PRTLST, "$dirname/$file") || die "Can't open\n";

  opendir PRTLST, "$dirname/$file" or die "Can't open $dirname/$file:
$!";

>   @prts = grep (!/^\./, grep (!/^d/, readdir(PRTLST)));

   my @prts = grep !/^[.d]/, readdir PRTLST;

>   closedir(PRTLST);
>   foreach $prt (@prts) {

  foreach my $prt ( @prts ) {

>     ($Dev,$Ino,$Mode,$Nlink,$Uid,$Gid,$Rdev,$Size,$Atime,$Mtime,$Ctime) =
> stat($prt);

    my $mtime = (stat "$dirname/$file/$prt")[9];

>       print "$file,$prt,$Mtime\n";
>   }
>   print ("\n");
> }
> =================================================================
> I am getting the following errors:
>   Name "main :Size" used only once: possible typo at ./test line 14
>   (Same error for Ino, Gid, Mode, etc...)
> 
> I can go directly to the directory and without the variable and array
> assignments, it works.
> 
> I can print the $file and the $prt as listed above, but not (stat($prt))
> which is what I am looking for.

Since you are not _in_ the directory where the file resides you can't
stat it without supplying the full path.


John
-- 
use Perl;
program
fulfillment


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

Date: 23 Nov 2001 05:55:20 -0800
From: genericax@hotmail.com (Sara)
Subject: Re: stat($file) help
Message-Id: <776e0325.0111230555.54b32982@posting.google.com>

"Rick" <raggmopp@NOSPAMix.netcom.com> wrote in message news:<9tkvg6$926$1@slb3.atl.mindspring.net>...
> Hi all:
> 
> Doing some work with lpstat and trying my hand at perl. Got perl 5.6.0 on
> hpux 11.00.
> 
> Trying to work the script listed below:
> ===============================================================
> #!/bin/perl -w
> 
> use constant VARLPDIR => "/var/spool/lp/request";
> $dirname = VARLPDIR;
> 
> opendir(VARLP, "$dirname") || die "Can't open the directory\n";
> @filelist = grep (!/^\./, grep (!/^PDR/, grep (!/\./, readdir(VARLP))));
> closedir(VARLP);
> foreach $file (@filelist) {
>   opendir(PRTLST, "$dirname/$file") || die "Can't open\n";
>   @prts = grep (!/^\./, grep (!/^d/, readdir(PRTLST)));
>   closedir(PRTLST);
>   foreach $prt (@prts) {
>     ($Dev,$Ino,$Mode,$Nlink,$Uid,$Gid,$Rdev,$Size,$Atime,$Mtime,$Ctime) =
> stat($prt);
>       print "$file,$prt,$Mtime\n";
>   }
>  print ("\n");
> }
> =================================================================
> I am getting the following errors:
>   Name "main :Size" used only once: possible typo at ./test line 14
>   (Same error for Ino, Gid, Mode, etc...)
> 
> I can go directly to the directory and without the variable and array
> assignments, it works.
> 
> I can print the $file and the $prt as listed above, but not (stat($prt))
> which is what I am looking for.
> 
> Any ideas?


First of all, add 

 use strict;

at the top of your programs it will make your perl life a lot easier..
Also add

 my ($Dev,$Ino,$Mode,$Nlink,$Uid,$Gid,$Rdev,$Size,$Atime,$Mtime,$Ctime);

or add the my in front of where you use these and you need a bunch of
other "my"s in there too..


The reson your script isn't working however is that you call stat on
the filename, without giving stat the path to the file! How is stat
supposed to know where the file is? You could use chdir() to find it,
or you can qualify the path.

Try this (use your own dirname)....



#!/usr/bin/perl -w

use strict;
use constant VARLPDIR => "/var/spool/lp/request";

my $dirname='TEST';
opendir(VARLP, $dirname) || die "Can't open the directory $!\n";

my @filelist = grep (!/^\./, grep (!/^PDR/, grep (!/\./,
readdir(VARLP))));
closedir(VARLP);

foreach my $file (@filelist) {
  opendir(PRTLST, "$dirname/$file") || die "Can't open $dirname/$file,
$!\n";

  my @prts = grep (!/^\./, grep (!/^d/, readdir(PRTLST)));

  closedir(PRTLST);
  foreach my $prt (@prts) {
    my $f=$dirname.'/'.$file.'/'.$prt;
    my @l=stat $f;

    print $! unless $l[9];
    print "$file,$prt,$l[9]\n" if $l[9];

} print ("\n");

}



now we get

  csh> ./x.pl

  X,y,1006522995
  X,x,1006522993

  Y,b,1006523011
  Y,a,1006523005


which is I think sort of what you were seeking? Also note the use of
$! variable. Its very helpful for understanding errors like this.



Good luck!

GX


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

Date: 23 Nov 2001 01:48:26 -0800
From: wil@fbagroup.co.uk (Wiliam Stephens)
Subject: Re: Using CGI.pm to obtain a list of params
Message-Id: <39e3e00a.0111230148.3b375d2a@posting.google.com>

jtbell@presby.edu (Jon Bell) wrote in message news:<Gn7Jxz.6v9@presby.edu>...

> Of course, if you know the parameter names in advance (as you should, 
> either because you created the form yourself, or you read the docs for 
> it), you can assign them straight away to specific variables without 
> bothering with a hash.  For example, if two of the parameters are named 
> 'firstname' and 'lastname':
> 
> my $FirstName = $cgi->param('firstname');
> my $LastName  = $cgi->param('lastname');
> 
> etc.  So far, I've used the read-into-hash thing only as a debugging
> measure.

I could do that, yes. But when I've got a few hundred different params
coming into my script from a form, I don't really want to sit there
and define them all. < shudder >.

Putting them all into a hash and looping through that hash is much
more efficent. It also saves me from coding a few hundred lines, and
if I make any changes to my FORM I don't have to make changest o my
script.

Wiliam Stephens
http://www.fbagroup.co.uk


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

Date: Fri, 23 Nov 2001 10:55:35 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Using CGI.pm to obtain a list of params
Message-Id: <3bfe2ac0.3116077442@News.CIS.DFN.DE>

On Thu, 22 Nov 2001 14:08:19 -0600, "William Alexander
Segraves" <wsegrave@mindspring.com> wrote:

> On Nov 22, William Alexander Segraves inscribed on the eternal scroll:

>No problem, really. If CGI.pm is available on the host web server, it is
>sometimes preferable to use it. If CGI.pm is not available, then ...

It is always available.

It is always preferable except occasionally when
CGI::Lite will do the job.

Regards,
Helgi Briem



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

Date: Fri, 23 Nov 2001 12:38:03 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Using CGI.pm to obtain a list of params
Message-Id: <Pine.LNX.4.30.0111231229330.13774-100000@lxplus023.cern.ch>

On Nov 22, William Alexander Segraves inscribed on the eternal scroll:

> > Hangonabit, they already come back from CGI.pm in a hash.  So what's
> > the problem?  ;-)
>
> No problem, really. If CGI.pm is available on the host web server,

CGI.pm has been a core module for quite some time.  If it's not
available, then either the Perl installation is hopelessly obsolete
(and so, probably insecure), or they've deliberately removed part of
the Perl core installation.  Either way, I don't think I'd want to
work with such a server.

> If CGI.pm is not available, then ...

Well, I've never been in quite that position, but I did install a
useful module on a service-provider's system whose CGI.pm version
level didn't meet the module's minimum requirements.  So I installed
my own copy of a recent CGI.pm, and pointed at it with an appropriate
'use' statement, just like it says in the Perl FAQs.

all the best




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

Date: 23 Nov 2001 12:23:14 GMT
From: news@roaima.freeserve.co.uk
Subject: Re: Using CGI.pm to obtain a list of params
Message-Id: <3bfe3fb2@news.netserv.net>

Wiliam Stephens <wil@fbagroup.co.uk> wrote:
> Putting them all into a hash and looping through that hash is much
> more efficent.

But they're *already* in a hash, thanks to CGI.pm itself. Why copy them
elsewhere as well? Bernard El-Hagin's ealier post pointed you to the
correct section of the manual. Let me quote some more:

    FETCHING THE PARAMETER LIST AS A HASH:

    Many people want to fetch the entire parameter list as a hash in
    which the keys are the names of the CGI parameters, and the values
    are the parameters' values. The Vars() method does this. Called
    in a scalar context, it returns the parameter list as a tied hash
    reference. [...] Called in a list context, it returns the parameter
    list as an ordinary hash.

Read the documentation to find out how to use this, as it even provides
an example.

Sigh.

Chris


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

Date: 23 Nov 2001 00:25:41 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: variable scope
Message-Id: <m3r8qq6otm.fsf@mumonkan.sunstarsys.com>

"Matt Garrish" <matthew.garrish@sympatico.ca> writes:

> I am not against allowing different variables with the same name in
> different scopes, but against the ability to mask an index variable
> within the only scope it knows, and not have a warning produced.

Matt,

  I'd like to apologize for the boorish and inappropriate tone in
my earlier post.  Your honest answer here convinced me that I 
misunderstood your intentions, and I'm sincerely very sorry about
how I responded to your post.

I do hope that someone else here will actually give you good advice,
and not more irrelevant oratory and posturing, about how to deal with 
this issue from a programmer's perspective.  Personally I think you'd 
be better served by a source-code scanner that checks for multiple 
declarations of a variable within a common context, but I think it's
a bad idea to add another special-case compiler warning to perl.

I could be wrong though; it's certainly not the first time.

Returning to the penalty box,
-- 
Joe Schaefer               "The inevitable catastrophe is at hand."
                                               -- Edgar Allen Poe



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

Date: Fri, 23 Nov 2001 11:07:51 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: variable scope
Message-Id: <b2bsvtglcanqs6rfr7a3uj6jpe93ei4fk8@4ax.com>

Joe Schaefer wrote:

>Personally I think you'd 
>be better served by a source-code scanner that checks for multiple 
>declarations of a variable within a common context, but I think it's
>a bad idea to add another special-case compiler warning to perl.

Perhaps that could be an addition to B::Xref, if it's not already in
there. (n.b. invoke with "-MO=Xref" on the command line)

Trying this on this script:

	my $x = 1;
	{
	    my $x = 2;
	    print "Inner \$x is $x\n";
	}
	print "Now \$x is $x\n";

Gives, among all the "junk":

File test.pl
  ...
  Subroutine (main)
    Package (lexical)
      $x                i2, i4, 5, 7

Two declarations, notice the line numbers marked with "i", but there's
no mention of the scope size. Which $x is used on lines 5 and 7? It
doesn't say.

-- 
	Bart.


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

Date: Fri, 23 Nov 2001 09:50:26 -0000
From: "jimbo" <jimbo@soundimages.co.uk>
Subject: Re: win32::ole - change excel worksheet name
Message-Id: <CZoL7.11312$JZ3.118848@NewsReader>

"Bobby Ray" <bobby@nationalgoat.com> wrote

>   $Book->Worksheets($count - $current)->Name = $Sheets[$current];

This may work:

  $Book->Worksheets($count - $current)->{Name} = $Sheets[$current];

> Can't modify non-lvalue subroutine call at excel.pl line 33.

It may be that the without the braces the offending line is being
interpreted as a call to a subroutine rather than a reference to the
name property of the worksheet.

jimbo
;-)




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

Date: Fri, 23 Nov 2001 07:19:40 GMT
From: Natanael Copa <nat@DONTSPAMPLEASEc2i.net>
Subject: Re: XML::Parser, DBI and unicode
Message-Id: <gMmL7.2872$N77.25494@news.world-online.no>

Bart Lateur wrote:

> Natanael Copa wrote:
> 
>>my $u = Unicode::String::utf8($line_from_xml);
>>
>>when I 'print $u->latin1;' it displays correctly but when I insert in
>>mysql it doesn't. the chars (for example &#233;) are show as two byte's.
>>Thats is not what I want.
>>
>>my $sql = "INSERT INTO tbl_name (col) VALUES
>>(".$dbh->qoute($line_from_xml).")";
>>
>>my $u = Unicode::String::utf8($sql);
>>$dbh->do($u->latin1);
> 
> You've got this reversed. ONLY the line from XML should be treated as
> UTF-8.
> 
> my $u = Unicode::String::utf8($line_from_xml);
> my $sql ="INSERT INTO tbl_name (col) VALUES ("
>   . $dbh->quote($u->latin1) .")";
> $dbh->do($sql);
> 
>>I wonder why 'print $u->latin1' works and not '$dbh->do($u->latin1)'???
> 
> Beats me. Probably treating the SQL as Unicode somehow corrupts the SQL
> statement.

None of them worked (thats why I posted here). The SQL statement works 
perfectly, the problem is that the value inserted is in unicode (chars over 
127 is inserted as two bytes) and not latin1 (with support for chars 
128-255). But if I print the line, it shows correctly. I think it would 
work if I first made a \t separated textfile and inserted that afterwards. 
But why does it not work directly with $dbh->do() while print $u->latin1 
does? Thats the problem.




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

Date: Fri, 23 Nov 2001 11:10:26 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: XML::Parser, DBI and unicode
Message-Id: <aibsvtcv8be7dl0e9q0nguhukbb9fepj93@4ax.com>

Natanael Copa wrote:

>None of them worked (thats why I posted here). The SQL statement works 
>perfectly, the problem is that the value inserted is in unicode (chars over 
>127 is inserted as two bytes) and not latin1 (with support for chars 
>128-255). But if I print the line, it shows correctly.

Well, it looks to me as if the conversion to Latin 1 works, but that
inserting it in the database turns it back to UTF-8. Try skipping the
first step, and entering some accented French words directly in the SQL,
and see what you get then. If I'm right, here, then it must be a dB
configuration issue.

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


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