Hey again, folks! Before I get to my real question, which relates to this non-working as I expected regex I came up with:
$phr =~ s/\s+(w+)\s+(w+)/$2\s+$1;
I would just like to say how much I'm LOVING this site! Learning much more than I ever expected! I'm just having a freakin' BLAST learning this stuff and getting the best feedback I've EVER gotten during a learning process! I wish that I had something analagous to this site back when I was learning C and C++!!! I would deem this process far superior to the classes I had for C (I had already taught myself some C++ by that point!) at NYU! No comparison, in my mind. This educational experience has been better than that. Okay, I'm done kissin' up to you schlubs! ;D Onto the matter at hand!
The problem I'm struggling with comes from exercise 2 p.272 in
Lemay's Book. Although, as
I pointed out earlier I fully
intend on reading merlyn's book. By the way, curious, but which author is merlyn? Randall or Tom? I digress. Okay, now, I'm really ready! :)
The problem states that one must
----------------------------------------------------
2. Write a subroutine that takes a string as an argument and returns the string in reverse order by words.
----------------------------------------------------
#!/usr/bin/perl -w
use strict # okay! okay! I give! uncle! (even though I still don't kno
+w what it does yet! :)
initargs(); # thanks for teaching me the more modern perl convention.
+Lemay's book is a bit dated.
print "\nPlease enter a phrase: ";
chomp ($phr = <STDIN>);
rev($phr);
print "\n\nDone.";
sub rev {
$len = length ($phr);
$phr =~ s/\s+(w+)\s+(w+)/$2\s+$1;
print "$phr\n";
}
sub initargs {
$phr;
}
Now just so you know this script is in an extremely
primitive state.
I usually like to get my scripts to a little highler level of sophistication before posting to the monks. Usually, what I do is start with making the script
ridiculously simple and get elements to work one at a time before proceeding. So, there are stylistic and logic issues
all over the place on this one. I think I know most of them already, but if you would still like to comment on those aspects, by all means! be my guest! that's what you get for
putting your learning curve on the 'net. Sorry to merlyn, btw. I think I may have misinterpreted your blog (if you do read this). It was late, I was tired and gumpy. Oh well. My point being, that the trap door on my jammies is open and my ass is hanging out on this one! And I don't particularly care who's lookin' at my bum!
But I just learned about regexes and how to 'write them' -which I still can't claim to know how to do, as evinced by this post! - a couple of weeks ago, and my facility with them is still incredibly shaky!
This book, by the way has been calling and calling to me from my bookshelf for over 6 mos now! My original intention was to get through
Lemay's Book - I really like
her chatty, personal style, by the way - but then dive into
MySQL in 21 Days and then proceed onto
Mastering Regular Expressions before taking on
merlyn's book or any other IT related projects.
The specific reason of the "quick learn" method I'm currently engaged in with the Sams 21 Days series is that my friend and I want to set up our little lemonade stand on the net and see who comes. If I don't learn it, he's going to find someone else! But I assure you that I fully intend on reading merlyn, wall and anyone else you'd care to suggest -
eric s. raymond was also a particularly good suggestion that someone made!
But, as usual, I welcome any and all comments, so if you would like to offer any suggestions on my learning process I would like to encourage you to fire away!!!
THANKS TO THE MONKS!!!