Solved

Splitting a string

Posted on 2004-10-13
5
185 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 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

11 Experts available now in Live!

Get 1:1 Help Now