In article
<5aa28f5e-d8f5-4989-b964-ef9f5ae9d...@em1g2000vbb.googlegroups.com>,
Pradeep <bubunia2000s
...@gmail.com> wrote:
> Hi,
> I am a new bie in perl. I have a string as follows
> xxxx:yyyy:zzzz:aaaa::bbbb.9.5
> I need to discard the 9.5 and my resultant string should be
> xxxx:yyyy:zzzz:aaaa::bbbb with .9.5 not be present.
> I tried to use split as follows. But its not working as expected. I
> will appreciate any help.
> use Data::Dumper;
> my @str="xxxx:yyyy:zzzz:aaaa::bbbb.9.5";
You should not be assigning a string to an array variable:
my $str = "xxxx:yyyy:zzzz:aaaa::bbbb.9.5";
> my @values;
> foreach my $val (@str) {
> @values = split('.', $val);
> }
There is no need for a loop, and you need to escape the period to match
only a period:
my @values = split(/\./,$str);
Your desired string is now in $values[0].
You could also use a regular expression:
$str =~ s/\..*//;