[9588] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3182 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 17 05:58:05 1998

Date: Thu, 16 Jul 98 21:00:34 -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           Thu, 16 Jul 1998     Volume: 8 Number: 3182

Today's topics:
    Re: %vHash = $vScalar doesn't work, why? <mpersico@erols.com>
        (Semi-)Repeatable SDBM problem in v5.004_04 and SunOS 5 <s-max@pacbell.net>
    Re: client server programming (Eric Weiss)
    Re: clp.moderated <rra@stanford.edu>
        confusing problem with perl make <mcmahan@cs.utk.edu>
    Re: efficiency: print<<"xxx" vs. print <tchrist@mox.perl.com>
    Re: Indentation <rra@stanford.edu>
        Javascript History -1 (Need the Perl equivalent) swhite@accessonline.com
    Re: Javascript History -1 (Need the Perl equivalent) (Martien Verbruggen)
    Re: newbie date format (Larry Rosler)
    Re: open (IN, "foo.txt") works, open (IN, "$foo") does  <mpersico@erols.com>
    Re: Perl 5.0005 for  Win32 ? (Eric Weiss)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Thu, 16 Jul 1998 22:38:47 -0400
From: "Matthew O. Persico" <mpersico@erols.com>
Subject: Re: %vHash = $vScalar doesn't work, why?
Message-Id: <35AEB937.7A87802A@erols.com>

Which is one reason why, I imagine, => was invented:

%hSDFInfo = ("NAME" => "Scott", 
	     "DESC" => "5ft10inches");

And with '=>' or ',' I think you need the parens.

Access is with $hSDFInfo{NAME} which yields "Scott".

Alternatively:

$hrSDFinfo = {"NAME" => "Scott", 
	     "DESC" => "5ft10inches"};

Now you have a hash reference. The difference:

1) Access:

	$hrSDFInfo->{NAME} yields "Scott".

2) Usage.

	If you were to pass $hSDFInfo into a subroutine, it would get flattened
and you'd lose the "hashiness" of it. To preserve, you'd have to pass a
reference like this: \%hSDFInfo. Since $hrSDFInfo is ALREADY a hash ref,
you pass $hrSDFInfo.

BTW, I am glad to see that SOMEONE ELSE besides me uses a "hungarian
notation" type of varialble naming. I'm sure that I'm about to get
flamed by many, many Perl hackers who will say that you can always tell
by the punctuation ($ or -> or {} or [], etc.) what something is.

Well that may be true but when I pass

	$junk

into a subroutine, how does the reader of my code know what junk is
without searching for the subroutine to see how its used OR slogging
through the previous code to find out how I defined it. A little bit of
hungarian can be quite a bit of help.

When I first started Perling, I used it all over the place. I have now
restricted its use strictly to refs. hr for hash ref, ar for array ref.
It may seem like overkill, but it makes debugging production problems at
2am a lot easier.



Steve Linberg wrote:
> 
> In article <6oldgs$av4@bilbo.ShireNet.com>, crusader@bilbo.ShireNet.com
> (Scott Cherkofsky) wrote:
> 
> > I've got a simple problem that's been driving me bonkers.  why doesn't
> > the following code work?
> >
> >         $vSDFGuts = "NAME,Scott,DESC,5ft10inches";
> >         %hSDFInfo = $vSDFGuts;
> >
> > I can't get $hSDFInfo{NAME} to give me back Scott!
> 
> Of course not.  You didn't put anything into $hSDFInfo{NAME}, so why
> should it give you anything back?
> 
> Try this:
> 
> $hSDFInfo{"NAME"} = "Scott";
> 
> You can't equate a scalar and a hash.  "NAME,Scott,DESC,5ft10inches" is a
> scalar string.  Maybe you were thinking of
> 
> %hSDFInfo = "NAME", "Scott", "DESC", "5ft10inches";
> 
> See the difference?
> 
> > any help would be muchly appreciated.  Ya know, its funny but in all of
> > the Nutshell books on PERL, not one of them (and I have 3) mentions or
> > gives examples for populating HASH's using Scalar variables containing
> > comma delimited values.
> 
> The Camel, and the free documentation on your system, go into this in
> depth.  Read up!  :)
> _____________________________________________________________________
> Steve Linberg                       National Center on Adult Literacy
> Systems Programmer &c.                     University of Pennsylvania
> linberg@literacy.upenn.edu              http://www.literacyonline.org


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

Date: 16 Jul 1998 20:52:57 -0700
From: Scott Maxwell <s-max@pacbell.net>
Subject: (Semi-)Repeatable SDBM problem in v5.004_04 and SunOS 5.5.1
Message-Id: <m3u34h2kx2.fsf@localhost.localdomain>


I'm getting a semi-repeatable error (happens almost always, but not
always) using SDBM_File with Perl 5.004_04 and SunOS 5.5.1.  The
appended script, written to demonstrate the problem, works fine until
1550 records have been stored in the SDBM_File database (which I
remove before running the script).  At that point, keys(%Db) reports
that there are only 1490 keys in the file.

So far, I've observed the problem only when storing the database in
/tmp; storing it in other directories doesn't *seem* to be a problem,
but since the behavior isn't 100% repeatable, I'm not sure of that
yet.  (/tmp has plenty of room, BTW.)  Also, I haven't been able to
reproduce the behavior on my Linux box (Perl 5.004_01, RHS Linux 5.1,
kernel version 2.0.32).

Since I have no experience with SDBM, I'm quite willing to believe I'm
doing something wrong -- but I've been staring at the code for a while
now, not seeing it, and I'd sure appreciate some help.


#!/usr/bin/perl -w

require 5.000;
use strict;

$[ = 0;				# Set array base to 0.
$\ = "\n";			# Set output record separator.
select(STDERR); $| = 1;		# Flush output buffer (STDERR).
select(STDOUT); $| = 1;		# Flush output buffer (STDOUT).


use Fcntl;			# Import O_* constants.
use Fcntl ':flock';		# Import LOCK_* constants.
use SDBM_File;			# Access SDBM files.




################
#
# "Constants."
#
################

my $DB_FILE = '/tmp/test.sdbm';	# Basename of files storing the SDBM data.




################
#
# Globals.
#
################

my %Db = ();			# Hash tied to database.




################
#
# The code really starts here.
#
################

tie(%Db, 'SDBM_File', $DB_FILE, O_RDWR|O_CREAT, 0640);
unless (defined(tied(%Db))) {
    print STDERR "Can't tie %Db to '$DB_FILE'.";
    exit(1);
}

while (1) {
    # See how many entries are in the database and enter a new one.
    my $count = &CountKeys();
    ++$count;
    $Db{$count} = $count;

    printf('%d%s',
	   $count,
	   ($count % 10)  ?  "\t"  :  "\n");

    # Make sure that the count now reported by the database agrees with
    # the predicted count.
    my $newCount = &CountKeys();
    if ($count != $newCount) {
	print STDERR "\n$count != $newCount";
	exit(1);
    }
}

# Not reached.
untie(%Db);
exit(0);




################################################################
#
# Return the number of keys in %Db.
#
################################################################

sub CountKeys {
    return scalar(@{ [ keys %Db ] });
}

__END__
-- 
-------------------------+----------------------------------
R H L U  Scott Maxwell:  | ``What the world needs now is
E A I X      s-max@      |   killfiles that actually kill.''
D T N 5    pacbell.net   |     -- Craig Dickson


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

Date: Thu, 16 Jul 1998 22:16:00 -0400
From: eweiss@winchendon.com (Eric Weiss)
Subject: Re: client server programming
Message-Id: <MPG.10187de8e032b2009896e7@news.dgsys.com>

There are some examples on socket level client server programming
in the camel book (a/k/a Programming Perl).  You can also check the
pod (plain old documentation) on perl which usually is under the lib
directory.

Of course client server covers a multitude of sins and virtues from
socket level stuff to Oracle to C/C++.  If you were more specific, we
could help more.

Eric


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

Date: 16 Jul 1998 20:25:57 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: clp.moderated
Message-Id: <m3d8b5upiy.fsf@windlord.Stanford.EDU>

Cameron Dorey <camerond@mail.uca.edu> writes:

> When (c.l.p.moderated -e) {
>      Please announce here, for (voice_of_experience=1) {
>           I don't trust my newsserver's feed to get the group
>                to me without a hassle;
>           }
>      }

It exists.  If it hasn't shown up at your site yet, time to start bugging
your local news admin.  :)

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Thu, 16 Jul 1998 22:08:42 -0400
From: Paul McMahan <mcmahan@cs.utk.edu>
Subject: confusing problem with perl make
Message-Id: <35AEB22A.EDD7925F@cs.utk.edu>

# uname -a
SunOS foo 5.5.1 Generic_103640-21 sun4u sparc SUNW,Ultra-Enterprise

# make test
[...]
base/cond.........ok
base/if...........ok
base/lex..........ok
base/pat..........ok
base/term.........panic: corrupt saved stack index, <try> chunk 1.
panic: corrupt saved stack index, <try> chunk 1.
panic: corrupt saved stack index, <try> chunk 1.
panic: corrupt saved stack index, <try> chunk 1.
panic: corrupt saved stack index, <try> chunk 1.
[ ...and so on... ]

Can anyone help me?

thanks,
Paul McMahan
Univ of Tennessee


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

Date: 17 Jul 1998 01:49:42 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: efficiency: print<<"xxx" vs. print
Message-Id: <6omajm$fqi$1@csnews.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:
:Real Programmers don't write comments!  Seriously, comments should deal 
:with higher-level function, not with implementation details, which should 
:speak for themselves (assuming the reader knows the language).

Why is it that so few programmers ever figure this out?  Even the
millionth time you see an "add one to i" comment, it doesn't help.

--tom

    Basically, avoid comments. If your code needs a comment to be
    understood, it would be better to rewrite it so it's easier to
    understand.  --Rob Pike

-- 
"All things are possible, but not all expedient."  (in life, UNIX, and perl) -me


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

Date: 16 Jul 1998 20:10:03 -0700
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Indentation
Message-Id: <m3iukxuq9g.fsf@windlord.Stanford.EDU>

Matthew H Gerlach <gerlach@netcom.com> writes:
> scribble@pobox.com writes:
>> rra@stanford.edu writes:

>>> Editors really should not insert tabs for anything.

>> I'll take that as the crux of the whole matter. Consider me a convert.

> I'm a convert too, but you better remember to turn tabs back on for
> makefiles or you will have many, many problems.

True.

;; Use only spaces when indenting or centering, no tabs.
(setq-default indent-tabs-mode nil)

will do the right thing, even in Makefiles, in emacs.

-- 
#!/usr/bin/perl -- Russ Allbery, Just Another Perl Hacker
$^=q;@!>~|{>krw>yn{u<$$<[~||<Juukn{=,<S~|}<Jwx}qn{<Yn{u<Qjltn{ > 0gFzD gD,
 00Fz, 0,,( 0hF 0g)F/=, 0> "L$/GEIFewe{,$/ 0C$~> "@=,m,|,(e 0.), 01,pnn,y{
rw} >;,$0=q,$,,($_=$^)=~y,$/ C-~><@=\n\r,-~$:-u/ #y,d,s,(\$.),$1,gee,print


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

Date: Fri, 17 Jul 1998 02:13:11 GMT
From: swhite@accessonline.com
Subject: Javascript History -1 (Need the Perl equivalent)
Message-Id: <35aeafcc.3726642@news.sprint.ca>

Hi,

How do I read the name of the HTML file that I used to call the perl
script?
I need a function like the javascript history -1 that I can call in
Perl.

Thanks alot everyone.

Stephen


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

Date: 17 Jul 1998 03:45:17 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Javascript History -1 (Need the Perl equivalent)
Message-Id: <6omhcd$g56$1@nswpull.telstra.net>

In article <35aeafcc.3726642@news.sprint.ca>,
	swhite@accessonline.com writes:
> Hi,
> 
> How do I read the name of the HTML file that I used to call the perl
> script?

You don't call a perl script with a HTML file. You can have a link or
a form submit thingie in HTML, which will cause your browser to
contact a server with a certain URL. The server will execute a CGI
process, etc. Outside of the scope of this group.

> I need a function like the javascript history -1 that I can call in
> Perl.

JavaScript, as you mean it, runs in the browser. CGI processes run on
the server. The server has no access to the client's history. Maybe
you can try one of the CGI environment variables. Go to a CGI group,
and ask there. Somewhere in comp.infosystems.www.* there should be at
least one.

You have not asked anything perl specific.

Martien
-- 
Martien Verbruggen                  | 
Webmaster www.tradingpost.com.au    | If it isn't broken, it doesn't have
Commercial Dynamics Pty. Ltd.       | enough features yet.
NSW, Australia                      | 


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

Date: Thu, 16 Jul 1998 18:58:00 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: newbie date format
Message-Id: <MPG.10184f7e455bc34a989754@nntp.hpl.hp.com>

In article <mqqr1.144374$on1.7145255@news2.voicenet.com> on Thu, 16 Jul 
1998 17:06:26 GMT, Matt Knecht <hex@voicenet.com> says...
 ...
> @date = localtime;
> $formatted = (++$date[4] < 10 ? '0' . $date[4] : $date[4]) . '/' .
>              ($date[5] + 1900);
> 
> Which seems pretty longwinded when compared with the sprintf method, but
> lets me use another super-fun feature from C, the ?: conditional.

Less longwinded:

  $formatted = (length(++$date[4]) < 2 && '0') . $date[4] . '/' .

but just as misguided, because you get to do it again for the day, hour, 
minute and second.  Use [s]printf '%.2d' ;

-- 
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Thu, 16 Jul 1998 22:50:42 -0400
From: "Matthew O. Persico" <mpersico@erols.com>
Subject: Re: open (IN, "foo.txt") works, open (IN, "$foo") does not???
Message-Id: <35AEBC02.CB57E3C1@erols.com>

Suggestion, maybe for the FAQ:

Whenever a statement ceases to work because of the substitution of a
variable for a constant, do this BEFORE asking the question, "Why
doesn't this work:

print "\n\n|$TheBadVar|\n\n";

That will certainly help find the non-chomped \n in the variable. It
might also find trailing/leading spaces, etc. If the |'s aren't cuddled
up to the value of the var, you've got extra stuff.


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

Date: Thu, 16 Jul 1998 22:23:38 -0400
From: eweiss@winchendon.com (Eric Weiss)
Subject: Re: Perl 5.0005 for  Win32 ?
Message-Id: <MPG.10187fb26071ccd19896e8@news.dgsys.com>

[This followup was posted to comp.lang.perl.misc and a copy was sent to the cited author.]

Check www.cpan.org for the latest release which is 5.004 for Win32.  
ActiveState is no longer the standard release for windows.

Eric


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

Date: 12 Jul 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 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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

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