Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
parse question
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Pradeep  
View profile  
 More options May 14 2012, 3:10 pm
Newsgroups: comp.lang.perl.misc
From: Pradeep <bubunia2000s...@gmail.com>
Date: Mon, 14 May 2012 12:10:44 -0700 (PDT)
Local: Mon, May 14 2012 3:10 pm
Subject: parse question
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";
my @values;
foreach my $val (@str) {
   @values = split('.', $val);


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jim Gibson  
View profile  
 More options May 14 2012, 8:01 pm
Newsgroups: comp.lang.perl.misc
From: Jim Gibson <JimSGib...@gmail.org>
Date: Mon, 14 May 2012 17:01:04 -0700
Local: Mon, May 14 2012 8:01 pm
Subject: Re: parse question
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/\..*//;


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »