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

hi every one
i have a file which contains the strings of various lengths. i want to keep all the strings (say of 10 charcters in to 1) file and so on here is an example of it
input file
ABCDEF
ABGHRI
ABDEFCRAVF
output ABCDEF and ABGHRI in file 1
ABDEFCRAVF in file 2 and so on..can any one help me

  • Comment on creating new files bases on string size

Replies are listed 'Best First'.
Re: creating new files bases on string size
by CountZero (Bishop) on Feb 11, 2012 at 11:17 UTC
    Something like this?
    use Modern::Perl; my @filehandle; my $maxlength = 10; for ( 1 .. $maxlength ) { open $filehandle[$_], '>', "text$_.txt" or die "Could not open tex +t$_.txt"; } while (<DATA>) { chomp; select $filehandle[ length($_) ]; say $_; } __DATA__ ABC DEFG HIJ KL 1234XYZ G HI S 12ER 34TY

    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

Re: creating new files bases on string size
by moritz (Cardinal) on Feb 11, 2012 at 07:18 UTC
Re: creating new files bases on string size
by Corion (Patriarch) on Feb 11, 2012 at 09:02 UTC