Papapep wrote:
> 
> How should I do to split a long string that the only thing I know is
> that is a multiple of a previous defined number (for example 26).
> 
> A graphic example:
> 
>abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
> 
> That's four times 26 (104) but I don't (I can't) count every string
> because they are really long (They can be of thousands of charachters).
> 
> So what I should do, I think, is a loop that get the first 26
> charachters and print them in a new file, after that evaluates if there
> is more string to get, and so on, but I am not able to see how it
> works... :-/
> 
> Give me some advice, please (the command I should use, or group of
> commands, etc...)

Here are a couple of ways to do it:

my $length = 26;
my $string = 'abcdefghijklmnopqrstuvwxyz' x 4;


Split on arbitrary length using match operator:

for my $line ( $string =~ /.{1,$length}/sg ) {
    # $line contains 1 to $length characters
    }


Split on arbitrary length using substr (C style):

for ( my $index = 0; my $line = substr $string, $index, $length; $index += $length ) {
    # $line contains 1 to $length characters
    }



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to