Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

split up text

Posted on 2000-02-24
6
180 Views
Last Modified: 2010-03-05
if my variable contains
$myvar="this=is=a=test=string";

and i do
($x,$y)=split("=",$myvar);

then $x becomes "this"
and $y becomes "is"

but how do i split it so that
$x becomes "this"
and $y becomes "is=a=test=string";

ie $y becomes the rest of the string

thanks
0
Comment
Question by:paulwhelan
6 Comments
 
LVL 16

Accepted Solution

by:
maneshr earned 50 total points
ID: 2555149
try this...

this script in flexible in that tomorrow if you have one more = field in myvar it would still work.

Eg. try this script with $myvar="this=is=a=test=string=for=testing";
==================================================
#!/usr/local/bin/perl

$myvar="this=is=a=test=string";

$x=substr($myvar,0,index($myvar,"="));
$y=substr($myvar,(index($myvar,"=")+1),length($myvar));

print $x,"\n",$y,"\n";

0
 
LVL 1

Expert Comment

by:mrachow
ID: 2555174
There is a thirt parameter for split available.
Try
($x,$y)=split("=",$myvar,2);

Greetings.
0
 
LVL 3

Expert Comment

by:RobWMartin
ID: 2556227
Or this:

($x,@y)=split("=",$myvar);
$y=join("=",@y);

Rob
0
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

 
LVL 3

Expert Comment

by:RobWMartin
ID: 2556237
Or this:

($x,$y)=$myvar=~/^(.+?)=(.*)/;

Rob
0
 

Author Comment

by:paulwhelan
ID: 2557215
sorry maneshr got there first....
0
 

Author Comment

by:paulwhelan
ID: 2557217
it works thats the main thing
;)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
perl script to count sepecial characters in a file 7 147
work on ods spreadsheet with perl in ubuntu 4 80
compress files in RAR using perl 13 83
Perl tar error 8 66
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question