Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: print format

by Zaxo (Archbishop)
on Apr 22, 2003 at 01:48 UTC ( [id://252175]=note: print w/replies, xml ) Need Help??


in reply to print format

There is format and write, which are designed for that sort of output.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: print format
by Anonymous Monk on Apr 22, 2003 at 15:17 UTC
    I am searching on GeneBank data, I got 480 Accession number, for each Accession number, I need two items: item1 and items, so I have the print format like:
    Accession item1 item2 12345678 abcd1234 als
    because I generate each accession number first, for each accession number, I use foreach loop to generate item1 and item2, maybe some of the accession number have a couple of groups item1 and item2, maybe some of them have none item1 and item2 at all. I tried to use:
    printf ("%08d",$accession);#which is before foreach loop. foreach (@accession){ .... $item1=....; $item2=....; printf("%16s%08s",$item1,$item2); }
    It printed out so messy. Please help! Thanks!

      Use a temporary variable. Set it to the value to print before entering the loop. After the first print in the loop, set it to an empty string. This assumes that the loop will produce at least one line of output.

      my ($print_accession) = sprintf("%08s",$accession); foreach (@accession) { ... $item1=...; $item2=...; printf("%8s%16s%8s\n",$print_accession,$item1,$item2); $print_accession = ""; }

      If you don't like your strings right aligned in their field, use '%-16s' - the minus indicates the field should be left aligned. See perldoc -f sprintf for details on the available formats.

      90% of every Perl application is already written.
      dragonchild

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://252175]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-26 02:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found