[17792] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5212 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 28 14:05:32 2000

Date: Thu, 28 Dec 2000 11:05:13 -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: <978030313-v9-i5212@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 28 Dec 2000     Volume: 9 Number: 5212

Today's topics:
        Almost a one-liner: generating 4 digits out of an e-mai (EED)
    Re: Code Review? (Tad McClellan)
    Re: Code Review? (Tad McClellan)
    Re: Code Review? (Tad McClellan)
    Re: Code Review? (Colin Watson)
    Re: convert decimal to hex??? <tony_curtis32@yahoo.com>
    Re: convert string to command? <nospam@nospam.com>
    Re: CPAN Eof error <nospam@nospam.com>
    Re: FAQ 6.21:   What's wrong with using grep or map in  (Abigail)
        File test <e.quesada@verizon.net>
    Re: File test (Brian Pontz)
    Re: File test (Rafael Garcia-Suarez)
    Re: File test (Richard Zilavec)
    Re: File test <e.quesada@verizon.net>
    Re: File test (Tad McClellan)
        flat file database question <adamm@stargate.net>
        help with no strict 'refs' (Richard Zilavec)
    Re: help with no strict 'refs' (Rafael Garcia-Suarez)
    Re: help with no strict 'refs' nobull@mail.com
    Re: help with no strict 'refs' (Tad McClellan)
    Re: help with no strict 'refs' (Richard Zilavec)
    Re: indexing web servers's content (Abigail)
    Re: just SELECT * from MSSQL 7.0 ?? (Abigail)
        looking for a critique - Thanks msalerno@my-deja.com
    Re: looking for a critique - Thanks (Tad McClellan)
        Net::Ftp and connection sumera.shaozab@lmco.com
    Re: Net::Ftp and connection <admin@j-enterprises.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 28 Dec 2000 19:19:11 +0100
From: "Alexander Farber (EED)" <eedalf@eed.ericsson.se>
Subject: Almost a one-liner: generating 4 digits out of an e-mail
Message-Id: <3A4B841F.D8960DC8@eed.ericsson.se>

Hi,

I would like to generate 4 digits out of an e-mail
address and mail them to the user, so that he/she
can enter it into my web form as verification:

  use Digest::HMAC_MD5;
  $SECRET  = 'shmablocks';
 ...

  ###########################################################
  # Generate a password (4 digits) out of an e-mail address #
  ###########################################################

  sub password ($)
  {
      my ($hmac, $digest);
      my $mail = shift;

      $hmac = Digest::HMAC_MD5 -> new ($SECRET);
      $hmac -> add ($mail);
      $digest = $hmac -> digest;

      return sprintf '%d%d%d%d', map {$_ % 10} unpack 'I4', $digest;
  }


Does anyone have a nicer/shorter suggestion or
notice some glitch here (like not-so-random numbers)?

Thank you
Alex


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

Date: Thu, 28 Dec 2000 08:46:25 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Code Review?
Message-Id: <slrn94mh1h.fpk.tadmc@magna.metronet.com>

Colin Watson <cjw44@flatline.org.uk> wrote:
>Arcana <emerald-arcana@home.com> wrote:
>>Does anyone here mind doing a review of my script and making appropriate 
>>comments?  I don't have specific problems, but I'd like to perhaps be 
>>enlightened in some of the finer points of programming.


>>    if ( $ARGV[0] eq "") {
>
>Perhaps 'if (@ARGV)'?


You should probably offer up a reason for that suggested change,
since it has a different semantic from the original.

   Perhaps 'if ( length $ARGV[0] )' 

could have gone unqualified, because it is equivalent. 
Your alternative is not equivalent to the original.

The original has the correct semantic if $ARGV[0] should happen
to be the empty string. The proposed change won't do The Right
Thing in that case...


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


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

Date: Thu, 28 Dec 2000 09:17:57 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Code Review?
Message-Id: <slrn94misl.fpk.tadmc@magna.metronet.com>

Arcana <emerald-arcana@home.com> wrote:
>Colin Watson wrote:

>> If you wanted to be more clever, you could have a hash from fields to
>> code references, where the referenced code does any special actions
>> required for individual fields. You could then iterate through that hash
>> with a 'foreach (keys %actions)' loop


What Colin describes above is known as a "dispatch table".


>Here I'm lost.  What I sense here is that the hashtable would store code 
>such that the code would execute based on which case?


Right.

The hash key would be an "action", the hash value would be a
reference to a subroutine (a "code ref") to execute when that
action is desired:

   $dispatch{savefile} = \&save_the_file;
   ...
   $dispatch{savefile}->();   # execute (call) the subroutine

>Do you have a reference or two for documentation I can look at?  I think I 
>need to do some research.  Thank you for your time!


All you really need to learn for this are "references":

   perldoc perlreftut
   perldoc perlref


There is also an example of a dispatch table in the Perl FAQ, part 7 under:

   "How do I create a switch or case statement?"

    my %commands = (
        "happy" => \&joy,
        "sad",  => \&sullen,
        "done"  => sub { die "See ya!" },
        "mad"   => \&angry,
    );


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


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

Date: Thu, 28 Dec 2000 10:33:31 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Code Review?
Message-Id: <slrn94mnab.g7h.tadmc@magna.metronet.com>

Tad McClellan <tadmc@metronet.com> wrote:
>Colin Watson <cjw44@flatline.org.uk> wrote:
>>Arcana <emerald-arcana@home.com> wrote:

>>>    if ( $ARGV[0] eq "") {
>>
>>Perhaps 'if (@ARGV)'?
>
>   Perhaps 'if ( length $ARGV[0] )' 
>
>could have gone unqualified, because it is equivalent. 


Doh!

   unless ( length $ARGV[0] )

would be equivalent. Sorry for saying the opposite of what
I was trying to say :-)


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


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

Date: 28 Dec 2000 18:22:03 GMT
From: cjw44@flatline.org.uk (Colin Watson)
Subject: Re: Code Review?
Message-Id: <92g0cb$av5$1@riva.ucam.org>

Tad McClellan <tadmc@metronet.com> wrote:
>Colin Watson <cjw44@flatline.org.uk> wrote:
>>Arcana <emerald-arcana@home.com> wrote:
>>>    if ( $ARGV[0] eq "") {
>>
>>Perhaps 'if (@ARGV)'?

Indeed, 'unless (@ARGV)', as your followup indirectly pointed out. :)

>You should probably offer up a reason for that suggested change,
>since it has a different semantic from the original.
>
>   Perhaps 'if ( length $ARGV[0] )' 
>
>could have gone unqualified, because it is equivalent. 
>Your alternative is not equivalent to the original.
>
>The original has the correct semantic if $ARGV[0] should happen
>to be the empty string. The proposed change won't do The Right
>Thing in that case...

That's true. Actually, both the original and yours give warnings if
there are no arguments, which I think was why I picked up on it in the
first place; 'unless (@ARGV and length $ARGV[0])' would be better and
otherwise equivalent.

I think I usually prefer just testing the length of @ARGV out of some
sense that if people are deliberately providing empty arguments then
they probably know what they're doing. (Are there any filesystems that
allow zero-length filenames?)

-- 
Colin Watson                                     [cjw44@flatline.org.uk]
"The game is on again / A lover or a friend
 A big thing or a small / The winner takes it all" - Abba


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

Date: 28 Dec 2000 11:11:03 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: convert decimal to hex???
Message-Id: <87r92sii8o.fsf@limey.hpcc.uh.edu>

>> On Thu, 28 Dec 2000 01:20:07 -0500,
>> "ben~" <hengst.1@osu.edu> said:

> sorry i'm new to perl, but i cant find a way to convert an integer
> to a hex value. I can do hex to integer but i need to go the other
> way.

To represent an integer value as a hexdecimal numeral:

    $hexnumeral = sprintf '%x', $value;

"perldoc -f sprintf"

hth
t
-- 
Eih bennek, eih blavek.


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

Date: 28 Dec 2000 17:08:56 GMT
From: The WebDragon <nospam@nospam.com>
Subject: Re: convert string to command?
Message-Id: <92fs38$1oq$0@216.155.32.209>

In article <slrn94h9rm.btt.tadmc@magna.metronet.com>, 
tadmc@metronet.com (Tad McClellan) wrote:

 | If you want to see them when running in a CGI environment, then
 | see the Perl FAQ, part 9:
 | 
 |    "How can I get better error messages from a CGI program?"

Something that I've been using ever since I discovered that CGI.pm could 
do it, was 

    use CGI::Carp qw(fatalsToBrowser set_message);
    BEGIN {

       sub handle_errors {
          my $msg = shift;
          print qq{<h2>aCk!</h2>};
          print qq{<p>I'm currently beta-testing some changes, so E-mail 
me, <a href="mailto:your\@e-mail.address.com">Your Name</a>, about this 
if it persists.</p><hr>};
          print qq{<p>Got an error:<br><br> $msg</p>};
          }

        set_message(\&handle_errors);
    }

which both dumps fatal errors to the browser (along with other bits) and 
also overrides the default admin e-mail address to be YOURS instead of 
the server owners (in cases where you are not also the hosting service, 
this can be important) along with the correct error message (instead of 
dumping it in the admin's server log file) 

very very useful. 

Have I mentioned that Lincoln Stein rocks?! :) 

If "Huzzah!" didn't sound so stupid, I'd be tempted to throw a few in. :D

-- 
send mail to mactech (at) webdragon (dot) net instead of the above address. 
this is to prevent spamming. e-mail reply-to's have been altered 
to prevent scan software from extracting my address for the purpose 
of spamming me, which I hate with a passion bordering on obsession.  


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

Date: 28 Dec 2000 17:25:29 GMT
From: The WebDragon <nospam@nospam.com>
Subject: Re: CPAN Eof error
Message-Id: <92ft29$1oq$2@216.155.32.209>

In article <pdT16.32437$xW4.255486@news-server.bigpond.net.au>, "John 
Boy Walton" <johngros@Spam.bigpond.net.au> wrote:

 | I am trying to use CPAN to update all the modules I have installed the 
 | CPAN
 | docs say
 | perl -MCPAN -e 'CPAN::Shell->install(CPAN::Shell->r)'
 | will do this.
 | 
 | But I am getting
 | Can't find string terminator "'" anywhere before EOF at -e line 1.
 | 
 | This is reminiscent of the EOF error people get when using the print
 | <<"HTMLDATA";
 | I have tried adding a space at the end of the line to no avail. Does 
 | anyone
 | know what I am doing wrong?

Here's something I saved a long time ago figuring it would prove useful 
at some time in the future :)

-=-
Tom Phoenix (rootbeer@redcat.com) wrote:
: This isn't trivial. Alas. But you can find all the .pm files along the 
old
: @INC, using a technique like the one shown here:
:     http://www.perlfaq.com/faqs/id/205
: Then you can check to see which of those modules is already available
: along the new @INC using a similar technique. After that, it shouldn't 
be
: too hard to run CPAN to install the module.

Tom, I cannot thank you enough. Your pointer lead me to this script:

#!/usr/local/bin/perl5.005_03 -w
use File::Find ;
foreach $start (@INC) { find(\&modules,$start) ; }
sub modules {
    if (-d && /^[a-z]/) { $File::Find::prune = 1 ; return }
    return unless /\.pm$/ ;
    my $filename = "$File::Find::dir/$_";
    $filename =~ s!^$start/!! ;
    $filename =~ s!\.pm$!!;
    $filename =~ s!/!::!g;
    print "$filename\n";
    }
    
the output of which I put into /tmp/mods.old . Then I wrote:

#!/usr/bin/perl -w
use CPAN ;
open (LIST,"/tmp/mods.old") ;
while (<LIST>) {
    chomp ;
    print "$_ \n";
    install $_ ;
    }

which took that file as input to CPAN and reinstalled all the modules.
I am right now doing the Snoopy happy dance. Thankyou again,

(originally posted by)
Danny Aldham     
Providing Certified Internetworking Solutions to Business
www.postino.com  
E-Mail, Web Servers, Mail Lists, Web Databases, SQL & Perl


HTH! :)

-- 
send mail to mactech (at) webdragon (dot) net instead of the above address. 
this is to prevent spamming. e-mail reply-to's have been altered 
to prevent scan software from extracting my address for the purpose 
of spamming me, which I hate with a passion bordering on obsession.  


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

Date: 28 Dec 2000 14:59:42 GMT
From: abigail@foad.org (Abigail)
Subject: Re: FAQ 6.21:   What's wrong with using grep or map in a void context?
Message-Id: <slrn94mlau.j0r.abigail@tsathoggua.rlyeh.net>

Tim Hammerquist (tim@degree.ath.cx) wrote on MMDCLXXVI September MCMXCIII
in <URL:news:slrn94l5f9.a3h.tim@degree.ath.cx>:
~~ Abigail <abigail@foad.org> wrote:
~~ > Tim Hammerquist (tim@degree.ath.cx) wrote on MMDCLXXV September MCMXCIII
~~ > in <URL:news:slrn94ijnl.9cd.tim@degree.ath.cx>:
~~ > ?? John Lin <johnlin@chttl.com.tw> wrote:
~~ > ?? > Hey, map and grep, you can save the trouble of building up a return list
~~ > ?? > when (not defined wantarray), right?  Don't blame the programmers.
~~ > ?? 
~~ > ?? Um, you can just use a for loop instead of map.  Then you don't waste
~~ > ?? the return list.  The chances that the implementation of grep() and
~~ > ?? map() will be changed are very slim with a construct so similar and
~~ > ?? frequently used already in existence.
~~ > 
~~ > Because one way of doing it in favour of another is all in the
~~ > spirit of Perl, right?
~~ 
~~ Good point, but why petition for a change in implementation when the
~~ contruct almost exactly like you'd be changing it to already exists?

Which construct is being suggested for change? map {} has been around
for quite a while. The concept of map predates Perl.

~~ > Besides, who needs both for, while, until, map, grep and bare blocks
~~ > when you can just use goto. Then you don't waste anything!
~~ 
~~ Ha ha.  =)
~~ 
~~ > The fact that map in void context is inefficient is a bug in perl, the
~~ > implementation. Not the language. Cure the disease, don't ridicule 
~~ > someone for the symptoms.
~~ 
~~ Is it inefficient?  Or is it just doing a lot of stuff that some
~~ programmers forfeit when using it in void context?  Or maybe both?

You were the person complaining about the return list being wasted,
so you make the call whether it's inefficient. But if it isn't why
bother suggesting a for loop instead of map?



Abigail
-- 
$" = "/"; split // => eval join "+" => 1 .. 7;
*{"@_"} = sub {foreach (sort keys %_) {print "$_ $_{$_} "}};
%_ = (Just => another => Perl => Hacker); &{%_};


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

Date: Thu, 28 Dec 2000 16:04:39 GMT
From: "Scaramouche" <e.quesada@verizon.net>
Subject: File test
Message-Id: <qwJ26.163$GX6.117276@paloalto-snr1.gtei.net>

I wrote the trivial script below that should tell me if a certain file is
binary or text, or so I thought.  I get nothing, no error msg, no warnings.
Does anyone know what I'm doing wrong ?

$fileName = $ARGV[0];
if( -e '$fileName')
{
 if( -T '$fileName'){print "\n$fileName is a text file.\n";}
 if( -B '$fileName'){print "\n$fileName is a binary file.\n";}
}
#strictly for debugging purposes
print "\n$fileName";




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

Date: Thu, 28 Dec 2000 16:12:00 GMT
From: pontz@NO_SPAM.channel1.com (Brian Pontz)
Subject: Re: File test
Message-Id: <3a4b65f4.4084533@news.e-dialog.com>

>$fileName = $ARGV[0];
>if( -e '$fileName')
>{
> if( -T '$fileName'){print "\n$fileName is a text file.\n";}
> if( -B '$fileName'){print "\n$fileName is a binary file.\n";}
>}
>#strictly for debugging purposes
>print "\n$fileName";

Your using single quotes where you should be using double quotes.

Brian Pontz



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

Date: Thu, 28 Dec 2000 16:13:09 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: File test
Message-Id: <slrn94mpk3.hrs.rgarciasuarez@rafael.kazibao.net>

Scaramouche wrote in comp.lang.perl.misc:
> I wrote the trivial script below that should tell me if a certain file is
> binary or text, or so I thought.  I get nothing, no error msg, no warnings.
> Does anyone know what I'm doing wrong ?
> 
> $fileName = $ARGV[0];
> if( -e '$fileName')

Variables are not interpolated into single quotes.
You're testing for the existence of a file whose name is $filename.

The right test is
  if (-e $fileName) { ... }
and, BTW, you should add an error message in case of the file does
not exist.

-- 
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: Thu, 28 Dec 2000 16:19:22 GMT
From: rzilavec@tcn.net (Richard Zilavec)
Subject: Re: File test
Message-Id: <3a4d6742.510593974@news.tcn.net>

On Thu, 28 Dec 2000 16:04:39 GMT, "Scaramouche"
<e.quesada@verizon.net> wrote:

>$fileName = $ARGV[0];
>if( -e '$fileName')
      ^^^^^^
singles quotes... should be double quotes or 
if(-e $fileName) {

The following shows what happenning...

$test = 'Hello';
print '$test' . "$test" . "\n";

You need double quotes to interpolate the variable.

--
 Richard Zilavec
 rzilavec@tcn.net


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

Date: Thu, 28 Dec 2000 17:42:47 GMT
From: "Scaramouche" <e.quesada@verizon.net>
Subject: Re: File test
Message-Id: <rYK26.205$GX6.166742@paloalto-snr1.gtei.net>

Thank you all for your much needed help.

"Richard Zilavec" <rzilavec@tcn.net> wrote in message
news:3a4d6742.510593974@news.tcn.net...
> On Thu, 28 Dec 2000 16:04:39 GMT, "Scaramouche"
> <e.quesada@verizon.net> wrote:
>
> >$fileName = $ARGV[0];
> >if( -e '$fileName')
>       ^^^^^^
> singles quotes... should be double quotes or
> if(-e $fileName) {
>
> The following shows what happenning...
>
> $test = 'Hello';
> print '$test' . "$test" . "\n";
>
> You need double quotes to interpolate the variable.
>
> --
>  Richard Zilavec
>  rzilavec@tcn.net




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

Date: Thu, 28 Dec 2000 10:47:17 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: File test
Message-Id: <slrn94mo45.g8c.tadmc@magna.metronet.com>

Brian Pontz <pontz@NO_SPAM.channel1.com> wrote:
>>$fileName = $ARGV[0];
>>if( -e '$fileName')
>>{
>> if( -T '$fileName'){print "\n$fileName is a text file.\n";}
>> if( -B '$fileName'){print "\n$fileName is a binary file.\n";}
>>}
>>#strictly for debugging purposes
>>print "\n$fileName";
>
>Your using single quotes where you should be using double quotes.
                                    ^^^^^^          ^^^^^^^^^^^^^

No he isn't.

He is using single quotes where he should be using no quotes at all!

:-)


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


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

Date: Thu, 28 Dec 2000 13:40:48 -0500
From: "Adam C. Mihlfried" <adamm@stargate.net>
Subject: flat file database question
Message-Id: <3A4B8930.58897065@stargate.net>

I was wondering if anyone has come across a good program that handles
flatfile databases through perl. More specifically one that can handle a
directory-like structure with category->subcategory->record information.

Sorry if this is the wrong newsgroup or anything.
Thanks
Adam
adamm@stargate.net



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

Date: Thu, 28 Dec 2000 16:13:26 GMT
From: rzilavec@tcn.net (Richard Zilavec)
Subject: help with no strict 'refs'
Message-Id: <3a4c5b8d.507596698@news.tcn.net>


In the following code I allowed refs, which occassionally I read about
in this NG, everybody says it bad to do.  The following works for me
but I'm interested in finding out if there is a more correct way of
writing the following code, suggestion, comments, etc.

use strict;
no strict 'refs';

my(%conf) = (
	# hashes I want to dump
	HASHES	=> ['ENV','in','cgi','sys'],
	DELIMITER	=> '=',
	PATH		=> '/somepath',
);

sub dumphashes {

	my ($self, $file) = @_;
	my ($hash, $key);

	open (OUT, "> $self->{'PATH'}/$file") or
		croak "$self->{'PATH'}/$file: $!\n";
	foreach $hash (@{$self->{'HASHES'}}) {
                	print OUT "[$hash]\n";
                        	foreach $key (keys %{$hash}) {
                                	print OUT $key .
$self->{'DELIMITER'} . $hash->{$key} . "\n";
                        	}
                }
                close(OUT);
}

Thanks..

--
 Richard Zilavec
 rzilavec@tcn.net


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

Date: Thu, 28 Dec 2000 16:41:18 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: help with no strict 'refs'
Message-Id: <slrn94mr8r.hvr.rgarciasuarez@rafael.kazibao.net>

Richard Zilavec wrote in comp.lang.perl.misc:
> 
> In the following code I allowed refs, which occassionally I read about
> in this NG, everybody says it bad to do.  The following works for me
> but I'm interested in finding out if there is a more correct way of
> writing the following code, suggestion, comments, etc.
> 
> use strict;
> no strict 'refs';

When you have to disable strict 'refs', you can disable it only in a
block. By doing so, you keep the strict checking of references in the
rest of your code.

> my(%conf) = (
> 	# hashes I want to dump
> 	HASHES	=> ['ENV','in','cgi','sys'],
> 	DELIMITER	=> '=',
> 	PATH		=> '/somepath',
> );
> 
> sub dumphashes {
> 	my ($self, $file) = @_;
> 	my ($hash, $key);
> 	open (OUT, "> $self->{'PATH'}/$file") or
> 		croak "$self->{'PATH'}/$file: $!\n";
> 	foreach $hash (@{$self->{'HASHES'}}) {
>                 	print OUT "[$hash]\n";
>                         	foreach $key (keys %{$hash}) {
>                                 	print OUT $key .
> $self->{'DELIMITER'} . $hash->{$key} . "\n";
>                         	}
>                 }
>                 close(OUT);
> }

In this particular case, it seems that hard references are OK, because
you're reading predefined variables, that look external. Pay attention
to package scoping issues : %ENV will be looked up in the main package,
the other hashes in the current one.

-- 
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: 28 Dec 2000 17:56:40 +0000
From: nobull@mail.com
Subject: Re: help with no strict 'refs'
Message-Id: <u9bstw77l3.fsf@wcl-l.bham.ac.uk>

rzilavec@tcn.net (Richard Zilavec) writes:

> In the following code I allowed refs, which occassionally I read about
> in this NG, everybody says it bad to do.

You mean you allowed _symbolic_ refs - which are, in general, a bad
solution to most problems.  Real refs are, in general, a good thing.

> The following works for me but I'm interested in finding out if
> there is a more correct way of writing the following code...

> my(%conf) = (
> 	# hashes I want to dump
> 	HASHES	=> ['ENV','in','cgi','sys'],
> );

my %conf = (
	# hashes I want to dump
	HASHES	=> [\%ENV,\%in,\%cgi,\%sys],
);

OTOH this may be one of those cases where symbolic refs are the right
approach in which case just put the "no strict 'refs'" right before
the point where you dereference the symbolic refs. 

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


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

Date: Thu, 28 Dec 2000 11:02:15 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: help with no strict 'refs'
Message-Id: <slrn94mp07.g8c.tadmc@magna.metronet.com>

Richard Zilavec <rzilavec@tcn.net> wrote:

>Subject: help with no strict 'refs'


I will not help you with that.


Subject: help with no no strict 'refs'
                   ^^^^^

*That* I would be eager to help you with :-)


>In the following code I allowed refs, which occassionally I read about
>in this NG, everybody says it bad to do.  


everybody is right.


>The following works for me


Driving without fastening my seat belt works for me.

[ Just because "something bad" has not yet happened, does not
  imply that it won't/can't happen  :-)
]


>but I'm interested in finding out if there is a more correct way of
>writing the following code, suggestion, comments, etc.


The "more correct" way would be to use real references instead of
symbolic references.


>use strict;
>no strict 'refs';
>
>my(%conf) = (
>	# hashes I want to dump
>	HASHES	=> ['ENV','in','cgi','sys'],


Store real references instead of strings (names):

   HASHES  => [ \%ENV, \%in, \%cgi, \%sys],


>sub dumphashes {

>	foreach $hash (@{$self->{'HASHES'}}) {


$hash used to be a string, repesenting the name of a hash,
but now it will be a (hard) reference to a hash instead.


>                        	foreach $key (keys %{$hash}) {
>                                	print OUT $key .
>$self->{'DELIMITER'} . $hash->{$key} . "\n";


None of that code needs to be changed at all.

There! Now you are getting the job done without evil Symbolic References.

You may now start to feel good about yourself  :-)


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


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

Date: Thu, 28 Dec 2000 18:29:08 GMT
From: rzilavec@tcn.net (Richard Zilavec)
Subject: Re: help with no strict 'refs'
Message-Id: <3a4b834d.1014960@news.tcn.net>

On Thu, 28 Dec 2000 16:41:18 GMT, rgarciasuarez@free.fr (Rafael
Garcia-Suarez) wrote:

>In this particular case, it seems that hard references are OK, because
>you're reading predefined variables, that look external. Pay attention
>to package scoping issues : %ENV will be looked up in the main package,
>the other hashes in the current one.

Hmmmm, this does lead to a problem, I was hoping to access the main
package hashes, can this be done?

In the main program:

use SomePackage;
my $test = "testing 123";

In the package:
print $main::test . "\n";

This fails, but I'm assuming there must be away to access $test in the
package SomePackage.

--
 Richard Zilavec
 rzilavec@tcn.net


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

Date: 28 Dec 2000 15:31:11 GMT
From: abigail@foad.org (Abigail)
Subject: Re: indexing web servers's content
Message-Id: <slrn94mn5v.j0r.abigail@tsathoggua.rlyeh.net>

Joseph (-nancy-@libero.it) wrote on MMDCLXXV September MCMXCIII in
<URL:news:g81k4tcd13b9gqutreuvatgv4pdmbujg07@4ax.com>:
"" Does anyone have a perl script that 
"" allows to browse the content of another server ?


    #!/opt/perl/bin/perl -w
    use strict;
    system mount => -F => 'nfs', "remote:/" => "/mnt";
    __END__


HTH. HAND.


Abigail
-- 
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"


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

Date: 28 Dec 2000 17:36:01 GMT
From: abigail@foad.org (Abigail)
Subject: Re: just SELECT * from MSSQL 7.0 ??
Message-Id: <slrn94mug1.j0r.abigail@tsathoggua.rlyeh.net>

Christian Tawfik (toughiq@i-one.at) wrote on MMDCLXXVI September MCMXCIII
in <URL:news:2o5m4tgis6kn7q1qs71i9ksj9u9m7ku983@4ax.com>:
 .. On 28 Dec 2000 12:08:54 +1100, "Kiel " <taboo@comcen.com.au> wrote:
 .. 
 .. >
 .. >Christian Tawfik <toughiq@i-one.at> wrote:
 .. >>hi,>
 .. >>i just want to execute a SELECT * in a perl script!
 .. >>
 .. >>perl is running on Solaris 2.6 and a MSSQL 7.0 server should be
 .. >>accessed.
 .. >>
 .. >>is there a possibility without installing DBD::Sybase module?? 
 .. >>(and setting up a workaround to get to this damn MS product?)
 .. >>
 .. >>or is there a direct way to connect to a MSSQL server??
 .. 
 .. 
 .. >open a pipe to mssql client.
 .. 
 .. hi,
 .. 
 .. this sounds good, but how to open a pipe to the microsoft sql server?

He said _client_, not server. You can of course connect to the server
using sockets, and talk the protocol that the server uses, but that
falls out of the scope of this newsgroup.

 .. AFAIK this pipe thing works with different jobs, but not to connect to
 .. a foreign host.
 .. 
 .. and if it works, have i the possibility to customize the SELECT
 .. statement?? (select what from which table)??

Well, yes, of course. 

You're much better off using a DBD:: module. But if you want to go
the hard way, it's fine with me.


Abigail
-- 
srand 123456;$-=rand$_--=>@[[$-,$_]=@[[$_,$-]for(reverse+1..(@[=split
//=>"IGrACVGQ\x02GJCWVhP\x02PL\x02jNMP"));print+(map{$_^q^"^}@[),"\n"


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

Date: Thu, 28 Dec 2000 17:45:22 GMT
From: msalerno@my-deja.com
Subject: looking for a critique - Thanks
Message-Id: <92fu7h$kd8$1@nnrp1.deja.com>

Please be honest. I know that this script will accomplish what I need it
to do, but I always like to read what other people would do to improve
it.

Thanks,
Matt

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

open(PASSWD, "</etc/passwd2") || die "ERROR: Cannot open $!\n";

my $search = "ern";
my %pwlist;
my $count = "1";
my $catalog = "1";
while (<PASSWD>) {
        my($user, $comment) = (split /:/)[0,4];
        if (lc($user) =~ /\Q$search/ or lc($comment) =~ /\Q$search/ ) {
                        $pwlist{$count} = [$user,$comment];
                        $count++;
                        }
                }

my $test = keys %pwlist;

foreach (sort keys %pwlist) {
print "Catalog # $catalog\tUser: $pwlist{$_}[0]\tComments:
$pwlist{$_}[1]\n";
$catalog++;


Sent via Deja.com
http://www.deja.com/


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

Date: Thu, 28 Dec 2000 11:40:48 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: looking for a critique - Thanks
Message-Id: <slrn94mr8g.gbp.tadmc@magna.metronet.com>

msalerno@my-deja.com <msalerno@my-deja.com> wrote:
>Please be honest. I know that this script will accomplish what I need it
>to do, but I always like to read what other people would do to improve
>it.



>my $count = "1";
>my $catalog = "1";


You use those as numbers, so they should _be_ numbers, not strings:

my $count = 1;


>        if (lc($user) =~ /\Q$search/ or lc($comment) =~ /\Q$search/ ) {


I looks like you are using pattern matching when you do not need to.

Is there some reason the code below won't work for you?


   if ( index( lc($user),    $search) >= 0 or 
        index( lc($comment), $search) >= 0    ) {



Your program looks pretty darn good as you had it though. 


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


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

Date: Thu, 28 Dec 2000 16:40:41 GMT
From: sumera.shaozab@lmco.com
Subject: Net::Ftp and connection
Message-Id: <92fqe8$gv4$1@nnrp1.deja.com>

Hello,

I need some help in trying to handle undefined value when the net::ftp
connection fails.  According to the manuel, when the CONSTRUCTOR for the
new Net::FTP object fails, undef will be returned and an error message
will be in $@. Before I tell the program to terminate, I would like to
send this error in a log file.  What would be a best way to this?

This is what I am trying to do:

$ftp = Net::FTP->new("myhost");
if ($ftp fails) {
    write to a log file
   }

also, if the login,cwd and get fail, what values are returned? How can I
handle their errors?

Any help is appreciated.

TIA

SAS


Sent via Deja.com
http://www.deja.com/


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

Date: Thu, 28 Dec 2000 18:50:21 GMT
From: GooglePlexed <admin@j-enterprises.com>
Subject: Re: Net::Ftp and connection
Message-Id: <92g21c$niu$1@nnrp1.deja.com>

 $ftp = Net::FTP->new("myhost");
 if (!defined($ftp)) {
     open(HANDLE,">>logfile.dat")||die "Cannot open logfile!";
     print HANDLE "FAILURE IN FTP: " . $@;
     close(HANDLE);
}

--
j-enterprises.com...
custom software solutions for the enterprise


Sent via Deja.com
http://www.deja.com/


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

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


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