Solved

Splitting a string

Posted on 2004-10-13
5
199 Views
Last Modified: 2010-03-05
Hi have a string

hostname.domain:abc="tag"

i want to get

$var1=hostname.domain
$var2=abc
$var3=tag

can someone help me on this

thanks
0
Comment
Question by:Vlearns
  • 3
  • 2
5 Comments
 

Author Comment

by:Vlearns
ID: 12305499
actually the problem is this:

i have @list containing hostname1.domain1:abc="tag" and
                                 hostname2.domain2:abc="tag"

i want @var1=hostname1.domain1,hostname2.domain2
          @var2=abc
           @var3=tag

Please suggest a solution, i am newbie to perl

Thanks
0
 
LVL 19

Accepted Solution

by:
Kim Ryan earned 500 total points
ID: 12305552
I don't know the exact pattern of your data. For example, istag always made up of letters, or could there be numbers too? Anyway, this should get you started.

@list = qw{hostname1.domain1:abc="tag" hostname2.domain2:abc="tag"};
foreach $line ( @list )
{
      $line =~ /^(.*):(\w+)=\"(\w+)\"$/;
      $var1 = $1;
      $var2 = $2;
      $var3 = $3;

      print("var1: $var1  var2 : $var2  var3 : $var3\n");
      
      
}
0
 

Author Comment

by:Vlearns
ID: 12305564
tag is always letter like  tag="product"

0
 
LVL 19

Expert Comment

by:Kim Ryan
ID: 12305590
this code should work then, give it a go.
0
 

Author Comment

by:Vlearns
ID: 12305635
thanks tera

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now