Hello mrityunjaynath,
If you say split(/X/, $string), then $string is split into chunks separated by whatever is matched by X. For example, in this one-liner:
18:05 >perl -MData::Dump -wE "my $s = 'Hello1234world!5678How9012are34 +56you?'; my @w = split /[0-9]{4}/, $s; dd \@w;" ["Hello", "world!", "How", "are", "you?"] 18:06 >
the string is split on 4-digit groups, and the array @w is populated with the words in $s which come between those digits.
To capture the digit groups, you could try to split on non-digits, but it’s much better (and more straightforward) to use a regular expression with a /g modifier, like this:
open(my $CFILE, '<', 'config.txt') or die "Couldn't open file 'config. +txt' for reading: $!"; $readline = <$CFILE>; @words = $readline =~ /([0-9]{4})/g;
as demonstrated in this one-liner:
18:06 >perl -MData::Dump -wE "my $s = 'Hello1234world!5678How9012are34 +56you?'; my @w = $s =~ /([0-9]{4})/g; dd \@w;" [1234, 5678, 9012, 3456] 18:18 >
Hope that helps,
| Athanasius <°(((>< contra mundum | Iustus alius egestas vitae, eros Piratica, |
In reply to Re^3: warning: use of uninitialized value
by Athanasius
in thread warning: use of uninitialized value
by mrityunjaynath
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |