freelanceprogrammers.org Forum Index » Perl

Newbie Help


View user's profile Post To page top
junoon_hai_m... Posted: Wed Apr 27, 2005 9:37 am


Joined: 27 Apr 2005

Posts: 4
Newbie Help
I want to know if there is a way to do this is perl
A sample of the data is:

field1,field2,"3232,34,56",field4,field5

and i need to convert it into three individual records:

field1,field2,3232,field4,field5
field1,field2,34,field4,field5
field1,field2,56,field4,field5

The field in quotes might contain many more or less entries, even at
times none.
Any help is greatly appreciated.
Thanks a lot.
Reply with quote
Send private message
View user's profile Post To page top
paulalapatt Posted: Wed Apr 27, 2005 10:22 pm


Joined: 06 Apr 2005

Posts: 12
Newbie Help
>
> I want to know if there is a way to do this is perl
> A sample of the data is:
>
> field1,field2,"3232,34,56",field4,field5
>
> and i need to convert it into three individual records:
>
> field1,field2,3232,field4,field5
> field1,field2,34,field4,field5
> field1,field2,56,field4,field5
>
>

Approx code for achieving the same, maybe not optimal:

$var1 = qq{field1,field2,"3232,34,56",field4,field5};

if($var1 =~ /(([w]+),([w]+),([d,"]+),([w]+),([w]+))/ig) {
$var1 =~ s/"//ig;
@ArepeatedValues = split /,/, $3;
$AfinalData = ();
foreach (@ArepeatedValues) {
push($1 . "," . $2 . "," . $_ . "," . $4 . "," . $5;
}

}


Hope this helps.

Paul Alapatt
Mo: +91-9820187987
Reply with quote
Send private message
View user's profile Post To page top
krish_tamil Posted: Thu Apr 28, 2005 9:47 am


Joined: 21 Feb 2005

Posts: 7
Newbie Help
Hi

The first pattern match results are not carry when another pattern was used

i.e $1,$2, etc values are not carried when used $var1=~ s/"//ig; this and also
push command syntax is incomplete

I have altered the following script. I think this will help you


$var1 = qq{field1,field2,"3232,34,56",field4,field5};
if($var1 =~ /(([w]+),([w]+),)([d,"]+),(([w]+),([w]+))/ig) {
$tmp1=$1;
$tmp2=$4;
$tmp3=$5;
$tmp2 =~ s/"//ig;
@ArepeatedValues = split /,/, $tmp2;
@AfinalData = ();
foreach (@ArepeatedValues) {
push(@AfinalData, "$tmp1$_,$tmp3");
}
foreach(@AfinalData)
{
print "$_
";
}
}




Paul Alapatt <paul.alapatt@...> wrote:

>
> I want to know if there is a way to do this is perl
> A sample of the data is:
>
> field1,field2,"3232,34,56",field4,field5
>
> and i need to convert it into three individual records:
>
> field1,field2,3232,field4,field5
> field1,field2,34,field4,field5
> field1,field2,56,field4,field5
>
>

Approx code for achieving the same, maybe not optimal:

$var1 = qq{field1,field2,"3232,34,56",field4,field5};

if($var1 =~ /(([w]+),([w]+),([d,"]+),([w]+),([w]+))/ig) {
$var1 =~ s/"//ig;
@ArepeatedValues = split /,/, $3;
$AfinalData = ();
foreach (@ArepeatedValues) {
push($1 . "," . $2 . "," . $_ . "," . $4 . "," . $5;
}

}


Hope this helps.

Paul Alapatt
Mo: +91-9820187987






---------------------------------
Yahoo! Groups Links

To visit your group on the web, go to:
http://groups.yahoo.com/group/perl_official/

To unsubscribe from this group, send an email to:
perl_official-unsubscribe@yahoogroups.com

Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.


Yahoo! India Matrimony: Find your life partneronline.

[Non-text portions of this message have been removed]
Reply with quote
Send private message
View user's profile Post To page top
paulalapatt Posted: Thu Apr 28, 2005 10:37 pm


Joined: 06 Apr 2005

Posts: 12
Newbie Help
________________________________________
From: perl_official@yahoogroups.com [mailto:perl_official@yahoogroups.com]
On Behalf Of Krishna R
Sent: Thursday, April 28, 2005 10:18 AM
To: perl_official@yahoogroups.com
Subject: RE: [Perl] Newbie Help


Hi

The first pattern match results are not carry when another pattern was used

i.e $1,$2, etc values are not carried when used $var1=~ s/"//ig; this and
also push command syntax is incomplete

I have altered the following script. I think this will help you


$var1 = qq{field1,field2,"3232,34,56",field4,field5};
if($var1 =~ /(([w]+),([w]+),)([d,"]+),(([w]+),([w]+))/ig) {
   $tmp1=$1;
   $tmp2=$4;
   $tmp3=$5;
   $tmp2 =~ s/"//ig;
   @ArepeatedValues = split /,/, $tmp2;
   @AfinalData = ();
   foreach (@ArepeatedValues) {
      push(@AfinalData, "$tmp1$_,$tmp3");
   }
   foreach(@AfinalData)
   {
      print "$_
";
   }
}



Sorry and Thanks Krishna
:)

Paul Alapatt


Paul Alapatt <paul.alapatt@...> wrote:

>
> I want to know if there is a way to do this is perl
> A sample of the data is:
>
> field1,field2,"3232,34,56",field4,field5
>
> and i need to convert it into three individual records:
>
> field1,field2,3232,field4,field5
> field1,field2,34,field4,field5
> field1,field2,56,field4,field5
>
>

Approx code for achieving the same, maybe not optimal:

$var1 = qq{field1,field2,"3232,34,56",field4,field5};

if($var1 =~ /(([w]+),([w]+),([d,"]+),([w]+),([w]+))/ig) {
      $var1 =~ s/"//ig;     
      @ArepeatedValues = split /,/, $3;
      $AfinalData = ();
      foreach (@ArepeatedValues) {
            push($1 . "," . $2 . "," . $_ . "," . $4 . "," . $5;
      }

}


Hope this helps.

Paul Alapatt
Mo: +91-9820187987






---------------------------------
Yahoo! Groups Links

   To visit your group on the web, go to:
http://groups.yahoo.com/group/perl_official/
 
   To unsubscribe from this group, send an email to:
perl_official-unsubscribe@yahoogroups.com
 
   Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.


Yahoo! India Matrimony: Find your life partneronline.

[Non-text portions of this message have been removed]





________________________________________
Yahoo! Groups Links
• To visit your group on the web, go to:
http://groups.yahoo.com/group/perl_official/
 
• To unsubscribe from this group, send an email to:
perl_official-unsubscribe@yahoogroups.com
 
• Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
Reply with quote
Send private message
Post new topic Reply to topic
Display posts from previous:   
 

All times are GMT
Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Freelace Website Designer - Customer web design and software building.
China Wholesale - Electronics Products
Character Studio - Tutorials and Help