Daylite
Daylite

Reputation: 509

Splitting a string into variable length strings in perl

I would like to do something like this: To my subroutine, a long string comes as an input. I need to split this string into multiple strings of variable length for ex: my string will be composed of numbers, spl characters, alphabet etc. I would like to have byte 1, 2 together as a string byte 3 - 30 together as another substring byte 31 - 35 as another substring and so till the end of the string is reached? How can I do this? Please help me out with a sample code

Upvotes: 0

Views: 258

Answers (1)

ikegami
ikegami

Reputation: 385744

my @fields = unpack 'a2 a28 a4', $_;

Upvotes: 1

Related Questions