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 [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
stephanelegault [ Mi, 19 September 2007 15:15 ] [ ID #1824579 ]

RE: split question

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 [at] listserv.ActiveState.com
[mailto:activeperl-bounces [at] listserv.ActiveState.com] On Behalf Of
Stephane Legault
Sent: Wednesday, September 19, 2007 9:16 AM
To: activeperl [at] 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 [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
eroode [ Mi, 19 September 2007 15:18 ] [ ID #1824580 ]

Re: split question

On 9/19/07, Stephane Legault <stephanelegault [at] yahoo.com> 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, [at] y)=split(/:/)
_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
David Totten [ Mi, 19 September 2007 15:21 ] [ ID #1824581 ]

Re: split question

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 <stephanelegault [at] yahoo.com> 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 [at] listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Lim Ee Wah [ Mi, 19 September 2007 15:22 ] [ ID #1824582 ]

RE: split question

Stephane,

Try this:

my $string=3D"sample1:sample2:sample3:sample4:sample5";
my($variable, [at] list)=3Dsplit(/:/, $string);

print "Variable: $variable\n";
print "List: $list[0]";

$variable will contain your sample1 value, while [at] list will contain the res=
t of the values.

Scott

-----Original Message-----
From: activeperl-bounces [at] listserv.ActiveState.com [mailto:activeperl-bounce=
s [at] listserv.ActiveState.com] On Behalf Of Stephane Legault
Sent: Wednesday, September 19, 2007 9:16 AM
To: activeperl [at] 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 [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Scott_Campbell [ Mi, 19 September 2007 15:24 ] [ ID #1824583 ]

Re: split question

--===============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 <stephanelegault [at] yahoo.com> 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 [at] 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

<div>
<div>Hello!</div>
<div> </div>
<div>A way to do it is:</div>
<div> </div>
<div>you can split the list and put the result in an array, lets say temp. =
$variable is then :</div>
<div> </div>
<div>$variable =3D temp[0] and $variable2 =3D temp[1].":".temp[2]=
..":".temp[3].":".temp[4];</div>
<div> </div>
<div>Hope this helps.<br> </div>
<div>Ahmed</div><br> </div>
<div><span class=3D"gmail_quote">On 19/09/2007, <b class=3D"gmail_sendernam=
e">Stephane Legault</b> <<a href=3D"mailto:stephanelegault [at] yahoo.com">st=
ephanelegault [at] yahoo.com</a>> wrote:</span>
<blockquote class=3D"gmail_quote" style=3D"PADDING-LEFT: 1ex; MARGIN: 0px 0=
px 0px 0.8ex; BORDER-LEFT: #ccc 1px solid">Hi, I want split a list in two p=
arts from the same delimiter character.<br><br>Here is the list [sample1:sa=
mple2:sample3:sample4:sample5]
<br><br>I would like a $variable containing sample1 and another one contain=
ing the rest.<br><br>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.<br><br=
>
Does anyone can help?<br><br><br>     Le tout nouveau Y=
ahoo! Courriel. Consultez vos fils RSS depuis votre bo=EEte de r=E9ception.=
  <a href=3D"http://us.rd.yahoo.com/evt=3D40705/*http://mrd.mail.=
yahoo.com/try_beta?.intl=3Dcf">http://us.rd.yahoo.com/evt=3D 40705/*http://m=
rd.mail.yahoo.com/try_beta?.intl=3Dcf
</a><br>_______________________________________________<br>ActivePerl maili=
ng list<br><a href=3D"mailto:ActivePerl [at] listserv.ActiveState.com">ActivePer=
l [at] listserv.ActiveState.com</a><br>To unsubscribe: <a href=3D"http://listser=
v.ActiveState.com/mailman/mysubs">
http://listserv.ActiveState.com/mailman/mysubs</a><br></blockquote></div><b=
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 [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
--===============0877122568==--
Ahmed Boussouf [ Mi, 19 September 2007 15:28 ] [ ID #1824584 ]

RE: split question

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 [at] listserv.ActiveState.com
[mailto:activeperl-bounces [at] listserv.ActiveState.com] On Behalf Of
Stephane Legault
Sent: Wednesday, September 19, 2007 09:16
To: activeperl [at] 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 [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
martin.thurn [ Mi, 19 September 2007 15:26 ] [ ID #1824585 ]

RE: split question

Split most certainly can do that.

Eric

-----Original Message-----
From: activeperl-bounces [at] listserv.ActiveState.com
[mailto:activeperl-bounces [at] listserv.ActiveState.com] On Behalf Of Thurn,
Martin
Sent: Wednesday, September 19, 2007 9:26 AM
To: Stephane Legault; activeperl [at] listserv.ActiveState.com
Subject: RE: split question

Split can not do that. Use a regex such as
_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
eroode [ Mi, 19 September 2007 16:03 ] [ ID #1824586 ]

RE: split question

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 [at] eds.com


>-----Original Message-----
>From: activeperl-bounces [at] listserv.ActiveState.com [mailto:activeperl-
>bounces [at] listserv.ActiveState.com] On Behalf Of Thurn, Martin
>Sent: Wednesday, September 19, 2007 9:26 AM
>To: Stephane Legault; activeperl [at] 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 [at] listserv.ActiveState.com
>[mailto:activeperl-bounces [at] listserv.ActiveState.com] On Behalf Of
>Stephane Legault
>Sent: Wednesday, September 19, 2007 09:16
>To: activeperl [at] 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 [at] listserv.ActiveState.com
>To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Paul.Brzezinski [ Mi, 19 September 2007 16:09 ] [ ID #1824587 ]

Re: split question

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 [at] listserv.ActiveState.com
> [mailto:activeperl-bounces [at] listserv.ActiveState.com] On Behalf Of
> Stephane Legault
> Sent: Wednesday, September 19, 2007 09:16
> To: activeperl [at] 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 [at] listserv.ActiveState.com
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
Paul Gowers [ Mi, 19 September 2007 16:14 ] [ ID #1824588 ]

Re: split question

On 9/19/07, David Totten <dstotten [at] gmail.com> wrote:
> On 9/19/07, Stephane Legault <stephanelegault [at] yahoo.com> 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, [at] 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 [at] rest = ();

($first, [at] rest) = split(/:/,$list);

print "$first\n$rest[0]\n$rest[1]\n";

and the output is:
sample1
sample2
sample3
_______________________________________________
ActivePerl mailing list
ActivePerl [at] listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
David Totten [ Mi, 19 September 2007 18:45 ] [ ID #1824590 ]
Perl » gmane.comp.lang.perl.active-perl » split question

Vorheriges Thema: How to resolve a and b when one knows the sum and the dividend
Nächstes Thema: split question