Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^9: Shorten a list...

by la (Novice)
on Oct 18, 2011 at 18:11 UTC ( [id://932211]=note: print w/replies, xml ) Need Help??


in reply to Re^8: Shorten a list...
in thread Shorten a list...

So in this case, I would be changing the file separator from defining a new paragraph with blank lines, to defining a new paragraph with ">Group". THen I need the script to print the paragraph if the paragraph is greater than 2 lines.

Is this along the right track?

local ($/, $\) = ('', ">Group");

Replies are listed 'Best First'.
Re^10: Shorten a list...
by Cristoforo (Curate) on Oct 18, 2011 at 20:23 UTC
    #!/usr/bin/perl use strict; use warnings; { local $/ = '>Group'; while (<DATA>) { chomp; print ">Group$_" if tr/\n// > 2; } } __DATA__ >Group 42 0 25ap, >name_06-T_1_0... at 92.00% 1 28ap, >name_06-T_1_0... * >Group 43 0 28ap, >name_07-N_1_0... * >Group 44 0 29ap, >name_07-N_1_0... * >Group 45 0 25ap, >name_03-T_1_0... * 1 25ap, >name_06-T_1_0... at 100.00% 2 25ap, >name_07-N_1_0... at 100.00% 3 25ap, >name_11-N_1_0... at 100.00% 4 25ap, >name_14-T_1_0... at 100.00%
    prints
    >Group 42 0 25ap, >name_06-T_1_0... at 92.00% 1 28ap, >name_06-T_1_0... * >Group 45 0 25ap, >name_03-T_1_0... * 1 25ap, >name_06-T_1_0... at 100.00% 2 25ap, >name_07-N_1_0... at 100.00% 3 25ap, >name_11-N_1_0... at 100.00% 4 25ap, >name_14-T_1_0... at 100.00%
    If you want to separate the records with a newline in the output, add a newline in the print. print ">Group$_\n" if tr/\n// > 2;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-25 06:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found