[16732] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4144 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 27 14:05:27 2000

Date: Sun, 27 Aug 2000 11:05:11 -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: <967399510-v9-i4144@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sun, 27 Aug 2000     Volume: 9 Number: 4144

Today's topics:
    Re: clearing a file (Craig Berry)
    Re: Counting across multiple lines? <someone@somewhere.com>
    Re: Counting across multiple lines? <elephant@squirrelgroup.com>
    Re: Counting across multiple lines? (Mike Stok)
    Re: Counting across multiple lines? <elephant@squirrelgroup.com>
    Re: Counting across multiple lines? (Mike Stok)
    Re: Development Tools <elephant@squirrelgroup.com>
    Re: Development Tools <tina@streetmail.com>
        Extracting data from STDIN (Eric Eekhof)
    Re: Extracting data from STDIN <tina@streetmail.com>
    Re: Extracting data from STDIN (Eric Eekhof)
    Re: Extracting data from STDIN <uri@sysarch.com>
    Re: Form Question <elephant@squirrelgroup.com>
    Re: Global symbol "$dbh" requires explicit package name <elephant@squirrelgroup.com>
    Re: Global symbol "$dbh" requires explicit package name <tina@streetmail.com>
    Re: Good companion book to Programming Perl? (Bill Feidt)
    Re: Good companion book to Programming Perl? <uri@sysarch.com>
        guestbook & file-upload under NT <darklord@libero.it>
    Re: How can I find an images size?? <speed.demon9999@virgin.net>
    Re: How to obtain information about shares Win NT <carvdawg@patriot.net>
    Re: Kill Me! <timewarp@shentel.net>
        move to NT from 98 killing my cgi.pm script (Eric White)
    Re: my($a)=shift or warn; <elephant@squirrelgroup.com>
    Re: Newsreaders (was Re: [OT] Re: stupid question proba (Steve Lamb)
        No Server Logs <brock_johnson@my-deja.com>
    Re: Parsing a Excell table - or - a "Tab New_Line" text <bwalton@rochester.rr.com>
        Print location in <IMG> on NT <tanya@hongkong.com>
    Re: selling perl to management (Alan Barclay)
    Re: selling perl to management <tina@streetmail.com>
        sorting a hash by key value (I've looked at the TIE fun (Eric White)
    Re: stupid question probably (BUCK NAKED1)
    Re: what does "to spider" mean? (Craig Berry)
    Re: What is a Linux file type of 'application/x-cgi' ? gevens@my-deja.com
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sun, 27 Aug 2000 17:05:40 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: clearing a file
Message-Id: <sqiij4tct91183@corp.supernews.com>

Michael Cook (mikecook@cigarpool.com) wrote:
:   open (TEMP, ">db/members.tmp") || die("Unable to open db/members.tmp");
:   flock(TEMP, $LOCK_EX);
:   print TEMP $null;
:   flock(TEMP, $LOCK_UN);
:   close (TEMP);
: 
: to clear a file - is there a better way (I would like results similar to
: using cat /dev/null > file) at the command line?

First, you should almost never explicitly unlock a file.  close() does
that automatically, and handles synchronization issues like flushing
better.

As for zero-lengthing the file, just opening it for write and then closing
it should do the trick.  No need to actually write something (well,
nothing)  to the file. 

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Every force evolves a form."
   |              - Shriekback


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

Date: Sun, 27 Aug 2000 08:14:49 -0500
From: "Sudhan" <someone@somewhere.com>
Subject: Re: Counting across multiple lines?
Message-Id: <8ob4i2$f8k$1@slb6.atl.mindspring.net>

If the file is small...

open(DNA,"dna");
@_ = <DNA>; # read everything
$_ = join("",@_);
$count = tr/A-Z//; # Don't change anything, just count the chars
print "The number of charcters are ...:".$count,"\n";



"Pedro A Navarro" <pnavarro@uswest.net> wrote in message
news:39A8981B.47000002@uswest.net...
> Hi:
> I'm new to Perl and programming in general, so I'm stumped by a simple
> problem. I'm trying to write a program that counts the number of
> characters in a file, such as
>
> >header
> TADSTWTASRTDRAFTARSGRQWTS
> AGSTDRASGATFSASDGTASTTAGS
> TQTRAEWSTATSGATSGTASTATST
>
> That is for a protein sequence file, in case you are wondering. When I
> use
>
> $count=tr/A-Z//;
> print "$count\n";
>
> I get the number of characters for each line, instead of for the whole
> thing. I have tried to get rid of the newline character with
>
> $count=tr/\n//d;
>
> but that gives me a count of "1" for each line, and I still have
> multiple lines!
> How do I get rid of the newline character, or at the very least, how do
> I join the multiple lines so I have one single string? I'm fairly sure
> this is a simple thing to do, but so far I don't know what else to try!
>
> Thanks for your time,
> Pedro A Navarro
> pnavarro@uswest.net




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

Date: Sun, 27 Aug 2000 15:11:14 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: Counting across multiple lines?
Message-Id: <MPG.1413cd078a7f7048989706@localhost>

Sudhan <someone@somewhere.com> provided the reason not to killfile all 
jeopardists by writing the appauling example code ..

>open(DNA,"dna");
>@_ = <DNA>; # read everything
>$_ = join("",@_);
>$count = tr/A-Z//; # Don't change anything, just count the chars
>print "The number of charcters are ...:".$count,"\n";

please lurk for a little longer Sudhan .. your code is inefficient and 
clobbers two builtin variables needlessly (and possibly harmfully)

also .. post your reply beneath the original in future

>"Pedro A Navarro" <pnavarro@uswest.net> wrote in message
>news:39A8981B.47000002@uswest.net...
>> Hi:
>> I'm new to Perl and programming in general, so I'm stumped by a simple
>> problem. I'm trying to write a program that counts the number of
>> characters in a file, such as
>>
>> >header
>> TADSTWTASRTDRAFTARSGRQWTS
>> AGSTDRASGATFSASDGTASTTAGS
>> TQTRAEWSTATSGATSGTASTATST
>>
>> That is for a protein sequence file, in case you are wondering. When I
>> use
>>
>> $count=tr/A-Z//;
>> print "$count\n";
>>
>> I get the number of characters for each line, instead of for the whole
>> thing. I have tried to get rid of the newline character with

as Tina's second shot mentioned - this will work perfectly as long as 
you have all the file in $count when you do the tr .. which you almost 
certainly do not

if the file's small then use $/ to allow you to slurp the whole file 
into a scalar and then do the count

  perldoc perlvar

if the file's large (which I suppose is a fair possibility if these are 
genetic sequences) then just iterate over each line of the file in a 
while loop counting the chars on each line and adding them to a running 
total .. the core loop would look something like the following

  my $runningTotal = 0;

  while(<DATA>)
  {
    $runningTotal += tr/A-Z//;
  }

>> How do I get rid of the newline character, or at the very least, how do
>> I join the multiple lines so I have one single string? I'm fairly sure
>> this is a simple thing to do, but so far I don't know what else to try!

if you need to join the lines together for some purpose other than 
counting the characters then you'll need to look at the chomp function 
and the .= operator (concatenate and assignment)

  perldoc -f chomp
  perldoc perlop

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: Sun, 27 Aug 2000 15:19:20 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Counting across multiple lines?
Message-Id: <Yjaq5.20139$C5.294480@typhoon.austin.rr.com>

In article <39A8981B.47000002@uswest.net>,
Pedro A Navarro  <pnavarro@uswest.net> wrote:
>Hi:
>	I'm new to Perl and programming in general, so I'm stumped by a simple
>problem. I'm trying to write a program that counts the number of
>characters in a file, such as 
>
>>header
>TADSTWTASRTDRAFTARSGRQWTS
>AGSTDRASGATFSASDGTASTTAGS
>TQTRAEWSTATSGATSGTASTATST
>
>That is for a protein sequence file, in case you are wondering. When I
>use
>
>$count=tr/A-Z//;
>print "$count\n";
>
>I get the number of characters for each line, instead of for the whole
>thing. I have tried to get rid of the newline character with
>
>$count=tr/\n//d;
>
>but that gives me a count of "1" for each line, and I still have
>multiple lines!
>How do I get rid of the newline character, or at the very least, how do
>I join the multiple lines so I have one single string? I'm fairly sure
>this is a simple thing to do, but so far I don't know what else to try!

If you count the newline at the end of the lines as a character and you
are using an operating system which represents the newline with a single
character then you might be able to use the -s file test operator to get
the size of the file without having to read it at all.

If you don't want the newlines counted then you might be able to do
something like:

  # assume FH is opened for reading

  $length = 0;

  while (<FH>) {
      chomp;
      $length += length;
  }

If you want to get the whole file into memory then you might say something
like:

  # assume FH is opened for reading

  {
      local $/;
      $data = <FH>;
  }

  $data =~ tr/\n//d;

  $length = length( $data );

These are just a few ways you might be able to do it in perl.  There are
many other ways, and which is best for you depends on things like your
personal preferences and the size of the dataset you're processing and
many other things I don't know.

Hope this helps,

Mike
-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |
GPG PGP Key 1024D/059913DA         | Fingerprint      0570 71CD 6790 7C28 3D60
stok@colltech.com (CT - work)      |                  75D2 9EC4 C1C0 0599 13DA


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

Date: Sun, 27 Aug 2000 15:50:15 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: Counting across multiple lines?
Message-Id: <MPG.1413d62be205292698970a@localhost>

Mike Stok <mike@stok.co.uk> wrote ..
>In article <39A8981B.47000002@uswest.net>,
>Pedro A Navarro  <pnavarro@uswest.net> wrote:
>>Hi:
>>	I'm new to Perl and programming in general, so I'm stumped by a simple
>>problem. I'm trying to write a program that counts the number of
>>characters in a file, such as 
>>
>>>header
>>TADSTWTASRTDRAFTARSGRQWTS
>>AGSTDRASGATFSASDGTASTTAGS
>>TQTRAEWSTATSGATSGTASTATST
>>
>>That is for a protein sequence file, in case you are wondering. When I
>>use
>>
>>$count=tr/A-Z//;
>>print "$count\n";
>>
>>I get the number of characters for each line, instead of for the whole
>>thing. I have tried to get rid of the newline character with
>>
>>$count=tr/\n//d;
>>
>>but that gives me a count of "1" for each line, and I still have
>>multiple lines!
>>How do I get rid of the newline character, or at the very least, how do
>>I join the multiple lines so I have one single string? I'm fairly sure
>>this is a simple thing to do, but so far I don't know what else to try!
>
>If you count the newline at the end of the lines as a character and you
>are using an operating system which represents the newline with a single
>character then you might be able to use the -s file test operator to get
>the size of the file without having to read it at all.

this would be a good solution *IF* you've got a known fixed number of 
chars per line in the file - otherwise you're going to have to open it 
to find out how many lines it has - so you know how many line-endings 
there are

>If you don't want the newlines counted then you might be able to do
>something like:
>
>  # assume FH is opened for reading
>
>  $length = 0;
>
>  while (<FH>) {
>      chomp;
>      $length += length;
>  }
>
>If you want to get the whole file into memory then you might say something
>like:
>
>  # assume FH is opened for reading
>
>  {
>      local $/;
>      $data = <FH>;
>  }
>
>  $data =~ tr/\n//d;
>
>  $length = length( $data );

neither of the above would work if - as the originator seemed to suggest 
- there was a header (or some other non-protein-sequence data) within 
that file

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: Sun, 27 Aug 2000 16:44:25 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Counting across multiple lines?
Message-Id: <Jzbq5.20190$C5.297028@typhoon.austin.rr.com>

In article <MPG.1413d62be205292698970a@localhost>,
jason  <elephant@squirrelgroup.com> wrote:
>Mike Stok <mike@stok.co.uk> wrote ..

[...]

>>If you count the newline at the end of the lines as a character and you
>>are using an operating system which represents the newline with a single
>>character then you might be able to use the -s file test operator to get
>>the size of the file without having to read it at all.
>
>this would be a good solution *IF* you've got a known fixed number of 
>chars per line in the file - otherwise you're going to have to open it 
>to find out how many lines it has - so you know how many line-endings 
>there are

Yes, this code fragment was tossed out with the condition "If you count
the newline at the end of the lines as a character..."  There wasn't
enough information in the question to provide any complete and reliable
solution, so I just tossed out a few ideas which might help the original
poster get on track.

If you could imagine that the header were a fixed size and contained the
number of lines of data somehow then it's possible to just read the
header and use the knowledge of the header and number of lines it's
possible to deduce the number of data characters from the file's size.  If
the data lines are all the same length then you might read the header (to
determine its size) and then it's a simple matter of arithmetic to
determine how much of the rest of the file is data and how much is
newlines.

>>If you don't want the newlines counted then you might be able to do
>>something like:
>>
>>  # assume FH is opened for reading
>>
>>  $length = 0;
>>
>>  while (<FH>) {
>>      chomp;
>>      $length += length;
>>  }
>>
>>If you want to get the whole file into memory then you might say something
>>like:
>>
>>  # assume FH is opened for reading
>>
>>  {
>>      local $/;
>>      $data = <FH>;
>>  }
>>
>>  $data =~ tr/\n//d;
>>
>>  $length = length( $data );
>
>neither of the above would work if - as the originator seemed to suggest 
>- there was a header (or some other non-protein-sequence data) within 
>that file

The comments above the code fragments both state the assumption that the
file is opened for reading.  In neither case did I say "and you mustn't
have read anything from it yet - maybe the original poster has enough
imagination to see that he might be able to read the header and then use
the ideas in the presented fragments to deal with the rest of the
file.  I didn't think that the jump from the presented fragments to some
useful code would be that hard.

I lurk somewhere between the "teach a man to fish" and "give him a
fish" camps ... I usually endeavour to leave enough clues that someone can
get to a working solution in a reasonable time, but not without thinking
about the suggestions.  Sometimes just tossing ous some of the other ways
to do it in perl can help people see the problem in a differnt light.

In general I believe that people are smart and imaginative, but I'm always
grateful to have reconsider my views.  I realise that old-timers in a
group like this have a duty to keep neophyte posters like me in line,
especially if I don't fully qualify and disclaim everything in my post.

Mike
-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |
GPG PGP Key 1024D/059913DA         | Fingerprint      0570 71CD 6790 7C28 3D60
stok@colltech.com (CT - work)      |                  75D2 9EC4 C1C0 0599 13DA


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

Date: Sun, 27 Aug 2000 14:59:40 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: Development Tools
Message-Id: <MPG.1413ca54248c2b8b989705@localhost>

Tina Mueller <tina@streetmail.com> wrote ..
>hi,
>jsaintc@my-deja.com wrote:
>> What is a good PERL Development tool?  I have
>> Visual Studio Eenterprise edition, but I don't
>> know if and don't think that it has any kind of
>> PERL compiler.  Are there any popular programs,
>> and besides that, programs from popular vendors
>> that are worth checking out, or do I just have to
>> be in a UNIX enviornment with a PERL compiler to
>> find what I want?...
>
>use an editor of your choice (vi, emacs, or
>for windows, textpad, ...)

vi and emacs are available in various forms for Windows platforms 
(amongst others)

http://www.vim.org/

http://www.gnu.org/software/emacs/windows/

>and a perl distribution of your choice
>(ActivePerl for windows, ...). then edit your
>perl program and type
>perl -c script
>
>that's all you need.

surely you need to also run it without the -c option ? .. unless you 
cram all your code into a BEGIN block ;)

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: 27 Aug 2000 17:14:16 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: Development Tools
Message-Id: <8obi46$aat2g$9@ID-24002.news.cis.dfn.de>

hi,
jason <elephant@squirrelgroup.com> wrote:
> Tina Mueller <tina@streetmail.com> wrote ..
>>jsaintc@my-deja.com wrote:
>>> What is a good PERL Development tool?  I have
>>

>>perl program and type
>>perl -c script
>>
>>that's all you need.

> surely you need to also run it without the -c option ? .. unless you 
> cram all your code into a BEGIN block ;)

the original poster just asked for a compiler... =)

tina

f'up2p
-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \__,_\___/\___/_| /__/ perception
please don't email unless offtopic or followup is set. thanx


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

Date: 27 Aug 2000 14:42:57 GMT
From: eekhof@bigfoot.com (Eric Eekhof)
Subject: Extracting data from STDIN
Message-Id: <slrn8qia7h.hih.eekhof@eric.wirehub.nl>

Hi,

I'm writing a mailfilter and have some trouble to extract certain data from
incoming mail.

Usually the data I want to extract is on the same line as the argument
searched for. Extracting data that comes next on the same line is easy.

But now I want to extract data from the next four lines from the incoming
mail. For example, the incoming mail looks like this:

Description:

	First line to extract

	Second line to extract

A 'if (m/Description:(.*)/) { $descr = $1; }' gives an empty $descr of
course, since there's nothing left on the same line. But how do I extract
the first and second line?

To be complete, I start the script with:

undef $/ ;
$_ = <STDIN> ;

to capture the entire mail in $_ .

Anyone?

TIA!
Eric


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

Date: 27 Aug 2000 15:39:28 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: Extracting data from STDIN
Message-Id: <8obcid$aat2g$4@ID-24002.news.cis.dfn.de>

hi,
Eric Eekhof <eekhof@bigfoot.com> wrote:

> Usually the data I want to extract is on the same line as the argument
> searched for. Extracting data that comes next on the same line is easy.

> But now I want to extract data from the next four lines from the incoming
> mail. For example, the incoming mail looks like this:

> Description:
> 	First line to extract
> 	Second line to extract

> A 'if (m/Description:(.*)/) { $descr = $1; }' gives an empty $descr of
> course, since there's nothing left on the same line. But how do I extract
> the first and second line?

try 
if (m/Description:(.*)/s) { $descr = $1; }
instead.
of course then you have the first and the second line
in $descr. 
(you can split $descr then or you have to
change the regex above a little bit.
read perldoc perlre to larn more about it.

tina

-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \__,_\___/\___/_| /__/ perception
please don't email unless offtopic or followup is set. thanx


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

Date: 27 Aug 2000 16:38:23 GMT
From: eekhof@bigfoot.com (Eric Eekhof)
Subject: Re: Extracting data from STDIN
Message-Id: <slrn8qigvv.hih.eekhof@eric.wirehub.nl>

On 27 Aug 2000 15:39:28 GMT, Tina Mueller <tina@streetmail.com> wrote:
>
>try 
>if (m/Description:(.*)/s) { $descr = $1; }
>instead.

I should have thought that one up myself.
Thanks!

Eric


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

Date: Sun, 27 Aug 2000 17:01:34 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Extracting data from STDIN
Message-Id: <x77l92sknl.fsf@home.sysarch.com>

>>>>> "EE" == Eric Eekhof <eekhof@bigfoot.com> writes:

  EE> I'm writing a mailfilter and have some trouble to extract certain
  EE> data from incoming mail.

before you go too far check out Mail::Procmail and Mail::Audit.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Sun, 27 Aug 2000 14:50:25 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: Form Question
Message-Id: <MPG.1413c825d2d8c710989704@localhost>

richie <rsmith@sympatico.ca> wrote ..
>Is there an easy way for me to have a selection menu like this:
>
>        print "<select name='place'>";
>        print "<option selected value'garbage'> Please click here";
>        print "<option value='maps'>Use the Maps ";
>        print "<option value='location'> Specify a location";
>        print "<option value='street'> Specify a street";
>        print "</select>";
>
>and then when I hit the button:
>
>  print "<input type='submit' value='&nbsp; Go To Location &nbsp;'>";
>        print "</FORM>\n";
>        print "<TD>\n";
>
>depending, on what option is selected it will pass it to one of three
>different scripts, and perform the following:
>
>$string1="origin_index_x=$coordx&origin_index_y=$coordy&>";
>$string1 =~ s/\=/\~/g;
>
>print "\n <INPUT TYPE = hidden NAME = string VALUE= $string1>\n";
>
>Or will I have to pass the selection into a script and then decide what
>script it has to go to next?

for the question to be relevant to this forum the latter is the only 
choice .. in this situation Perl cannot help you (assuming an unknown 
and/or uncontrollable browser target) in any other way

alternatively you can write some client-side code (unless IE is your 
sole target that will have to be in Javascript - which is still fraught 
with danger that's WAY too off topic to go into here)

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: Sun, 27 Aug 2000 15:25:45 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: Global symbol "$dbh" requires explicit package name at d:\...\Behzad.pl line 17.
Message-Id: <MPG.1413d0729ecb6957989707@localhost>

bjg <bGhassemlou@home.com> wrote ..
>I am trying to write a small program to use DBI and I get "Global symbol
>require...." error
>I am running Perl on Win-NT, I installed MySql on the same.
>I appreciate if anyone could give me instruction to get rid of the errors.
>Thanks
>
>Here is the source code, error :
>===========================
>require "subparseform.lib";
>&Parse_Form;
>use DBI;
>use strict;
>my $database = "OpenTraders";
>my $data_source = "DBI:mySQL:$database";
>my $username = "Administrator";
>my $password = "********";
>##############################
>## check VHD DB for Jobs and status
>##
>my $dbh = DBI->connect($data_source, $username, $password)  or die "cant
>connect to $data_source : $dbh->errstr\n";

see how you use $dbh within the die call ? .. well what if the 
DBI::connect DOES fail .. then $dbh will not have been declared .. so 
strict will complain (and it will complain a number of other times as 
well)

change the above to

  my $dbh;  # separate declaration

  $dbh = DBI->connect($data_source, $username, $password)
       or die "cant connect to $data_source : $dbh->errstr\n";

THEN have another look at the DBI documentation .. the above die message 
will almost certainly not be what you expect

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: 27 Aug 2000 15:45:55 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: Global symbol "$dbh" requires explicit package name at d:\...\Behzad.pl line 17.
Message-Id: <8obcug$aat2g$5@ID-24002.news.cis.dfn.de>

hi,
jason <elephant@squirrelgroup.com> wrote:
> bjg <bGhassemlou@home.com> wrote ..
>>I am trying to write a small program to use DBI and I get "Global symbol
>>require...." error

>>my $dbh = DBI->connect($data_source, $username, $password)  or die "cant
>>connect to $data_source : $dbh->errstr\n";

> see how you use $dbh within the die call ? .. well what if the 
> DBI::connect DOES fail .. then $dbh will not have been declared .. so 
> strict will complain (and it will complain a number of other times as 
> well)

> change the above to

>   my $dbh;  # separate declaration

>   $dbh = DBI->connect($data_source, $username, $password)
>        or die "cant connect to $data_source : $dbh->errstr\n";

another thing: $dbh->errstr won't be interpolated
as you might expect.

tina

-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \__,_\___/\___/_| /__/ perception
please don't email unless offtopic or followup is set. thanx


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

Date: Sun, 27 Aug 2000 13:17:01 GMT
From: wfeidt@cpcug.org (Bill Feidt)
Subject: Re: Good companion book to Programming Perl?
Message-Id: <8F9D5CCFAwfeidthiscom@207.126.101.97>

wfeidt@cpcug.org (Bill Feidt) wrote in 
<8F9D40F09wfeidthiscom@207.126.101.97>:

>To a great extent it depends on your learning style.  Apart from
>offering solid approaches to common Perl tasks, "Programming Perl"
>excels in its detailed explanation of how and why the approaches
>work.  If you like to learn by studying solutions to specific
>problems, it's an excellent choice.

Arghhh.  I have to stop posting first thing in the morning.
The foregoing remarks were in reference to "Perl Cookbook",
not "Programming Perl". Sorry.

Bill


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

Date: Sun, 27 Aug 2000 16:58:19 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Good companion book to Programming Perl?
Message-Id: <x7bsyeskt0.fsf@home.sysarch.com>

>>>>> "SD" == Speed Demon <speed.demon9999@virgin.net> writes:

  SD> Perl for Dummies is AMAZING. Ok, its a dummies book but it teaches
  SD> you everything you need to know, I have created an searchable Only
  SD> database, admin scripts, cookies + loads more from this book
  SD> alone. Well worth it, it goes through alot of advanced perl and
  SD> you don't even fell the pressure :))

please don't promote that pile of smoldering dung in this newsgroup. it
is an condescending and insulting tome, full of bugs, written by an
idjit who knows not from perl nor programming nor english and edited by
yellow stained wretches. and saying advanced perl and dummies in the
same sentence is a maximal oxymoron.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Sun, 27 Aug 2000 15:10:25 GMT
From: "Dark" <darklord@libero.it>
Subject: guestbook & file-upload under NT
Message-Id: <Bbaq5.144203$dF5.2425033@news.infostrada.it>

Can anyone tell me where to find a script for file-uploading and a script
for a guestbook, both working under a win NT server?
Thanks!




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

Date: Sun, 27 Aug 2000 14:56:01 +0100
From: "Speed Demon" <speed.demon9999@virgin.net>
Subject: Re: How can I find an images size??
Message-Id: <8ob6m8$7gp$1@uk21.supernews.com>

Cheers m8, I tried Deja, only came up with useless junk...

I can't open the tar.gz files as im on windows, can someone send the files
in either a .zip or uncompressed format to me so I can upload to my UNIX
host?


Cheers once again, best regards T.Mistry

"Martien Verbruggen" <mgjv@tradingpost.com.au> wrote in message
news:slrn8qi3bn.3fr.mgjv@martien.heliotrope.home...
> On Sun, 27 Aug 2000 12:41:51 +0100,
> Speed Demon <speed.demon9999@virgin.net> wrote:
> > Hi, using either Perl or Javascript is it possible to find out the
> > dimensions of an image.
>
> This question gets asked quite a lot on this group, and was actually
> asked in the last week. You should consider using archives like
> www.deja.com to do searches against. It might save you waiting for
> answers.
>
> You want the Image::Size module. Available from CPAN:
> http://www.cpan.org/
>
> Martien
> --
> Martien Verbruggen              |
> Interactive Media Division      | Can't say that it is, 'cause it
> Commercial Dynamics Pty. Ltd.   | ain't.
> NSW, Australia                  |




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

Date: Sun, 27 Aug 2000 11:18:47 -0400
From: H C <carvdawg@patriot.net>
Subject: Re: How to obtain information about shares Win NT
Message-Id: <39A93157.A280BB4A@patriot.net>

Dave Roth's Win32::Perms module allows this...

A tool called ForixNT provides a wrapper that makes it easy to get this
information...

http://www.forixnt.com

Marek Kozniewski wrote:

> How to obtain information about share permission in Win NT (network
> permission and file permission)
>
> Marek

--
Q: Why is Batman better than Bill Gates?
A: Batman was able to beat the Penguin.




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

Date: Sun, 27 Aug 2000 11:35:40 -0400
From: Albert Dewey <timewarp@shentel.net>
Subject: Re: Kill Me!
Message-Id: <39A9354C.3249FEB7@shentel.net>



Martien Verbruggen wrote:

> On Sat, 26 Aug 2000 18:04:27 -0400,
>         Albert Dewey <timewarp@shentel.net> wrote:
>
> I saw a few followups to your stuff, so I temporarily removed the kill.
> I believe I can help you out here.

Martien -

Okay - based on what you sent me, as you are the first person who is civilized
enough to back up what he is alleging, I will post my comments after the quote.
My main reason for raising such a fuss is that I find it absolutely incredible
that people are so frikken immature that they will, as several said in this group
(I won't name names), automatically add to their kill file anyone who posts
jeopardy style. Seems kinda irrational to me. Actually very childlike. My major
point was to make an issue about their comments regarding jeopardy postings and
that is all. In fact, I read a very large number of news group etiquette pages
(in excess of a dozen) and found a number of interesting things. First, only two
even mentioned posting after quoting, but that is not the issue. These very
people who have jumped down my throat on this issue are equally guilty of bad
netiquette behavior according to many of these sites. The remainder of my list
that I had posted specifically deal with these things that I personally saw as
posting violations that most of my abusers are indeed guilty of at least one of
them on regular occasion. <list follows>

# I will continue to answer other's posts 'Jeopardy Style'.
# I will answer off topic questions if I really believe that I can help
that person with an answer that is Perl related or even combining Perl
with other solutions.
# I will not flame other people with worthless masturbatory replies.
# I won't criticize people for posting Newbie Questions other than
suggest that they get a good book on Perl to help them in their quest to
learn Perl.
# I won't answer people's questions with snippets of a solution that are
clearly over the poster's head in an effort to razzle dazzle that person
with my sheer brilliance.
# I won't even criticize people such as yourselves when you post after
the quoted content.

I am a very stubborn person who will not admit to being wrong until I am proven
wrong simply because this is how I feel about most issues in life. Call me a jerk
for this or whatever, but I have seen countless times where other people are
wrong and try to hammer me into believing in their system and I am not going to
let myself be pursuaded unless there is a very compelling reason to do so. I will
say that I do make up for this by being to first to admit that I am wrong when
indeed it can be properly shown to me this fact. In the case of jeopardy style
postings, I am willing to modify my habit, not because of the dozen or so flames
I have received over this issue, but because you personally were willing to back
up what you said with fact. This is how things are properly debated and how
civilized people handle things, not with curt and rude responses followed by
*plonk* or what ever the hell that is supposed to mean. Still, I think that it
would be equally as wise for my flamers to take the time to review their own
newsgroup posting etiquette and make changes to their behavior as is necessary.

Just trying to make a point here and not cause trouble.

Albert Dewey





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

Date: Sun, 27 Aug 2000 15:32:11 GMT
From: ejwhite1@facstaff.wisc.edu (Eric White)
Subject: move to NT from 98 killing my cgi.pm script
Message-Id: <8obbt1$etq$2@news.doit.wisc.edu>

Hello All,

(I realize this is more of a cgi question rather than a perl question,
but maybe someone here knows the answer?  I've also posted
this to comp.infosystems.www.authoring.cgi.)

I'm guessing that the answer to my question is something 
obvious, but I've looked high and low w/o any luck, so here goes:

I've got a series of pages that rely on information being carried over from 
one to the other via the hidden() function.  This all works fine and dandy on 
the win98 machine on my desk, but when I loaded the script to an NT box the 
script acts as if none of the hidden values are being passed from page to 
page. 

The script is written in perl 5.6.  The web server in question is running NT 4 

and Xitami 2.4d7.  

Am I missing something in this setup?  The script compiles under NT so I think 

the script itself is ok, but something's getting dropped somewhere along the 
line...

Any suggestions are greatly appreciated.


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

Date: Sun, 27 Aug 2000 14:40:03 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: my($a)=shift or warn;
Message-Id: <MPG.1413c5ba8fe61c25989703@localhost>

Hans Ginzel <Hans@kolej.mff.cuni.cz> wrote ..
>   What does the assignmen my($a)=shift return?

obviously - true

>   Try this:
>	sub test {
>	        print @_, "\n";
>        	(my($a)=shift) or print "A\n";
>	        (my($b)=shift) and print "B\n";
>	}
>
>	test;
>	test "X";
>	test "X", "Y";
>
>The output is:
>
>	B
>	X
>	B
>	XY
>	B

try the following (all red herring code from your example removed)

  my @x = undef or die;

and then

  my $x = undef or die;

assigning a scalar to a list actually assigns the scalar to the first 
element of the list .. so in your examples  .. the return value from 
'shift' is a scalar .. but the LHS has parens and so is a list (of one 
element) .. so the assignment itself was true because the list is true

your code will exhibit the appropriate behaviour if you remove the 
parens from the my declarations (as shown below) .. shift returns a 
scalar - so you should be assigning to a scalar - and not a list

  sub test
  {
    print "[@_]\n";

    my $a = shift or print "A\n";

    my $b = shift and print "B\n";
  }

  test;
  test 'X';
  test 'X', 'Y';

  __END__

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: 27 Aug 2000 12:25:10 GMT
From: grey@despair.rpglink.com (Steve Lamb)
Subject: Re: Newsreaders (was Re: [OT] Re: stupid question probably)
Message-Id: <slrn8qi1vk.c7.grey@teleute.rpglink.com>

On 27 Aug 2000 01:10:00 +0100, Jonathan Stowe <gellyfish@gellyfish.com> wrote:
>Unix/Linux users in this thread are using slrn or tin on the whole and
>the cognoscenti amongst the windows users are using Forte Agent or Gravity.

    What about XNews on the Windows side.  One must admit that a quick look at
news.software.readers the most talked about newsreader appears to be XNews.
Not my style, being a SLRN/VIM person myself, but I do use it in a pinch.

-- 
         Steve C. Lamb         | I'm your priest, I'm your shrink, I'm your
         ICQ: 5107343          | main connection to the switchboard of souls.
-------------------------------+---------------------------------------------


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

Date: Sun, 27 Aug 2000 17:53:24 GMT
From: Brock <brock_johnson@my-deja.com>
Subject: No Server Logs
Message-Id: <8obkie$p4q$1@nnrp1.deja.com>

I do not have access to my webserver's logs to see my perl coding errors. Is
there a better way to show errors to my browser than using
CGI::Carp('FatalsToBrowser')... or using R. Schwartz's script that only shows
errors from die or warn? Thanks.

--
The Best to all!
Brock Johnson


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Sun, 27 Aug 2000 17:36:36 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Parsing a Excell table - or - a "Tab New_Line" text file?
Message-Id: <39A9524F.D0ADF6C4@rochester.rr.com>

Jeff Zucker wrote:
> 
> Etienne Laverdiere wrote:
> >
> > I need to parse in a 2 dimentional array from an Excell document through a
> > Perl script that will isolate all the colonnes and the rows of this Excell
> > table.
> > ...
> > I would like, finaly to access my ODBC database with each value, and build a
> > database table (I have already done that with DBI).
> 
> Excel *is* an ODBC accessible database.  You don't need to take the
> information out of Excel into something else and then put it back into
> some other ODBC source, you just access the Excel spreadsheet just like
> any other DBI database:
> 
> use DBI;
> my $drv   = 'ODBC:driver=Microsoft Excel Driver (*.xls)';
> my $dir   = $directory_where_spreadsheet_is_stored;
> my $table = $name_of_spreadsheet; # e.g. 'test.xls'
> my $dbh   = DBI->connect( "dbi:$drv;Dbq=$dir",,,{RaiseError=>1} )
>             or die $DBI::errstr;
> my $sth   = $dbh->prepare("SELECT * FROM $table");
> # ... etc.
> 
> If you really want to go the route of exporting the Excel spreadsheet to
> a tab delimited file and then putting that into an array, then use
> DBD::RAM or DBD::CSV and the fetchall_arrayref method.
> 
> --
> Jeff

Jeff, thanks very much for your input -- I didn't know you could do that
with Excel.  Where does one find docs on this? -- I looked through
everything I've got on Excel, and it is not mentioned.  I think I'll use
this method most of the time from now on, rather than OLE.  

I found, though, that some of the stuff in your example code isn't quite
right -- the $dir needs to include the spreadsheet file, and the $table
is an Excel range name (insert..name..define), not the name of the
spreadsheet.  Here is a complete working example, given a spreadsheet
that has a range with the name "table1".  The SQL field names are taken
from the first row of the named range, unless that row is numeric, in
which case it makes up field names.

#example of using DBI with Excel
use DBI;
use Data::Dumper;
my $drv   = 'ODBC:driver=Microsoft Excel Driver (*.xls)';
my $dir   = 'c:/bob/junk/junk194.xls'; #an Excel file
my $table = 'table1'; #a range name
my $dbh   = DBI->connect( "dbi:$drv;Dbq=$dir",,,{RaiseError=>1} )
            or die $DBI::errstr;
my $sth   = $dbh->prepare("select * from $table");
$names=$sth->{NAME};
for (@$names){print "field:$_\n"}
my $ref   = $dbh->selectall_arrayref($sth);
print Dumper($ref);

-- 
Bob Walton


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

Date: Sun, 27 Aug 2000 23:37:22 +0800
From: patrick <tanya@hongkong.com>
Subject: Print location in <IMG> on NT
Message-Id: <39A935B1.69AF3D9C@hongkong.com>

Would anybody please tell me why i can't get the image load in the html
file (Windows 2000 server/IIS 5.0)

my html statement are as follow
==========================
<img src=http://xxx.com/cgi-bin/image.cgi>
==========================

my "image.cgi" are as follow
==========================
#d:\perl\bin

print "Pragma: no-cache\n";
print "Location: http://xxx.com/abc.jpg\n\n";
==========================

PS: Unix/Linux can work



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

Date: 27 Aug 2000 13:53:40 GMT
From: gorilla@elaine.furryape.com (Alan Barclay)
Subject: Re: selling perl to management
Message-Id: <967384407.631489@elaine.furryape.com>

In article <slrn8qhskl.3fr.mgjv@martien.heliotrope.home>,
Martien Verbruggen <mgjv@tradingpost.com.au> wrote:
>But I can turn the argument around again. No standard out there
>guarantees anything either. And again I can point to the java language
>as well as the C language standards, and the various Unices. They change
>too when necessary. No standard will stop that. What a standard does is
>formalise what a given application should behave like during the

Which java language standards? Sun withdrew from the standardization 
process, and the only definition of what java is is what Sun provides.

There is an ANSI/ISO/BSI/etc standard for C, however for many 'real life'
programs, it won't prevent changes from affecting your program, because
many of the functions you need to use are platform defined, not standard
defined, because of the impossibility of implementing them the same on
all platforms which support C.

Other people have noted that standards change. This is a real problem,
even with a standard that is revised only once every 10 years, programs
can easily live through 3 or 4 revisions.

And of course, even when a standard exists, there are always instances
where the installation does not properly behave. These are usually fixed
when the author is notified, in which case you either have a problem
writing your program before it's fixed, or after it's fixed.

Language standards are the begining for compatability, not the end.


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

Date: 27 Aug 2000 16:15:06 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: selling perl to management
Message-Id: <8obel8$aat2g$6@ID-24002.news.cis.dfn.de>

hi,
Olivier Dehon <o_dehon@my-deja.com> wrote:
> In article <8oafgc$n7d$1@provolone.cs.utexas.edu>,
>   logan@cs.utexas.edu (Logan Shaw) wrote:
>> "@" is still allowed in double-quoted strings, but a warning is
>> generated.

> Bad example, it is not a warning, but a fatal error (trappable)...

> From the perldiag manpage:

> In string, @%s now must be written as \@%s

>      (F) It used to be that Perl would try to guess whether you wanted
> an array interpolated or a literal @. ...

but it doesn't produce an error if it isn't
ambiguous:

|          Now strings are parsed at compile time, and ambiguous
|          instances of @ must be disambiguated, either by
|          prepending a backslash to indicate a literal, or by
|          declaring (or using) the array within the program
|          before the string (lexically).  (Someday it will
|          simply assume that an unbackslashed @ interpolates an
|          array.)

so "this @ would now work, but not name@email.com";

tina

-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \__,_\___/\___/_| /__/ perception
please don't email unless offtopic or followup is set. thanx


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

Date: Sun, 27 Aug 2000 15:20:02 GMT
From: ejwhite1@facstaff.wisc.edu (Eric White)
Subject: sorting a hash by key value (I've looked at the TIE functions and I'm still confused...)
Message-Id: <8obb68$et8$1@news.doit.wisc.edu>

Hello,

I'm using CGI.pm and one thing I'm trying to do is use a hash for my values 
and labels in a checkbox_group form.  Everything works, but now I'd like to 
have the labels displayed in the value order, not the default order of the 
hash.  I'm not sure how to do this.  

Here's what I've got now:

        #we look at all the related adults
        my(@relatives) = qw(B1B B2B B3B B4B B5B B6B B9B B10B B11B B12B B16B);

        foreach $rel (@relatives) {
                if (param("$rel") eq '1') {
                        $care{"1"} = "Primary Caregiver";
                } elsif (param("$rel") eq '2') {
                        $care{"2"} = "Secondary Caregiver";
                } elsif (param("$rel") eq '3') {
                        $care{"3"} = "Other Adult Relative";
                }
        }
                                                                   

        #and then the non-relative adults
        my(@nonrel) = qw(B7B B8B B17B);
        foreach $nonrel (@nonrel) {
                if (param("$nonrel") eq '1') {
                        $care{"1"} = "Primary Caregiver";
                } elsif (param("$nonrel") eq '2') {
                        $care{"2"} = "Secondary Caregiver";
                } elsif (param("$nonrel") eq '3') {
                        $care{"4"} = "Non-Relative Adult";
                }
        }                                         

        #and then the sibs or other child relative
        my(@sib_oth) = qw(B13B B13B2 B13B3 B14B B14B2 B14B3 B15B B15B2 B15B3);
        foreach $sib_oth (@sib_oth) {
                if (param("$sib_oth") >= 1 ) {
                        $care{"5"} = "Sibling or Other Dependent Child";
                }
        }                                         
                                                          
        #we're always going to have these 2 on the list          
        $care{"97"} = "Other";
        $care{"98"} = "Unknown / Don't Know";                                  
                  

        return %care;
}


************
and from the page using %care....

        strong("D1A2. "),
        "Who were the caregivers?",
        p,
                checkbox_group(-name=>'D1A2', -linebreak=>1, Values=>\%care),
        p,

*************


What I'd like is for the values always to be displayed in order from 1 - 98 
(the key values).  I've tried a variety of methods and I've looked at the 
IxHash module but I can't find anything that allows me just refer to or create 
a %hash in default value order.  Can I do what I'm trying to do?

Thanks very much for any help!

Eric





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

Date: Sun, 27 Aug 2000 11:37:10 -0500 (CDT)
From: dennis100@webtv.net (BUCK NAKED1)
Subject: Re: stupid question probably
Message-Id: <7384-39A943B6-12@storefull-248.iap.bryant.webtv.net>

>>On Sat, 26 Aug 2000,
>>BUCKNAKED1 wrote: 
>>Sometimes instead of using 
>>server-side includes or .shtml,
>>you can insert a perl script just
>>by using the HTML embed tag, 

>flavell@mail.cern.ch (Alan=A0J.=A0Flavell) >wrote: Standard HTML has no
such
>tag... 

Huh? Of course HTML has an embed tag, such as <embed src=3D"xxx.pl">.
Though it's deprecated, it's not obsolete, and appears to be more
cross-browser-friendly than the <object src=3D"xxx.pl">  <object
id=3D"xxx.pl">  or the <object data=3D"xxx.pl"> tags. 

--Regards,
Dennis 



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

Date: Sun, 27 Aug 2000 16:50:20 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: what does "to spider" mean?
Message-Id: <sqihmc4at9155@corp.supernews.com>

dunno2k@my-deja.com wrote:
: Suppose I have a link. What does it mean
: to "spider" the link?

Basically to walk the tree of references from the page linked, to some
arbitrary depth or to all other pages residing on that same server, or
limited by some other criterion.  The idea is to generate a map of the
entire site, or simply to index the entire site, based on your single-url
point of entry.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "Every force evolves a form."
   |              - Shriekback


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

Date: Sun, 27 Aug 2000 13:58:05 GMT
From: gevens@my-deja.com
Subject: Re: What is a Linux file type of 'application/x-cgi' ?
Message-Id: <8ob6pb$abh$1@nnrp1.deja.com>

Thank you all.

It's hard to know when you have done enough reading before posting a
plea for help.

It seems I have some more to do !

I appreciate the answers you have given to point me in the right
direction.

Have a good day everyone.

Graham.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

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


Administrivia:

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

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

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

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

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

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


------------------------------
End of Perl-Users Digest V9 Issue 4144
**************************************


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