Disappointed by perl..

C

chacallot

Hi,

Yes, am disappointed by perl.
There is this "sub variable scope" thing, I posted just earlier.
And there are those win32::process and Win32::Daemon glitches I posted
in comp.lang.perl.module.
And there is also for example this pop split thing.

The pop split thing is that you cant do a :
$toto=pop split /\t/,$titi;
To get the last tab delimited field from $titi.

The explanation given in comp.lang.perl does not convince me.
I dont understand why pop couldnt work on an anonymous array returned by
split..

Perl have lots of modules, but if you cant rely on them, what's the point.
There's more than one way to do it, but some which sounds logical doesnt
work..

Rgds,
Chacallot.
 
S

Scott Bryce

chacallot said:
I dont understand why pop couldnt work on an anonymous array returned
by split..

Becasue split doesn't return an array. But I think we've been through
this already.
 
U

Uri Guttman

c> The pop split thing is that you cant do a :
c> $toto=pop split /\t/,$titi;
c> To get the last tab delimited field from $titi.

c> The explanation given in comp.lang.perl does not convince me.
c> I dont understand why pop couldnt work on an anonymous array returned
c> by split..

there isn't an anonymous array there. split returns a list on the stack.

how is pop supposed to know it is getting a list? it is defined to take
a real array as its target and a list is not a real array. what if it
worked your way and you passed it:

$foo = pop @bar, @baz ;

what is popped? can something from @bar be popped?

or this one:

$foo = pop @bar, split /./, 'abcd' ;

perl already has a builtin SYNTACTICAL way to get the last element from
a list. it is called indexing. you just append a [] part to the list but
the problem is that you have to wrap the list in () since [] binds very
tightly. and you want it to bind tightly as that is how it is used most
of the time. take a look at most uses of [] for indexing and imagine if
it had very low precedence. you would be using tons of () to make up for
it. but this means the more rare indexing of a list will need the ()
around its list.

what you have just read is a classic syntax/semantic tradeoff in a
langauge design. larry in general is very good at these choices and you
are not yet one to actually see the reasons behind them. until then and
when you can properly argue about language design, don't be disappointed
in perl. designing a lang this powerful is much harder than you realize
and there are other real mistakes all over the place. one reason for perl6 is
to correct many of those mistakes. but list indexing won't change much
at all since the same binding issue will arise. array indexing is done
so much more than list indexing that p6 will still bind [] tightly.

uri

c> Perl have lots of modules, but if you cant rely on them, what's the point.
c> There's more than one way to do it, but some which sounds logical
c> doesnt work..

then write your own versions of them. supply patches to the
authors. rate the modules. post bug reports to rt.cpan.org. whining here
is the least productive way to get things the way you want them.

uri
 
M

Matt Garrish

chacallot said:
Hi,

Yes, am disappointed by perl.

Then find another language.
There is this "sub variable scope" thing, I posted just earlier.

Which is your misunderstanding of how perl works. You must be new to
programming if you think languages work the way you want and/or expect them
to. It's your problem to figure out the correct way to code. If you employ
bad practices, like accessing global variables from a subroutine and relying
on poor scoping to justify it, then don't blame the language. You have to
ask yourself what gave you that crazy notion in the first place. My guess it
was a poor attempt to get around strictures.
And there are those win32::process and Win32::Daemon glitches I posted in
comp.lang.perl.module.

I've used Win32::Daemon a number of times and never had any problems. The
service suddenly shutting down is usually a sign of bad coding. Did you
bother to test your code before trying to run it as service? Are you writing
to a debug log to find out what is happening inside the script when it dies?
And there is also for example this pop split thing.

The pop split thing is that you cant do a :
$toto=pop split /\t/,$titi;
To get the last tab delimited field from $titi.

No, but you can do:

$toto = (split( /,/,$titi))[-1];

Matt
 
B

Bob Walton

chacallot said:
Hi,

Yes, am disappointed by perl.
There is this "sub variable scope" thing, I posted just earlier.

Perl's sub's are extremely well thought out. Just because they
don't work the way you preconceived they should doesn't mean they
are deficient in some regard. They do what they are documented
to do -- read the docs and use them properly. Using a sub
without declaring in the sub all the variables used in it is
naturally fraught with error possibilities. But that same
mechanism permits closures.
And there are those win32::process and Win32::Daemon glitches I posted
in comp.lang.perl.module.
And there is also for example this pop split thing.

The pop split thing is that you cant do a :
$toto=pop split /\t/,$titi;
To get the last tab delimited field from $titi.

The explanation given in comp.lang.perl does not convince me.
I dont understand why pop couldnt work on an anonymous array returned by
split..

split() doesn't return an anonymous array. It returns a list.
pop() requires an array, not a list. Arrays and lists are two
different things. Read the docs. The idiom for what you want is:

$toto=(split /\t/,$titi)[-1];

That's better anyway, since you can easily and naturally return,
for example, the next to last item by using a subscript of -2.
Perl have lots of modules, but if you cant rely on them, what's the point.
There's more than one way to do it, but some which sounds logical doesnt
work..

Modules vary in quality. Ones for Windoze perhaps reflect
somewhat the quality of the underlying operating system, as well
as the fact that lots of the better module developers avoid
Windoze. Rather than just bitching about them, try submitting
fixes for the problems. That's how they get improved.
 
J

Jürgen Exner

chacallot said:
Yes, am disappointed by perl.

Happens, nothing wrong with that.
The pop split thing is that you cant do a :
$toto=pop split /\t/,$titi;
To get the last tab delimited field from $titi.

Why would you want to do _that_? split() returns a list, pop() expects an
array. Of course that's not going to work.
Is there anything wrong with a simple

$toto = (split/\t/, $titi)[-1]
The explanation given in comp.lang.perl does not convince me.

Considering that comp.lang.perl has been defunct for many years this is not
surprising.
I dont understand why pop couldnt work on an anonymous array returned
by split..

Maybe because split() doesn't return an array in the first place?

jue
 
J

John Bokma

Bob Walton said:
Modules vary in quality. Ones for Windoze perhaps reflect
somewhat the quality of the underlying operating system,

Please don't post crap like this. You sound more ignorant then the OP.
 
I

Ilya Zakharevich

[A complimentary Cc of this posting was sent to
Bob Walton
Perl's sub's are extremely well thought out.

What makes you believe this nonsense? *WHO* do you think had these
"thoughts"? Most of the Perl is just a result of slow aggregation of
a hodgepodge of features (and misfeatures) during the last 2 decades.
Since these (mis)features were invented in more or less random order,
for most features there is very little consistency and/or well-thought-ness.

*In practice*, Perl subroutines are not as bad as one could imagine
(given the Perl history). But they could be much improved.

On the other hand, they could be much worsened. Witness the mess of
subroutines in Perl6...

Hope this helps,
Ilya
 
A

Anno Siegel

chacallot said:
Hi,

Yes, am disappointed by perl.
There is this "sub variable scope" thing, I posted just earlier.
And there are those win32::process and Win32::Daemon glitches I posted
in comp.lang.perl.module.
And there is also for example this pop split thing.

The pop split thing is that you cant do a :
$toto=pop split /\t/,$titi;
To get the last tab delimited field from $titi.

The right way to do that is a list slice, but if you must use pop:

my $last = pop @{ [ split /\t/, $titi] };

Anno
 
M

Michele Dondi

The pop split thing is that you cant do a :
$toto=pop split /\t/,$titi;
To get the last tab delimited field from $titi.

But you can do

$toto=(split /\t/,$titi)[-1]; # nice, isn't it?
The explanation given in comp.lang.perl does not convince me.
I dont understand why pop couldnt work on an anonymous array returned by
split..

Because split() does NOT return an anonymous array. Just a list. You
can put that list into an anonimous array, if you like:

$toto=pop @{[ split /\t/,$titi ]}; # not that I'd do it this way...


Michele
 
B

Bart Lateur

chacallot said:
Yes, am disappointed by perl.
There is this "sub variable scope" thing, I posted just earlier.

Perl has block scoped lexicals, which can easily be used for sub scopes,
but which is much broader than that.

If you don't declare your subs lexical in the sub, then perl will use
wider scope, possibly even global variables. That can be annoying... but
it also means you can have a variable that's only seen by two subs.
Isn't that just lovely?
And there are those win32::process and Win32::Daemon glitches I posted
in comp.lang.perl.module.

The Win32::* modules are often poorly designed, IMO. Non-perlish.
Win32::process' Create produces a new object, but not as a returned
value, but stuffed into the first parameter. WTF?

But that's the style of one series of modules. That does not reflect on
Perl itself. They could be done differently.
And there is also for example this pop split thing.

The pop split thing is that you cant do a :
$toto=pop split /\t/,$titi;
To get the last tab delimited field from $titi.

The explanation given in comp.lang.perl does not convince me.
I dont understand why pop couldnt work on an anonymous array returned by
split..

split doesn't return an anonymous array. split returns a list, i.e. an
ordered bunch of unrelated items. An anonymous array looks like

[ your, data, here ]

which actually is an array ref. You can turn it back into a "real"
array using @{REF}. And it *does* work like this:

$toto=pop @{[split /\t/, $titi]};

But that's just plain ugly. Perl allows for other ways, like this:

$toto= (split /\t/, $titi)[-1];

which I like better. I doubt PHP allows indexing into an anonymous
array, like Perl allows indexing into a list.
 
R

Robert Sedlacek

chacallot said:
Yes, am disappointed by perl.

It's often the problem that people project their own responsibilities.
The real problem as I see is, for example...
I dont understand why pop couldnt work on an anonymous array returned by
split..

Try to understand the *basics* of a language first. *Then* judge. Of
course you can make judgements as much as you want. But there's no point
unless you know what you're talking about. Without understanding, it's
less worth than a downscored slashdot rant.

You can have

An array:
my @foo = (1, 2, 3); # @foo is the array

A list:
print (1, 2, 3); # (1, 2, 3) is a list

An anonymous array reference
my $foo = [1, 2, 3]; # $foo is the reference

pop only takes an array as argument. You might ask "Why? It's just
returning the last element." Wrong! It's *removing* the last element.
Therefore it needs a container, not a constant value.

my $foo = 1;
$foo++; # works, the container holds the value
1++; # does not work, it *is* the value 1.

my @bar = (1, 2);
pop @bar; # works, the container holds the values, last is
# removed.
pop (1, 2); # can't work. (1, 2) is constant and can't be
# altered.

After seeing that I've wanted to write a sentence and written a bunch
more, I really hope you aren't just the regular day-to-day troll.


p
 
B

brian d foy

J M Davitt said:
chacallot wrote:
Yes, well... In the old days, CPAN provided some of the most carefully
reviewed, bug-free modules loose in the wild. Lately, anyone who wishes
to can post a module. I've been appalled at the number of
poorly-scoped, bug-ridden modules one finds on CPAN.

CPAN has always allowed anyone ot post any module. There has never been
a review process for that, and even in the old days there was bad code.

The difference today is that there are more people contributing to
CPAN, and since most of the major tasks have been solved, people
re-invent a lot of things.

Don't pine for a past that never existed, though.

*** ***
 
C

chacallot

Robert said:
chacallot said:
Yes, am disappointed by perl.

It's often the problem that people project their own responsibilities.
The real problem as I see is, for example...
I dont understand why pop couldnt work on an anonymous array returned by
split..

Try to understand the *basics* of a language first. *Then* judge. Of
course you can make judgements as much as you want. But there's no point
unless you know what you're talking about. Without understanding, it's
less worth than a downscored slashdot rant.

You can have

An array:
my @foo = (1, 2, 3); # @foo is the array

A list:
print (1, 2, 3); # (1, 2, 3) is a list

An anonymous array reference
my $foo = [1, 2, 3]; # $foo is the reference

pop only takes an array as argument. You might ask "Why? It's just
returning the last element." Wrong! It's *removing* the last element.
Therefore it needs a container, not a constant value.

my $foo = 1;
$foo++; # works, the container holds the value
1++; # does not work, it *is* the value 1.

my @bar = (1, 2);
pop @bar; # works, the container holds the values, last is
# removed.
pop (1, 2); # can't work. (1, 2) is constant and can't be
# altered.

After seeing that I've wanted to write a sentence and written a bunch
more, I really hope you aren't just the regular day-to-day troll.


p


Hi!

Thx to all those who took some time to answer this. It was not a troll
but some kind of cry of frustration.

Many focused on the pop split thing while it was not really the main
point here but an illustration of a limitation in the "there's more than
one way to do it" thing.
Thanks to your explanations I understood one important perl thing that I
overlooked until now : arrays and list are not the same.

I have looked back at the manuals and I didnt find anyplace where I
could have been warned about that. Specially in perlintro about Arrays,
I read :
"Arrays
An array represents a list of values:"
Then
"You can do various useful things to lists:
my @sorted = sort @animals;"
Reading that I just lazily deduce that list and arrays are two names for
the same thing.


Reading again perldata doesnt help either :
"Perl has three built-in data types: scalars, arrays of scalars, and
associative arrays of scalars"
"There are two major contexts: list and scalar. Certain operations
return list values in contexts wanting a list, and scalar values otherwise"
Am still meditating about how is it that one of the data types is also a
context type (scalar) while the other context type isnt.



Concerning the "sub variable scope" thing (more detailed about that in
the "Variables scope. Am lost..." thread I posted earlier) I still think
that "use strict" or "use warnings" where there to prevent me from doing
such mistake.
Cause if you cant rely on those switches "there's more than one way to
do it" becomes "sometimes it works the way you think, sometimes not :
have fun!"



Concerning CPAN modules, there's too many of them doing more or less the
same thing. Looks to me there's is a lack of collaborative work on
those. It's nearly always one person committing one module. The obvious
consequence of that is that the modules are poorly maintained as the guy
who did it wont stay focused on the thing very long.
Seems there was lots of activity on CPAN between 2000 and 2002 and much
less since then.

Those who tell me that I should just contribute instead of complaining
could be right.
But I chose perl to do sysadmin scripts with the idea this was the
universal language I could use to do Unix and Windows (and maybe others)
sysadmin task without having to spend too much time learning each of the
"genuine" system language.
Now to be able to develop win32 modules, I must first learn VC/VC++ and
the Windows internals. When/if I know enough about those, maybe I'll
be able to use this knowledge to commit the corresponding win32 modules.
But there is many other more interesting subjects I should be working on
and the time I can invest in all those subject is obviously limited...

Rgds,
Chacallot.
 
D

Dr.Ruud

chacallot schreef:
But I chose perl to do sysadmin scripts with the idea this was the
universal language I could use to do Unix and Windows (and maybe
others) sysadmin task without having to spend too much time learning
each of the "genuine" system language.
Now to be able to develop win32 modules, I must first learn VC/VC++
and the Windows internals.

Not necessarily: you can also build a module on top of another module.
There are for example already good modules to interface to the
Win32-API.
 
C

Ch Lamprecht

chacallot said:
Thanks to your explanations I understood one important perl thing that I
overlooked until now : arrays and list are not the same.

I have looked back at the manuals and I didnt find anyplace where I
could have been warned about that.

perldoc -q list

Regards, Christoph
 
E

Emmanuel Florac

Le Mon, 08 May 2006 18:28:24 +0200, chacallot a écrit :
Concerning the "sub variable scope" thing (more detailed about that in
the "Variables scope. Am lost..." thread I posted earlier) I still think
that "use strict" or "use warnings" where there to prevent me from doing
such mistake.

The only common procedural language I know of that behaves differently
than Perl in this aspect is PHP. AFAIK Perl, Python, C, C++, Java and most
other commonly used languages around work about the same way in this
aspect.
 
C

chacallot

Ch said:
perldoc -q list

Regards, Christoph

You got a point.

What is the difference between a list and an array?
An array has a changeable length. A list does not. An array is something
you can push or pop, while a list is a set of values. Some people make
the distinction that a list is a value while an array is a variable.
Subroutines are passed and return lists, you put things into list
context, you initialize arrays with lists, and you foreach() across a
list. "@" variables are arrays, anonymous arrays are arrays, arrays in
scalar context behave like the number of elements in them, subroutines
access their arguments through the array @_, and push/pop/shift only
work on arrays.

Rgds,
Chacallot.
 
C

chacallot

Emmanuel said:
Le Mon, 08 May 2006 18:28:24 +0200, chacallot a écrit :


The only common procedural language I know of that behaves differently
than Perl in this aspect is PHP. AFAIK Perl, Python, C, C++, Java and most
other commonly used languages around work about the same way in this
aspect.


???
That's completely dumb.
There is no way you could do the kind of thing I talk about in the
"Variables scope. Am lost..." thread in C, C++ or Java.

Rgds,
Chacallot.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,104
Latest member
LesliVqm09
Top