[12128] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5728 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 19 19:07:31 1999

Date: Wed, 19 May 99 16:00:18 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 19 May 1999     Volume: 8 Number: 5728

Today's topics:
    Re: _Please_ improve localtime! esperanto@my-dejanews.com
    Re: about:  use strict; <cassell@mail.cor.epa.gov>
    Re: An /e for a match rather than a substitution (Tad McClellan)
    Re: best way to database stuff using Perl? <gellyfish@gellyfish.com>
    Re: CGI/ISAPI problem <sbansal@roartech.com>
    Re: Changing format of (long!) flat text file to make s <cassell@mail.cor.epa.gov>
    Re: Converting url encoded strings (eg. %20 to space) (Larry Rosler)
    Re: creating raw sockets with pack <gellyfish@gellyfish.com>
        Dynamic Naming of a Hash <jalil@corp.home.net>
    Re: Dynamic Naming of a Hash <tchrist@mox.perl.com>
    Re: email attachment bmccormack7477@my-dejanews.com
        How to make directory handles local? <anand@my-dejanews.com>
    Re: How to move a directory? <jalil@corp.home.net>
        Perl and Databases <jalil@corp.home.net>
    Re: PERLFUNC: ref - find out the type of thing being re (Larry Rosler)
    Re: PERLFUNC: ref - find out the type of thing being re <tchrist@mox.perl.com>
    Re: Printing hash of hashes. (Tad McClellan)
        Question about -T <gbc1@axe.humboldt.edu>
        Return Value from Sort subroutine jj@versys.com
        Seek on STDIN? <asharka@my-dejanews.com>
    Re: Y2K. localtime(time) <gellyfish@gellyfish.com>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Wed, 19 May 1999 21:28:17 GMT
From: esperanto@my-dejanews.com
Subject: Re: _Please_ improve localtime!
Message-Id: <7hvade$m39$1@nnrp1.deja.com>

In article <slrn7k4il1.1qh.fl_aggie@thepentagon.com>,
  fl_aggie@thepentagon.com wrote:
> On Tue, 18 May 1999 21:41:05 GMT, Daniel Pfeiffer
<occitan@esperanto.org>, in
> <7hsmpi$r6q$1@nnrp1.deja.com> wrote:
>
> + Going from 2 to 3 digits in the year returned by localtime is hardly
a
> + feature, though it should mostly avert the Y2k headaches.  This
likely
> + means touching a lot of proggies before year's end.
>
> What is so FSCKing hard about:
>
> $year=1900+(localtime)[5]; #add back the offset!
>
> Laziness is a virtue, but there's no virtue in not consulting the
docset.
>
> + So, hey, give us poor programmers a break.
>
> And to do so, you'll be breaking hundreds, if not thousands of other
> programs. No thanks.
>
> James
>


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---


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

Date: Wed, 19 May 1999 15:01:37 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: about:  use strict;
Message-Id: <374334C1.E0988A69@mail.cor.epa.gov>

Bart Lateur wrote:
> 
> David Cassell wrote:
> 
> >And also for rather small scripts, if yuo type like me.
> >                                       ^^
> >[example appearing conveniently here   || ]
> 
> "use strict" won't help if you have both variables $yuo and $you...

I make enough typos that I have a *few* rules about variable
names.  Like not having $lines and $liens in the same package.
:-)

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Wed, 19 May 1999 12:48:59 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: An /e for a match rather than a substitution
Message-Id: <r1quh7.29c.ln@magna.metronet.com>

Tom Christiansen (tchrist@mox.perl.com) wrote:
: [Posted and a courtesy copy mailed.]

: In article <vn9uh7.k1c.ln@magna.metronet.com> on Wed, 19 May 1999 
: 08:10:39 -0400, Tad McClellan <tadmc@metronet.com> says...

: > Steven Primrose-Smith (steven.peter.primrose-smith@avl.com) wrote:
: ....
: > : For example, if the user provides $string as "hello"
                          ^^^^^^^^^^^^^
                          ^^^^^^^^^^^^^
: > : and $expression as "he\w\wo", the statement:

: > my $expression = 'he\w\wo';

: You changed his comparison string to make it work.  :-)

   I didn't change his comparison string.

   He gave one only with a natural language description.

   Double quotes don't do backslash escapes in English.

   :-)



   He said he was reading it in.

   It does not appear as a literal in his code (of course we are
   all guessing here, since there wasn't any code provided).

   If he had given code showing it being read in, then I would
   have used that method. He didn't, so I didn't.

   Had to get a value in there _somehow_.


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


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

Date: 19 May 1999 21:34:11 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: best way to database stuff using Perl?
Message-Id: <7hvaoj$j6$1@gellyfish.btinternet.com>

In comp.lang.perl.misc Jared Hecker <jhecker@iago.nac.net> wrote:
> In comp.lang.perl Dr. A R Daniels <a.daniels@umist.ac.uk> wrote:
>> I have found that Win32 - ODBC works well.  Try the following web site for
> 
>> Note:  This only applies to WinNT based servers - and lets face it lots of
>> people (apart from the die hard 'shag microsoft' strange people) are moving
>> over to this platform according to a survey by a leading IT company over
>> here in the UK.
> 
> 
> Actually, here in the "colonies", Linux servers grew as much
> percentage-wise last year as NT for databases.  I would put an
> equally-configured box running Red Hat 5.2 against NT with both running,
> say, Oracle or Sybase any day of the week.
> 

I'd like to throw in Informix here as well,  I've got a copy of a largish
billing database from work on this here machine at home with a view to
shifting the 4GL code base over to a web-based system in Perl.


/J\ 
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Wed, 19 May 1999 18:49:03 -0400
From: Sharad Bansal <sbansal@roartech.com>
Subject: Re: CGI/ISAPI problem
Message-Id: <37433FDF.7B4AADCC@roartech.com>

Sorry, I can't help u with this. But, I have my own perl IIS issue . Did u try
to redirect STDERR ? ie
carpout(LOGG) ? IIS just gives an error witht this ...

It very well might be that Carp and File have bugs under IIS.

- Sharad

Gunther Schmidl wrote:

> I'm having huge troubles with below script (apart from the obvious bad
> style, probably, but I'm a beginner, so please bear with me :-). In
> interactive mode (that is, on the command line), everything works perfectly
> well - but if I want to run the script on a Microsoft IIS via Perl-ISAPI,
> 'File::Find' stops processing every file recursively and only 'does' the
> directories; this without my changing a single line. The script is running
> as IIS-Administrator, so I'm guessing it's not a security problem. Is there
> a bug in File::Find, am I doing something fundamentally wrong, or what is
> the matter?
>
> ===BEGIN INCLUDED FILE VOLLTEXT.PLX===
> Content-type: text/plain
> #! perl -w
> $| = 1;
>
> use CGI qw(:standard);
> # use CGI::Carp;
> use File::Find;
>
> my $dir = "archiv/";
> my $sdir = "c:/projekte/20jahre/archiv/";
>
> my $search = param("such") || "";
>
> print "<HTML><HEAD><TITLE>Results:</TITLE></HEAD><BODY>";
>
> if ($search eq "")
> {
>
>  print "<H1>Error: no parameter passed!</H1></BODY></HTML>";
>  exit;
> }
>
> sub search_text
> {
>  my $line;
>
>  # ignore non-.html files and directories
>  print $File::Find::name; # this is where it seems to break
>  return if ($File::Find::name !~ m/\.html/i);
>  return if (-d $File::Find::name);
>
>  # open file
>  open(FILE, $File::Find::name) || die "couldn't open file: $!";
>
>  # search
>  DOIT: while(defined($line = <FILE>))
>  {
>   if ($line =~ m/$search/ig)
>   {
>    close(FILE);
>    open(FILE, $File::Find::name);
>    print "<A HREF=\"$File::Find::name\">$File::Find::name</A>";
>    print "<PRE>";
>    for (my $i = 1; $i < 4; $i++)
>    {
>     $line = <FILE>;
>     $line =~ s/</&lt;/;
>     $line =~ s/>/&gt;/;
>     print "$line<BR>";
>    }
>    print "</PRE><HR>";
>    last DOIT;
>   }
>  }
>  close(FILE);
> }
> find(\&search_text, $sdir);
>
> print "</BODY></HTML>";
> ===END INCLUDED FILE VOLLTEXT.PLX===
> --
> +------------------------+----------------------------------------------+
> + Gunther Schmidl        + "I couldn't help it. I can resist everything +
> + Ferd.-Markl-Str. 39/16 +  except temptation"           -- Oscar Wilde +
> + A-4040 LINZ            +---------------+------------------------------+
> + Tel: 0732 25 28 57     + ICQ: 22447430 + IF: http://sgu.home.dhs.org/ +
> +------------------------+---+-----------+------------------------------+
> + gschmidl (at) gmx (dot) at + please remove the "xxx." before replying +
> +----------------------------+------------------------------------------+



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

Date: Wed, 19 May 1999 14:59:46 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: Changing format of (long!) flat text file to make searches faster
Message-Id: <37433452.577B0B79@mail.cor.epa.gov>

Eduardo Fernandez Corrales wrote:
> 
> Hello,
> 
> I want to make a catalog of articles searchable in Internet, via some
> CGI scripts in perl and
> forms in web pages.
> 
> I have a comma separated file, running about 70000 lines long, and have
> developed a simple cgi

a CGI 'script'?  'program'?

Is it in Perl?  If so, why aren't you showing it here [properly
trimmed to reduce eyeball injury]?  If not, then is this the
right newsgroup for your question?

> that searchs the fields in the file and outputs the results to a web
> page.
> 
> The problem though, is that this is too slow.

I can believe that.
 
> I need to convert the file to a format that makes searchs faster.
> 
> The search is made over two fields of the 8 that each register has.
> 
> -What kind of file format could I use?

I suggest you give up on keeping this a home-grown search system
on a CSV file, and investigate storing the data in a proper
database, with indices and enough normalization to reduce 
convenient parts of your problem.  Perl uses DBI and DBD::*
modules to access a wide variety of databases.  Perl comes with
at least one straightforward database as well.  It interfaces
beautifully with such free databases as GDBM and MySQL.
And, best of all, there's plenty of documentation included
with the Perl install.

> Thanks in advance.

HTH,
David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: Wed, 19 May 1999 14:30:22 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Converting url encoded strings (eg. %20 to space)
Message-Id: <MPG.11accd4a5823f59f989ab2@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <7hv6bb$2eb$1@planja.arnes.si> on Wed, 19 May 1999 22:17:09 
+0200, Bostjan Marusic <bostjan.marusic@megaklik.si> says...
> Is there a function that converts strings passed to the program with the
> url?
> Example:
> example.cgi?param1&string%20parameter%20with%20spaces
> 
> I would like to get this in to the form
> $ARGV[0] = param1
> $ARGV[1] = string parameter with spaces

I'm sure the CGI module would make this trivial.  However, for the 
module-deficient, the following 'one-long-liner' is easy too (and 
handles all URL escapes, not just %20-encoded spaces):

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

$_ = 'example.cgi?param1&string%20parameter%20with%20spaces';

@ARGV = !($_ = (split /\?/)[1]) ? () :
    map { tr/+/ /; s/%([\da-zA-Z]{2})/chr hex $1/eg; $_ } split /&/;

print "@ARGV\n";

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 19 May 1999 22:37:13 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: creating raw sockets with pack
Message-Id: <7hveep$kr$1@gellyfish.btinternet.com>

On Mon, 17 May 1999 19:18:24 GMT Corey Saltiel wrote:
> 
>   I'm a complete novice to network socket programming and would like
>   to learn using perl.  I'm pretty confident as a perl programmer,
>   and where/how/which docs to read for info - but I could really use
>   some pointers on the creation of raw headers/ ip packets.  

I'm sorry but I'm at a loss as to know why you want to start at what
would best be described as the 'Heavy Magic' end of the network
programming spectrum, a lot of network programming *is* done in Perl
but the vast majority of it is at the application layer, rather than
the transport or network layers as you seem to indicate.  The closest
thing that you will find (as far as I know anyhow) is the Net::RawIP
module available from CPAN :

<http://www.perl.com/CPAN/authors/id/S/SK/SKOLYCHEV/Net-RawIP-0.06.tar.gz>

>                                                             Looking
>   at the net modules code with the standard lib in perl I see the
>   use of the 'pack' function, however reading 'perldoc -f pack' leaves
>   me totally in the dust, as it does nothing to explain to explain
>   the purpose/method of it's use in the creation of raw sockets.
> 

The pack function has no direct connection to network programming, its
function is for the creation of binary or fixed length data structures,
and yes you will be using these in network programming of the sort you
describe, but its description in the documentation is generic to the
variety of uses it might be put.  You will need to refer to this
documentation in relation to the specification of the data structures
you will need to create.

>   If anyone would be so kind as to give me an example of some code generating
>   a standard ip header and explaining it - I would appreciate it emmensely.
> 

Quite honestly apart from the module cited above I cant think of any other
source I could tell you about.  

>   Or even just giving me some pointers to any perl related documentation on
>   this specific topic.
> 

Again I dont know of any such source, however I actually think you are
coming at this from the wrong direction:  If you want to learn network
programming at the level you describe then you are going to have to
look at texts specific to this subject, that deal with low-level 
networking issues - these are likely to be heavy on the theory and light
on the code examples and it is probable that what examples there are are
going to be in C or even assembler such is the nature of this area.  You
will find that you will get a better quality of answer from some newsgroup
with 'network' in its name - but again these people will mostly talk in C.

Of course you might be getting carried away with yourself, or have been
blinded by the technological marvel that is networking.  The vast majority
of network programming is at the application layer and the vast majority
of that is done to the Berkely Sockets API or some derivative thereof - the
network support in Perl is firmly rooted in this ground.  The perlipc
manpage describes the networking support in Perl and further examples
might be found in perlfaq8 & perlfaq9, you will also want to look at the
Socket manpage and possibly that for IO::Socket.  The libnet bundle of
modules provide classes for a variety of common protocols.

A good Sockets primer can be find in the 4.4BSD programmers reference -
if you dont have this available you will be able to find it at:

  <http://www.freebsd.org/docs/> # sorry cant remember the full URL

I'm beginning to get paranoid about your motivation behind this, but hey
we eat ScriptKiddies for breakfast ;-}

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Wed, 19 May 1999 22:02:13 GMT
From: "Jalil Feghhi" <jalil@corp.home.net>
Subject: Dynamic Naming of a Hash
Message-Id: <927151332.992880@zeppelin.svr.home.net>

Let' s assume I have two hash tables %X and %Y. I also have a scalar var in
my program: $a which is either "X" or "Y". How can I make a hash var that
points to my %X or %Y based on the value of $a. I dont want to do:

if ($a eq "X") {
# use %X
}
else{
# use %Y
}


Rather, I like something like:

%($a);

Is there a way to do this?

Thanks,

-Jalil





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

Date: 19 May 1999 16:10:45 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Dynamic Naming of a Hash
Message-Id: <374336e5@cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    "Jalil Feghhi" <jalil@corp.home.net> writes:
:Let' s assume I have two hash tables %X and %Y. I also have a scalar var in
:my program: $a which is either "X" or "Y". How can I make a hash var that
:points to my %X or %Y based on the value of $a. 

You make a multi-level hash.

--tom

=head2 How can I use a variable as a variable name?

Beginners often think they want to have a variable contain the name
of a variable.

    $fred    = 23;
    $varname = "fred";
    ++$$varname;         # $fred now 24

This works I<sometimes>, but it is a very bad idea for two reasons.

The first reason is that they I<only work on global variables>.
That means above that if $fred is a lexical variable created with my(),
that the code won't work at all: you'll accidentally access the global
and skip right over the private lexical altogether.  Global variables
are bad because they can easily collide accidentally and in general make
for non-scalable and confusing code.

Symbolic references are forbidden under the C<use strict> pragma.
They are not true references and consequently are not reference counted
or garbage collected.

The other reason why using a variable to hold the name of another
variable a bad idea is that the question often stems from a lack of
understanding of Perl data structures, particularly hashes.  By using
symbolic references, you are just using the package's symbol-table hash
(like C<%main::>) instead of a user-defined hash.  The solution is to
use your own hash or a real reference instead.

    $fred    = 23;
    $varname = "fred";
    $USER_VARS{$varname}++;  # not $$varname++

There we're using the %USER_VARS hash instead of symbolic references.
Sometimes this comes up in reading strings from the user with variable
references and wanting to expand them to the values of your perl
program's variables.  This is also a bad idea because it conflates the
program-addressable namespace and the user-addressable one.  Instead of
reading a string and expanding it to the actual contents of your program's
own variables:

    $str = 'this has a $fred and $barney in it';
    $str =~ s/(\$\w+)/$1/eeg;		  # need double eval

Instead, it would be better to keep a hash around like %USER_VARS and have
variable references actually refer to entries in that hash:

    $str =~ s/\$(\w+)/$USER_VARS{$1}/g;   # no /e here at all

That's faster, cleaner, and safer than the previous approach.  Of course,
you don't need to use a dollar sign.  You could use your own scheme to
make it less confusing, like bracketed percent symbols, etc.

    $str = 'this has a %fred% and %barney% in it';
    $str =~ s/%(\w+)%/$USER_VARS{$1}/g;   # no /e here at all

Another reason that folks sometimes think they want a variable to contain
the name of a variable is because they don't know how to build proper
data structures using hashes.  For example, let's say they wanted two
hashes in their program: %fred and %barney, and to use another scalar
variable to refer to those by name.

    $name = "fred";
    $$name{WIFE} = "wilma";     # set %fred

    $name = "barney";           
    $$name{WIFE} = "betty";	# set %barney

This is still a symbolic reference, and is still saddled with the
problems enumerated above.  It would be far better to write:

    $folks{"fred"}{WIFE}   = "wilma";
    $folks{"barney"}{WIFE} = "betty";

And just use a multilevel hash to start with.

The only times that you absolutely I<must> use symbolic references are
when you really must refer to the symbol table.  This may be because it's
something that can't take a real reference to, such as a format name.
Doing so may also be important for method calls, since these always go
through the symbol table for resolution.

In those cases, you would turn off C<strict 'refs'> temporarily so you
can play around with the symbol table.  For example:

    @colors = qw(red blue green yellow orange purple violet);
    for my $name (@colors) {
        no strict 'refs';  # renege for the block
        *$name = sub { "<FONT COLOR='$name'>@_</FONT>" };
    } 

All those functions (red(), blue(), green(), etc.) appear to be separate,
but the real code in the closure actually was compiled only once.

So, sometimes you might want to use symbolic references to directly
manipulate the symbol table.  This doesn't matter for formats, handles, and
subroutines, because they are always global -- you can't use my() on them.
But for scalars, arrays, and hashes -- and usually for subroutines --
you probably want to use hard references only.
-- 
 "A man who has never gone to school may steal from a freight car;
 but if he has a university education, he may steal the whole
 railroad." -T Roosevelt


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

Date: Wed, 19 May 1999 21:21:33 GMT
From: bmccormack7477@my-dejanews.com
Subject: Re: email attachment
Message-Id: <7hva0q$lnq$1@nnrp1.deja.com>

In article <7h7ca0$ft$1@gellyfish.btinternet.com>,
  Jonathan Stowe <gellyfish@gellyfish.com> wrote:
> On Mon, 10 May 1999 17:24:09 +0100 David Craig wrote:
> >>MIME::Lite is available from CPAN the documentation that comes with
it has
> >
> >
> > Thanks for that, I found it and the documentation, I am having
difficulty
> > extracting the module.  The instructions for use I guess are on a
UNIX
> > machine - I'm running WIN32.  Do you have the module to hand that
you could
> > mail me?
> >
>
> Er.  If you are using a recent ActiveState Perl then you will be able
to
> use PPM to install it which is by far the best thing to do ...
>
> /J\
> --
> Jonathan Stowe <jns@gellyfish.com>
> Some of your questions answered:
> <URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
> Hastings:
<URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>
> You can just extract lite.pm and put in the path
 $yourPerlDirectory/lib/MIME/lite.pm


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---


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

Date: Wed, 19 May 1999 22:15:02 GMT
From: Anand <anand@my-dejanews.com>
Subject: How to make directory handles local?
Message-Id: <7hvd54$o2e$1@nnrp1.deja.com>

Perl beginner (reading "Learning Perl") asks:

I am trying to write a recursive perl subroutine to print the unix
directory tree. So the subroutine needs to recursively open directories.
For this I need to make the directory handle (that I use in opendir)
local. How do I do it?

Thanks
Anand

P.S: Here is my subroutine which will not work because the directory
handle is not defined local:

sub printdir {
    local($file,$pathname);
    opendir(DIR,$_[0]) || die "opendir failed for $_[0]\n";
    while ($file = readdir(DIR)) {
	$pathname = $_[0]."/$file";
	if (-d $pathname && $file ne "." && $file ne "..") {
	    print "$file\n";
	    &printdir($pathname);
	}
    }
    closedir(DIR);
}


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---


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

Date: Wed, 19 May 1999 22:11:14 GMT
From: "Jalil Feghhi" <jalil@corp.home.net>
Subject: Re: How to move a directory?
Message-Id: <927151874.617016@zeppelin.svr.home.net>

I also noticed that rename does not work accross file system boundaries or
network, which is what I want

Is there any perl function or module that can help me with that? Or, should
I write my own function and move all the files one by one?

Thanks,

-Jalil

David Cassell wrote in message <3741FB52.96BAC4D9@mail.cor.epa.gov>...
>Tad McClellan wrote:
>>
>> Jalil Feghhi (jalil@corp.home.net) wrote:
>> : Is there a function for moving directories in Perl?
>>
>>    Yes. The same one that moves files.
>>
>>       perldoc -f rename
>
>But.. Tad didn't bother to mention that `rename' has some
>portability issues that you might want to investigate
>before getting too deeply enmired.  Read the perlport
>POD page.
>
>HTH,
>David
>--
>David Cassell, OAO                     cassell@mail.cor.epa.gov
>Senior computing specialist
>mathematical statistician




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

Date: Wed, 19 May 1999 22:07:38 GMT
From: "Jalil Feghhi" <jalil@corp.home.net>
Subject: Perl and Databases
Message-Id: <927151658.525511@zeppelin.svr.home.net>

Is there any database module in Perl (other that dbm)? For example, any way
to interface with an Access (or any other) database on Windows?

Thanks,

-Jalil





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

Date: Wed, 19 May 1999 14:01:58 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: PERLFUNC: ref - find out the type of thing being referenced
Message-Id: <MPG.11acc6a18a9fb814989ab1@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <374315af@cs.colorado.edu> on 19 May 1999 13:49:03 -0700, Tom 
Christiansen <perlfaq-suggestions@perl.com> says...
 ...
>         REF  <--- duplicated
>         SCALAR
>         ARRAY
>         HASH
>         CODE
>         GLOB
>         REF  <--- duplicated
>         LVALUE

How does one get LVALUE?  If I have a ref to a scalar lvalue, for 
example, I get SCALAR; similarly for the other types.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 19 May 1999 16:13:10 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: PERLFUNC: ref - find out the type of thing being referenced
Message-Id: <37433776@cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, lr@hpl.hp.com (Larry Rosler) writes:
:How does one get LVALUE?  

    $name = "Fred Flintstone";
    $rl = \substr($name, 5, 5);
    $$rl = "Cobble";
    print "$name\n";
Fred Cobblestone

--tom
-- 
    echo "Your stdio isn't very std."
            --Larry Wall in Configure from the perl distribution


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

Date: Wed, 19 May 1999 09:04:51 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Printing hash of hashes.
Message-Id: <jtcuh7.a4c.ln@magna.metronet.com>

rajeshsharda@my-dejanews.com wrote:

:   I have a hash array.
:   The values in this hash array are the names of the other hash arrays.
                                          ^^^^^^^^           ^^^^^^^^^^^

:   Is there any way I can print the key-value pair of the hash arrays
: which are in the values of the first hash array?


   Yes.


:    first hash is: $first_hash
:    its contents are:
:     Key           Value
:     a             A


:   Here, the values A,B,C,D are hash arrays in themselves. how does one
                                 ^^^^^^^^^^^    ^^^^^^^^^^
: can print the key/value of the hash array A(or B or C or D or all of
: them)? We don't know the keys/values which will exist in the hash array
: A/B/C/D.


   You have said the the values in %first_hash are names, and that
   they are hashes.

   Which is it?



   Why do folks stumble around attempting to describe things in
   ambiguous natural language when they are unambiguously
   and more succinctly said with real Perl code?

   If you had said it in Perl code, then not only would people
   know for sure what you meant, but they also might be able
   to correct the code for you.


If values are names:

my %first_hash = ( a => 'A', b => 'B', c => 'C' );
my %A;
my %B;
my %C;


If values are hashes:

my %first_hash = (  a => { A1 => 1, A2 => 2 },  # hash "A"
                    b => { B1 => 3, B2 => 4 },  # hash "B"
                    c => { C1 => 5, C2 => 6 },  # hash "C"
                 );


   How you do it is different for the 2 cases that you say you have.

   If the values are _names_ of hashes, then don't do that
   (symbolic references are a Very Bad Idea).

   If the values are anonymous hashes, then:


foreach my $hashkey ( keys %first_hash ) {
   my $hashref = $first_hash{$hashkey};
   foreach my $key ( sort keys %$hashref ) {
      print "$key  ==>  $$hashref{$key}\n";
   }
}


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


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

Date: Wed, 19 May 1999 14:13:16 -0700
From: Greg Coit <gbc1@axe.humboldt.edu>
Subject: Question about -T
Message-Id: <3743296C.C9D1885E@axe.humboldt.edu>

Hello all,

a snippet of code is giving me problems while running my script under
-T:

 @mispelled = system 'spell', "${base}/storage/${id}.spell";

which is generating this error:

Insecure directory in $ENV{PATH} while running with -T switch at ...

In this script, $base is a hard coded variable (assigned at the top of
the script), and $id has been untainted.  This error is not generated
when I try to open the file ${base}/storage/${id}.spell for writing,
only when trying to send it to spell.  After reading perlsec, I think
the problem is that one of these directories is writable by other than
the owner or group:

$ENV{"PATH"} = "/usr/local/bin:/usr/bin:/bin:/usr/sbin:.";
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};

Does my guess at the problem seem correct?  If so,  I don't have any
control over these directories.  Any way of temporarily disabling -T for
this subroutine?  Any other way around this?

Thanks in advance for any help and advice.

--
Greg Coit                                                         =^
Email: gbc1@humboldt.edu - Phone: (707)826-6109 - FAX: (707)826-6100
Humboldt State University: Computing and Telecommunications Services
********************************************************************
*Linux is not The Answer. Yes is the answer. Linux is The Question.*
********************************************************************




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

Date: Wed, 19 May 1999 22:43:56 GMT
From: jj@versys.com
Subject: Return Value from Sort subroutine
Message-Id: <7hverb$pat$1@nnrp1.deja.com>

Have mercy, I am only beginning to learn about the wonderful world of
Perl.  i have never programmed previously and the _return_ value from
the customized sort subroutines has me stumped.  All the documention I
have on this seems to assume that i am knowledgeable about this type of
function.  i am not.  Does the subroutine evaluate every item in the
list against every other item in the list?  How does the return _value_
re-order the data?  Is it just that the return value of -1,0,or 1
determines which item should be where and it moves it appropriately (via
the magic of Perl) and there is nothing more to know?  If so, then I
guess I have answered my own question, otherwise any help would be
appreciated.  Thanks


--== Sent via Deja.com http://www.deja.com/ ==--
---Share what you know. Learn what you don't.---


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

Date: Wed, 19 May 1999 16:10:19 -0500
From: Al Sharka <asharka@my-dejanews.com>
Subject: Seek on STDIN?
Message-Id: <374328BB.2055@my-dejanews.com>

So you've finally convinced me to use the magic wand.  I feel like the
sorcerer's apprentice though.  Ouch! Ow!  Stop throwing things.  Weren't
you a newbie once?  Anyway, here's my question.  I need to read a very
large compressed fixed record file with mixed integer, packed decimal,
and ebcdic data, and send formatted output to STDOUT.  I *have* to use
Revision: 4.0.1.8 Patch level: 36, because that's the distributed
vendor "supported" Perl on Aix 4.3, and I have no "C" compiler.

I want to make the program display from the start of the file if no
ARGV[1] is present, but start at a record offset if one is given.
I have gotten something to work, probably inefficiently, but I can't
seem to get seek to skip to where I want it to.  Do I have to use a
read loop to accomplish what I want?  It seems like it would be more
efficient to use seek if I could.  Here's how I execute the code
(I have taken bits from Dejanews, Programming Perl, and Perl Cookbook):

reader BIGFILE.Z 1000000 | pg

--Here's the code for reader --
#!/usr/lpp/ssp/perl/bin/perl
# set up EBCDIC to ASCII conversion function (which works ok)
$set = join('', grep($_ = sprintf("\\0%lo", $_), 0..255));
$a = `echo '$set\\c' | dd conv=ascii 2>/dev/null`;
$a = unpack("H*", $a);
$a =~ s/../\\x$&/g;
eval "sub toascii  { for (\@_) { tr//$a/c } }";

open(README, "zcat $ARGV[0] |") || die "Couldn't fork: $!\n";

$RECORDSIZE=68;
$TEMPLATE="i H14 i a5 s H16 H14 H4 H14 H16 H14 H14";

#this doesn't work to skip records.  What's wong here?
seek(README, $RECORDSIZE * $ARGV[1], 0) if $ARGV[1];

until ( eof(README) ) {
#(one) unpack.  Process 12 fields, then use "write" with a "format"
#statement.  This part works seemingly ok.  Is format slower than
#separate print statements?  Several of the fields would need printf.
}
close(README);
exit;
#format statemet here
--end readme--
-- 
Al Sharka <asharka@my-dejanews.com>


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

Date: 19 May 1999 20:57:49 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Y2K. localtime(time)
Message-Id: <7hv8kd$j0$1@gellyfish.btinternet.com>

On Wed, 19 May 1999 12:08:15 -0700 Larry Rosler wrote:
> [Posted and a courtesy copy mailed.]
> 
> In article <3742e3cd.0@usenet.fccj.cc.fl.us> on Wed, 19 May 1999 
> 12:17:13 -0400, Bill Jones <bill@fccj.org> says...
> ...
>> > [about Matt's script archive]
> ...
>> Which ones do you find more worthwhile to rewrite ?
>> (Some should be dumped and started over...)
> 
> The only one I have used (actually, passed on to a non-Perl-programmer 
> to use) is formmail, which simply accepts CGI input from a static HTML 
> form and generates e-mail with the form's field contents.  The 
> 'sendmail' address is probably hard-wired into the program.
> 
> In addition to being '-w' and 'use strict;' intolerant, this script does 
> inadequate error checking.  That is probably typical of all of the 
> scripts.  But the 'logic' of this particular dummy is probably adequate, 
> and maybe for all of them.  After all, they are supposed to be 
> functional, no?
> 

Just for fun I printed out the aforementioned wwwboard.pl so I could take
a good look at it on the train home (and two hours is easily enough).

Aside from the previously mentioned 19$year atrocity it commits two other
instances of treating $year as a two digit number between 0 and 99.

Other date handling is to say the least eccentric:

   if ($sec < 10 )
     {
       $sec = "0$sec";
     }

And so on.

There is one instance of an unchecked open - all others use '|| die $!'
there being no handler for this occurrence, presumably yielding a '500'
error to the confused user.  There is no file locking protecting any of
the files.  

scalar variables are consistenly quoted on the RHS of an assignment, and
in print statements when they are the only things being printed.

There are several instances of numbers being quoted on the RHS of an
assignment.

Consistent use of :

  if ($variable == 0 )
    {

    }

Constructs where $variable is only used as a boolean flag.

I particularly like :

  chop($date) if ( $date =~ /\n$/ );

OK it says it was last modified on 25/11/95 so perhaps we could let that
slide ;-P

Of course no here-documents are used when printing large chunks of HTML.

Some dubious logic to do with dequoting:

   if( $FORM{'body'}){
  
     $body = "$FORM{'body'}";

     # snip some substitutions on $body

     $body =~ s/&lt;/</g;
     $body =~ s/&gt;/>/g;
     $body =~ s/&quot;/"/g;
   }
   else {
     &error(no_body); 
   }

   if ($quote_text == 1 ) {
     $hidden_body = "$body";
     $hidden_body =~ s/</&lt;/g;

     # You get the picture
   }


I only just noticed that bare word there - weird in the context of the rest
of the quoting paranoia.     

    
And so on.

I won't even begin to describe the rococo storage mechanism.  I'll leave
that for the readers entertainment.

Anyhow I think it would probably be kinder to take it for 'the long walk'.

The worrying thing is that this is a fairly popular program - infact it
could possibly be suggested that quite a lot of the stranger notions
that are exhibited in this group could be derived from this peculiar
piece of code.

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

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


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 5728
**************************************

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