freelanceprogrammers.org Forum Index » Perl
Newbie Help
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.
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
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]
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.
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
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.
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help
Booking Calendar - reservation calendar script
Land Surveying - total station instruments and equipments
China Wholesale - Electronics Products
Character Studio - Tutorials and Help







