in reply to Re: Extract the variable
in thread Extract the variable

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re^3: Extract the variable
by EvanK (Chaplain) on Jun 25, 2007 at 15:58 UTC
    The docs for substr are mostly straightforward, but it won't really do precisely what you're looking for:
    $raw = ".declare book_num a13"; $var = substr $raw, 9; print $var; # prints "book_num a13"
    However, you could also try split. I don't think there would be a noticeable performance difference either way, but splitting would also give you the value if you need it:
    (undef, $var, $val) = split /\s+/, $raw, 3; printf '%s=%s', $var, $val; # prints book_num=a13

    __________
    Systems development is like banging your head against a wall...
    It's usually very painful, but if you're persistent, you'll get through it.

Re^3: Extract the variable
by blazar (Canon) on Jun 26, 2007 at 09:08 UTC
    Hey this also working !!! Thanx dear!!! But how to use substr function for the same functionality?

    denzil_cactus, I see you're relatively new to PM. You'll notice that you already asked that particular question, and that you received an actual answer. So what's wrong with that?

    Anyway... back to your question... in my experience I've found that people tend to want to use regexen based solutions even where simpler tools like substr and index would do, or -to mention a classic scenario- to "do it with one regex", where two would better fill the bill. But here a regex based approach is the most natural one, and if you want to know about substr just for curiosity and your own personal education, then fine, but otherwise go with a regex by all means.

A reply falls below the community's threshold of quality. You may see it by logging in.