Solved

split up text

Posted on 2000-02-24
6
187 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
[X]
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
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Need help with bash and/or perl commands on OS X Terminal 9 114
Port 80 requests 16 111
Parse csv file and generate graphs in HTML in bash 8 301
Edit Odbc.ini using perl module 2 96
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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…

751 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