Ask a Question related to PERL Miscellaneous, Design and Development.
-
Arjen #1
Need help on split-function
Hi All,
What I want to is using a string as PATTERN in a split function. This makes
it possible for me to change the PATTERN on one place in my script...
For example:
$separator = ";";
$line = "field1;value1";
local($field, $value) = split(/$separator/, $line);
How can I make this work ?
Arjen
Arjen Guest
-
#39838 [NEW]: split function correctly
From: lu at icst dot org dot tw Operating system: Fedora Core 3 and 6 PHP version: 5.2.0 PHP Bug Type: Unknown/Other Function... -
#39838 [Com]: split function correctly
ID: 39838 Comment by: judas dot iscariote at gmail dot com Reported By: lu at icst dot org dot tw Status: Open... -
javascript split function
I'm using the split method to put values into an array. When I pass in the argument to the function and then use the split method, the delimiters... -
Problem with split function
Hi all, I am having a problem with the split function. Here is my code: $_ = "123 a 456 b 789 c"; my @words = split /+/, $_; print... -
note 33878 added to function.str-split
str_split for older versions of PHP, it should behave just the same (let's hope that code indentation remains the same ^^). function... -
Matthew Browning #2
Re: Need help on split-function
On Mon, 15 Sep 2003 11:17:25 +0200, Arjen wrote:
>
> For example:
> $separator = ";";
> $line = "field1;value1";
> local($field, $value) = split(/$separator/, $line);
>
> How can I make this work ?
In what sense exactly does that not work?
Matthew Browning
Matthew Browning Guest
-
Thens #3
Re: Need help on split-function
On Mon, 15 Sep 2003 11:17:25 +0200
"Arjen" <mijn_postbak@msn.com> wrote:
# Hi All,
#
# What I want to is using a string as PATTERN in a split function. This makes
# it possible for me to change the PATTERN on one place in my script...
#
# For example:
# $separator = ";";
# $line = "field1;value1";
# local($field, $value) = split(/$separator/, $line);
I dont know why this will fail. But you can also quote the
meta-characters in your PATTERN using \Q and \E if they have any.
$separator = "++";
$line = "field1++value1";
local($field, $value) = split(/\Q$separator\E/, $line);
Regards,
Thens.
Thens Guest
-
Arjen #4
Re: Need help on split-function
Hi Matthew,
You are right. I will give an example:
Code:
$line = "field1|value1";
$separator = "|";
local($field, $value) = split(/$separator/, $line);
Gives back:
$field = f
$value= v
Code:
$line = "field1^value1";
$separator = "^";
local($field, $value) = split(/$separator/, $line);
Gives back:
$field = field1^value1
$value=
Code:
$line = "field1;value1";
$separator = ";";
local($field, $value) = split(/$separator/, $line);
Gives back:
$field = field1
$value= value1
The last example is working right. The others are not. Even not when i'm
using "\|" instead of "|" for the seperator.
Arjen
"Matthew Browning" <usenet@NOSPAM.matthewb.org> wrote in message
news:pan.2003.09.15.10.16.29.11643@NOSPAM.matthewb .org...> On Mon, 15 Sep 2003 11:17:25 +0200, Arjen wrote:>> >
> > For example:
> > $separator = ";";
> > $line = "field1;value1";
> > local($field, $value) = split(/$separator/, $line);
> >
> > How can I make this work ?
>
> In what sense exactly does that not work?
>
>
> Matthew Browning
Arjen Guest
-
Jürgen Exner #5
Re: Need help on split-function
Arjen wrote:
[snipped]
You won't believe it but a namesake of yours just posted exactly the same
question in CLP where I just happened to answer it.
You may want to check there.
And you also may want to read the nettiquette why multiposting will put you
on the fast path into many killfiles.
jue
Jürgen Exner Guest
-
Arjen #6
Re: Need help on split-function
you> You won't believe it but a namesake of yours just posted exactly the same
> question in CLP where I just happened to answer it.
> You may want to check there.
>
> And you also may want to read the nettiquette why multiposting will putI'm really sorry, I didn't know that I should not post this message in more> on the fast path into many killfiles.
>
> jue
then one newsgroup. Or is it because comp.lang.perl and comp.lang.perl.misc
are related that I shouldn't post in both ?!
Arjen
Arjen Guest
-
Helgi Briem #7
Re: Need help on split-function
On Mon, 15 Sep 2003 12:56:47 +0200, "Arjen" <mijn_postbak@msn.com>
wrote:
Comp.lang.perl is extinct. It doesn't exist except on>I'm really sorry, I didn't know that I should not post this message
>in more ten one newsgroup. Or is it because comp.lang.perl and
>omp.lang.perl.misc are related that I shouldn't post in both ?!
misconfigured servers. You should never ever post
to it.
Cross-posting is OK, but in moderation and only
with very good cause. Multi-posting is a definite
no-no.
--
Helgi Briem hbriem AT simnet DOT is
Excuses the munged address. My last
e-mail address was killed by spammers.
Helgi Briem Guest
-
Alan J. Flavell #8
Re: Need help on split-function
On Mon, Sep 15, Helgi Briem inscribed on the eternal scroll:
Having a regular posting on comp.lang.perl to warn people that it> Comp.lang.perl is extinct. It doesn't exist except on
> misconfigured servers. You should never ever post
> to it.
doesn't really exist (and with an authoritative link to the original
control message which should have rmgroup-ed it) would seem to be a
self-contradictory thing to do, but I'm not sure how else the message
is ever going to get out. :-{
Alan J. Flavell Guest



Reply With Quote

