[23878] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6081 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Feb 4 21:05:35 2004

Date: Wed, 4 Feb 2004 18:05:06 -0800 (PST)
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, 4 Feb 2004     Volume: 10 Number: 6081

Today's topics:
    Re: Clarifications <usenet@morrow.me.uk>
    Re: Clarifications <jwkenne@attglobal.net>
    Re: Clarifications <edgrsprj@ix.netcom.com>
    Re: Clarifications <jwkenne@attglobal.net>
    Re: Copy Constructor Craziness <usenet@morrow.me.uk>
    Re: Difficulty cleaning oddly encoded whitespace (from  <usenet@morrow.me.uk>
    Re: Docs comprehensibility [was: Perl For... ] <tassilo.parseval@rwth-aachen.de>
    Re: Docs comprehensibility [was: Perl For... ] <noreply@gunnar.cc>
    Re: Docs comprehensibility [was: Perl For... ] <usenet@morrow.me.uk>
    Re: Docs comprehensibility <noreply@gunnar.cc>
    Re: Docs comprehensibility <usenet@morrow.me.uk>
    Re: group but do not capture <usenet@morrow.me.uk>
    Re: newbie help <spam@spammer.com>
    Re: newbie help <noreply@gunnar.cc>
    Re: Perl data types <skweek@no.spam>
    Re: Perl data types <no@spam.uk>
    Re: Perl data types <usenet@morrow.me.uk>
    Re: Perl data types <usenet@morrow.me.uk>
    Re: Perl data types <emschwar@pobox.com>
    Re: Perl For Amateur Computer Programmers <edgrsprj@ix.netcom.com>
    Re: Perl For Amateur Computer Programmers <usenet@morrow.me.uk>
    Re: Perl For Amateur Computer Programmers <bigiain@mightymedia.com.au>
    Re: Perl For Amateur Computer Programmers <bigiain@mightymedia.com.au>
    Re: Perl-Cgi Newbee! <jgibson@mail.arc.nasa.gov>
    Re: Turn $5 into $15,000 or more!!! Here's how.... <usenet@morrow.me.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Wed, 4 Feb 2004 23:43:30 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Clarifications
Message-Id: <bvs032$c25$1@wisteria.csv.warwick.ac.uk>


Michele Dondi <bik.mido@tiscalinet.it> wrote:
> On Wed, 04 Feb 2004 01:00:15 GMT, "John W. Kennedy"
> <jwkenne@attglobal.net> wrote:
>
> Well, in practice *I* (not you) have *only* "initials" and
> "abbreviation". But indeed "sigla" is also used for monograms.
> 
> To cut the story down, the point is that both officially and to common
> people a "thing" like "USA", "CCCP" (i.e. "SSSR", btw!), etc. is a
> sigla.

So you wouldn't make the distinction between something like 'USA' and
something like 'NATO'? Interesting.

> >acronyms now than there were then, thanks to computers.  (But none as 
> >famous as "Vittorio Emmanuele, Re D'Italia".)
> 
> Huh?!? I just don't know it, but in any case you mean *Emanuele*,
> don't you? Oh, come on, what's its meaning?

http://en.wikipedia.org/wiki/Giuseppe_Verdi

(I *keep* wanting to spell that 'wikipaedia', dammit!)

Ben

-- 
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/'                                                 # ben@morrow.me.uk


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

Date: Wed, 04 Feb 2004 23:54:52 GMT
From: "John W. Kennedy" <jwkenne@attglobal.net>
Subject: Re: Clarifications
Message-Id: <gDfUb.11416$%93.3170759@news4.srv.hcvlny.cv.net>

edgrsprj wrote:
> Do you know if Ruby will generate code which can be used for CGI programs at
> Web sites?  That is another feature that made Perl look attractive.

Ruby has, in its standard distribution, a CGI package that is similar, 
on the whole, to the PERL CGI package.  If you are building your own 
server, either one will work.

Note, however, that many website-hosting services (e.g., Tripod), 
support _only_ Perl (and Tripod supports only an obsolete and badly 
broken version of Perl at that).

-- 
John W. Kennedy
"But now is a new thing which is very old--
that the rich make themselves richer and not poorer,
which is the true Gospel, for the poor's sake."
   -- Charles Williams.  "Judgement at Chelmsford"


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

Date: Thu, 05 Feb 2004 00:02:40 GMT
From: "edgrsprj" <edgrsprj@ix.netcom.com>
Subject: Re: Clarifications
Message-Id: <AKfUb.10015$jH6.4847@newsread1.news.atl.earthlink.net>

"Joe Smith" <Joe.Smith@inwap.com> wrote in message
news:MDdUb.173729$Rc4.1316159@attbi_s54...
> edgrsprj wrote:
>

> It's not a problem with any browser.  It's your source code.
>
> 1: open FILENAME “> c:\textfile.txt”;  # “smart quotes”
> 2: open FILENAME "> c:/textfile.txt";  # "double quotes" forward slash
>
> Any code you post needs to be formatted such that the quote marks
> are vertical, not slanted left and right like line 1 above.
> -Joe

Now I see what you mean.  I will have to check on how my word processor is
generating those quotes.  There is probably some way to ensure that they all
look the same.




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

Date: Thu, 05 Feb 2004 01:53:51 GMT
From: "John W. Kennedy" <jwkenne@attglobal.net>
Subject: Re: Clarifications
Message-Id: <PmhUb.11754$%93.3864550@news4.srv.hcvlny.cv.net>

Michele Dondi wrote:
> Huh?!? I just don't know it, but in any case you mean *Emanuele*,
> don't you? Oh, come on, what's its meaning?

Oh how short is human memory!

During the Risorgimento, the graffito "VIVA VERDI!" became wildly
popular.  It stymied the Austrians, for who could complain about the
popularity of the great composer?  But Italian patriots knew that
"VERDI" was more than "green", and more than a man's name, too, for it
also stood for "Vittorio Emanuele Re D'Italia".

-- 
John W. Kennedy
"But now is a new thing which is very old--
that the rich make themselves richer and not poorer,
which is the true Gospel, for the poor's sake."
   -- Charles Williams.  "Judgement at Chelmsford"




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

Date: Thu, 5 Feb 2004 00:02:34 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Copy Constructor Craziness
Message-Id: <bvs16q$cm0$3@wisteria.csv.warwick.ac.uk>


use63net@yahoo.com (Unknown Poster) wrote:
> The behavior I'm seeing in Perl 5.6 contradicts what I understand
> about copy constructors - specifically, when they are autogenerated.
> 
> # $f is a reference to an object
> my $g = $f;
> print "\$g = $g, ";
> ++$g;
> print "after ++, \$g = $g, \$f = $f\n";  # The value of $g changes,
> but the
>                                          #  value of $f does not!
> 
> There is no overloading of "=" - no explicit copy constructor in the
> class.
<snip>
> There are two separate scalar values in every object of the class,
> so I don't see why the copy constructor is apparently being
> autogenerated in this case.

Please post a short *complete* program exhibiting the problem, and
explain how what it is doing differs from what you want it to do.

Ben

-- 
'Deserve [death]? I daresay he did. Many live that deserve death. And some die
that deserve life. Can you give it to them? Then do not be too eager to deal
out death in judgement. For even the very wise cannot see all ends.'
 :-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-:-: ben@morrow.me.uk


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

Date: Wed, 4 Feb 2004 23:57:02 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Difficulty cleaning oddly encoded whitespace (from MS HTML)
Message-Id: <bvs0se$cm0$1@wisteria.csv.warwick.ac.uk>


throop@cs.utexas.edu (David R. Throop) wrote:
> I'm perplexed.  I'm writing a PERL script that reads a single large
> many-sectioned HTML document, breaks it into smaller files and
> extracts some information for another text-manipulation tool to read.
> The first HTML file comes from saving a 150+ page MS-Word file as HTML.
> 
> I'm having fits with some nonstandard whitespace in the HMTL file.  It
> appears like a long whitespace and acts as a single character, but it
> doesn't patternmatch a \s.  When I view it in Emacs, it appears as
>     %/1\200\216iso8859-15^B\201 \201 \201 

Hmmmm... I bet that's mangled UTF8. What 'iso8859-15' is doing in
there I'm not sure, but anyhow... Which perl are you using? If you're
using 5.8, try pushing :utf8 or (better) :encoding(utf8) onto your
input filehandle. If you're stuck with 5.6, you can try one of the
Unicode:: modules, but if you're doing character encoding stuff you'd
be much better off with 5.8.

Ben

-- 
It will be seen that the Erwhonians are a meek and long-suffering people,
easily led by the nose, and quick to offer up common sense at the shrine of
logic, when a philosopher convinces them that their institutions are not based 
on the strictest morality.  [Samuel Butler, paraphrased]       ben@morrow.me.uk


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

Date: 4 Feb 2004 23:05:48 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Docs comprehensibility [was: Perl For... ]
Message-Id: <bvrtsc$f5l$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Gunnar Hjalmarsson:

> I agree as well. The documentation occationally introduces the nature
> of functions etc. very poorly, which the examples posted by Iain and
> Greg illustrate.
> 
> Perl is my first (and so far only) programming language, and with a
> better documentation it would certainly have taken less time to learn
> some things.
> 
> This isn't the first time this issue is brought up. One reason why
> nothing is changed may be that the most skilled and dedicated Perl
> programmers don't see the shortcomings, since the nature of those
> functions and other features has been natural to them since long.
> 
> Maybe a beginner should be engaged to proof read and suggest changes
> to the docs? ;-)

In the past, there were often complains about the perldocs on the
porters-list. The reason why not so many things change is that those
complaining weren't the ones providing patches. 

It's a question of priority. There aren't so many people that can work
on the core of perl. It would be a waste of ressources if those people
additionally had to spend excessive time on the perldocs. Doc-patches
can also be provided by all those people who are solid Perl programmers
but don't understand the perlguts. Those who do are rare enough.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Thu, 05 Feb 2004 00:55:58 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Docs comprehensibility [was: Perl For... ]
Message-Id: <bvs0nm$vvv23$1@ID-184292.news.uni-berlin.de>

Tassilo v. Parseval wrote:
> Also sprach Gunnar Hjalmarsson:
>> One reason why nothing is changed may be that the most skilled
>> and dedicated Perl programmers don't see the shortcomings, since
>> the nature of those functions and other features has been natural
>> to them since long.
>> 
>> Maybe a beginner should be engaged to proof read and suggest
>> changes to the docs? ;-)
> 
> In the past, there were often complains about the perldocs on the 
> porters-list. The reason why not so many things change is that
> those complaining weren't the ones providing patches.

I'm not surprised. :(

> It's a question of priority. There aren't so many people that can
> work on the core of perl. It would be a waste of ressources if
> those people additionally had to spend excessive time on the
> perldocs.

Would it, really? Shouldn't the docs be given high priority? After
all, the value of new and/or sophisticated features is limited if they
are understood by just a few...

> Doc-patches can also be provided by all those people who are solid
> Perl programmers but don't understand the perlguts. Those who do
> are rare enough.

Would it be that impossible to involve not so solid programmers? I'm
not suggesting that beginners should write docs *independently*, but
giving a few of the more dedicated beginners an opportunity to give
their *input* might add value.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Thu, 5 Feb 2004 00:22:38 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Docs comprehensibility [was: Perl For... ]
Message-Id: <bvs2ce$cm0$6@wisteria.csv.warwick.ac.uk>


Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> Tassilo v. Parseval wrote:
> > It's a question of priority. There aren't so many people that can
> > work on the core of perl. It would be a waste of ressources if
> > those people additionally had to spend excessive time on the
> > perldocs.
> 
> Would it, really? Shouldn't the docs be given high priority? After
> all, the value of new and/or sophisticated features is limited if they
> are understood by just a few...

The docs are perfectly *comprehensible*, indeed comprehensive. They
are just not very friendly: if you know nothing, and in particular
with some of the older docs if you know no C, you have to work quite
hard to figure out what's going on. Or buy a book, of course.

> > Doc-patches can also be provided by all those people who are solid
> > Perl programmers but don't understand the perlguts. Those who do
> > are rare enough.
> 
> Would it be that impossible to involve not so solid programmers? I'm
> not suggesting that beginners should write docs *independently*, but
> giving a few of the more dedicated beginners an opportunity to give
> their *input* might add value.

The standard response at this point is that if you wish to submit a
patch to the docs I'm sure it will be well received. If you are not so
confident of your ability to write clearly enough, post here for
criticism. It's much easier to improve a piece of text someone else
has written than to write one yourself.

Ben

-- 
$.=1;*g=sub{print@_};sub r($$\$){my($w,$x,$y)=@_;for(keys%$x){/main/&&next;*p=$
$x{$_};/(\w)::$/&&(r($w.$1,$x.$_,$y),next);$y eq\$p&&&g("$w$_")}};sub t{for(@_)
{$f&&($_||&g(" "));$f=1;r"","::",$_;$_&&&g(chr(0012))}};t    # ben@morrow.me.uk
$J::u::s::t, $a::n::o::t::h::e::r, $P::e::r::l, $h::a::c::k::e::r, $.


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

Date: Thu, 05 Feb 2004 01:51:26 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Docs comprehensibility
Message-Id: <bvs3vm$vusq9$1@ID-184292.news.uni-berlin.de>

Ben Morrow wrote:
> Gunnar Hjalmarsson wrote:
>> Tassilo v. Parseval wrote:
> 
> The docs are perfectly *comprehensible*, indeed comprehensive. They
> are just not very friendly: if you know nothing, and in particular
> with some of the older docs if you know no C, you have to work
> quite hard to figure out what's going on.

And what a few of us are trying to say is that that is not very good.

>>> Doc-patches can also be provided by all those people who are
>>> solid Perl programmers but don't understand the perlguts. Those
>>> who do are rare enough.
>> 
>> Would it be that impossible to involve not so solid programmers?
>> I'm not suggesting that beginners should write docs
>> *independently*, but giving a few of the more dedicated beginners
>> an opportunity to give their *input* might add value.
> 
> The standard response at this point is that if you wish to submit a
> patch to the docs I'm sure it will be well received. If you are
> not so confident of your ability to write clearly enough, post here
> for criticism. It's much easier to improve a piece of text someone
> else has written than to write one yourself.

Standard response, indeed, that did not actually address my point. ;-)

Personally I may try to contribute to the docs some day when I feel
confident enough.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Thu, 5 Feb 2004 01:14:03 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Docs comprehensibility
Message-Id: <bvs5cr$g48$1@wisteria.csv.warwick.ac.uk>


Gunnar Hjalmarsson <noreply@gunnar.cc> wrote:
> Ben Morrow wrote:
> > 
> > The docs are perfectly *comprehensible*, indeed comprehensive. They
> > are just not very friendly: if you know nothing, and in particular
> > with some of the older docs if you know no C, you have to work
> > quite hard to figure out what's going on.
> 
> And what a few of us are trying to say is that that is not very
> good.

Fine. Fix it, then. Personally, I like the docs how they are; if you
want them to be different, rewrite them.

> >> Would it be that impossible to involve not so solid programmers?
> >> I'm not suggesting that beginners should write docs
> >> *independently*, but giving a few of the more dedicated beginners
> >> an opportunity to give their *input* might add value.
> > 
> > The standard response at this point is that if you wish to submit a
> > patch to the docs I'm sure it will be well received. If you are
> > not so confident of your ability to write clearly enough, post here
> > for criticism. It's much easier to improve a piece of text someone
> > else has written than to write one yourself.
> 
> Standard response, indeed, that did not actually address my
> point. ;-)

Umm... did it not? I'm not sure whether you class yourself as a
'dedicated beginner' or not, but if you do then feel free to put
forward suggestions for specific changes, and if you don't then go ask
some beginners for suggestions and put forward a collation. In either
case we have input from the beginners to the docs, which is what you
want.

Perl is the product of a community. Something will only get done if
someone either needs it to be done so they can use it or feels
sufficiently strongly that it ought to be done that they do it out of
the goodness of their heart.

> Personally I may try to contribute to the docs some day when I feel
> confident enough.

If confidence is the only thing stopping you then I would say your
grasp of both Perl and English is quite sufficient to write a decent
explanation of sprintf.

Ben

-- 
  Joy and Woe are woven fine,
  A Clothing for the Soul divine       William Blake
  Under every grief and pine          'Auguries of Innocence'
  Runs a joy with silken twine.                                ben@morrow.me.uk


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

Date: Thu, 5 Feb 2004 00:11:20 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: group but do not capture
Message-Id: <bvs1n8$cm0$4@wisteria.csv.warwick.ac.uk>

[don't top-post]

naren_tech@yahoo.com (naren) wrote:
> I understand that we can get this in $1 and $2, but the challenge I
> faced is to get this in one step, basically I feed this regex to a
> configuration file, which will use this regex to parse the line, it
> can only take $1, it can't append $1 and $2.

Can't be done. Each $N captures a contiguous sequence of characters
from the target string, so you can't get two sections from different
places into $1.

>  That is why I considered to use (?:\|), group but do not capture,I
> haven't undestood how this works??

No... () captures *everything* inside it. Even if some of the inside
is captured again. If you execute

"abc" =~ /(.(.).)/

then $1="abc" and $2="b": the "b" has been captured twice. If that had
been

"abc" =~ /(.(?:.).)/

then you would have $1="abc" still but no $2 as there's only one set
of capturing parens.

Ben

-- 
Musica Dei donum optimi, trahit homines, trahit deos.    |
Musica truces mollit animos, tristesque mentes erigit.   |   ben@morrow.me.uk
Musica vel ipsas arbores et horridas movet feras.        |


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

Date: Wed, 4 Feb 2004 17:14:22 -0600
From: "Ram" <spam@spammer.com>
Subject: Re: newbie help
Message-Id: <bvruaj$oro$1@grandcanyon.binc.net>

Script I used:

#!/usr/bin/perl
use strict;
my $el;
open(ONE, "ordsts.txt" ) or die "Can't open file $! \n";
while (<ONE>) {
#print "$_ \n";
my @lastmatch = /.*(<ordsts>.*<\/ordsts>)/s;
print "@lastmatch \n";
$el= my @lastmatch;
}
print "$el \n";



I am not the Ram you know!!


"Chris" <ceo@nospan.on.net> wrote in message
news:3uaUb.32014$Kn6.23964@newssvr33.news.prodigy.com...
> Ram wrote:
> > How do I search for just the ordsts start(<ordsts>) and end
tags(</ordsts>)
> > and the data between them, and get just the last matched one. Also would
> > need an idea of how to get the last two matches.
> >
> > Thanks for the pointers.
> >
> > [snipped sample XML]
>
> If this is XML, as it appears to be, you might do better parsing and get
> better overall mileage from using XML::Simple or one of its close cousins.
>
> (Wondering if this is the "Ram" that *I* know.  If so, I hope you are
> doing well.)
>
> Chris
> -----
> Chris Olive
> chris -at- technologEase -dot- com
> http://www.technologEase.com
> (pronounced "technologies")
>




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

Date: Thu, 05 Feb 2004 00:43:36 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: newbie help
Message-Id: <bvs00f$109jb0$1@ID-184292.news.uni-berlin.de>

Ram wrote:
> Script I used:
> 
> #!/usr/bin/perl
> use strict;
> my $el;
> open(ONE, "ordsts.txt" ) or die "Can't open file $! \n";
> while (<ONE>) {
> #print "$_ \n";
> my @lastmatch = /.*(<ordsts>.*<\/ordsts>)/s;
> print "@lastmatch \n";
> $el= my @lastmatch;
> }
> print "$el \n";

It proves that gnari guessed right: You are applying the regex to one 
line at a time, which obviously can't work.

Try this instead:

     #!/usr/bin/perl
     use strict;
     use warnings;
     open ONE, "ordsts.txt" or die "Can't open file $!";
     $_ = do { local $/; <ONE> };  # slurp file into $_
     close ONE;
     my ($el) = /.*(<ordsts>.*<\/ordsts>).*/s;
     print "$el\n";

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



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

Date: Thu, 05 Feb 2004 00:05:08 +0100
From: AlV <skweek@no.spam>
Subject: Re: Perl data types
Message-Id: <bvrtr5$kkd$1@news-reader4.wanadoo.fr>

Eric Schwartz wrote:
> "David Holmes" <no@spam.uk> writes:

[snip]

>>as far as I can tell, since perl is not a typed language as such it
>>is imposible to tell the differnce between the types, for example a
>>case statement is impossible.
> 
> 
> Case statements are possible, they're just not built into the
> language.  See perlfaq7, "How do I create a switch or case statement?".
> 
> And perl is typed, albeit loosely.

Just to add my two cents, Damian Conway has made a module named 
Attribute::Types which adds strong typing (at run time, not compile 
time) to Perl 5:

http://search.cpan.org/~dconway/Attribute-Types-0.10/lib/Attribute/Types.pm
(this module requires Attribute::Handlers)

Have a nice day,


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

Date: Wed, 4 Feb 2004 23:06:23 -0000
From: "David Holmes" <no@spam.uk>
Subject: Re: Perl data types
Message-Id: <NVeUb.2076$%i5.185@news-binary.blueyonder.co.uk>

Hi,

The definition of a product type is a type that collects together a number
of data items in a single value. This is why I think that it is a struct. I
know that a product type would be a strinct in c, and in java it would just
be a case of specifying multiple variables, to a class.

Basically I dont know what languages you know but take java for example,
which of course would be similar for c++. If you have an object called Test
that has two string variables, you can deal with the Test object as an
individual item, but can get access to the individual elements.

Similar in a way to a perl hash, you can deal with the hash as a whole
thing, whilst being able to get access to the keys and values, as if they
are two variables of the hash object.

As for sum types, they are subtly different. Values of a sum type are
tagged. This can take several forms but again in the example of a java.
Incase you cant tell this is the language I use most. If you have a base
class that extends a superclass1 and a superclass2. You can initialise a
variable as the base class, and then say:

if (instanceOf(superclass1)) { do something }
else if (instanceOf(superclass2)) { do something else }

As I said the values of a sum type are tagged, so I guess in perl since
there are few primative types, it would be like taking a variable,
initialising it to some value and asking:

if this is a scalar { do something }
else if it is a hash { foreach hash { do something }}
else if it is an array.....


Hope that at least makes some sense.

Regards

Dave

"Eric Schwartz" <emschwar@pobox.com> wrote in message
news:etobroebj4s.fsf@fc.hp.com...
> "David Holmes" <no@spam.uk> writes:
> > firstly product types, as I see it the only way of doing this is to use
> > Class::Struct. This will allow the use of multiple variables to be
> > identified as a single value.
>
> What is a "product type"?  I've not heard this terminology before.
>
> > secondly, does this make a hash a product type, because the keys are
> > referenced by scalars, and these point to variables, which i guess could
be
> > anything but allows a simple structure.
>
> Not knowing what a product type is, I can't help.
>
> > thirdly, does perl support sum types
>
> What is a 'sum type'?
>
> > as far as I can tell, since perl is not a typed language as such it
> > is imposible to tell the differnce between the types, for example a
> > case statement is impossible.
>
> Case statements are possible, they're just not built into the
> language.  See perlfaq7, "How do I create a switch or case statement?".
>
> And perl is typed, albeit loosely.
>
> > The could obviously be overcome using the a regex to an extent to
> > tell whether a scalar is a number or a string, but apart from that
> > it is not really possible.
>
> You don't (generally) care if it's a number or a string.  If you use
> it like a string, it's a string.  If you use it like a number, it's a
> number.
>
> $foo = '4';
>
> $bar = $foo + 3; # $bar is now 7
>
> print "bar is [$bar]" if $bar eq '7';
>
> -=Eric
> -- 
> Come to think of it, there are already a million monkeys on a million
> typewriters, and Usenet is NOTHING like Shakespeare.
> -- Blair Houghton.




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

Date: Wed, 4 Feb 2004 23:14:04 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Perl data types
Message-Id: <bvrubs$avg$1@wisteria.csv.warwick.ac.uk>


"David Holmes" <no@spam.uk> wrote:
> I have a few questions regarding perl composite data types:

I take it you are coming from a Pascal/ML-ish background? From what
little I know of such languages, Perl works quite differently. You do
not need to worry about types in the same way.

> firstly product types, as I see it the only way of doing this is to use
> Class::Struct. This will allow the use of multiple variables to be
> identified as a single value.
> 
> secondly, does this make a hash a product type, because the keys are
> referenced by scalars, and these point to variables, which i guess could be
> anything but allows a simple structure.

I take it a 'product type' is something like a C struct, where you
define that a Foo, foo, consists of a Bar, foo.bar, and a baz,
foo.baz?

Class::Struct is indeed one way of doing this, although for simple
situations it is overkill. The standard Perl way is, as you say, with
a hash:

my %foo = (bar => "something", baz => "something else");

or with an anonymous hash:

my $foo = { bar => "something", baz => "something else");

my $x = { y => $foo, z => "Z" };

You can build up complex data structures like this on the fly, without
needing to declare the types beforehand.

> thirdly, does perl support sum types, as far as I can tell, since perl is
> not a typed language as such it is imposible to tell the differnce between
> the types, for example a case statement is impossible. The could obviously
> be overcome using the a regex to an extent to tell whether a scalar is a
> number or a string, but apart from that it is not really possible.

Again, I take it a 'product type' is like a C union, where a Foo is
either a Bar or a Baz but not both, and you can switch on the runtime
type? This is not really something you need in Perl: as the data
structures are all flexible, you just switch on the values instead.

Having never got my head round one of the 'type-oriented' languages, I
don't really know what you'd use them for to tell you how to do that
in Perl. If you can give me an example of a situation where you'd want
to use one, I'll think how I'd code it.

Ben

-- 
I've seen things you people wouldn't believe: attack ships on fire off the
shoulder of Orion; I've watched C-beams glitter in the darkness near the
Tannhauser Gate. All these moments will be lost, in time, like tears in rain.
Time to die.  |-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-|  ben@morrow.me.uk


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

Date: Wed, 4 Feb 2004 23:27:14 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Perl data types
Message-Id: <bvrv4i$beh$1@wisteria.csv.warwick.ac.uk>

[don't top-post]

"David Holmes" <no@spam.uk> wrote:
> As for sum types, they are subtly different. Values of a sum type are
> tagged. This can take several forms but again in the example of a java.
> Incase you cant tell this is the language I use most. If you have a base
> class that extends a superclass1 and a superclass2.

Surely you mean 'you have a base class that is extended by a subclass1
and a subclass2'? You're talking normal single inheritance, rather
than a class which has two base classes (or implements two interfaces,
or whatever mess Java's made of multiple inheritance)?

> You can initialise a variable as the base class, and then say:
 
> if (instanceOf(superclass1)) { do something }
> else if (instanceOf(superclass2)) { do something else }

Well, you can do that in Perl perfectly easily.

package Base;
sub new { return bless {}, shift }  # a constructor

sub method {
    my $self = shift;
    if ($self->isa("Sub1")) {
        # do summat
    }
    elsif ($self->isa("Sub2")) {
        # do summat else
    }
}

package Sub1;
push @ISA, "Base";  # set up inheritance
sub new { 
    my $class = shift;
    my $self = $class->SUPER::new;
    my $self->{sub1} = "data";
}

package Sub2;
push @ISA, "Base";  # set up inheritance
sub new { 
    my $class = shift;
    my $self = $class->SUPER::new;
    my $self->{sub2} = "data";
}

IMHO, Perl's OO is *really* well done. It supports all the concepts if
you need them, but doesn't force them down your throat the way Java
and C++ do. Of course, if you're a fan of Java you're likely to
disagree... :)

Ben

-- 
Like all men in Babylon I have been a proconsul; like all, a slave ... During
one lunar year, I have been declared invisible; I shrieked and was not heard,
I stole my bread and was not decapitated.
~ ben@morrow.me.uk ~                   Jorge Luis Borges, 'The Babylon Lottery'


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

Date: Wed, 04 Feb 2004 16:35:11 -0700
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: Perl data types
Message-Id: <eto7jz2beq8.fsf@fc.hp.com>

"David Holmes" <no@spam.uk> writes:
> The definition of a product type is a type that collects together a number
> of data items in a single value. This is why I think that it is a struct.

As Ben Morrow pointed out, you'd use a hash for this in Perl, as a
rule.

> As for sum types, they are subtly different. Values of a sum type are
> tagged. This can take several forms but again in the example of a java.
> Incase you cant tell this is the language I use most. If you have a base
> class that extends a superclass1 and a superclass2. You can initialise a
> variable as the base class, and then say:
>
> if (instanceOf(superclass1)) { do something }
> else if (instanceOf(superclass2)) { do something else }

But that's crappy OO programming.  You should do

object.method()

instead, and let inheritance take care of what gets done, no?

> As I said the values of a sum type are tagged,

How are they tagged?  I don't see anything like that in your example.

> so I guess in perl since there are few primative types, it would be
> like taking a variable, initialising it to some value and asking:
>
> if this is a scalar { do something }
> else if it is a hash { foreach hash { do something }}
> else if it is an array.....

But in Perl, you already know what type it is, by the sigil in front
of the variable:

$var is a scalar
@var is an array
%var is a hash

So what would be the point?

> Hope that at least makes some sense.

Sorry, not really.  I don't see what you'd want to use a sum type for.

And please don't top-post, it's rude, and it's against the Posting
Guidelines which are posted regularly to this group.

-=Eric
-- 
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
		-- Blair Houghton.


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

Date: Wed, 04 Feb 2004 23:53:23 GMT
From: "edgrsprj" <edgrsprj@ix.netcom.com>
Subject: Re: Perl For Amateur Computer Programmers
Message-Id: <TBfUb.9997$jH6.5826@newsread1.news.atl.earthlink.net>

"David K. Wall" <dwall@fastmail.fm> wrote in message
news:Xns9482824C73591dkwwashere@216.168.3.30...
> "edgrsprj" <edgrsprj@ix.netcom.com> wrote:
>
>
> *  There's code there that uses open() without a comma after the
> filehandle, which will not compile.
>

I changed some of the code on the page.  I still suspect that parts of it
might just look different with other browsers.  I will check further on
that.

I am guessing that you are referring to that open statement in the section
of code I listed for an optional way to open files.  I have tried it a
number of time and it appears to work without the comma.  I suspect that
this is because there is no file address included in the statement.




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

Date: Thu, 5 Feb 2004 00:16:26 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Perl For Amateur Computer Programmers
Message-Id: <bvs20q$cm0$5@wisteria.csv.warwick.ac.uk>


"edgrsprj" <edgrsprj@ix.netcom.com> wrote:
> "David K. Wall" <dwall@fastmail.fm> wrote in message
> news:Xns9482824C73591dkwwashere@216.168.3.30...
> >
> > *  There's code there that uses open() without a comma after the
> > filehandle, which will not compile.
> >
> 
> I changed some of the code on the page.  I still suspect that parts of it
> might just look different with other browsers.  I will check further on
> that.

No matter what browser you use, it'll still be WRONG. localtime DOES
NOT RETURN ONE LONG NUMBER.

> I am guessing that you are referring to that open statement in the section
> of code I listed for an optional way to open files.  I have tried it a
> number of time and it appears to work without the comma.  I suspect that
> this is because there is no file address included in the statement.

Oh, for God's sake! Earnest misunderstanding I can cope with,
stupidity I can cope with, complete lack of sense of humour I can cope
with, but lying I cannot.

*PLONK*

Ben

-- 
               We do not stop playing because we grow old; 
                  we grow old because we stop playing.
                            ben@morrow.me.uk


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

Date: Thu, 05 Feb 2004 11:40:31 +1100
From: Iain Chalmers <bigiain@mightymedia.com.au>
Subject: Re: Perl For Amateur Computer Programmers
Message-Id: <bigiain-20BCB6.11403105022004@news.fu-berlin.de>

In article <168f035a.0402041403.7effb0bc@posting.google.com>,
 g_klinedinst@hotmail.com (G Klinedinst) wrote:

> Iain Chalmers <bigiain@mightymedia.com.au> wrote in message news:
> 
> > "Perl makes a lousy first programming language, thats because its 
> > designed to be the *last* programming language you ever need to learn."
> 
> <snip>
> 
> Iain, I am one of the few who agrees with you I guess. The Perl docs
> often have terrible form.
> 

Err, let me clarify, I think they have "terrible form" for _some_ of the 
target audience. 

I think they are probably close to optimally worded for *nix using 
programmers at least familiar with C and the "unix way" of doing things. 
Those poeple are _perfectly_ happy with doco that says "foo emulates the 
C function foo. See foo(3) for details".

There's also _mountains_ of perl doco that _isn't_ like this (lwpcook, 
perlreftut, and perlboot spring to mind), *but* I can easily understand 
why some people don't understand lots of perlfunc if they don't have any 
*nix/c background at all.

big

-- 
'When I first met Katho, she had a meat cleaver in one hand and
half a sheep in the other. "Come in", she says, "Hammo's not here.
I hope you like meat.' Sharkey in aus.moto


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

Date: Thu, 05 Feb 2004 11:44:49 +1100
From: Iain Chalmers <bigiain@mightymedia.com.au>
Subject: Re: Perl For Amateur Computer Programmers
Message-Id: <bigiain-7F9A18.11444905022004@news.fu-berlin.de>

In article <c39Ub.10288$GO6.9784@newsread3.news.atl.earthlink.net>,
 "edgrsprj" <edgrsprj@ix.netcom.com> wrote:

> "Uri Guttman" <uri@stemsystems.com> wrote in message
> news:x74quan0ls.fsf@mail.sysarch.com...
> > >>>>> "DKW" == David K Wall <dwall@fastmail.fm> writes:
> >
> 
> > i was taught that it was because we didn't appease the gods and they
> > were stomping around doing polkas. and that we can stop them by offering
> > up perl virgins in sacrifice. i should put this up in a web page
> > too. does anyone who knows how to *program* in html wanna help me?
> >
> 
> Netscape has a free, downloadable Web page editor which I find works nicely.
> You don't really need to understand html to create Web pages though it
> helps.

perldoc perlnewsgroupsarcasm

ISAGN...

big

-- 
'When I first met Katho, she had a meat cleaver in one hand and
half a sheep in the other. "Come in", she says, "Hammo's not here.
I hope you like meat.' Sharkey in aus.moto


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

Date: Wed, 04 Feb 2004 17:08:47 -0800
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: Perl-Cgi Newbee!
Message-Id: <040220041708472947%jgibson@mail.arc.nasa.gov>

In article <9e8ef4c1.0401240118.1735134c@posting.google.com>, Andrew
<arobcorp@yahoo.com.au> wrote:

[details snipped]

> 
> Could some-one be kind enough write a simple loop that could scan the
> array @myArray and compare to the $emailAddress.
> Thanks Heaps
> Andrew

You can use grep to find out if a given string is the same as one or
more of an array of strings:

if( grep { $_ eq $emailAddress } @myArray ) {
  # its a known address
}

See perldoc -f grep


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

Date: Wed, 4 Feb 2004 23:59:51 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Turn $5 into $15,000 or more!!! Here's how....
Message-Id: <bvs11n$cm0$2@wisteria.csv.warwick.ac.uk>


throop@cs.utexas.edu (David R. Throop) wrote:
> s/\$5/\$15,000/g

s/\$5/'$15,'.sprintf "%03u", rand 1000/eg;

;)

Ben

-- 
Musica Dei donum optimi, trahit homines, trahit deos.    |
Musica truces mollit animos, tristesque mentes erigit.   |   ben@morrow.me.uk
Musica vel ipsas arbores et horridas movet feras.        |


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 6081
***************************************


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