Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mid - left - right Im confused...

Status
Not open for further replies.

LinuXelite

Programmer
Joined
Jun 21, 2002
Messages
150
Location
CA
Hi!

We are coders, right? I'll show you what I wanna do in a very simple language, VB.
I program Perl but I dont know how to "convert" this code.

Lets say I wanna convert into perl:
if left(string,1) = "1" then msgbox "V

in perl?!? I am wrong.. What can I write.
$_ = $string; if (s/1/[-1]/) {print "hey hey"; }

Also I wanna program something like this:
if right(left(string,2),1) then....

How would u write that with a regular expression?

Thanks in advance.

Frank

 
Code:
$_ = '1 blue car - text stuff to examine';


# a parallel treatment to your vb approach broken into
# tiny pieces....
$left_char = substr($_, 0, 1);
if ($left_char eq '1') { $msgbox = 'V'; }
print "MSG1: $msgbox\n";
undef $msgbox;

# Or, you can compress it a little,
if (substr($_,0,1) eq '1') { $msgbox = 'V'; }
print "MSG2: $msgbox\n";
undef $msgbox;

# Or, you can use a regular expression search 
if (/^1/) { $msgbox = 'V'; }
print "MSG3: $msgbox\n";
undef $msgbox;

# Or, you can use a regex with a conditional syntax
$msgbox = (/^1/) ? 'V' : 'Nope';
print "MSG4: $msgbox\n";
'hope this helps

If you are new to Tek-Tips, please use descriptive titles, check the FAQs, and beware the evil typo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top