Often processing using regular expressions is more suitable.
For example, code like (not tested, you get the idea):
You could instead do...:# Pull token from line (Not good perl style) $end = index( $line, / /, 0 ); $token = substr( $line, 0, $end ); $line = substr( $line, $end ); # still need to lose whitespace #
or even:( $token, $line ) = split( /\s+/, $line, 2 );
It perhaps looks a little funnier if you are used to other languages and you are of course free to code how you want. But, IMHO you don't get the warm fuzzy perl feeling unless you are in the idiom.( $token, $line ) = $line =~ /^(\S+)\s+(\S+)$/;
Now someone is going to tell me how I should be doing the above in a much more efficient way ;-)
Hmmm...last thought is that if you don't have to deal with quoting issues (or you do and you are red hot at regexps ;-) you get to do things like:
And lastly if you do have to deal with quoted whitespace etc (isn't the real world a tough place) you might find what you need in the Text::ParseWords module. (You shouldn't even have to go to CPAN for that...its part of the base install).@tokens = split( $line, /\s+/ ); # Split all words into the array foreach my $word ( @words ) { # drive state machine }
In reply to Re: Character Index
by jbert
in thread Character Index
by wyvern
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |