[opensuse] Quick perl question - why are @array[$num] and $array[$num] the same?
Listmates: I don't know who I have to thank for this, but I think it was Anders who recommended that I look at perl after one of my last weird bash questions. I have a syntax question as I go though perl. The situation. I read a file into an array and then go to reference each line. my $NUM = 1; open FILE, ".bashrc" or die $!; my @array = <FILE>; How is it legal that I can reference the array element either as @array[element] or $array[element]?: while (@array[$NUM]) { print "$NUM : @array[$NUM]\n"; $NUM++; } while ($array[$NUM]) { print "$NUM : $array[$NUM]\n"; $NUM++; } From what I've read, it seems like the list $array[element] would just return the number of characters in the list $array[element] not the text itself. How should I think about this? -- David C. Rankin, J.D., P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
David C. Rankin wrote:
Listmates:
I don't know who I have to thank for this, but I think it was Anders who recommended that I look at perl after one of my last weird bash questions. I have a syntax question as I go though perl.
The situation. I read a file into an array and then go to reference each line.
my $NUM = 1; open FILE, ".bashrc" or die $!; my @array = <FILE>;
How is it legal that I can reference the array element either as @array[element] or $array[element]?:
while (@array[$NUM]) { print "$NUM : @array[$NUM]\n"; $NUM++; }
while ($array[$NUM]) { print "$NUM : $array[$NUM]\n"; $NUM++; }
From what I've read, it seems like the list $array[element] would just return the number of characters in the list $array[element] not the text itself. How should I think about this?
I gave up on perl. It makes my brain hurt -- like trying to read 1970's era BASIC code.
-- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Thursday 01 May 2008 00:36, Sam Clemens wrote:
...
I gave up on perl. It makes my brain hurt -- like trying to read 1970's era BASIC code.
I concur. Perl verges on being an abomination. "Pathetically eclectic rubbish lister" indeed! I once (in the Perl 4 era) wrote a code generation tool in Perl, but I no longer can even read that stuff. If you're going to start programming things that go beyond what works well in BASH, you'd be better off with Python or Ruby or even Groovy. Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Randall R Schulz wrote:
On Thursday 01 May 2008 00:36, Sam Clemens wrote:
...
I gave up on perl. It makes my brain hurt -- like trying to read 1970's era BASIC code.
I concur. Perl verges on being an abomination. "Pathetically eclectic rubbish lister" indeed!
I once (in the Perl 4 era) wrote a code generation tool in Perl, but I no longer can even read that stuff.
If you're going to start programming things that go beyond what works well in BASH, you'd be better off with Python or Ruby or even Groovy.
Randall Schulz
That's real, real bad news Randall, I'm already 60% through perl. Bummer. Python huh? I'll look at it. I presume it handles floating point, and has the capabilities of perl? (oh no, here we go again...) -- David C. Rankin, J.D., P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Thursday 01 May 2008 07:43, David C. Rankin wrote:
Randall R Schulz wrote:
On Thursday 01 May 2008 00:36, Sam Clemens wrote:
...
I gave up on perl. It makes my brain hurt -- like trying to read 1970's era BASIC code.
I concur. Perl verges on being an abomination. "Pathetically eclectic rubbish lister" indeed!
I once (in the Perl 4 era) wrote a code generation tool in Perl, but I no longer can even read that stuff.
If you're going to start programming things that go beyond what works well in BASH, you'd be better off with Python or Ruby or even Groovy.
Randall Schulz
That's real, real bad news Randall, I'm already 60% through perl. Bummer. Python huh? I'll look at it. I presume it handles floating point, and has the capabilities of perl? (oh no, here we go again...)
Well, I'm probably overstating it. Perl is immensely practical, but it's offensive from a programming language theory standpoint and from a programming-in-the-large perspective it will lead you down the garden path to impenetrable and unmaintainable spaghetti code. But for for simple programming tasks that go beyond what's comfortable in the shells, I suppose it's OK. It also has lots of libraries and the whole CPAN mechanism is nice.
-- David C. Rankin
Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Thursday 01 May 2008 08:52, Randall R Schulz wrote:
...
Well, I'm probably overstating it. Perl is immensely practical, but it's offensive from a programming language theory standpoint and from a programming-in-the-large perspective it will lead you down the garden path to impenetrable and unmaintainable spaghetti code.
I think I must retract that last statement, about "the garden path to impenetrable and unmaintainable spaghetti code." Perl 5 does have a good module system, and if you use it well, you can probably manage medium scale systems in Perl. But it does not really support either object-oriented programming or polymorphism (as far as I know), so it still isn't going to work well for programming large systems, I don't think. Also, I think it's data abstraction capabilities are quite limited. On the other hand, it is apparently possible to do higher-order programming in Perl, and that's not nothin': "Higher-Order Perl" <http://www.amazon.com/Higher-Order-Perl-Transforming-Programs/dp/1558607013> And here's a good one, bringing this all back to the original question. The author of "Higher-Order Perl" is Mark Jason Dominus (don't make me enter his Chinese name—I can't even write my own, not even in Pinyin) who is also the author of the man page "perlreftut - Mark's very short tutorial about references". So David: "man perlreftut" to get a tutorial that goes directly to your question about those Perl expressions that once confused you.
...
Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Well, I'm probably overstating it. Perl is immensely practical, but it's offensive from a programming language theory standpoint and from
True it is offensive.
Perl 5 does have a good module system, and if you use it well, you can probably manage medium scale systems in Perl. But it does not really support either object-oriented programming or polymorphism (as far as I know), so it still isn't going to work well for programming large systems, I don't think. Also, I think it's data abstraction capabilities are quite limited.:
(Although not true object oriented programming,) it is possible to do object oriented programming with perl, see: http://perldoc.perl.org/perlobj.html See also Tom Christiansen's tutorial: perltoot - Tom's object-oriented tutorial for perl http://perldoc.perl.org/perltoot.html Inheritance, multiple inheritance and hence polymorphism are also supported. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
David C. Rankin wrote:
Randall R Schulz wrote:
If you're going to start programming things that go beyond what works well in BASH, you'd be better off with Python or Ruby or even Groovy.
Randall Schulz
That's real, real bad news Randall, I'm already 60% through perl. Bummer. Python huh? I'll look at it. I presume it handles floating point, and has the capabilities of perl? (oh no, here we go again...)
Don't give up on perl on the basis of a few naysayers. Programming language preferences are a very personal matter, and have a lot to do with your own peculiar personality and "wiring" if you will. Consider this: First of all, perl is not going away - it has been called "the duct tape of the internet" for good reason. Keep in mind also that proficiency in one language enhances your ability to learn additional languages. Finally, any perl program reflects the coding style of the programmer - sure, it is possible to write obfuscated perl, but it's also possible (and my preference) to write perl code that looks at first glance just like well structured c. Some like perl, some hate it, but I'd recommend that you dig in and decide for yourself. Personally I like perl, as I do all the c-like languages (c, c++, c#, java, php, etc) Joe -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
David C. Rankin wrote:
Randall R Schulz wrote:
On Thursday 01 May 2008 00:36, Sam Clemens wrote:
...
I gave up on perl. It makes my brain hurt -- like trying to read 1970's era BASIC code.
I concur. Perl verges on being an abomination. "Pathetically eclectic rubbish lister" indeed!
I once (in the Perl 4 era) wrote a code generation tool in Perl, but I no longer can even read that stuff.
If you're going to start programming things that go beyond what works well in BASH, you'd be better off with Python or Ruby or even Groovy.
Randall Schulz
That's real, real bad news Randall, I'm already 60% through perl. Bummer. Python huh? I'll look at it. I presume it handles floating point, and has the capabilities of perl? (oh no, here we go again...)
I hear Seaside with Squeak is a cool way to go. Jim F -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Friday 02 May 2008 06:35, Jim Flanagan wrote:
...
I hear Seaside with Squeak is a cool way to go.
Squeak being an open-source Smalltalk, yes? I don't know what Seaside is. My guess is that the strong "horse of a different color" characteristic of Smalltalk will be an impediment for most people. I had a brief interest in it, but it was so long ago, I could never get my hands on an implementation. Remember the colorful hot-air-balloon issue of Byte??
Jim F
Are you realted to David Flanagan? <http://www.amazon.com/JavaScript-Definitive-Guide-David-Flanagan/dp/0596101996> Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Randall R Schulz wrote:
On Thursday 01 May 2008 00:36, Sam Clemens wrote:
...
I gave up on perl. It makes my brain hurt -- like trying to read 1970's era BASIC code.
I concur. Perl verges on being an abomination. "Pathetically eclectic rubbish lister" indeed!
I once (in the Perl 4 era) wrote a code generation tool in Perl, but I no longer can even read that stuff.
If you're going to start programming things that go beyond what works well in BASH, you'd be better off with Python or Ruby or even Groovy.
Randall Schulz
How legible a bit of code is really down to the programmer not the language the code is written in. There are people that tend to think that abstracting a language to a level closer to pseudo code improves the coding experience, IMHO all that tends to do is reduce the scope of the programmer to control and tune the code. Personally I have a pathological dislike of languages which use indentation to define blocks and use eol as a statement terminator. Which is the reason I have never bothered too much with Python, but that is a personal preference not a comment on the language itself. PHP is not just a web site language and has been used a non-web application script language, and javascript can also be used this way. (Though I have not done this on a *NIX platform). Ruby ... you are having a laugh I hope... performs like a dog according to the bench marks... a bit of Web 2 nonsense.. Groovy.. is it even a standard?? - -- ============================================================================== I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my telephone. Bjarne Stroustrup ============================================================================== -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iD8DBQFIGde5asN0sSnLmgIRAlwtAJ4u6qNKeLVpg1o/cwQTQc+9PpWdTwCgrUKO PgvdymQ6NPvd1yy3jQuOQgA= =WIjj -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
G T Smith wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Randall R Schulz wrote:
On Thursday 01 May 2008 00:36, Sam Clemens wrote:
...
I gave up on perl. It makes my brain hurt -- like trying to read 1970's era BASIC code. I concur. Perl verges on being an abomination. "Pathetically eclectic rubbish lister" indeed!
I once (in the Perl 4 era) wrote a code generation tool in Perl, but I no longer can even read that stuff.
If you're going to start programming things that go beyond what works well in BASH, you'd be better off with Python or Ruby or even Groovy.
Randall Schulz
How legible a bit of code is really down to the programmer not the language the code is written in.
Obviously you've never seen APL.
There are people that tend to think that abstracting a language to a level closer to pseudo code improves the coding experience, IMHO all that tends to do is reduce the scope of the programmer to control and tune the code.
Personally I have a pathological dislike of languages which use indentation to define blocks and use eol as a statement terminator. Which is the reason I have never bothered too much with Python, but that is a personal preference not a comment on the language itself. PHP is not just a web site language and has been used a non-web application script language, and javascript can also be used this way. (Though I have not done this on a *NIX platform).
Ruby ... you are having a laugh I hope... performs like a dog according to the bench marks... a bit of Web 2 nonsense.. Groovy.. is it even a standard??
In the OP's case, I don't think performance is a big issue, or he wouldn't be using Perl in the first place. -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Sam Clemens wrote:
G T Smith wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Randall R Schulz wrote:
On Thursday 01 May 2008 00:36, Sam Clemens wrote: How legible a bit of code is really down to the programmer not the language the code is written in.
Obviously you've never seen APL.
*wince* :-) or PL/1 However to englishman who does not understand dutch, all dutch becomes double dutch... :-) - -- ============================================================================== I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my telephone. Bjarne Stroustrup ============================================================================== -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iD8DBQFIGtv1asN0sSnLmgIRAnGqAJ0fy+hYBdPsDVs04jhuTTkr+OaFJgCgzUju 8mZMMvKOubjKTjws1b/m3Gg= =kRo9 -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Thursday 01 May 2008 07:46, G T Smith wrote:
Randall R Schulz wrote:
On Thursday 01 May 2008 00:36, Sam Clemens wrote:
...
I gave up on perl. It makes my brain hurt -- like trying to read 1970's era BASIC code.
I concur. Perl verges on being an abomination. "Pathetically eclectic rubbish lister" indeed!
I once (in the Perl 4 era) wrote a code generation tool in Perl, but I no longer can even read that stuff.
If you're going to start programming things that go beyond what works well in BASH, you'd be better off with Python or Ruby or even Groovy.
Randall Schulz
How legible a bit of code is really down to the programmer not the language the code is written in. ...
Not entirely. And in my experience, most programmers are absolutely lousy graphic artists and write ugly, unreadable code.
Personally I have a pathological dislike of languages which use indentation to define blocks and use eol as a statement terminator. ...
Ruby ... you are having a laugh I hope... performs like a dog according to the bench marks... a bit of Web 2 nonsense.. Groovy.. is it even a standard??
Personally, I agree about Python's indenting business. But it's a decent scripting language. Ruby is sound and for scripting purposes, it's meager performance is not generally a problem. Both of them have JVM-based implementations that are actively developed and perform well. Asking about standards in this realm is meaningless. None of these languages are standardized, not BASH, not Perl, not Python, not Ruby and not Groovy. But they're all real, powerful, supported and actively maintained languages. They're all well enough defined for the purposes to which they're put. (Well, I'm still harping on the G2One people to document and specify Groovy better, but they're overworked, it seems.) The trend of re-hosting once-experimental languages on the JVM or CLR is a good one, 'cause the big-time vendors of those runtimes (Sun and Microsoft, resp.) put in tremendous work on improving performance and maintaining them for the common OS platforms, so that work carries along the work of the other languages not specifically owned by the platform / virtual machine vendor. Randall Schulz -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Randall R Schulz wrote:
On Thursday 01 May 2008 07:46, G T Smith wrote:
Randall R Schulz wrote:
On Thursday 01 May 2008 00:36, Sam Clemens wrote:
<snip>
Randall Schulz How legible a bit of code is really down to the programmer not the language the code is written in. ...
Not entirely. And in my experience, most programmers are absolutely lousy graphic artists and write ugly, unreadable code.
I would agree with the former (and the converse.. most graphics artist are lousy programmers). However, I do think in the latter you incorrect (or unlucky), if you in any form of collaborative project and you collaborators cannot make head or tail of your code *you* have the problem. Even if you are the sole author and there is any chance you have to go back to it at a former date it is a good idea to try and make in comprehensible, (it is a bit embarrassing as going back to something and wondering who the idiot was who wrote this, knowing the idiot was yourself).
Asking about standards in this realm is meaningless. None of these languages are standardized, not BASH, not Perl, not Python, not Ruby and not Groovy. But they're all real, powerful, supported and actively maintained languages. They're all well enough defined for the purposes to which they're put. (Well, I'm still harping on the G2One people to document and specify Groovy better, but they're overworked, it seems.)
Probably not formally, BASH, Perl, and Python have a community which maintain the primary interpreter and hence implicitly the formal spec. (Dunno about Groovy..., though the OpenOffice scripting component suffer greatly but the rather poor documentation). Javascript does have a formal standard. The first thing I ask about a new language is does it address something which currently is not being done well by current languages. C++ extends C to give objects, D is attempting to extend C++ so dependence on STL for certain constructs is less of an issue. Java creates a network orientated multi-platform programming model. Python does address the rather clever and obscure kludge that gives Perl objects, (but as far as I can see little else). Perl 6 is supposed to adopting a similar object definition model to that of Python, but AFAIK that is not going to happen soon. PHP addresses the complexity of integration of Perl::DBI and Perl::CGI for web design work by giving a simpler model (but unfortunately handing the design issue to some that have little awareness of Web security). Ruby as far as I can work out is a fashion statement... Mono, VB, .NET and C# is a finger in throat moment... :-) - -- ============================================================================== I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my telephone. Bjarne Stroustrup ============================================================================== -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iD8DBQFIGtvoasN0sSnLmgIRAo/pAJ9u2VyVb1a9yusYnLNG4gRVQ6RfIACgtpGX xL2XNC0+u2uFgNElMRGW4g8= =0+ga -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
G T Smith wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
Randall R Schulz wrote:
On Thursday 01 May 2008 07:46, G T Smith wrote:
Randall R Schulz wrote:
On Thursday 01 May 2008 00:36, Sam Clemens wrote:
<snip>
Randall Schulz How legible a bit of code is really down to the programmer not the language the code is written in. ... Not entirely. And in my experience, most programmers are absolutely lousy graphic artists and write ugly, unreadable code.
I would agree with the former (and the converse.. most graphics artist are lousy programmers). However, I do think in the latter you incorrect (or unlucky), if you in any form of collaborative project and you collaborators cannot make head or tail of your code *you* have the problem. Even if you are the sole author and there is any chance you have to go back to it at a former date it is a good idea to try and make in comprehensible, (it is a bit embarrassing as going back to something and wondering who the idiot was who wrote this, knowing the idiot was yourself).
Asking about standards in this realm is meaningless. None of these languages are standardized, not BASH, not Perl, not Python, not Ruby and not Groovy. But they're all real, powerful, supported and actively maintained languages. They're all well enough defined for the purposes to which they're put. (Well, I'm still harping on the G2One people to document and specify Groovy better, but they're overworked, it seems.)
Probably not formally, BASH, Perl, and Python have a community which maintain the primary interpreter and hence implicitly the formal spec. (Dunno about Groovy..., though the OpenOffice scripting component suffer greatly but the rather poor documentation). Javascript does have a formal standard.
The first thing I ask about a new language is does it address something which currently is not being done well by current languages. C++ extends C to give objects, D is attempting to extend C++ so dependence on STL for certain constructs is less of an issue. Java creates a network orientated multi-platform programming model. Python does address the rather clever and obscure kludge that gives Perl objects, (but as far as I can see little else). Perl 6 is supposed to adopting a similar object definition model to that of Python, but AFAIK that is not going to happen soon. PHP addresses the complexity of integration of Perl::DBI and Perl::CGI for web design work by giving a simpler model (but unfortunately handing the design issue to some that have little awareness of Web security). Ruby as far as I can work out is a fashion statement...
Mono, VB, .NET and C# is a finger in throat moment... :-)
100% Graham -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Fri, 2008-05-02 at 11:12 -0400, Sam Clemens wrote:
G T Smith wrote: [lots of barely on-topic stuff trimmed]
Mono, VB, .NET and C# is a finger in throat moment... :-)
100% Graham
Jeebus Mr Clemens, can't you learn to trim when you're just sending a stupid "me too" reply? I'm on the road today getting mail a byte-at-a-time on a tediously slow link. I'd already read what Mr Smith had to say about various programming languages, I (and the thousand or so other subscribers to this list) didn't need to read it all again, and we don't much care if you agree 100% or just 85%. This is covered nicely in the netiquette page for the openSUSE lists. Please read it. -- N. B. Day N 39° 28' 25" W 119° 48' 37" 1404 meters up Epictetus up 5 days 3:41, 3 users, load average: 0.37, 0.11, 0.09 2.6.22.17-0.1-default x86_64 GNU/Linux openSUSE 10.3 (X86-64) -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 The Friday 2008-05-02 at 09:29 -0700, N B Day wrote:
Jeebus Mr Clemens, can't you learn to trim when you're just sending a stupid "me too" reply?
+1 - -- Cheers, Carlos E. R. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.4-svn0 (GNU/Linux) iD8DBQFIG2jStTMYHG2NR9URAmupAJ98loE//B/QdUdLJGMI3CPy79EItQCgmEcx sYGDaICg/QqGDKQ1ejnvKWA= =J2qQ -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Thursday 01 May 2008 00:36, Sam Clemens wrote:
...
I gave up on perl. It makes my brain hurt -- like trying to read 1970's era BASIC code.
I concur. Perl verges on being an abomination. "Pathetically eclectic rubbish lister" indeed!
I once (in the Perl 4 era) wrote a code generation tool in Perl, but I no longer can even read that stuff.
If you're going to start programming things that go beyond what works well in BASH, you'd be better off with Python or Ruby or even Groovy.
Randall Schulz
Thanks for the "Uninformed people bashing Perl and promoting buzzword language of the day" imitation. -- Med venlig hilsen Kaare Rasmussen, Jasonic Jasonic Telefon: +45 3816 2582 Nordre Fasanvej 12 2000 Frederiksberg Email: kaare@jasonic.dk -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Kaare Rasmussen wrote:
On Thursday 01 May 2008 00:36, Sam Clemens wrote:
...
I gave up on perl. It makes my brain hurt -- like trying to read 1970's era BASIC code. I concur. Perl verges on being an abomination. "Pathetically eclectic rubbish lister" indeed!
I once (in the Perl 4 era) wrote a code generation tool in Perl, but I no longer can even read that stuff.
If you're going to start programming things that go beyond what works well in BASH, you'd be better off with Python or Ruby or even Groovy.
Randall Schulz
Thanks for the "Uninformed people bashing Perl
I assure you that both Randall and I are quit familiar with perl.
and promoting buzzword language of the day" imitation.
-- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
I assure you that both Randall and I are quit familiar with perl.
I believe it was true 5-10 years ago. Perl 2008 is another beast. People get things done writing maintainable code with the best pick from CPAN and Catalyst, Moose, DBIC etc. No need to scare people with outdated information. -- Med venlig hilsen Kaare Rasmussen, Jasonic Jasonic Telefon: +45 3816 2582 Nordre Fasanvej 12 2000 Frederiksberg Email: kaare@jasonic.dk -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
David C. Rankin wrote:
Listmates:
I don't know who I have to thank for this, but I think it was Anders who recommended that I look at perl after one of my last weird bash questions. I have a syntax question as I go though perl.
The situation. I read a file into an array and then go to reference each line.
my $NUM = 1; open FILE, ".bashrc" or die $!; my @array = <FILE>;
So far okay.
How is it legal that I can reference the array element either as @array[element] or $array[element]?:
How did you come to that conclusion?!?
while (@array[$NUM]) { print "$NUM : @array[$NUM]\n"; $NUM++; }
while ($array[$NUM]) { print "$NUM : $array[$NUM]\n"; $NUM++; }
No, the output is definitely not what you want. The answer comes if you follow best practice and insert the following lines at the top of your script: #!/usr/bin/perl use strict; use warnings; These three lines should be the very first thing you ever write in every perl script.
From what I've read, it seems like the list $array[element] would just return the number of characters in the list $array[element] not the text itself. How should I think about this?
./perltest.pl Scalar value @array[$NUM] better written as $array[$NUM] at ./perltest.pl line 12. Scalar value @array[$NUM] better written as $array[$NUM] at ./perltest.pl line 13. The "use warnings;" gives you the message above. Perl is just lenient in this case, though the output is not what you would expect: 1 @: Id:a, Mode_altscr=0, Mode_irixps=1, Delay_time=3.000, Curwin=0 2 @: Def fieldscur=AEHIOQTWKNMbcdfgjplrsuvyzX 3 @: winflags=30009, sortindx=10, maxtasks=0 4 @: summclr=1, msgsclr=1, headclr=3, taskclr=1 5 @: Job fieldscur=ABcefgjlrstuvyzMKNHIWOPQDX 6 @: winflags=62777, sortindx=0, maxtasks=0 7 @: summclr=6, msgsclr=6, headclr=7, taskclr=6 8 @: Mem fieldscur=ANOPQRSTUVbcdefgjlmyzWHIKX 9 @: winflags=62777, sortindx=13, maxtasks=0 10 @: summclr=5, msgsclr=5, headclr=4, taskclr=5 11 @: Usr fieldscur=ABDECGfhijlopqrstuvyzMKNWX 12 @: winflags=62777, sortindx=4, maxtasks=0 13 @: summclr=3, msgsclr=3, headclr=2, taskclr=3 You see that the while loop is executed 13 times, and the first line is missing because the first array element is referenced as $array[0], not $array[1]. This is what you probably want: foreach my $array_element ( @array) { print $array_element; RCfile for "top with windows" # shameless braggin' Id:a, Mode_altscr=0, Mode_irixps=1, Delay_time=3.000, Curwin=0 Def fieldscur=AEHIOQTWKNMbcdfgjplrsuvyzX winflags=30009, sortindx=10, maxtasks=0 summclr=1, msgsclr=1, headclr=3, taskclr=1 Job fieldscur=ABcefgjlrstuvyzMKNHIWOPQDX winflags=62777, sortindx=0, maxtasks=0 summclr=6, msgsclr=6, headclr=7, taskclr=6 Mem fieldscur=ANOPQRSTUVbcdefgjlmyzWHIKX winflags=62777, sortindx=13, maxtasks=0 summclr=5, msgsclr=5, headclr=4, taskclr=5 Usr fieldscur=ABDECGfhijlopqrstuvyzMKNWX winflags=62777, sortindx=4, maxtasks=0 summclr=3, msgsclr=3, headclr=2, taskclr=3 The number of elements are given by $#array. #!/usr/bin/perl use strict; use warnings; open FILE, ".toprc" or die $!; my @array = <FILE>; print "Number of elements in array: " . eval($#array + 1) . "\n"; my $NUM = 0; while ($NUM < $#array + 1) { print "$NUM : $array[$NUM]"; $NUM++; } # alternative, much better suited for arrays: $NUM = 0; foreach my $array_element ( @array) { print "$NUM : $array_element"; $NUM++; } Though in this case $NUM is just superfluous. The most simple and effective is: foreach my $array_element ( @array) { print $array_element; } -- Sandy List replies only please! Please address PMs to: news-reply2 (@) japantest (.) homelinux (.) com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
Sandy Drobic wrote:
David C. Rankin wrote:
Listmates:
This is what you probably want:
foreach my $array_element ( @array) { print $array_element;
Thanks Sandy! Again.. P.S. - Is there any thing you don't know Sandy? -- David C. Rankin, J.D., P.E. Rankin Law Firm, PLLC 510 Ochiltree Street Nacogdoches, Texas 75961 Telephone: (936) 715-9333 Facsimile: (936) 715-9339 www.rankinlawfirm.com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
David C. Rankin wrote:
Sandy Drobic wrote:
David C. Rankin wrote:
Listmates:
This is what you probably want:
foreach my $array_element ( @array) { print $array_element;
Thanks Sandy! Again..
P.S. - Is there any thing you don't know Sandy?
LOTS!! I never had anything to do with Exchange... -- Sandy List replies only please! Please address PMs to: news-reply2 (@) japantest (.) homelinux (.) com -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
On Thursday 2008-05-01 08:52, David C. Rankin wrote:
Quick perl question - why are @array[$num] and $array[$num] the same?
They are not. As per the perl manual or so, $ denotes the singular form, and @ the plural form. Like, $apple but @apples. IOW, $a[2] to extract one element, and @a[2,3,4] to extract three (same with hashes: $a{onething}, @a{one,another}). Of course, @a[2] should be valid just in case the list passed in has only one element. (Allows you to write something like @a[&all_interesting_indexes($of_this_array)] -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 David C. Rankin wrote:
Listmates:
I don't know who I have to thank for this, but I think it was Anders who recommended that I look at perl after one of my last weird bash questions. I have a syntax question as I go though perl.
The situation. I read a file into an array and then go to reference each line.
my $NUM = 1; open FILE, ".bashrc" or die $!; my @array = <FILE>;
How is it legal that I can reference the array element either as @array[element] or $array[element]?:
while (@array[$NUM]) { print "$NUM : @array[$NUM]\n"; $NUM++; }
while ($array[$NUM]) { print "$NUM : $array[$NUM]\n"; $NUM++; }
From what I've read, it seems like the list $array[element] would just return the number of characters in the list $array[element] not the text itself. How should I think about this?
The other (serious) responders are accurate however I suggest you get a copy of the "Llama", i.e. Learning Perl, Randall L.Schwatz and Tom Pheonix, O'Reilly Press (I do not know whether there is a newer edition but I have the 3rd )... The language has its nuances and this a good starting point to help avoiding some beginner traps... - -- ============================================================================== I have always wished that my computer would be as easy to use as my telephone. My wish has come true. I no longer know how to use my telephone. Bjarne Stroustrup ============================================================================== -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.5 (GNU/Linux) Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org iD8DBQFIGXlCasN0sSnLmgIRAnxxAJ9rjlU4evJJOiA51VVIuT6R5q0dtgCfRuai TxOoAUD81DIjI20Ts8dkHvM= =bZLL -----END PGP SIGNATURE----- -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org
participants (12)
-
Carlos E. R.
-
David C. Rankin
-
G T Smith
-
Jan Engelhardt
-
Jim Flanagan
-
Kaare Rasmussen
-
N B Day
-
Randall R Schulz
-
Razi Khaja
-
Sam Clemens
-
Sandy Drobic
-
Sloan