[13261] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 671 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 29 02:07:36 1999

Date: Sat, 28 Aug 1999 23:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 28 Aug 1999     Volume: 9 Number: 671

Today's topics:
    Re: Debug question (T. Alex Beamish)
    Re: email address verification <webmaster@mendonet.com>
    Re: email address verification <webmaster@mendonet.com>
        Encryption <igloo@wecandoit.com>
        hashes of arrays of arrays <nead@neadwerx.com>
    Re: hashes of arrays of arrays <nead@neadwerx.com>
    Re: hashes of arrays of arrays <jkline@one.net>
    Re: hashes of arrays of arrays <mike@crusaders.no>
    Re: hashes of arrays of arrays <mike@crusaders.no>
    Re: help on debug: Odd number of elements in hash list  <jkline@one.net>
        help on debug: Odd number of elements in hash list at . <tungyat@yahoo.com>
    Re: How do you use @TIME? (Marcel Grunauer)
    Re: How do you use @TIME? (Matthew Bafford)
    Re: How do you use @TIME? <mike@crusaders.no>
        Larry's and Guido's REAL sigs aaron_watters@my-deja.com
    Re: Larry's and Guido's REAL sigs (Larry Rosler)
    Re: Perl Y2K Bugs on the Internet <conserv3@infi.net>
    Re: Perl Y2K Bugs on the Internet <conserv3@infi.net>
    Re: Perl.exe has an interpreted mode? (elephant)
    Re: Style question: where should my declarations go? <jbc@shell2.la.best.com>
    Re: Style question: where should my declarations go? (Eric Bohlman)
        unicode and perl <goatholl@sonic.net>
    Re: Wacky Programming Tales (Was Re: Why use Perl when  <xah@weborder.com>
        Will you help me solve this jp_48504@yahoo.com
    Re: Will you help me solve this (Larry Rosler)
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

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

Date: Sun, 29 Aug 1999 01:24:22 GMT
From: talexb@tabsoft.on.ca (T. Alex Beamish)
Subject: Re: Debug question
Message-Id: <37c88ba6.189985468@news1.on.sympatico.ca>

On Fri, 27 Aug 1999 18:46:22 +0100, "Richard" <richard@madchicken.com>
wrote:

>My ISP has given me access and permission to create and run my own perl/cgi
>scripts, but I can't telnet to the system in order to debug the scripts
>using the perl -c function ( I think it's that). Telnet access is not
>allowed. Is there some way I can view the output of what would have been at
>the telnet prompt via the borwser? I'll tear my hair out if I see that
>"Internal Server Error" message one more time!!

DO it through your browser; that's how I've been doing my debugging.
Put debug messages into the HTML, either in plaintext or as comments
within the <!-- and --> open and close tags.

The other thing that's handy to have access to is the error log file;
at least that way when Nothing Happens you can peek at it to see what
the web server thought about the whole thing.

Good luck.


T. Alex Beamish, Principal -- TAB Software
  Toronto, Ontario -- www.tabsoft.on.ca


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

Date: Sat, 28 Aug 1999 22:07:17 -0700
From: Jon Hollcraft <webmaster@mendonet.com>
To: Michel Dalle <michel.dalle@usa.net>
Subject: Re: email address verification
Message-Id: <37C8C005.39CE@mendonet.com>

Michel Dalle wrote:
> 
> >the trade off is allowing 200 million addresses in quickly with out any
 
> I'm almost afraid to ask what you're planning to do with 200 million
> addresses. The only legal application I see off-hand is statistical :

repeating:  "allowing 200 million addresses in"

This is a simple filter which is used only by people who may wish to
subscribe to a particular mailing list.  I don't plan on doing anything
with 200 whatever email addresses, except allowing those who choose, to
subscribe to that list.  Very simple. "allowing 200 million addresses
in"
is just an expression of a guestimate of possible addressees.  To
clarify,
I do not have, want, or need 200 million addresses.  Neither do my
clients.


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

Date: Sat, 28 Aug 1999 22:26:48 -0700
From: Jon Hollcraft <webmaster@mendonet.com>
Subject: Re: email address verification
Message-Id: <37C8C498.6339@mendonet.com>

Randal L. Schwartz wrote:

> However, to use that routine as a draconian "all addresses shall
> conform to this" sounds...so... Microsoftian. :)

 Randal,

Man, now THAT is really hitting below the belt!  I post a little chunk
of
code to help a fellow neophyte, and you gotta bust my chops.

How about this then   if($in{'address'}!~ /@/){&bademail} 

Geese, lighten up.


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

Date: Sat, 28 Aug 1999 20:26:12 -0700
From: "Bill Miles" <igloo@wecandoit.com>
Subject: Encryption
Message-Id: <rsh9viu6j7191@corp.supernews.com>

Is there a pure perl port of any public/private key encryption/decryption
algorithm? I'd ideally like to have a cgi script take a form (https),
encrypt the contents using a public key and email it to pgp enabled clients
(or tripleDES, Blowfish or any other algorhithm - within US export
regulations of course)




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

Date: 29 Aug 1999 02:47:59 GMT
From: "Nick Downey" <nead@neadwerx.com>
Subject: hashes of arrays of arrays
Message-Id: <01bef1c8$c275dd10$73463d80@r52h83>

Ok, now I must admit, that I have not tried everything, but this I believe
to be fairly complex, I will write basically what I am trying to accomplish
in perl code that I *know* does not work, but better explains my efforts

#!/usr/bin/perl -w

use strict;

my(@text1) = qw( zero one two three four five six seven eight nine );
my(@numb1) = qw( 0 1 2 3 4 5 6 7 8 9 );
my(@alph1) = qw( a b c d e f g h i j );

my(@text2) = qw( ten eleven twelve thirteen fourteen fifteen sixteen
seventeen
		 eighteeen nineteen );
my(@numb2) = qw( 10 11 12 13 14 15 16 17 18 19 );
my(@alph2) = qw( k  l  m  n  o  p  q  r  s  t );


my(%hash) = (
	     'line1' => [ @text1, @numb1, @alph1 ],
	     'line2' => [ @text2, @numb2, @alph2 ]
	     );

You see, each value in the hash, is an array of arrays....

I have the camel and the ram, if I have overlooked simple examples that
would help me with those in either of said books, simply re-direct. Also, I
am open to better ideas of how to store the same information. I have to
sore (to return from a sub) multiple sets of three arrays.

Thanks.


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

Date: 29 Aug 1999 03:54:27 GMT
From: "Nick Downey" <nead@neadwerx.com>
Subject: Re: hashes of arrays of arrays
Message-Id: <01bef1d2$0b2b0ef0$73463d80@r52h83>

 

Nick Downey <nead@neadwerx.com> wrote in article
<01bef1c8$c275dd10$73463d80@r52h83>...
> Ok, now I must admit, that I have not tried everything, but this I
believe
> to be fairly complex, I will write basically what I am trying to
accomplish
> in perl code that I *know* does not work, but better explains my efforts

I believe I have figure this out, this is how I am accomplishing it, if
there is any *style* or bad practice errors I would appreciate the input.

#!/usr/bin/perl -w

use strict;

my(@array1) = qw( 0 1 2 3 4 5 6 7 8 9 );
my(@array2) = qw( zero one two three four five six seven eight nine );
my(@array3) = qw( 10 20 30 40 50 60 70 80 90 );
my(@array4) = qw( ten twenty thirty forty fifty sixty seventy eighty nintey
);

my(@total, $key);

my(%hash);

push @total, [ @array1 ];
push @total, [ @array2 ];

$hash{'line1'} = [ @total ];

undef @total;

push @total, [ @array3 ];
push @total, [ @array4 ];

$hash{'line2'} = [ @total ];

foreach $key (sort keys %hash ){

    print "$key: ";

    print "$hash{$key}[0][1]\n";

}



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

Date: Sat, 28 Aug 1999 23:58:22 -0400
From: Joe Kline <jkline@one.net>
Subject: Re: hashes of arrays of arrays
Message-Id: <37C8AFDE.FEF857A2@one.net>

[posted and mail bcc'd ]

Nick Downey wrote:
<SNIP>
> #!/usr/bin/perl -w
> use strict;
<SNIP>
> my(%hash) = (
>              'line1' => [ @text1, @numb1, @alph1 ],
>              'line2' => [ @text2, @numb2, @alph2 ]
>              );
> 
> You see, each value in the hash, is an array of arrays....
> 
> I have the camel and the ram, if I have overlooked simple examples that
> would help me with those in either of said books, simply re-direct. Also, I
> am open to better ideas of how to store the same information. I have to
> sore (to return from a sub) multiple sets of three arrays.

I am not totally sure what you're asking, so here goes...

perldoc perldsc   <--- read it, it's your friend

Here goes my best mind-reading attempt...

You will probably want to return references.

so...

sub esp
{
    my ( $key ) = @_;
    #
    # insert holol initialization here (???)
    #
    
    #
    # $key is the hash key and we will return
    # a ref to the lol
    #

    my $ref_to_lol = $hash{$key};

    return ($ref_to_lol);
}

Until you give better info, I can't think of a better answer.


joe - perplexed by the stunning lack of info here


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

Date: Sun, 29 Aug 1999 06:25:23 +0200
From: "Trond Michelsen" <mike@crusaders.no>
Subject: Re: hashes of arrays of arrays
Message-Id: <5D2y3.42$sd.89@news1.online.no>


Nick Downey <nead@neadwerx.com> wrote in message
news:01bef1c8$c275dd10$73463d80@r52h83...
> my(@text1) = qw( zero one two three four five six seven eight nine );
> my(@numb1) = qw( 0 1 2 3 4 5 6 7 8 9 );
> my(@alph1) = qw( a b c d e f g h i j );
>
> my(@text2) = qw( ten eleven twelve thirteen fourteen fifteen sixteen
> seventeen
> eighteeen nineteen );
> my(@numb2) = qw( 10 11 12 13 14 15 16 17 18 19 );
> my(@alph2) = qw( k  l  m  n  o  p  q  r  s  t );

So far everything is fine. You have created a bunch of arrays.

> my(%hash) = (
>      'line1' => [ @text1, @numb1, @alph1 ],
>      'line2' => [ @text2, @numb2, @alph2 ]
>      );

But this is probably not what you want. Here you create a reference to 1
array including 30 elements. You want a reference to 1 array including
the reference to 3 arrays with 10 elements each.
Like this:

my(%hash) = (
     'line1' => [ \@text1, \@numb1, \@alph1 ],
     'line2' => [ \@text2, \@numb2, \@alph2 ]
     );

test it with:

for (0..9) {
 print <<END;
text: $hash{line1}[0][$_]
numb: $hash{line1}[1][$_]
alph: $hash{line1}[2][$_]
END
}

--
Trond Michelsen





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

Date: Sun, 29 Aug 1999 06:33:56 +0200
From: "Trond Michelsen" <mike@crusaders.no>
Subject: Re: hashes of arrays of arrays
Message-Id: <6L2y3.44$sd.79@news1.online.no>


Nick Downey <nead@neadwerx.com> wrote in message
news:01bef1d2$0b2b0ef0$73463d80@r52h83...
> I believe I have figure this out, this is how I am accomplishing it,
if
> there is any *style* or bad practice errors I would appreciate the
input.

I must say that I don't understand what you are trying to accomplish.

> push @total, [ @array1 ];
> push @total, [ @array2 ];

This will copy @array1 (and @array2) into an anonymous array and return
the reference to the anonymous array. Not terribly effective compared to
returning the reference to each array directly.

--
Trond Michelsen




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

Date: Sun, 29 Aug 1999 01:40:13 -0400
From: Joe Kline <jkline@one.net>
Subject: Re: help on debug: Odd number of elements in hash list at ././rt.pl line  56, <STDIN> chunk 1
Message-Id: <37C8C7BD.B2F72D05@one.net>



Winter wrote:
> 
> Hi all,
> 
> Anyone know what is the meaning of "Odd number of elements in hash list at
> ././rt.pl line 56, <STDIN> chunk 1"?
> 

Consulting the ever bountiful 'perldoc perldiag' we find:

"...You specified an odd number of elements to initialize a hash,
which is odd, because hashes come in key/value pairs."

Maybe you need to also look at 'perldoc perldata' to achieve a better
understanding of Perl's wonderful data structures.

joe


  -----------== Posted via Newsfeeds.Com, Uncensored Usenet News ==----------
   http://www.newsfeeds.com       The Largest Usenet Servers in the World!
------== Over 73,000 Newsgroups - Including  Dedicated  Binaries Servers ==-----


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

Date: Sun, 29 Aug 1999 05:23:45 GMT
From: "Winter" <tungyat@yahoo.com>
Subject: help on debug: Odd number of elements in hash list at ././rt.pl line 56, <STDIN> chunk 1
Message-Id: <Bt3y3.1216$p11.55835@news1.rdc2.on.home.com>

Hi all,

Anyone know what is the meaning of "Odd number of elements in hash list at
 ././rt.pl line 56, <STDIN> chunk 1"?

Any help is appreipate, I would prefer reply via email at tungyat@yahoo.com
Thanks in advanced.




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

Date: Sun, 29 Aug 1999 00:01:59 GMT
From: marcel.grunauer@lovely.net (Marcel Grunauer)
Subject: Re: How do you use @TIME?
Message-Id: <37cc852a.24700457@news>

On Sat, 28 Aug 1999 16:13:10 -0700, "Mace" <mace@calweb.com> wrote:

> This is the subroutine:
> 
> sub GET_TIME
>  {
>  @TIME = localtime(time);
>  if ($TIME[4] == 0){$MONTH = "January"};
>  if ($TIME[4] == 1){$MONTH = "February"};
>  if ($TIME[4] == 2){$MONTH = "March"};
>  if ($TIME[4] == 3){$MONTH = "April"};
>  if ($TIME[4] == 4){$MONTH = "May"};
>  if ($TIME[4] == 5){$MONTH = "June"};
>  if ($TIME[4] == 6){$MONTH = "July"};
>  if ($TIME[4] == 7){$MONTH = "August"};
>  if ($TIME[4] == 8){$MONTH = "September"};
>  if ($TIME[4] == 9){$MONTH = "October"};
>  if ($TIME[4] == 10){$MONTH = "November"};
>  if ($TIME[4] == 11){$MONTH = "December"};
> 
>  if ($TIME[6] == 0){$DAY = "SUNDAY"};
>  if ($TIME[6] == 1){$DAY = "MONDAY"};
>  if ($TIME[6] == 2){$DAY = "TUESDAY"};
>  if ($TIME[6] == 3){$DAY = "WEDNESDAY"};
>  if ($TIME[6] == 4){$DAY = "THURSDAY"};
>  if ($TIME[6] == 5){$DAY = "FRIDAY"};
>  if ($TIME[6] == 6){$DAY = "SATURDAY"};
>  }

Get rid of this, presto!

You've already been given a few good solutions.

And please use all-caps only for constants and file handles and such.
Not for variables and sub names.

> However, when I put:
> 
> print "$DAY\n"; nothing happened, the screen was just blank.  Thanks.

Well, did you call GET_TIME() before?

The code above is ugly as sin, but it did output "SUNDAY" when I tried
it. That is, when I tried on a Sunday. :-)


Marcel
Perl Padawan
-- 
sub AUTOLOAD{($_=$AUTOLOAD)=~s,^.*::,,;y,_, ,;print} Just_Another_Perl_Hacker();


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

Date: Sat, 28 Aug 1999 23:53:26 GMT
From: *@dragons.duesouth.net (Matthew Bafford)
Subject: Re: How do you use @TIME?
Message-Id: <slrn7sgslg.23t.*@dragons.duesouth.net>

On Sat, 28 Aug 1999 16:13:10 -0700, Mace" <mace@calweb.com> was
attempting to recharge the laptop battery by typing: 
: This is the subroutine:
: 
: sub GET_TIME
:  {
:  @TIME = localtime(time);
 ...
snip
 ...
:  if ($TIME[6] == 0){$DAY = "SUNDAY"};
:  if ($TIME[6] == 1){$DAY = "MONDAY"};
:  if ($TIME[6] == 2){$DAY = "TUESDAY"};
:  if ($TIME[6] == 3){$DAY = "WEDNESDAY"};
:  if ($TIME[6] == 4){$DAY = "THURSDAY"};
:  if ($TIME[6] == 5){$DAY = "FRIDAY"};
:  if ($TIME[6] == 6){$DAY = "SATURDAY"};
:  }

AHA!

You discovered how @TIME was set!
 
: print "$DAY\n"; nothing happened, the screen was just blank.  Thanks.

Sorry, that's not enough information.

HTH,

--Matthew


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

Date: Sun, 29 Aug 1999 02:19:39 +0200
From: "Trond Michelsen" <mike@crusaders.no>
Subject: Re: How do you use @TIME?
Message-Id: <K0%x3.613$jL.4458@news1.online.no>

Mace <mace@calweb.com> wrote in message news:37c86dea@calwebnnrp...

You use @TIME like any other array. If you are curious about the localtime()
function, I suggest trying  the command 'perloc -f localtime' again

> This is the subroutine:
>
> sub GET_TIME
>  {
>  @TIME = localtime(time);
>  if ($TIME[4] == 0){$MONTH = "January"};
 ..
>  if ($TIME[4] == 11){$MONTH = "December"};
>
>  if ($TIME[6] == 0){$DAY = "SUNDAY"};
 ..
>  if ($TIME[6] == 6){$DAY = "SATURDAY"};
>  }

ohmydog.. You /really/ need to read up on the usefullness of arrays.

> However, when I put:
> print "$DAY\n"; nothing happened, the screen was just blank.  Thanks.

You haven't shown the entire program here, but unless you call the
subroutine &GET_TIME somewhere it won't be executed and $DAY won't be set.

You need a book like "Learning Perl". Well any book on programming in
general would be helpful I think.

Anyway.

@Months = qw/January February March April May June July August September
October November December/;
@Days = qw/Monday Tuesday Wednesday Thursday Friday Saturday Sunday/;
@TIME = localtime;
$MONTH = $Months[$TIME[4]];
$DAY = $Days[$TIME[6]];

is a bit cleaner.

If you only want to extract the month and day you should use a slice to get
the values

($MONTH, $DAY) = (localtime)[4,6];
$MONTH = $Months[$MONTH];
$DAY = $Days[$DAY];

But as Larry R. has suggested; You should refrain from using variablenames
in capital-letters, since that implies that they are constants. This is of
course only a matter of programming style, and your program won't behave
differently in any way, but it is a good idea to follow at least a few
standard programming styles.

--
Trond Michelsen





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

Date: Sun, 29 Aug 1999 00:32:30 GMT
From: aaron_watters@my-deja.com
Subject: Larry's and Guido's REAL sigs
Message-Id: <7q9v2u$1jk$1@nnrp1.deja.com>

At the ORA Open Source Conference I got
Mark Lutz and David Ascher to sign their
"Learning Python", but for fun I also got
Tom Christiansen, Larry Wall, and Guido
van Rossum to sign it too.

If you want to get the other sigs you'll
have to visit me or buy the book from me
(at a highly inflated price) but I make
public the page that Guido and Larry signed:

   http://www.chordate.com/sigs.GIF

enjoy!  -- Aaron Watters

===

How many Mac developers does it take to
change a lightbulb?
One.  she holds the bulb up and expects
the universe to revolve around her.
   --Guy Kawasaki (former chief Apple Evangelist)


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


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

Date: Sat, 28 Aug 1999 22:39:18 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Larry's and Guido's REAL sigs
Message-Id: <MPG.1232675d6e885633989ec9@nntp.hpl.hp.com>

In article <7q9v2u$1jk$1@nnrp1.deja.com> on Sun, 29 Aug 1999 00:32:30 
GMT, aaron_watters@my-deja.com <aaron_watters@my-deja.com> says...
 ...
>    http://www.chordate.com/sigs.GIF
> 
> enjoy!  -- Aaron Watters

Can't.  No such page.  Even with lower-case .gif.  Try again?

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


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

Date: Sat, 28 Aug 1999 20:57:25 -0400
From: Joe Wright <conserv3@infi.net>
Subject: Re: Perl Y2K Bugs on the Internet
Message-Id: <37C88575.7C0B@infi.net>

Lee Fesperman wrote:
> 
> Martin Ambuhl wrote:
> > Please change your newsgroups and followups to not include comp.lang.c,
> > where this stuff is off-topic.  It does not win Perl or its programmers
> > any friends.
> 
> It is hardly off-topic. As I said, "this date 'feature' is a weakness in Perl (and C,
> Javascript, ...) - a poor design."
> 
> This date deficiency is in C also (tm_year). Do C programmers have the same parochial
> view of it as Perl programmers?
> 
Why do you suppose tm_year is deficient?  It is an int.  It won't roll
over from 99 to 00.
-- 
Joe Wright                                 mailto:conserv3@infi.net
"Everything should be made as simple as possible, but not simpler."
                    --- Albert Einstein ---


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

Date: Sat, 28 Aug 1999 21:06:03 -0400
From: Joe Wright <conserv3@infi.net>
Subject: Re: Perl Y2K Bugs on the Internet
Message-Id: <37C8877A.1C0C@infi.net>

Bart Lateur wrote:
> 
> Lee Fesperman wrote:
> 
> >In reality, this date 'feature' is a weakness in Perl (and C, Javascript, ...) - a poor
> >design. Because of cross-posting, I'm viewing this from the Java NG. Java has this
> >deficiency but has recognized it, replaced it with a correct implementation and
> >deprecated the problematic stuff.
> 
> How on earth can you "correct the implementation" without loosing
> backward compatibility? By adding another function? I think that's why
> Perl people object to this addition, which would make the perl
> executable bigger: because it's so easy to compensate. All you have to
> do is to add 1900 to the year.
> 
> And I'm pretty sure that in the original design, tm_year was intended to
> return the year in 2 digits. All that "years since 1900" nonsense is
> nothing but a backward compatible patch.
> 
I really doubt that.  The original time() yielded a 32-bit long and it
was immediately clear that the largest positive number indicated a date
and time in the year 2038.  Thus, tm_year would be 138.  Even way back
then.
-- 
Joe Wright                                 mailto:conserv3@infi.net
"Everything should be made as simple as possible, but not simpler."
                    --- Albert Einstein ---


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

Date: Sun, 29 Aug 1999 10:24:35 +1000
From: elephant@squirrelgroup.com (elephant)
Subject: Re: Perl.exe has an interpreted mode?
Message-Id: <MPG.123328cd856d796f989c95@news-server>

[ item posted to comp.lang.perl.misc and CCed to revjack ]

revjack writes ..
>elephant explains it all:
>
>:oh god - here we go .. don't tell me they've changed it in Windows98
>
>Yes. Empirical testing here yields the following results:
>
>       |    ^D        ^Z
>-------+-------------------
>Win NT |   runs     runs
>       |
>Win 98 |   runs     exits
>       |
>Win 95 |   runs     exits
>
>Different perl builds may conceivably yield different results.

thank you for taking the time to point this out .. unbelievable that 
Win9x and WinNT have different EOF characters .. thankfully (as you 
show) Perl makes it simple when run interactively

just to dot all the 'i's .. it should be noted that the EOF character in 
NT is still ^Z .. so when you're running code like this on NT

#!perl -w
use strict;

@_ = <STDIN>;
print @_;
__END__

you need to use ^Z to end your input (ie. signify EOF) .. ^Z^M to be 
exact (^M for the uninitiated is the <ENTER> key)

I know that this was not what this thread was about - but I can see some 
people getting caught by this behaviour if they get used to ending the 
interpreter mode with ^D on WinNT

-- 
 jason - elephant@squirrelgroup.com -


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

Date: 29 Aug 1999 00:52:58 GMT
From: John Callender <jbc@shell2.la.best.com>
Subject: Re: Style question: where should my declarations go?
Message-Id: <37c8846a$0$207@nntp1.ba.best.com>

Larry Rosler <lr@hpl.hp.com> wrote:

> As Perl allows a choice, my style is to declare the variable where it is 
> used, to restrict its scope.  Declaring a 'my' variable ahead of a loop 
> is slightly more efficient than declaring it within the loop, but it 
> implies that the final value will be used later on.  It is better to 
> declare it within the loop, so its limited scope will be clear.  It is 
> also necessary if references to different data stored in the variable on 
> each iteration are to be saved.

I think I understand this point, but I was actually asking about
something slightly different. If I *can* declare it inside the block,
then I do it there, in order to keep the scope as limited as possible.
What I was actually wondering about is the case where a variable needs
to be declared outside the block, because it is going to be used not
only in the block, but also elsewhere within the script, inside another
block or in the script's outermost scope.

The specific thing I was working on when I started wondering about this
was a script that runs each day to create a summary line from a log
file, and then prints a report that combines that summary line with the
summaries from previous days' script runs. The following occurs about
halfway through a script of about 400 lines:

if (-e $summary_file) {
    open SUMMARY, $summary_file or
        die "can't open $summary_file for reading: $!\n";
    @summary_lines = <SUMMARY>;
    close SUMMARY 
        or die "can't close $summary_file after reading: $!\n";
}

my $summary_line = sprintf 
    "$begin_time $end_time %6u %6u %6u %6u\n", 
    $total_hits, $total_views, $total_visits, $total_mb;
unshift @summary_lines, $summary_line;
if (@summary_lines > $summary_count) {
    $#summary_lines = $summary_count - 1;
}

my $report = <<EndOfText;
$site_name Access Report -- $end_time

Summary of last $summary_count reporting periods:

        From                  To           Hits   Views Visits   Mb
==================== ==================== ====== ====== ====== ======
EndOfText

open SUMMARY, ">$summary_file" or
    die "couldn't open $summary_file for writing: $!\n";

foreach (@summary_lines) {
    $report .= $_;
    print SUMMARY;
}

close SUMMARY or die "couldn't close $summary_file after writing:
$!\n";

My question concerns the my declaration for the @summary_lines array. I
need it declared in the script's outermost scope, and my initial notion
was to declare it with a bunch of other script-wide variables up at the
top of the script as a whole. But since this is the only part of the
script that uses it, I'm thinking maybe it would be clearer to declare
it immediately before this section. I'm looking for style advice,
mainly.

-- 
John Callender
jbc@west.net
http://www.west.net/~jbc/


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

Date: 29 Aug 1999 02:16:32 GMT
From: ebohlman@netcom.com (Eric Bohlman)
Subject: Re: Style question: where should my declarations go?
Message-Id: <7qa560$2kj@dfw-ixnews19.ix.netcom.com>

John Callender (jbc@shell2.la.best.com) wrote:
: My question concerns the my declaration for the @summary_lines array. I
: need it declared in the script's outermost scope, and my initial notion
: was to declare it with a bunch of other script-wide variables up at the
: top of the script as a whole. But since this is the only part of the
: script that uses it, I'm thinking maybe it would be clearer to declare
: it immediately before this section. I'm looking for style advice,
: mainly.

My preference in that case would be to declare it right before it's 
used.  If, however, the variable were to be used again much later in the 
program, then I'd declare it at the beginning.  The idea is that if you 
see a variable name, it should be easy to find out where it's declared 
(imagine viewing the program a screen at a time).  With my style, you can 
back up until you stop seeing the variable name in the code, at which 
point:

1) You'll see the declaration or
2) You'll know that you need to go to the beginning to see the declaration.

What you *won't* have to do is go looking in the middle of the code
(unless that's where you already are) to find the declaration; I find that
frustrating. 



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

Date: Sat, 28 Aug 1999 18:00:40 -0800
From: chris jaffe <goatholl@sonic.net>
Subject: unicode and perl
Message-Id: <37C89446.B7E5E997@sonic.net>

how do I use unicode with perl?
thanks for the info, -Karen



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

Date: Sat, 28 Aug 1999 22:50:36 -0700
From: Xah Lee <xah@weborder.com>
Subject: Re: Wacky Programming Tales (Was Re: Why use Perl when we've got  Python?!)
Message-Id: <37C8CA2C.ECAE285C@weborder.com>



Brad Howes wrote:
>...
> ...now back to my language is bigger/longer/wider/stiffer than yours

No, my language is not bigger/longer/wider/stiffer than yours. My language just makes your girlfriend happier.

 Xah
 xah@best.com
 http://www.best.com/~xah/PageTwo_dir/more.html
 Me: "There are more than one way to do it."
 Her: <grin>


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

Date: Sun, 29 Aug 1999 04:02:28 GMT
From: jp_48504@yahoo.com
Subject: Will you help me solve this
Message-Id: <7qabcg$9d2$1@nnrp1.deja.com>

I am sure that this is a simple problem to most of you, but i am still
very much an infant when it comes to perl.  This is my problem: I have
a program that is to figure out some totals, but it will print out a
number like 32.0746153846154 what I want it to do is to round it to the
nearest tenth such as 32.1 for this number. Can anyone help me with
this. I really do appreciate it.

JP


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


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

Date: Sat, 28 Aug 1999 22:47:40 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Will you help me solve this
Message-Id: <MPG.1232694c6c4b99b2989eca@nntp.hpl.hp.com>

In article <7qabcg$9d2$1@nnrp1.deja.com> on Sun, 29 Aug 1999 04:02:28 
GMT, jp_48504@yahoo.com <jp_48504@yahoo.com> says...
> I am sure that this is a simple problem to most of you, but i am still
> very much an infant when it comes to perl.  This is my problem: I have
> a program that is to figure out some totals, but it will print out a
> number like 32.0746153846154 what I want it to do is to round it to the
> nearest tenth such as 32.1 for this number. Can anyone help me with
> this. I really do appreciate it.

Others have run into this problem before, and have written down their 
solutions.  In fact, it is the very first question in perlfaq4, which is 
available on your machine or on the Internet.

"Why am I getting long decimals (eg, 19.9499999999999) instead of the 
numbers I should be getting (eg, 19.95)?"

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


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

Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 1 Jul 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.  

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" from
almanac@ruby.oce.orst.edu. The real FAQ, as it appeared last in the
newsgroup, can be retrieved with the request "send perl-users FAQ" from
almanac@ruby.oce.orst.edu. 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" from
almanac@ruby.oce.orst.edu. 

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


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