Splitting a string

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
VlearnsAsked:
Who is Participating?
 
Kim RyanConnect With a Mentor IT ConsultantCommented:
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
 
VlearnsAuthor Commented:
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
 
VlearnsAuthor Commented:
tag is always letter like  tag="product"

0
 
Kim RyanIT ConsultantCommented:
this code should work then, give it a go.
0
 
VlearnsAuthor Commented:
thanks tera

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.