harry34 has asked for the wisdom of the Perl Monks concerning the following question:

I am very new to perl. would like some help please.
If I have the following line in a file,
SYMM     1/4 - X, 1/8 + Y, 1/2 + Z
How would I undef SYMM and store the rest of the line in a variable.
Also I want to, in a different variable store the same line but with +ve & -ve signs reversed.
i.e SYMM     1/4 + X, 1/8 - Y, 1/2 - Z
cheers

Replies are listed 'Best First'.
Re: reverse signs
by dragonchild (Archbishop) on Dec 18, 2001 at 17:07 UTC
    This looks surprisingly like another question asked here yesterday. Homework assignment?

    As for the questions ...

    1. To "undef a variable", you simply undef $foo;. The rest of your first question indicates that you don't really understand what you're asking. Think about it further - what exactly do you want to do? If you don't know, then nothing I say can help you.
    2. Swapping a character for another character is called transliteration. Perl uses an operator called tr. Click on the hyperlink for more information.

    ------
    We are the carpenters and bricklayers of the Information Age.

    Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Re: reverse signs
by cfreak (Chaplain) on Dec 18, 2001 at 21:29 UTC

    As dragonchild said this sounds a bit like homework and if it is it wouldn't be really fair to give you the answer :). But heres a hint.

    If I understand you correctly you want to get rid of the SYMM part form the line. For that you probably want to use regular expressions. Look into the 's' (switch) operator. And follow dragonchild's suggestion on reversing the signs.

    Hope that helps.
    Chris

    Update: That should be 's' for the substitution operator. I was still asleep when I wrote this :). (Thanks to premchai21 for pointing that out)