in reply to unexpected behavior with split
Oh dear.
Allow me to quote from talexb's reply to a post earlier today:
I'm guessing that you won't get much (serious) help on this -- you're asking us to spend significant time to debug a piece of code. You've come to the wrong site for that. Here's what this site (and community) is about: you bring your boiled-down, condensed, pithy Perl question to us, and we give you lots of varied answers and different approaches. You learn something, and perhaps we do too. I suggest you go away and do some work on your question, and come back when you've narrowed it down a bit...
We don't want to see your entire code (in particular, when you've learned a little more about Perl, you'll be ashamed about stuff such as:
if ($subscript == 1) { $aphor = $aphor1 } elsif ($subscript == 2) { $aphor = $aphor2 #... up to and including elsif (subscript == 7) { .. }
but as you're learning, at present, that's OK).
But what's not OK is to post the whole mess here. Note my emphasis of talexb's 'boiled-down, condensed, pithy' (if you don't know what 'pithy' means, well, er... it's pretty much the same as 'condensed' (or 'boiled-down' :) ).
I simply don't have the time to look through all of your 135 lines (in my editor) of code, and I imagine that most other Monks don't, either.
The moral is: Condense it! Boil it down! Extract the pith!
First, for example, your question has nothing to do with command-line processing, so take out all the stuff about @ARGV.
Second, we don't need to know how you define and select your aphorisms according to user input. If you have a problem with parsing user input, make it the subject of a separate post, not one entitled 'unexpected behavior with split'. This means that you could replace 43 lines (in my editor) of code (including the @ARGV stuff) - from if ($subscript == 1) { to the '}' just after die "ARGV out of range"; - with just one line, namely:
my $aphor = 'whatever';where 'whatever' corresponds to one of the aphorisms that you are having problems with.
How to post condensed (boiled-down, pithy) code: Let's say I write some code that Perl doesn't want to compile (a regular occurrence, I assure you). After examining the error messages, and correcting my most ridiculous mistakes, and other stuff, if it still doesn't do what I want, I postulate that there might be an error in the line:
my @sect = split /$splBRK/;So, I create a new perl file (I call it 'test.pl', YMMV):
use strict; use warnings; my $str = 'aa~~bb'; my $splBRK = '~~'; my @sect = split /$splBRK/, $str; print "<$_>\n" for @sect;
Well, it seems that test.pl (after trying as many test cases as I can think of) works as expected , implying that the problem is elsewhere in my code. So, ikegami++ (how I envy his/her patience!) is probably right.
I could go on, but I think that a Tutorial entitled 'Basic Debugging' (or something...) might be in order. A lot of interesting stuff has already been posted in PM, such a tutorial could be mainly just be a synthesis of these nodes, but time (as ever) is not extensible...
dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: unexpected behavior with split
by ww (Archbishop) on Sep 01, 2004 at 02:33 UTC |