CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
swaping variable values

 



RussianSpy
Novice

Aug 30, 2002, 2:33 PM

Post #1 of 9 (1820 views)
swaping variable values Can't Post

$a= "tom"; $b="ann"

is there an ez way in Perl to swap values of $a and $b w/ using temporary variable?



also, /^abc/ means string starts w/ "abc".. how to say it doesn't start w "abc" ?



TIA!
_________________________________________________
[ noobie alert ] WinXP :: Xitami Webserver :: Active Perl 5.8.6


andrew_b
stranger

Aug 30, 2002, 5:53 PM

Post #2 of 9 (1815 views)
Re: [RussianSpy] swaping variable values [In reply to] Can't Post


In Reply To
$a= "tom"; $b="ann"

is there an ez way in Perl to swap values of $a and $b w/ using temporary variable?

how about ($a, $b) = ($b, $a);



In Reply To
also, /^abc/ means string starts w/ "abc".. how to say it doesn't start w "abc" ?

!~ /^abc/


jryan
User

Aug 30, 2002, 5:58 PM

Post #3 of 9 (1814 views)
Re: [RussianSpy] swaping variable values [In reply to] Can't Post

Sure, use the power of lists:


Code
$a= "tom"; 
$b="ann";

($b,$a) = ($a,$b);



RussianSpy
Novice

Aug 31, 2002, 12:03 AM

Post #4 of 9 (1809 views)
Re: [jryan] swaping variable values [In reply to] Can't Post

thanks a lot guys!

more i try Perl, more i love it : )
_________________________________________________
[ noobie alert ] WinXP :: Xitami Webserver :: Active Perl 5.8.6


jryan
User

Aug 31, 2002, 12:33 AM

Post #5 of 9 (1807 views)
Re: [RussianSpy] swaping variable values [In reply to] Can't Post


In Reply To
also, /^abc/ means string starts w/ "abc".. how to say it doesn't start w "abc" ?


Sorry, I didn't see that part earlier. Here is how:


Code
$string =~ /^abc/; # check to see if $string starts with "abc" 
$string !~ /^abc/; # check to see if $string doesn't start with "abc"



RussianSpy
Novice

Aug 31, 2002, 1:17 AM

Post #6 of 9 (1805 views)
Re: [jryan] swaping variable values [In reply to] Can't Post

yeah, i fugured it out : )

thank you again!

its my 1st Perl program (russian-slovak online dictionary). b4 i only wrote some proggies in VB and b4 that in Pascal and QBasic which all, as u know, are very different from Perl. im looking through a lot of examples as i learn it, but im having a lot of problems understanding RE strings, but feeling is ones i get it it'd be so much eazier to write some stuff in Perl then in VB... damn, my script now is so much smaller if i'd try to write it in VB!! im loving it! Sly
_________________________________________________
[ noobie alert ] WinXP :: Xitami Webserver :: Active Perl 5.8.6


jryan
User

Aug 31, 2002, 12:24 PM

Post #7 of 9 (1802 views)
Re: [RussianSpy] swaping variable values [In reply to] Can't Post

For getting started with regular expressions, give perlretut a look.


RussianSpy
Novice

Sep 1, 2002, 12:45 AM

Post #8 of 9 (1798 views)
Re: [jryan] swaping variable values [In reply to] Can't Post

thanks!



and here i go again: are

if (index ("Hello World", "World") >= 0)

and

if ("Hello World" =~ /World/)

are really the same thing? if yes, do u know if any one is faster then the other?
_________________________________________________
[ noobie alert ] WinXP :: Xitami Webserver :: Active Perl 5.8.6


Paul
Enthusiast

Sep 1, 2002, 2:46 AM

Post #9 of 9 (1797 views)
Re: [RussianSpy] swaping variable values [In reply to] Can't Post

use index()

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives