Solved

split up text

Posted on 2000-02-24
6
155 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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 …
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…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now