split question
am 19.09.2007 15:15:47 von stephanelegault
Hi, I want split a list in two parts from the same delimiter character.
=
Here is the list [sample1:sample2:sample3:sample4:sample5]
=
I would like a $variable containing sample1 and another one containing the =
rest.
=
I search a lot on Internet and find how to split this in many variable ($x,=
$y)=3Dsplit(/:/) but this is not useful for me.
=
Does anyone can help?
Le tout nouveau Yahoo! Courriel. Consultez vos fils RSS depuis votre =
bo=EEte de r=E9ception. http://us.rd.yahoo.com/evt=3D40705/*http://mrd.mai=
l.yahoo.com/try_beta?.intl=3Dcf
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: split question
am 19.09.2007 15:18:05 von eroode
split() has a third argument which specifies the maximum number of
pieces to split the string into. So:
($first, $rest) = split /:/, $_, 2;
will do what you want.
Bonne chance,
Eric J. Roode
-----Original Message-----
From: activeperl-bounces@listserv.ActiveState.com
[mailto:activeperl-bounces@listserv.ActiveState.com] On Behalf Of
Stephane Legault
Sent: Wednesday, September 19, 2007 9:16 AM
To: activeperl@listserv.ActiveState.com
Subject: split question
Hi, I want split a list in two parts from the same delimiter character.
Here is the list [sample1:sample2:sample3:sample4:sample5]
I would like a $variable containing sample1 and another one containing
the rest.
I search a lot on Internet and find how to split this in many variable
($x,$y)=split(/:/) but this is not useful for me.
Does anyone can help?
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: split question
am 19.09.2007 15:21:02 von David Totten
On 9/19/07, Stephane Legault wrote:
> Hi, I want split a list in two parts from the same delimiter character.
>
> Here is the list [sample1:sample2:sample3:sample4:sample5]
>
> I would like a $variable containing sample1 and another one containing the rest.
>
> I search a lot on Internet and find how to split this in many variable ($x,$y)=split(/:/) but this is not useful for me.
you should be able to change that a little and do ($x,@y)=split(/:/)
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: split question
am 19.09.2007 15:22:48 von Lim Ee Wah
Hi,
In this case, you can try use normal regular expression instead of split
my $test =3D "aaa;bbbb;cccc;dddd;eeee";
my ($aaa,$bbb) =3D $test =3D~ /^(.*?);(.*)$/;
print "\$aaa=3D$aaa\n";
print "\$bbb=3D$bbb\n";
On 9/19/07, Stephane Legault wrote:
> Hi, I want split a list in two parts from the same delimiter character.
>
> Here is the list [sample1:sample2:sample3:sample4:sample5]
>
> I would like a $variable containing sample1 and another one containing th=
e rest.
>
> I search a lot on Internet and find how to split this in many variable ($=
x,$y)=3Dsplit(/:/) but this is not useful for me.
>
> Does anyone can help?
>
>
> Le tout nouveau Yahoo! Courriel. Consultez vos fils RSS depuis votre=
bo=EEte de r=E9ception. http://us.rd.yahoo.com/evt=3D40705/*http://mrd.ma=
il.yahoo.com/try_beta?.intl=3Dcf
> _______________________________________________
> ActivePerl mailing list
> ActivePerl@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: split question
am 19.09.2007 15:24:26 von Scott_Campbell
Stephane,
Try this:
my $string=3D"sample1:sample2:sample3:sample4:sample5";
my($variable,@list)=3Dsplit(/:/, $string);
print "Variable: $variable\n";
print "List: $list[0]";
$variable will contain your sample1 value, while @list will contain the res=
t of the values.
Scott
-----Original Message-----
From: activeperl-bounces@listserv.ActiveState.com [mailto:activeperl-bounce=
s@listserv.ActiveState.com] On Behalf Of Stephane Legault
Sent: Wednesday, September 19, 2007 9:16 AM
To: activeperl@listserv.ActiveState.com
Subject: split question
Hi, I want split a list in two parts from the same delimiter character.
=
Here is the list [sample1:sample2:sample3:sample4:sample5]
=
I would like a $variable containing sample1 and another one containing the =
rest.
=
I search a lot on Internet and find how to split this in many variable ($x,=
$y)=3Dsplit(/:/) but this is not useful for me.
=
Does anyone can help?
Le tout nouveau Yahoo! Courriel. Consultez vos fils RSS depuis votre =
bo=EEte de r=E9ception. http://us.rd.yahoo.com/evt=3D40705/*http://mrd.mai=
l.yahoo.com/try_beta?.intl=3Dcf
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: split question
am 19.09.2007 15:26:19 von martin.thurn
Split can not do that. Use a regex such as
my $sList = 'sample1:sample2:sample3:sample4:sample5';
my ($s1, $s2) = ($sList =~ m!\A([^:]*):(.+)\Z!);
print "s1=$s1= s2=$s2=\n";
- - Martin
-----Original Message-----
From: activeperl-bounces@listserv.ActiveState.com
[mailto:activeperl-bounces@listserv.ActiveState.com] On Behalf Of
Stephane Legault
Sent: Wednesday, September 19, 2007 09:16
To: activeperl@listserv.ActiveState.com
Subject: split question
Hi, I want split a list in two parts from the same delimiter character.
Here is the list [sample1:sample2:sample3:sample4:sample5]
I would like a $variable containing sample1 and another one containing
the rest.
I search a lot on Internet and find how to split this in many variable
($x,$y)=split(/:/) but this is not useful for me.
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: split question
am 19.09.2007 15:28:25 von Ahmed Boussouf
--===============0877122568==
Content-Type: multipart/alternative;
boundary="----=_Part_38314_10163366.1190208505752"
------=_Part_38314_10163366.1190208505752
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
Hello!
A way to do it is:
you can split the list and put the result in an array, lets say temp.
$variable is then :
$variable =3D temp[0] and $variable2 =3D
temp[1].":".temp[2].":".temp[3].":".temp[4];
Hope this helps.
Ahmed
On 19/09/2007, Stephane Legault wrote:
>
> Hi, I want split a list in two parts from the same delimiter character.
>
> Here is the list [sample1:sample2:sample3:sample4:sample5]
>
> I would like a $variable containing sample1 and another one containing th=
e
> rest.
>
> I search a lot on Internet and find how to split this in many variable
> ($x,$y)=3Dsplit(/:/) but this is not useful for me.
>
> Does anyone can help?
>
>
> Le tout nouveau Yahoo! Courriel. Consultez vos fils RSS depuis votre
> bo=EEte de r=E9ception.
> http://us.rd.yahoo.com/evt=3D40705/*http://mrd.mail.yahoo.co m/try_beta?.i=
ntl=3Dcf
> _______________________________________________
> ActivePerl mailing list
> ActivePerl@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
------=_Part_38314_10163366.1190208505752
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline
Hello!
A way to do it is:
you can split the list and put the result in an array, lets say temp. =
$variable is then :
$variable =3D temp[0] and $variable2 =3D temp[1].":".temp[2]=
..":".temp[3].":".temp[4];
Hope this helps.
Ahmed
On 19/09/2007,
e">Stephane Legault <st=
ephanelegault@yahoo.com> wrote:
px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Hi, I want split a list in two p=
arts from the same delimiter character.
Here is the list [sample1:sa=
mple2:sample3:sample4:sample5]
I would like a $variable containing sample1 and another one contain=
ing the rest.
I search a lot on Internet and find how to split this =
in many variable ($x,$y)=3Dsplit(/:/) but this is not useful for me.
>
Does anyone can help?
Le tout nouveau Y=
ahoo! Courriel. Consultez vos fils RSS depuis votre bo=EEte de r=E9ception.=
yahoo.com/try_beta?.intl=3Dcf">http://us.rd.yahoo.com/evt=3D 40705/*http://m=
rd.mail.yahoo.com/try_beta?.intl=3Dcf
_______________________________________________
ActivePerl maili=
ng list
ActivePer=
l@listserv.ActiveState.comTo unsubscribe:
v.ActiveState.com/mailman/mysubs">
http://listserv.ActiveState.com/mailman/mysubs
r>
------=_Part_38314_10163366.1190208505752--
--===============0877122568==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0877122568==--
RE: split question
am 19.09.2007 16:03:42 von eroode
Split most certainly can do that.
Eric
-----Original Message-----
From: activeperl-bounces@listserv.ActiveState.com
[mailto:activeperl-bounces@listserv.ActiveState.com] On Behalf Of Thurn,
Martin
Sent: Wednesday, September 19, 2007 9:26 AM
To: Stephane Legault; activeperl@listserv.ActiveState.com
Subject: RE: split question
Split can not do that. Use a regex such as
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
RE: split question
am 19.09.2007 16:09:07 von Paul.Brzezinski
I think split can do that:
($x, $y) =3D split( /:/, $_, 2 );
http://perldoc.perl.org/functions/split.html
--
Paul J. Brzezinski
EDS - Integration Engineering
=A0
=A0 Phone:+1-248-365-9615(8-355)
P paul.brzezinski@eds.com
>-----Original Message-----
>From: activeperl-bounces@listserv.ActiveState.com [mailto:activeperl-
>bounces@listserv.ActiveState.com] On Behalf Of Thurn, Martin
>Sent: Wednesday, September 19, 2007 9:26 AM
>To: Stephane Legault; activeperl@listserv.ActiveState.com
>Subject: RE: split question
>
>Split can not do that. Use a regex such as
>
>my $sList =3D 'sample1:sample2:sample3:sample4:sample5';
>my ($s1, $s2) =3D ($sList =3D~ m!\A([^:]*):(.+)\Z!);
>print "s1=3D$s1=3D s2=3D$s2=3D\n";
>
>
> - - Martin
>
>-----Original Message-----
>From: activeperl-bounces@listserv.ActiveState.com
>[mailto:activeperl-bounces@listserv.ActiveState.com] On Behalf Of
>Stephane Legault
>Sent: Wednesday, September 19, 2007 09:16
>To: activeperl@listserv.ActiveState.com
>Subject: split question
>
>Hi, I want split a list in two parts from the same delimiter character.
>
>Here is the list [sample1:sample2:sample3:sample4:sample5]
>
>I would like a $variable containing sample1 and another one containing
>the rest.
>
>I search a lot on Internet and find how to split this in many variable
>($x,$y)=3Dsplit(/:/) but this is not useful for me.
>_______________________________________________
>ActivePerl mailing list
>ActivePerl@listserv.ActiveState.com
>To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: split question
am 19.09.2007 16:14:48 von Paul Gowers
I think it can:
my ($data) = "sample1:sample2:sample3:sample4";
my ($var1, $var2) = split (/:/, $data, 2);
print "var1 is $var1\nvar2 is $var2\n";
perl test.pl
var1 is sample1
var2 is sample2:sample3:sample4
perldoc -f split
Paul
On 19 Sep 2007, at 14:26, Thurn, Martin wrote:
> Split can not do that. Use a regex such as
>
> my $sList = 'sample1:sample2:sample3:sample4:sample5';
> my ($s1, $s2) = ($sList =~ m!\A([^:]*):(.+)\Z!);
> print "s1=$s1= s2=$s2=\n";
>
>
> - - Martin
>
> -----Original Message-----
> From: activeperl-bounces@listserv.ActiveState.com
> [mailto:activeperl-bounces@listserv.ActiveState.com] On Behalf Of
> Stephane Legault
> Sent: Wednesday, September 19, 2007 09:16
> To: activeperl@listserv.ActiveState.com
> Subject: split question
>
> Hi, I want split a list in two parts from the same delimiter
> character.
>
> Here is the list [sample1:sample2:sample3:sample4:sample5]
>
> I would like a $variable containing sample1 and another one containing
> the rest.
>
> I search a lot on Internet and find how to split this in many variable
> ($x,$y)=split(/:/) but this is not useful for me.
> _______________________________________________
> ActivePerl mailing list
> ActivePerl@listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Re: split question
am 19.09.2007 18:45:11 von David Totten
On 9/19/07, David Totten wrote:
> On 9/19/07, Stephane Legault wrote:
> > Hi, I want split a list in two parts from the same delimiter character.
> >
> > Here is the list [sample1:sample2:sample3:sample4:sample5]
> >
> > I would like a $variable containing sample1 and another one containing the rest.
> >
> > I search a lot on Internet and find how to split this in many variable ($x,$y)=split(/:/) but this is not useful for me.
>
> you should be able to change that a little and do ($x,@y)=split(/:/)
>
Now that I have a computer with perl installed on it, I have tested this:
#!/usr/bin/perl -w
use strict;
my $list = "sample1:sample2:sample3:sample4:sample5";
my $first = "";
my @rest = ();
($first,@rest) = split(/:/,$list);
print "$first\n$rest[0]\n$rest[1]\n";
and the output is:
sample1
sample2
sample3
_______________________________________________
ActivePerl mailing list
ActivePerl@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs