For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > August 2005 > perl string operations - query









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author perl string operations - query
Prakash M

2005-08-03, 10:00 pm

I have written a small code which will just try to split a string based on the Key.
-----------------
$val="sample1a+2.8sample2a+2.8sample3a";
print "String=$val\n";
print "split Key: 2.8\n";
@arr=split(/2.8/,$val);
foreach $i (@arr)
{
print "**Split value: $i\n";
}
print "******************\n";
print "split Key: a+2.8\n";
@arr1=split(/a+2.8/,$val);
foreach $j (@arr1)
{
print "**Split value: $j\n";
}
----------------
The first case the key is 2.8 and the output is correct, but if i want to split the string based on key "a+2.8"
it's giving an improper result.
String=sample1a+2.8sample2a+2.8sample3a
split Key: 2.8
**Split value: sample1a+
**Split value: sample2a+
**Split value: sample3a
******************
split Key: a+2.8
**Split value: sample1a+2.8sample2a+2.8sample3a
Can anyone tell me what changes are needed to split the string based on "a+2.8"
Thanks,
Prakash

________________________________________
__________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Greg Maruszeczka

2005-08-03, 10:00 pm

prakash m wrote:
> I have written a small code which will just try to split a string based on the Key.
> -----------------
> $val="sample1a+2.8sample2a+2.8sample3a";
> print "String=$val\n";
> print "split Key: 2.8\n";
> @arr=split(/2.8/,$val);
> foreach $i (@arr)
> {
> print "**Split value: $i\n";
> }
> print "******************\n";
> print "split Key: a+2.8\n";
> @arr1=split(/a+2.8/,$val);
> foreach $j (@arr1)
> {
> print "**Split value: $j\n";
> }
> ----------------
> The first case the key is 2.8 and the output is correct, but if i want to split the string based on key "a+2.8"
> it's giving an improper result.
> String=sample1a+2.8sample2a+2.8sample3a
> split Key: 2.8
> **Split value: sample1a+
> **Split value: sample2a+
> **Split value: sample3a
> ******************
> split Key: a+2.8
> **Split value: sample1a+2.8sample2a+2.8sample3a
> Can anyone tell me what changes are needed to split the string based on "a+2.8"



backwhack the '+' (ie. "\+")
Wagner, David --- Senior Programmer Analyst --- WG

2005-08-03, 10:00 pm

prakash m wrote:
> I have written a small code which will just try to split a string
> based on the Key. -----------------
> $val=3D"sample1a+2.8sample2a+2.8sample3a";
> print "String=3D$val\n";
> print "split Key: 2.8\n";
> @arr=3Dsplit(/2.8/,$val);
> foreach $i (@arr)
> {
> print "**Split value: $i\n";
> }
> print "******************\n";
> print "split Key: a+2.8\n";
> @arr1=3Dsplit(/a+2.8/,$val);
> foreach $j (@arr1)
> {
> print "**Split value: $j\n";
> }
> ----------------
> The first case the key is 2.8 and the output is correct, but if i
> want to split the string based on key "a+2.8" it's giving an improper
> result.=20
> String=3Dsample1a+2.8sample2a+2.8sample3a
> split Key: 2.8
> **Split value: sample1a+
> **Split value: sample2a+
> **Split value: sample3a
> ******************
> split Key: a+2.8
> **Split value: sample1a+2.8sample2a+2.8sample3a
> Can anyone tell me what changes are needed to split the string based
> on "a+2.8"=20


If really a+2.8 then /a\+2\.8/ would be the split. The + has meaning in th=
e regex as give me 1 or more a's. Also should \ the period since a+218 woul=
d be a valid split on a\+2.8 where the . says anything can be there.

Wags ;)
> Thanks,
> Prakash
>=20
> ________________________________________
__________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com




****************************************
***************
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
****************************************
***************

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2009 codecomments.com