in reply to Re^2: warning: use of uninitialized value
in thread warning: use of uninitialized value
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, |
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: warning: use of uninitialized value
by mrityunjaynath (Acolyte) on Jun 25, 2015 at 09:47 UTC | |
by Athanasius (Archbishop) on Jun 25, 2015 at 13:39 UTC | |
by u65 (Chaplain) on Jun 25, 2015 at 17:14 UTC | |
by hippo (Archbishop) on Jun 25, 2015 at 19:22 UTC | |
by u65 (Chaplain) on Jun 25, 2015 at 20:18 UTC | |
by mrityunjaynath (Acolyte) on Jun 26, 2015 at 04:00 UTC | |
by robby_dobby (Hermit) on Jun 26, 2015 at 05:05 UTC | |
by mrityunjaynath (Acolyte) on Jun 26, 2015 at 05:26 UTC | |
|