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

Hi Guys,
I have got stuck in a simple formatting problem as shown below. Can somebody give me clue howto deal with this ? I am using $_ so not able to format multiple lines at one go.
85988 86615 gene=C21orf99 ;transcript_id=XR_040882.1 ;HGNC=16620
I want it like this:-
85988 86615 gene=C21orf99;transcript_id=XR_040882.1;HGNC= +16620
Thanks

Replies are listed 'Best First'.
Re: Formatting problem
by CountZero (Bishop) on Feb 10, 2009 at 07:00 UTC
    Did you try stripping all EOL / linefeed characters from your strings? A simple regular expression should do the trick. Or do perhaps stray space characters mess up with your formatting? Again, a regular expression to trim your data is the way forward.

    In case you are reading your data from a file, chomping the input will get rid of any EOL.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      Thanks trim and rtrim did it for me ;-)
        In which module did you find the trim and rtrim functions? Text::Trim perhaps?

        I use

        for ($variable) { s/^\s+//; s/\s+$//; }
        to trim I can type that faster than looking-up the name of the module and checking the syntax of the functions.

        CountZero

        A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James