[10516] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4108 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 29 21:07:28 1998

Date: Thu, 29 Oct 98 18:00:19 -0800
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, 29 Oct 1998     Volume: 8 Number: 4108

Today's topics:
    Re: Checking for only numbers (Harold Bamford)
    Re: Checking Input for Exactly 2 numbers (Matthew Bafford)
    Re: Checking Input for Exactly 2 numbers <bill@fccj.org>
    Re: Checking Input for Exactly 2 numbers <rootbeer@teleport.com>
    Re: Checking Input for Exactly 2 numbers (brian d foy)
    Re: Checking Input for Exactly 2 numbers (brian d foy)
    Re: Checking Input for Exactly 2 numbers <bill@fccj.org>
        Easy Question: Rounding Numbers <webmaster@topproducer.com>
    Re: Easy Question: Rounding Numbers (Brand Hilton)
    Re: Easy Question: Rounding Numbers (Matthew Bafford)
    Re: Easy Question: Rounding Numbers <webmaster@topproducer.com>
    Re: Easy Question: Rounding Numbers <rootbeer@teleport.com>
    Re: Easy Question: Rounding Numbers (Matthew Bafford)
    Re: Easy Question: Rounding Numbers (Martien Verbruggen)
    Re: Easy Question: Rounding Numbers <webmaster@topproducer.com>
        Help Needed <srao@india.hp.com>
    Re: named arguments (David Formosa)
    Re: Need help appending a string to a hash <r28629@email.sps.mot.com>
    Re: Need help appending a string to a hash (Martien Verbruggen)
    Re: Not to start a language war but.. <spamsux-tex@habit.com>
    Re: Not to start a language war but.. (Alan Barclay)
    Re: Not to start a language war but.. <jorendorff@ixl.com>
    Re: Not to start a language war but.. (Jon Drukman)
    Re: Not to start a language war but.. <zenin@bawdycaste.org>
    Re: Not to start a language war but.. <zenin@bawdycaste.org>
    Re: pass array to sub (Matthew Bafford)
    Re: Perl & Y2K - booby trap code <rra@stanford.edu>
    Re: Perl & Y2K - booby trap code <rra@stanford.edu>
    Re: Perl how-to question <webmaster@topproducer.com>
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: 30 Oct 1998 00:00:13 GMT
From: hbamford@marconi.ih.lucent.com (Harold Bamford)
Subject: Re: Checking for only numbers
Message-Id: <71avid$bgi@ssbunews.ih.lucent.com>

I assume you are referring to numbers to mean more than just the digits
0-9. If you just use \D then this is the kind of matching you will get:
	
	#!e:/perl5/bin/perl -w
	use strict;
	
	my(@nums) = qw( 1 -1 2.0 -3.0 0.8 -0.8 0x123 );
	foreach(@nums) {
	        /\D/ && print("'$_' is not a number\n") && next;
	        print "'$_' seems to be a number\n";
	}
	----------------------------	
	'1' seems to be a number
	'-1' is not a number
	'2.0' is not a number
	'-3.0' is not a number
	'0.8' is not a number
	'-0.8' is not a number
	'0x123' is not a number

OTOH, as others have pointed out, the FAQ has more on this. Look for:

  How do I determine whether a scalar is a number/whole/integer/float?

-- Harold
-- 
-- Harold Bamford
   mailto:hbamford@lucent.com
   (630)713-1351


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

Date: Thu, 29 Oct 1998 19:42:12 -0500
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: Checking Input for Exactly 2 numbers
Message-Id: <MPG.10a2d56ec39092a29896ec@news.scescape.net>

In article <<_47_1.39$wo5.165011@nsw.nnrp.telstra.net>>, 
mgjv@comdyn.com.au (Martien Verbruggen) pounded the following:
=> In article <1dhmuv8.1rlm5ki9mzchcN@bay1-214.quincy.ziplink.net>,
=> 	rjk@coos.dartmouth.edu (Ronald J Kimball) writes:
=> > Mike <support@counter.w-dt.com> wrote:
=> > 
=> >> How would you check the input then to make sure it has exactly two
=> >> numbers inputed. Not more not less.
=> > 
=> > 2 == (() = /\d+/g);
=> 
=> Are you sure you want that '+' in there?

If you take the question in the sense that:

'22 sheep, 10 cows'

should pass through, then the + is needed.

Take for example:

% perl -le 'print scalar(() = "22 sheep, 10 cows" =~ /\d/g)'
4
% perl -le 'print scalar(() = "22 sheep, 10 cows" =~ /\d+/g)'
2
%

=> Martien

HTH,

--Matthew


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

Date: Thu, 29 Oct 1998 19:42:51 -0500
From: Bill Jones <bill@fccj.org>
Subject: Re: Checking Input for Exactly 2 numbers
Message-Id: <36390B8B.579E55F2@fccj.org>

Ronald J Kimball wrote:
> 
> Mike <support@counter.w-dt.com> wrote:
> 
> > How would you check the input then to make sure it has exactly two
> > numbers inputed. Not more not less.
> 
> 2 == (() = /\d+/g);
> 

What about -

unless ($number =~ /(\d+)/ && /^[1-99]$/) {
    print "Number entered not numeric or greater than 99...\n\n";
    exit;
}


Confusd...
-Sneex-  :]
________________________________________________________________________
Bill Jones  |  FCCJ Webmaster  |  x3089  |  http://webmaster.fccj.org:81
------------------------------------------------------------------------
       __ _  RedHat 5.1 Manhatten 
      / /(_)_ __  _   ___  __   http://www.apache.org 
     / / | | '_ \| | | \ \/ /   http://www.redhat.com 
    / /__| | | | | |_| |>  <    http://www.perl.com 
    \____/_|_| |_|\__,_/_/\_\   http://www.gimp.org


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

Date: Fri, 30 Oct 1998 01:23:53 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Checking Input for Exactly 2 numbers
Message-Id: <Pine.GSO.4.02A.9810291716540.3421-100000@user2.teleport.com>

On Thu, 29 Oct 1998, Bill Jones wrote:

> unless ($number =~ /(\d+)/ && /^[1-99]$/) {
>     print "Number entered not numeric or greater than 99...\n\n";
>     exit;
> }

What happened when you tried this code before you posted it? Ouch!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 29 Oct 1998 21:33:59 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Checking Input for Exactly 2 numbers
Message-Id: <comdog-ya02408000R2910982133590001@news.panix.com>

In article <_47_1.39$wo5.165011@nsw.nnrp.telstra.net>, mgjv@comdyn.com.au (Martien Verbruggen) posted:

> In article <1dhmuv8.1rlm5ki9mzchcN@bay1-214.quincy.ziplink.net>,
>         rjk@coos.dartmouth.edu (Ronald J Kimball) writes:
> > Mike <support@counter.w-dt.com> wrote:
> > 
> >> How would you check the input then to make sure it has exactly two
> >> numbers inputed. Not more not less.
> > 
> > 2 == (() = /\d+/g);
> 
> Are you sure you want that '+' in there?

i think the idea for that example was to find two groups of digits
rather than two digits.

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Thu, 29 Oct 1998 21:35:49 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Checking Input for Exactly 2 numbers
Message-Id: <comdog-ya02408000R2910982135490001@news.panix.com>

In article <36390B8B.579E55F2@fccj.org>, bill@astro.fccj.org posted:
> What about -
> 
> unless ($number =~ /(\d+)/ && /^[1-99]$/) {
>     print "Number entered not numeric or greater than 99...\n\n";
>     exit;
> }

try it with

   $number = 11;

finding the bug is left as an exercise for the reader.

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
not everything needs a regex.


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

Date: Thu, 29 Oct 1998 20:47:24 -0500
From: Bill Jones <bill@fccj.org>
To: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Checking Input for Exactly 2 numbers
Message-Id: <36391AAC.C22BC961@fccj.org>

Tom Phoenix wrote:
> 
> On Thu, 29 Oct 1998, Bill Jones wrote:
> 
> > unless ($number =~ /(\d+)/ && /^[1-99]$/) {
> >     print "Number entered not numeric or greater than 99...\n\n";
> >     exit;
> > }
> 
> What happened when you tried this code before you posted it? Ouch!


Ouch is right :]

:(

It didn't do what I was thinking.  I want a range between
1 and 99 ONLY.  So after a some testing, I went back to old ways:

unless ($number > 0 && $number < 100) {
	# ...
}


Sorry,
________________________________________________________________________
Bill Jones  |  FCCJ Webmaster  |  x3089  |  http://webmaster.fccj.org:81
------------------------------------------------------------------------
       __ _  RedHat 5.1 Manhatten 
      / /(_)_ __  _   ___  __   http://www.apache.org 
     / / | | '_ \| | | \ \/ /   http://www.redhat.com 
    / /__| | | | | |_| |>  <    http://www.perl.com 
    \____/_|_| |_|\__,_/_/\_\   http://www.gimp.org


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

Date: Thu, 29 Oct 1998 16:12:31 -0800
From: "Alistair Calder" <webmaster@topproducer.com>
Subject: Easy Question: Rounding Numbers
Message-Id: <71b0bv$lu6$2@supernews.com>

I have looked through the Camel book, but I could not find an answer to this
question:

I have a variable that is the result of a division, and I want to round it
to 1 or 2 decimal places.

The only thing I have at my disposal is INT(), but it just truncates, it
doesn't round up or down.

How do I turn this number:

12.591237489

Into this one:

12.6



Thanks,
Alistair Calder




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

Date: 30 Oct 1998 00:17:16 GMT
From: bhilton@tsg.adc.com (Brand Hilton)
Subject: Re: Easy Question: Rounding Numbers
Message-Id: <71b0ic$9qv12@mercury.adc.com>

So easy, in fact, that it's in the FAQ.  perlfaq4, to be exact.

-- 
 _____ 
|///  |   Brand Hilton  bhilton@adc.com
|  ADC|   ADC Telecommunications, ATM Transport Division
|_____|   Richardson, Texas


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

Date: Thu, 29 Oct 1998 19:52:24 -0500
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: Easy Question: Rounding Numbers
Message-Id: <MPG.10a2d7d64068df4a9896f0@news.scescape.net>

In article <<71b0bv$lu6$2@supernews.com>>, webmaster@topproducer.com 
(Alistair Calder) pounded the following:
=> Subject: Easy Question: Rounding Numbers

Yep, quite easy.  It's in the FAQ. :)

=> [snip]
=> How do I turn this number:
=> 
=> 12.591237489
=> 
=> Into this one:
=> 
=> 12.6
=> 

perlfaq4:

=head2 Does perl have a round function? What about ceil() and floor()? 
Trig functions? 

=> Thanks,

HTH,

=> Alistair Calder

--Matthew


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

Date: Thu, 29 Oct 1998 17:23:03 -0800
From: "Alistair Calder" <webmaster@topproducer.com>
Subject: Re: Easy Question: Rounding Numbers
Message-Id: <71b4dv$fb6$1@supernews.com>

Well, thanks for helping me find it in the FAQ, but it still doesn't help
me.  I am obvoiusly not in the loop when it comes to understanding how to
use printf or sprintf.

I read through the manpages for both, but I got nothing out of how to format
variable $example so that it will round like this: xx.x or this: xx.xx

I'm having some problems understanding how it works, I guess.  Can someone
offer any more help?

Thanks,
Alistair Calder.


Brand Hilton wrote in message <71b0ic$9qv12@mercury.adc.com>...
>So easy, in fact, that it's in the FAQ.  perlfaq4, to be exact.
>
>--
> _____
>|///  |   Brand Hilton  bhilton@adc.com
>|  ADC|   ADC Telecommunications, ATM Transport Division
>|_____|   Richardson, Texas




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

Date: Fri, 30 Oct 1998 01:31:45 GMT
From: Tom Phoenix <rootbeer@teleport.com>
Subject: Re: Easy Question: Rounding Numbers
Message-Id: <Pine.GSO.4.02A.9810291730330.3421-100000@user2.teleport.com>

On Thu, 29 Oct 1998, Alistair Calder wrote:

> Well, thanks for helping me find it in the FAQ, but it still doesn't
> help me.  I am obvoiusly not in the loop when it comes to
> understanding how to use printf or sprintf.

Did you see this example from the FAQ?

    To get rid of the superfluous digits, just use a format (eg,
    printf("%.2f", 19.95) ) to get the required precision.

If the FAQ and manpages are still insufficient for your needs, please let
us know how they should be made clearer. Thanks!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 29 Oct 1998 20:32:46 -0500
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: Easy Question: Rounding Numbers
Message-Id: <MPG.10a2e149278a23179896f1@news.scescape.net>

In article <<71b4dv$fb6$1@supernews.com>>, webmaster@topproducer.com 
(Alistair Calder) pounded the following:
=> Well, thanks for helping me find it in the FAQ, but it still doesn't help
=> me.  I am obvoiusly not in the loop when it comes to understanding how to
=> use printf or sprintf.
=> 
=> I read through the manpages for both, but I got nothing out of how to format
=> variable $example so that it will round like this: xx.x or this: xx.xx
=> 
=> I'm having some problems understanding how it works, I guess.  Can someone
=> offer any more help?

I'm sorry, I guess I'm not understanding your problem.

What's wrong with:

<quote from="perlfaq4">

For rounding to a certain number of digits, sprintf() or printf() is 
usually the easiest route. 

    printf("%.3f", 3.1415926535);       # prints 3.142

</quote>

Of course to assign 3.142 to a variable you'd use:

$roundpie = sprintf('%.3f', 3.1416926535);

If this isn't what you are looking for, please repost with a little 
more detail and we'll see what we can do.

=> Thanks,

HTH,

=> Alistair Calder.

--Matthew


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

Date: Fri, 30 Oct 1998 01:34:44 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Easy Question: Rounding Numbers
Message-Id: <UI8_1.7$kr5.134@nsw.nnrp.telstra.net>

In article <71b4dv$fb6$1@supernews.com>,
	"Alistair Calder" <webmaster@topproducer.com> writes:
> Well, thanks for helping me find it in the FAQ, but it still doesn't help
> me.  I am obvoiusly not in the loop when it comes to understanding how to
> use printf or sprintf.
> 
> I read through the manpages for both, but I got nothing out of how to format
> variable $example so that it will round like this: xx.x or this: xx.xx

>From the FAQ that you just read:

         printf("%.3f", 3.1415926535);       # prints 3.142

Hmm... I wonder if that 3 in %.3f means 'round at three decimals'.
That would mena that if I change it to a two, it would round at two
decimals. Maybe I should try it! While I am trying, I may as well use
a variable instead of a constant.

	$variable = '3.123455';
	printf("%.2f", $variable);

Well. it works! Now, lets see where I can find out why it works

# perldoc sprintf
[snip]
Perl permits the following universally-known flags between the C<%>
                                                   ^^^^^^^^^^^^^^^^
and the conversion letter:
^^^^^^^^^^^^^^^^^^^^^^^^^
[snip]
   .number "precision": digits after decimal point for
           floating-point, max length for string, minimum length
[snip]

If you need more help, I suggest you first try a few things, with the
documentation in hand. You leanr most from just trying, and fiddling
with these things.

Martien
-- 
Martien Verbruggen                      |
Webmaster www.tradingpost.com.au        | "In a world without fences,
Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
NSW, Australia                          |


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

Date: Thu, 29 Oct 1998 17:40:56 -0800
From: "Alistair Calder" <webmaster@topproducer.com>
Subject: Re: Easy Question: Rounding Numbers
Message-Id: <71b5fg$gnp$1@supernews.com>

Apologies to all.  The FAQ that I read did mention sprintf and printf, but I
could not find any examples at all.  Appreciate your help.


Matthew Bafford wrote in message ...
>In article <<71b4dv$fb6$1@supernews.com>>, webmaster@topproducer.com
>(Alistair Calder) pounded the following:
>=> Well, thanks for helping me find it in the FAQ, but it still doesn't
help
>=> me.  I am obvoiusly not in the loop when it comes to understanding how
to
>=> use printf or sprintf.
>=>
>=> I read through the manpages for both, but I got nothing out of how to
format
>=> variable $example so that it will round like this: xx.x or this: xx.xx
>=>
>=> I'm having some problems understanding how it works, I guess.  Can
someone
>=> offer any more help?
>
>I'm sorry, I guess I'm not understanding your problem.
>
>What's wrong with:
>
><quote from="perlfaq4">
>
>For rounding to a certain number of digits, sprintf() or printf() is
>usually the easiest route.
>
>    printf("%.3f", 3.1415926535);       # prints 3.142
>
></quote>
>
>Of course to assign 3.142 to a variable you'd use:
>
>$roundpie = sprintf('%.3f', 3.1416926535);
>
>If this isn't what you are looking for, please repost with a little
>more detail and we'll see what we can do.
>
>=> Thanks,
>
>HTH,
>
>=> Alistair Calder.
>
>--Matthew




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

Date: Thu, 29 Oct 1998 17:23:47 +0530
From: "M.R. Raman Subba Rao" <srao@india.hp.com>
Subject: Help Needed
Message-Id: <3638574B.EEE0F417@india.hp.com>

Hi,

I have ".gif" file stored as OLE object in MS Access database. I need to
post that image on the html form. Can any one help me  how to do this. I
am new to PERL programming.

Thanks in advance
Regards
Raman




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

Date: 30 Oct 1998 00:09:05 GMT
From: dformosa@zeta.org.au (David Formosa)
Subject: Re: named arguments
Message-Id: <slrn73i0t0.8bt.dformosa@godzilla.zeta.org.au>

In article <36390ABF.40D1F964@ixl.com>, Jason Orendorff wrote:
>> Unless you are like me, and write functions that can accept a
>> myriad of named arguments.
>> 
>> $result = some_function  parameter1 => value1,
>>                          parameter2 => value2,
>>                          parameter3 => value3,
>>                          parameter4 => value4;
>
>This type of syntax might be annoying in Perl; I guess that's one
>reason Perl doesn't have it.

What Abbagale wrote is valid perl.  It would look something like this

sub some_function (%) {
  my %args=@_;

#Insurt code hear.

}



-- 
Please excuse my spelling as I suffer from agraphia. See the URL in my
header to find out more.



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

Date: Thu, 29 Oct 1998 18:13:37 -0600
From: Tk Soh <r28629@email.sps.mot.com>
To: Gary Jackson <garyj@dsp.sps.mot.com>
Subject: Re: Need help appending a string to a hash
Message-Id: <363904B1.2EBD055B@email.sps.mot.com>

[posted and copy emailed]
Gary Jackson wrote:
> #!/usr/local/bin/perl

#!/usr/local/bin/perl -w     # -w is your friend :)

> #
> # This perl script counts the number of failing vectors
> # from a dlog file and creates a useful report.  GJ--21oct98
> #
> 
> %Fail_Vec = ();
> 
> while (<>) {
>     chomp;      # strip record separator (pesky newline)
> 
>     # CALCULATE TOTAL NUMBER OF FAILING VECTORS USING ASSOCIATIVE ARRAYS
>     if
>     (/^(\d+)\.\s+\S+\s+\S+\s+\S+\s+(\d+)\,\s+(\d+)\,.*PATTERNS(\S+).*/) {
>        if ($Fail_Vec{$2} == 0) {
>            push( @{$Fail_Vec{$2}}, $4 ); # SAVE THE STRING AT END OF ROW
>        }
>        $Fail_Vec{$2}++; # INCREMENT THE NUMBER OF FAILS
         ^^^^^^^^^^^^^^^
Oops, $Fail_Vec{$2} is a reference to array. Who know where is pointing
to now after getting incremented.

>       }
> }
> 
> foreach $fail (keys %Fail_Vec) {
>    write;
> }
> 
> format STDOUT=
> @######  @######
> @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
> 
> $fail, $Fail_Vec{$fail}, @{$Fail_Vec{$fail}}
         ^^^^^^^^^^^^^^^^
         scalar @{$Fail_Vec{$fail}}
> .
> 

I believe there is an error with your 'format', but I will leave it to
you.

-tk


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

Date: Fri, 30 Oct 1998 01:06:57 GMT
From: mgjv@comdyn.com.au (Martien Verbruggen)
Subject: Re: Need help appending a string to a hash
Message-Id: <Ri8_1.1$kr5.134@nsw.nnrp.telstra.net>

In article <363904B1.2EBD055B@email.sps.mot.com>,
	Tk Soh <r28629@email.sps.mot.com> writes:

>>        }
>>        $Fail_Vec{$2}++; # INCREMENT THE NUMBER OF FAILS
>          ^^^^^^^^^^^^^^^
> Oops, $Fail_Vec{$2} is a reference to array. Who know where is pointing
> to now after getting incremented.

Nothing. It changes to a scalar.

#!/usr/local/bin/perl -w
use strict;
my $a = [1, 2, 3];
print "$a, @$a\n";
$a++;
print "$a, ";
print "@$a\n";

ARRAY(0xd9064), 1 2 3
Can't use string ("888933") as an ARRAY ref while "strict refs" in use at ./tt.pl line 7.
888933,

Martien
-- 
Martien Verbruggen                      |
Webmaster www.tradingpost.com.au        | "In a world without fences,
Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
NSW, Australia                          |


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

Date: Thu, 29 Oct 1998 14:13:10 +0000
From: Austin Schutz <spamsux-tex@habit.com>
Subject: Re: Not to start a language war but..
Message-Id: <363877F6.4B29@habit.com>

> : The bottom line is that both languages are freely available - it just
> : costs some of your time to try them both and make up your own mind.
> 
>         Yep, and a bit of time to wade through the BS each side dish
>         out to see what is really there.
> 

	It would be very interesting to see how Perl would be created
if it were to be redone from the ground up, without all the legacy code
and '7 deadly sins'. Ever try overloading print()?

	A couple of the things I think are really cool about python that
I wish perl had are jpython and the ability to compile to bytecode. The
python thread module seems to be more mature (and better documented!)
than the Perl equivalent.
	On the other hand I like a couple of simple lazy features of perl.
	@files = `ls`;
	`rm this_file_sucks`;
	perl -ne 's/#.*//g;print';
	chdir $d or die $!;
	
	It would be really swell if someone were to write a perl programmer's
roadmap to python. I've never really been able to get very
far with it because my brain is pretty perl-ized in terms of ways to
structure data (shove it all in a hash) and my purely lazy attitude.
Well, I shouldn't say that. I haven't really had the time.

	Austin


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

Date: 29 Oct 1998 23:53:50 GMT
From: gorilla@elaine.drink.com (Alan Barclay)
Subject: Re: Not to start a language war but..
Message-Id: <909705228.834267@elaine.drink.com>

In article <909679180.381062@thrush.omix.com>,
Zenin  <zenin@bawdycaste.org> wrote:
>: If you claim Perl has had exceptions for dog years, don't come with
>: a spiffy OO example which has only been there since 5.005 - and then
>: as an undocumented experimental feature.
>
>	eval {
>	    die ('boom');
>	};
>	if ($@) {
>	    die "I went $@";
>	}
>
>	Works quite nicely under perl 4, and I think 3 (though I don't have
>	a copy to try off hand).

I happen to have a copy of perl3 lying around, so I tried it:
#!/usr/bin/perl3

eval "
    die ('boom');
";

if ($@) {
    die("I went $@");
}

produced the output:
I went boom at (eval) line 3.

Perl 3 couldn't eval a block, only a string, so that explains the slight
difference between the program above, and the one I ran.



I happen to have a copy of perl2 lying around, so I tried it. The same program,
with only the #! line changed, produced:

I went boom at (eval) line 2.

Same error message, but the line number is counted slightly differently.



I happen to have a copy of perl1 lying around, so I tried it. The same program,
with only the #! line changed, produced:

I went boom

Same error message, but the line number isn't output.

Therefore I deduce that perl has had exceptions since day 1, or at least
at the patch level I have (perl v1.0.1.3 Patch level 10).


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

Date: Thu, 29 Oct 1998 17:59:36 -0800
From: Jason Orendorff <jorendorff@ixl.com>
Subject: Re: Not to start a language war but..
Message-Id: <36391D88.34EA64D9@ixl.com>

>         Different and much more limited OO.  If you want Python style
>         OO in Perl you have only to use your own self control to limit
>         yourself to it.

And learn the semantics of bless's default arguments, and learn to
appreciate the beauty of $x->{y} versus x.y  :-)


re: Exceptions in Perl
>        sub MyException::new { bless {}, shift() }
>        eval {
>            trySomething()
>                or die new MyException ();
>        };
>        if ($@) {
>            if (ref $@ eq 'MyException') {
>                cleanUp();
>            }
>            else {
>                die; // propagate the exception
>            }
>        }

Equivalent Python:

  class MyException:  pass

  try:
      something()
  except MyException:
      cleanUp()

I think this speaks for itself...

Anyway, Perl allows a lot of silent errors throughout the
language and libraries that would subvert any exception system
you might claim exists.  I'm not saying this is a bad thing, I'm
just saying Perl doesn't have exceptions.

>         Name a platform Python supports that Perl doesn't, I dare you.

JVM.  What do I win?

Also, I'm curious about Windows CE; there's a Perl for Windows CE, right?


>         However I'd be surprised if I couldn't name a few that Perl
>         supports but Python doesn't.

I dunno, it seems like it *should* be that way, since (or so I hear) Perl
has 4000 times as many users.  Please go ahead.

> And there goes your praised "truely cross-platform" argument. :-)

Look, typical Python code really has an easier time porting than typical
Perl code.  I promise.

>         Ever try 'perl -d'?

Wow!  I just did, for the first time.  Better than I expected, actually.
Well, at least something good came from this flame war.  :-)

>         your right all this punctuation stuff just makes languages harder to
>         read i dont understand why english does it as well it must just

*half-frown*  I have to assume this is facetiousness.


<heinous Java code snipped>
>         Please show me how the readability of this code would be helped by
>         either indent style blocks or max 80 column text.  Give me a couple
>         minutes and I'm sure I could dig up a couple dozen Perl and C
>         examples as well.

Please go right ahead.  The resulting discussion may help you to
understand that which you are so ardently slagging.

The equivalent of all that Java in JPython is:

    def append(self, x): self._extractStringBuffer().append(x); self.type = STRING; return self.string

I hope you appreciate that; I had to reconfigure my mailer so it wouldn't
wrap the line.  :-)  I would normally write it like this:

    def append(self, x):
        self._extractStringBuffer().append(x)
        self.type = STRING
        return self.string

The Python code is loosely typed, but dispatches to the properly
typed java methods.  Nice, eh?  Even if it is useless.  ;-)

And where does the "max 80 column text" idea come from?
Calm down, brother!

-- 
Jason


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

Date: 30 Oct 1998 01:06:30 GMT
From: jsd@hudsucker.gamespot.com (Jon Drukman)
Subject: Re: Not to start a language war but..
Message-Id: <slrn73i4e3.9k9.jsd@hudsucker.gamespot.com>

In article <909705228.834267@elaine.drink.com>, Alan Barclay wrote:
>Therefore I deduce that perl has had exceptions since day 1, or at least
>at the patch level I have (perl v1.0.1.3 Patch level 10).

unfortunately what it has lacked since day 1 (and still lacks) is a
way of getting the built-in functions to generate exceptions.

anxiously awaiting "use Fatal",

-- 
Jon Drukman                                            jsd@gamespot.com
-----------------------------------------------------------------------
Fear the government that fears your computer.


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

Date: 30 Oct 98 01:50:09 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Not to start a language war but..
Message-Id: <909712475.164200@thrush.omix.com>

Austin Schutz <spamsux-tex@habit.com> wrote:
	>snip<
: 	It would be really swell if someone were to write a perl programmer's
: roadmap to python. I've never really been able to get very
: far with it because my brain is pretty perl-ized in terms of ways to
: structure data (shove it all in a hash) and my purely lazy attitude.

	I've always thought a Python programmer's roadmap to Perl would
	be far more useful. :-)
-- 
-Zenin (zenin@archive.rhps.org)           From The Blue Camel we learn:
BSD:  A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts.  Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.)  The full chemical name is "Berkeley Standard Distribution".


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

Date: 30 Oct 98 01:54:30 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Not to start a language war but..
Message-Id: <909712736.95827@thrush.omix.com>

[posted & mailed]

Alan Barclay <gorilla@elaine.drink.com> wrote:
	>snip<
: I happen to have a copy of perl3 lying around, so I tried it:
: I happen to have a copy of perl2 lying around, so I tried it. The same program,
: I happen to have a copy of perl1 lying around, so I tried it. The same program,
: with only the #! line changed, produced:
	>snip<
: Therefore I deduce that perl has had exceptions since day 1, or at least
: at the patch level I have (perl v1.0.1.3 Patch level 10).

	Cool info to know, thanks!

	BTW, would you happen to have copies of the source for versions
	1, 2, and 3?  I'd like to have them around for such historical
	testing.

-- 
-Zenin (zenin@archive.rhps.org)           From The Blue Camel we learn:
BSD:  A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts.  Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.)  The full chemical name is "Berkeley Standard Distribution".


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

Date: Thu, 29 Oct 1998 19:48:08 -0500
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: pass array to sub
Message-Id: <MPG.10a2d6d069c5bdf39896ee@news.scescape.net>

In article <<8cvhl3tafp.fsf@gadget.cscaper.com>>, 
merlyn@stonehenge.com (Randal Schwartz) gently reminded me that:
=> >>>>> "Matthew" == Matthew Bafford <dragons@scescape.net> writes:
=> 
=> Matthew> print "Array1 Before: ", join(" ", @array1), "\n";
=> 
=> Typing optimization:
=> 
=>   join " ", @foo
=> 
=> is easier typed as
=> 
=>   "@foo"
=> 
=> making that statement:
=> 
=> 	print "Array1 before: @array1\n";
=> 
=> Much easier. :)

ACK!  Oh my.

I guess I was getting print's behavior with a list confused with how 
arrays are handled in strings.

Whoops. :)

Thanks!

--Matthew
There you are, Larry (R)!  My got-me for the day. :)


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

Date: 29 Oct 1998 16:19:13 -0800
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Perl & Y2K - booby trap code
Message-Id: <yl1znqhpfi.fsf@windlord.stanford.edu>

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

> perl -we '...' (correct) is not the same as perl -ew '...' (wrong).  In
> this respect, Perl command-line processing differs from the Unix norm,
> in which any number of single-letter no-argument options may be mixed
> with one single-argument option, in any order.

That's disputable.  There doesn't seem to be much standardization on that
point; I've seen some Unix tools behave one way and some the other way.
The problem is that perl uses strong argument bundling as opposed to weak
argument bundling, which allows you to say things like perl -e42 since the
space separation isn't required.

> grep -f => readdir DIR; returns all the entries in the directory, not
> just the files, because the => operator 'forces any word to the left of
> it to be interpreted as a string' (from perlop).  So the grep is for
> '-f', which is TRUE.  But '-f' is not a word, it is an operator.  Perl
> defines a 'word' as a string that matches /^\w+$/.  See perlre: '\w
> Match a "word" character (alphanumeric plus "_") ... To match a word
> you'd need to say \w+.'  But perl doesn't seem to think so.

Er... if you literally mean the code:

        grep -f => readdir DIR;

I'd find that horribly obfuscated.  Yeah, there are a lot of syntax
weirdnesses around boundary cases like that, but isn't:

        grep { -f } readdir DIR;

a lot clearer?  Point about documentation inconsistency taken, but
unfortunately I think => is right to treat things beginning with - as
words due to the number of people who think it's a cool way to do option
parsing to pass in a hash or flattened hash with options beginning with
-.  I personally utterly detest that style, but....

> Unescaped '$' at the end of a regex does not necessarily match the end
> of the operand string.  From perlop:  '$ Match the end of the line (or
> before newline at the end)'.  But this caught me and others.

That's a DWIM thing.  And in 99% of the cases, it succeeds in being that.

> $n = /xyz/g; does not count the number of 'xyz's in $_, but has values
> TRUE or FALSE.  To count them, one may say $n = () = /xyz/g; or ++$n
> while /xyz/g; or $n = s/xyz/xyz/g; (as someone posted recently; ugh!).

Using regexes to do counts is something that I'd consider "advanced."

> $n = tr/x//; counts the number of 'x's in $_, the same as tr/x/x/; To
> delete them, one must say tr/x//d;

This is semi-consistent with the behavior of the traditional tr utility.
The fact that it's not consistent with regex matching is certainly
something that confuses people, but people generally get confused about
all sorts of things with tr (thinking they can use regex metacharacters,
etc.).  tr is *not* using regular expressions, and people just have to
keep that in mind.

-- 
#!/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: 29 Oct 1998 16:20:00 -0800
From: Russ Allbery <rra@stanford.edu>
Subject: Re: Perl & Y2K - booby trap code
Message-Id: <ylyapygatr.fsf@windlord.stanford.edu>

Uri Guttman <uri@fastengines.com> writes:

> i like the look of => but not always its quoting. i like to see quotes
> on my strings. in general i am against bare words as hash keys. this is
> a visual style thing and not a syntax or semantic thing with me.

Ew.  We're pretty much completely opposed there.  :)

-- 
#!/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, 29 Oct 1998 16:09:32 -0800
From: "Alistair Calder" <webmaster@topproducer.com>
Subject: Re: Perl how-to question
Message-Id: <71b0bu$lu6$1@supernews.com>

That worked very well, thanks much.  Them scalar arrays can confuse me
sometimes.

Appreciate it.


Martien Verbruggen wrote in message ...
>In article <718grq$elf$1@supernews.com>,
> "Alistair Calder" <webmaster@topproducer.com> writes:
>> I am creating an online survey for the company I work for.  I have
>> programmed in perl before, but this question has flummoxed me.
>>
>> I want to create a single file that will store all the survey values,
>> including the survey Question, the possible responses and the number of
>> respondants.  The catch is that the surveys will have a varying number of
>> responses and I don't know how to tell perl to read that in.
>>
>> Here is what the file will look like:
>>
>>
Survey_Date|Survey_Question|Number_Of_Responses|Response_A|Total_A|Response_
>> B|Total_B
>>
>> So a real life example would be:
>>
>> 01/01/98|Do you think that Clinton should be impeached?|3|Yes, I think
>> so|301|Not Really|268|Couldn't care less|65
>>
>> I know how to do a split on a file I have read in, but only if I know the
>> number of responses that I have.  How can I do this properly?
>
>Do the split, in such a way:
>
>($date, $question, $n, @f) = split(/\|/, $line);
>
>$n will contain the number of responses, @f will contain the responses
>and the numbers. of course, you don't need $n, because @f in a scalar
>context will give you that same number doubled (if $n is correct). Or
>$#f + 1 will also give you that number. Now all you need to do is loop
>over @f to get each response and their number in turn. You might want
>to check that @f actually contains an even number of elements.
>
>Martien
>--
>Martien Verbruggen                      |
>Webmaster www.tradingpost.com.au        | "In a world without fences,
>Commercial Dynamics Pty. Ltd.           |  who needs Gates?"
>NSW, Australia                          |




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

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

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