Solved

split up text

Posted on 2000-02-24
6
172 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
perl rename 2 142
Perl - Mawk 2 95
grep that displays 4 lines above & 1 line below of what's found 10 80
Edit Odbc.ini using perl module 2 83
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 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

10 Experts available now in Live!

Get 1:1 Help Now