in reply to How to split a string

(aside: In a future language, I'm going to make sure that variable names cannot use digits as part of the name.)

You really don't want sequential names. You should learn to use arrays:

my @f = split //, $s;

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.

Replies are listed 'Best First'.
Re^2: How to split a string
by ikegami (Patriarch) on Jan 28, 2005 at 15:49 UTC

    Is there a way in a-future-language to slice a string (say '1029') into serialized variables and end up with

    f_zero = 1; f_one = 0; f_two = 2; f_three = 9;

    *grin*

      Obviously…

      my @numword = qw( zero one two three four five six seven eight nine te +n ); my $i = 0; ${ "f_" . $numword[ $i++ ] } = $_ for split //, $string;

      Nevermind the fact that you can vandalize the symbol table to put things in it with whose names don't conform to identifier rules, such as ${ '[ ha ha ha ]' } = 1;.

      Makeshifts last the longest.

        Perl has identifier rules? I never knew.

Re^2: How to split a string
by osunderdog (Deacon) on Jan 28, 2005 at 16:05 UTC

    I object! There are valid cases where a digit can be embedded in a variable name that aren't sequential.

    $payload_32 $sensor_7 $sensor_125 $thermistor_10um_1

    I won't use your tyrannical anti-numerical variable name future language. You'll have to educate people instead.


    "Look, Shiny Things!" is not a better business strategy than compatibility and reuse.

      $payload_32 $sensor_7 $sensor_125

      Didn't you just prove merlyn's point?

      Makeshifts last the longest.

        No, I don't think so. My examples correspond to pin out locations and are hardly ever sequential. I guess I could use an array to store them but it would be extremly sparse.

        I believe merlyn's point (if I may bo so bold) is that a developer shouldn't just enumerate variables. IE ($t1, $t2, $t3, etc). Which I agree with whole heartedly.

        However I disagree that digits should be disallowed from a variable name in a language to avoid the problem. There are a lot of valid uses for a digit in a variable. The only way to keep developers from doing this is to educate them on the disadvantages.


        "Look, Shiny Things!" is not a better business strategy than compatibility and reuse.