Computer Science Canada

I am new to the world of programming

Author:  mummified zombie [ Wed Sep 01, 2004 6:30 pm ]
Post subject:  I am new to the world of programming

Hi I just created an acount on this site cause i came across it on msn. I now basic html and want to learn how to make first person shooter games in the long run. I have been facinated with computers as long as i can remember but i have had no place to learn how to program. If any one could tell me were i can find a tutorial on the easiest game creation program that is preferable downloadable for free.

ty all

Twisted Evil mummified zombie Twisted Evil

Author:  wtd [ Wed Sep 01, 2004 6:50 pm ]
Post subject: 

I don't think it's as simple as you think.

Your path will likely look something like:


  1. Become more familiar with the fundamentals of computers. What they're made of, how those parts work together, etc.
  2. Learn the fundamentals of programming.
  3. Learn object-oriented programming techniques.
  4. Learn the details of pointers and memory management.
  5. Pick up a set of tools for dealing with 3D graphics, sound, etc. and play with them until you've got a handle on how they work.

Author:  Anime Freak [ Wed Sep 01, 2004 7:51 pm ]
Post subject: 

i was mummified zombie but i changed to this cause i didn't like the other name ><, .

Can u guys help me with learning all about the computer. if there r ne experience computer programmers or game programmers that live close to calgary, alberta (within a 1 hour drive) plz tell me and we can talk at a later time

Author:  Paul [ Wed Sep 01, 2004 7:53 pm ]
Post subject: 

I never had to learn the parts of a computer, other than monitor, mouse, computer and keyboard... mayber thats why i suck at programming Laughing

Author:  Anime Freak [ Wed Sep 01, 2004 7:58 pm ]
Post subject: 

well could ne of u help me with my quest to becoming an "ok" game programmer

Author:  wtd [ Wed Sep 01, 2004 8:00 pm ]
Post subject: 

Of course, I should have specified that it's not a purely linear path. Smile

I learn new stuff about all of the above all the time (trying my hand at Ada95 right now).

And if you feel like coming to Vancouver, I'd be happy to talk with you. Wink

Author:  Amailer [ Wed Sep 01, 2004 8:04 pm ]
Post subject: 

sit on the comp as much as you can, play games you'll learn Razz

Author:  Anime Freak [ Wed Sep 01, 2004 8:04 pm ]
Post subject: 

well i am only 14 and i just started school. my parents would never be able to take me. i live 30 min drive outside of calgary, alberta lol

so i couldnt until next summer or spring vacation.

do u know were vernan is. if so how long of a drive is it from there to vancouver


------------------------

and i alrdy spend all my free time on the comp and play games lol

i play runescape most l8ly

if ne of u play rs can u tell me your usernames and we can chat there

Author:  Paul [ Wed Sep 01, 2004 8:10 pm ]
Post subject: 

ech... runescape... why... do u have a bad computer? Lynk Hyrule : level 65, haven't logged on in a long time. But still playing runescape isn't going to help you. Um... install windows 95, or windows ME on ur computer, wait for it to screw up, I guaruntee that you'll learn how to use a computer fast, either that, or get a bad motherboard.

Author:  Anime Freak [ Wed Sep 01, 2004 8:12 pm ]
Post subject: 

i have a p4 computer, and it runs almost perfectly when i dont go on a "download junk off the internet" frenzy again that got my computer a virus and my dad had to reformat the c drive lol

i just play rs to past time.

why would playing games be able to help me on my road to programming.

Author:  wtd [ Wed Sep 01, 2004 8:21 pm ]
Post subject: 

And of course, the first language you'll want to learn to make you a better programmer is English.

By this I mean learn to express yourself eloquently. The best programmers are well-spoken and express themselves with clarity. To communicate with such individuals, and thus learn from them, you'll need to be able to communicate on their level.

Use well-formed sentences, and avoid "cute" things like "l8ly". Smile

Now, as for actual programming...

I suggest grabbing a copy of the Ruby installer for Windows.

http://rubyinstaller.rubyforge.org/wiki/wiki.pl

And I rather like this tutorial:

http://pine.fm/LearnToProgram/

Author:  Tony [ Wed Sep 01, 2004 8:31 pm ]
Post subject: 

well its not quite like that. Playing games will just give you a better idea of the elements involved (UI, graphics, physics, AI, networking, etc) once you actually get to making your own games Razz

point is - programming is not just about games (althogh its the most common driving force behind the interest in the subject)

so you'd have to pick out a programming language to start with (HTML is not programming... its just making your text document looking preaty by making some of the words bold). Since you're just starting, I would suggest to go for syntax simplicity rether than power. Turing will be perfect to familiarize yourself with the basic consepts (variables, i/o, loops, conditions, basic graphics).

We have loads of tutorials available. Take it slow. People will direct you tawards tutorials with consepts you'll need to cover. Best way to learn programming is compleat understanding of basic elements and being able to use them in various combinations. Start practicing with really basic small programs and move up Very Happy

eh... and yeah, what wtd said Razz Ruby is another good choice for starting out.

Author:  wtd [ Wed Sep 01, 2004 8:37 pm ]
Post subject: 

tony wrote:
eh... and yeah, what wtd said Razz Ruby is another good choice for starting out.


And free... and you know... actually popular and stuff... Wink

Author:  rizzix [ Wed Sep 01, 2004 8:50 pm ]
Post subject: 

yea i'd agree Ruby is a nice language Smile a good idea to start of with that.. then lean all the concepts and later on move to other languages.. but if u want to straight-away code simple graphics-oriented scripts etc.. i guess u might as well just start of with turing. heh.

Author:  Anime Freak [ Wed Sep 01, 2004 8:51 pm ]
Post subject: 

well, i type like "l8ly" and "w8" just cause i am used to it cause i play runescape so much and i need to use shortcuts for speach in the game.

so that is why i type like that...and i will do my best to stop with that habbit of typing.

i will be off for a bit cause of a thunder storm that has tornado winds Sad and plz wish me luck to live through the storm lol (i hope typing "lol" and "rofl" is ok)

I will try those sites after the storm and thanks for helping me get started on programming all of you.

Author:  wtd [ Wed Sep 01, 2004 8:55 pm ]
Post subject: 

Anime Freak wrote:
well, i type like "l8ly" and "w8" just cause i am used to it cause i play runescape so much and i need to use shortcuts for speach in the game.

so that is why i type like that...and i will do my best to stop with that habbit of typing.

i will be off for a bit cause of a thunder storm that has tornado winds Sad and plz wish me luck to live through the storm lol (i hope typing "lol" and "rofl" is ok)


Don't worry too much about it. I can sound like a bit of a wet blanket at times. It is ok in casual conversation.

The important thing is that you can break out of that mode of communication when necessary. I've gotten to the point where I can be talking with one friend and committing all kinds of AOL-Speak sins, and then I talk to a friend who's an accomplished writer, and I instantly switch back to using very proper english.

Anyway, proper English is a good (and all too rare) skill to have.

Author:  Anime Freak [ Wed Sep 01, 2004 9:51 pm ]
Post subject: 

is proper english just speaking without all the short cuts.

can u give me a sample

and one more question....wut are "bits" for and how do i get/use them

Author:  wtd [ Wed Sep 01, 2004 10:08 pm ]
Post subject: 

There certainly are basic syntax issues that help. Proper capitalization, punctuation, and avoiding ambiguous use of pronouns are major considerations. In the end, though, it comes from practice.

I would suggest reading some of the comp.lang.* newsgroups. There are a lot of good examples there.

http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&group=comp.lang

Bits, as I understand it, are this site's points system, with points being gained by participation.

Author:  Anime Freak [ Wed Sep 01, 2004 10:08 pm ]
Post subject: 

i am now starting the tutorial for ruby and i dont know any of the comands in comand prompt

Author:  wtd [ Wed Sep 01, 2004 10:18 pm ]
Post subject: 

Go to Start, select Run. Type "irb". This is the Ruby interactive interpreter. You type in a line of code and it executes it and shows you the result. Smile

Author:  Anime Freak [ Wed Sep 01, 2004 10:21 pm ]
Post subject: 

if i try to go to start then run then i type in "irb" and press "ok" it comes up with a error

oh ya and can u donate me some bits lol just to get the ball rolling for me

Author:  wtd [ Wed Sep 01, 2004 10:25 pm ]
Post subject: 

Can you tell me exactly what the error is?

Author:  Anime Freak [ Wed Sep 01, 2004 10:30 pm ]
Post subject: 

well i just went on to the next part of the tutorial and it is the claculator part that says to put "puts 1+2" in this case i used SciTE. and now it tells me to put "ruby calc.rb" into the comand line. at this point i have alrdy saved it under the name "calc.rb". now whats the comand line they are talking about.

Author:  Anime Freak [ Wed Sep 01, 2004 10:33 pm ]
Post subject: 

i just went into browser from right clicking on start menu and then i went to were i saved my mini program and opened it. it opened and closed immediatle. why is that?

Author:  wtd [ Wed Sep 01, 2004 10:37 pm ]
Post subject: 

Anime Freak wrote:
well i just went on to the next part of the tutorial and it is the claculator part that says to put "puts 1+2" in this case i used SciTE. and now it tells me to put "ruby calc.rb" into the comand line. at this point i have alrdy saved it under the name "calc.rb". now whats the comand line they are talking about.


The command-line they're talking about is DOS under Windows 95, 98, ME, and cmd.exe under NT, 2000, and XP.

Which operating system is your computer running?

Author:  Anime Freak [ Wed Sep 01, 2004 10:39 pm ]
Post subject: 

i am running XP so i go to run and type in cmd.exe? but then wut

Author:  wtd [ Wed Sep 01, 2004 10:48 pm ]
Post subject: 

Anime Freak wrote:
i am running XP so i go to run and type in cmd.exe? but then wut


Then you have to make sure you're in the same directory as your Ruby source file: "calc.rb" in this case. If you need help with this, I or others can provide it.

Once there...

code:
C:\> ruby calc.rb


Alternatively you can use the interactive runtime, which should be installed with the installer. At the command prompt, simply type "irb --simple-prompt".

You'll get a prompt that looks like:

code:
>>


Here you can type any Ruby code and have it executed.

code:
>> 1+ 1
=> 2
>> 3 * 4
=> 12

Author:  Anime Freak [ Wed Sep 01, 2004 11:06 pm ]
Post subject: 

i dont need help right now. i phoned up my grampa who is taking a course on almost the exact same stuff and he got my through my problem and i helped him study lol Very Happy

Author:  wtd [ Wed Sep 01, 2004 11:25 pm ]
Post subject: 

Congrats on the progress. Smile

Author:  Anime Freak [ Thu Sep 02, 2004 1:38 pm ]
Post subject: 

thank you luckily my grampa is taking a course similar to whatt i am trying to learn

Author:  the_short1 [ Thu Sep 02, 2004 3:16 pm ]
Post subject: 

well... i can help u with a couple things...


turing: i sent ua link (pm) where u can get help to 'buying' a copy... Wink

try making a program that says 'hello world'.... lol... < yea... u can say that ..,. and rofl... wtd is trying to be... ''proper'.... its also fully aceptable to spell worlds really badly.. (search for posts made by 'hacker dan' <admin) for example Razz lol

but wtd is right... being able to comunicate is important.. we get enuf noobs here just saying... help... why doesnlt it work...... and we cant do squat... cuz we dont know whats not working ... or have any idea about it.... because we were not fed any info to work with...

Author:  Tony [ Thu Sep 02, 2004 3:58 pm ]
Post subject: 

the_short1 : it is not acceptable to spell words really badly... Hacker Dan is an exception because he's an admin Confused can't really do much about that. Doesn't mean you have to follow his example.

The point remains though. The computer will not be guessing what you're trying to tell it to do. It will do exactly what you tell it to do. So be accurate in communication

Author:  Mazer [ Thu Sep 02, 2004 4:17 pm ]
Post subject: 

I can't remember where this quote came from, but it goes with what tony said. "Computers don't make mistakes. They carry out your bad instructions perfectly." And spelling badly because you don't want to type out the full word isn't cool. Neither is leet speak.

Author:  wtd [ Thu Sep 02, 2004 4:38 pm ]
Post subject: 

Mazer wrote:
I can't remember where this quote came from, but it goes with what tony said. "Computers don't make mistakes. They carry out your bad instructions perfectly." And spelling badly because you don't want to type out the full word isn't cool. Neither is leet speak.


Garbage in, garbage out.

Strict computer languages which catch the vast majority of error at compile time can be very helpful in this regard. It can be confusing when an obvious error is still code that will run.

I'd say O'Caml, Eiffel, and Ada95 are probably the very best languages out there in this regard.

Author:  Amailer [ Thu Sep 02, 2004 4:48 pm ]
Post subject: 

But when you'r programming you must use short form (for words that is) or your script and variables and fucntiosn and etc become to large and etc... rit?

Author:  the_short1 [ Thu Sep 02, 2004 6:13 pm ]
Post subject: 

wow ,... wtd.. im impressed.... u write like a english professor... u really got it down good..
.




yea... well Razz..... i dont care.. i spell pretty dam good... as long as i am sitting upright and not on my side.... ( i sit on bed while using computer, due to the fact that my room is too small to have a chair infront of the monitor... well until we do renovations to make it bigger that is... i got too much stuff in there already..

yea... since he is the mod cant really do anything about it... hahaaha... Razz

ruby is sposed to be easy? yea.. dont sound like it so far... DOS programming language is kinda outdated a bit...

XP? i thought u couln;t run any dos apps in xp... can u ?

Author:  Genesis [ Thu Sep 02, 2004 7:18 pm ]
Post subject: 

Why would you not be able to run DOS apps? I'm pretty sure you can.

Author:  Tony [ Thu Sep 02, 2004 7:32 pm ]
Post subject: 

XP is build on top of the new base (don't remember what it's called) so old DOS apps don't work.

anyways...

the_short1 : no, try to find out what ruby is first Laughing

Ruby is one of the newer languages out there (5 years? somebody check that for me).

using cmd to execute those scripts is equivalent to using cmd to compile C++ or a java source.

Author:  wtd [ Thu Sep 02, 2004 8:07 pm ]
Post subject: 

Windows XP is built on a different base than Windows 85, 98, and ME, which were all built on top of DOS. Instead it is built on top of Windows NT, which became Windows 2000. However, since Microsoft's empire is solely built on DOS compatibility, they had to maintain that in Windows NT, 2000 and XP. CMD is almost a replica of DOS. The small differences can be frustrating, but mostly they can be used the same way.

Ruby is roughly a decade old. It was conceived of by Yukihiro Matsumoto originally as a replacement for Perl. It is newer than many languages out there, but also older than some as well. The age of a programming language, however, has little to do with its technical merit. Ruby takes many of its best traits from Smalltalk, which goes back to the early 80s, when it was at the heart of the GUI research being done at Xerox's PARC research facility.

Amailer: When programming, you should use descriptive names. Doing so makes your code easier to read and maintain. If you find that your variable or function names are growing too long, then that's probably a sign that your program was not well designed. I find object-oriented programming helps eliminate long variable names while keeping everything understandable.

Consider the case where you want to keep track of a bunch of people, who all have names. The person we'll consider is "Bob Smith" (a friend of mine whose name I like to use because it's quite generic).

I could use variables with descriptive names to keep track of things.

code:
bobs_first_name = "Bob"
bobs_last_name = "Smith"
puts bobs_first_name + " " + bobs_last_name


However, in this case the full variable names have to beused everywhere and they get rather unwieldy. Instead I could define classes and use objects.

code:
class Name
   attr_reader :first, :last
   def initialize(first, last)
      @first, @last = first, last
   end
   def to_s
      @first + " " @last
end

class Person
   attr_reader :name
   def initialize(first_name, last_name)
      @name = Name.new(first_name, last_name)
   end
end

bob = Person.new("Bob", "Smith")
puts bob.name


Note: it is a common, and exceptable idiom to use variables like i, j, and k for loop counters, as these are very common in code, and easy to understand. It shold also be noted that this is acceptable in a great many languages. In Ada95 I'm currently running into lots of:

code:
procedure Some_Proc(Some_Arg: in Some_Type; Result: out Some_Type) is
begin
   for I in 1 .. 3 loop
      Result := Result + Some_Arg;
   end loop;
end Some_Proc;

Author:  rizzix [ Thu Sep 02, 2004 8:22 pm ]
Post subject: 

replacement for perl eh?
obviously someone was terribly mistaken.. he obvioulsy didn't understand the philosophy behind the perl language.. and wrote something that is.. well just different Laughing

Author:  rizzix [ Thu Sep 02, 2004 8:24 pm ]
Post subject: 

speaking of ada.. i heard it was a mathamatically sound (and proven) language! and is used by the us gov. hmm well thats what i heard anyways

Author:  wtd [ Thu Sep 02, 2004 8:37 pm ]
Post subject: 

Ruby is an excellent replacement for Perl, in that it provides many of the same tools for easily parsing text, as well as some better ones. One of my favorites is the form of "gsub" that accepts a block. Say you want to match every group of one or more letter 'a' case insensitively, and replace it with the same number of instances of "Foo".

code:
sample = "hello a world aa bar aaa baz"
revised = sample.gsub(/(a+)/i) { |match| "Foo" * match.length }


Now do it in Perl. Smile

As for Ada: It's a very strongly, statically typed language that provides elegant generic functions, procedures, types, and packages, as well as syntactic support for multitasking (multithreading). It was initially developed by the United Stated Department of Defense but has since found its way into academic and commercial use. It probably owes some of that to a slight resemblance to Pascal, but the resemblance is superficial, though Pascal programmers should feel somewhat familiar.

Plus it has a free compiler: Gnat, which works with GCC.

The downside to Ada95 is that the syntax is very rich, and I imagine mastering it would be a Herculean task.

Author:  rizzix [ Fri Sep 03, 2004 12:09 am ]
Post subject: 

wtd wrote:


code:
sample = "hello a world aa bar aaa baz"
revised = sample.gsub(/(a+)/i) { |match| "Foo" * match.length }




soo what would that result to? ehmm something like: "hello Foo world FooFoo bar FooFooFoo bFooz" ?

Author:  wtd [ Fri Sep 03, 2004 2:00 am ]
Post subject: 

rizzix wrote:
wtd wrote:


code:
sample = "hello a world aa bar aaa baz"
revised = sample.gsub(/(a+)/i) { |match| "Foo" * match.length }




soo what would that result to? ehmm something like: "hello Foo world FooFoo bar FooFooFoo bFooz" ?


Yep. The basic form is:

code:
string.gsub(pattern) { |match| <operations> }


The matched substring in the string is replaced by the results of the operations.

Author:  Anime Freak [ Fri Sep 03, 2004 11:33 pm ]
Post subject: 

ok i have a question to ask...i am interested in learning one laguage at first that will be ideal for righting a program (in the long run when i am ok) that is similar to the runescape type game. what language would be best for righting a program like that and how much gigobytes of space would it require to right a program that big with that many graphix.

Author:  shorthair [ Fri Sep 03, 2004 11:43 pm ]
Post subject: 

how many gigabytes


0.050 Gigabytes

My entire FPS was cmpressed down to 19 megs , Dude if you want runescape you could get away with 50 megs or less , forget gigabytes , a true Ninja Programmer will make his programs as small as possible , dont let size fool you ,

there are 20 minute video clips of high quality rendered enviroment that are only 64Kilobytes, Master compression in your code and your programs will be very fast and very efficiant , dont waste code and use it sparingly , and you will make great programs


Its a skill that needs to be learned through making programs then keeping their capabilities but decreasing there size , i oftem make a program say 100 lines long and se how small i can make them ,

Dont worry about size until you have some basic Knowledge ( no pun intended ) We can talk about things like that later ,first lets get you ready and into a language

Author:  wtd [ Fri Sep 03, 2004 11:52 pm ]
Post subject: 

Anime Freak wrote:
ok i have a question to ask...i am interested in learning one laguage at first that will be ideal for righting a program (in the long run when i am ok) that is similar to the runescape type game. what language would be best for righting a program like that and how much gigobytes of space would it require to right a program that big with that many graphix.


Many languages can work for this, and the choice depends on the toolkit you use for the graphics. Do you want to work with Microsoft's DirectX, which may give you some advantage on Windows, or do you want to use OpenGL, which will give you the ability to run on many different operating systems and hardware platforms?

Of course, at your age, and your level of knowledge, programming language syntax is not the big challenge. The challenge is understanding the concepts. Once you understand programming concepts in general, learning the syntax is the easy part.

In order to understand the concepts, you want a programming language that for the most part gets out of the way and lets you understand what's going on without a lot of extra information that has nothing to do with the important logic.

It's a trivial example, but which of the following language samples are easiest to understand?

code:
// in Java
import java.lang.*;
import java.io.*;

public class HelloWorld {
   public static void main(String[] args) {
      System.out.println("Hello world");
   }
}

// in C++
#include <iostream>

int main(int argc, char **argv)
{
   std::cout << "Hello world" << std::endl;
   return 0;
}

-- in Eiffel
class
   HELLO_WORLD
creation { ANY }
   make
feature { ANY }
   make is
      do
         std_output.put_string("Hello world")
         std_output.put_new_line
      end
end

-- in Ada95
with Ada.Text_IO; use Ada.Text_IO;
procedure Hello_World is
begin
   Put_Line("Hello world");
end Hello_World;

// in C#
using System;

public class HelloWorld
{
   public static void Main(string[] args)
   {
      Console.WriteLine("Hello world");
   }
}

/* in C */
#include <stdio.h>

int main(int argc, char *argv[])
{
   puts("Hello world");
   return 0;
}

(* in O'Caml *)
print_endline "Hello world"

# in Perl
print "Hello world\n";

# in Python
print "Hello world"

# in Ruby
puts "Hello world"

% in Turing
put "Hello world"


This is not to say any one of these languages is necessarily any better or worse for experienced programmers, but which of them makes it the easiest to understand what's going on, especially when you have just about zero programming experience?

Author:  wtd [ Fri Sep 03, 2004 11:56 pm ]
Post subject: 

shorthair wrote:
Dont worry about size until you have some basic Knowledge ( no pun intended ) We can talk about things like that later ,first lets get you ready and into a language


Do it right, then do it fast.

This goes for every program, no matter who's writing it. Premature optimization is evil.

Author:  Anime Freak [ Sat Sep 04, 2004 12:09 am ]
Post subject: 

is anyone in the "mountain time" time zone or close to that and if so can you please give me your email address if u have msn so i can chat with u and get emediat help if you are online.

Author:  Anime Freak [ Sat Sep 04, 2004 12:18 am ]
Post subject: 

wtd i added u to my friends list on instant messaging and it says that u are not using msn so it sent u and auto email that told u how to install it (like u need to know how lol) but my email address is buzzsaw228@hotmail.com if anyone cares

Author:  wtd [ Sat Sep 04, 2004 12:21 am ]
Post subject: 

Could be Microsoft showing their disdain for people who use Trillian.

I'm online, and have been for some time. I'm showing you as offline as well.

Real geeks use ICQ...

Author:  Anime Freak [ Sat Sep 04, 2004 12:51 am ]
Post subject: 

i dont like icq (actually i have never tryied it and most ppl use msn any ways).

Author:  wtd [ Sat Sep 04, 2004 4:26 am ]
Post subject: 

Young'ens...

Back in my day ICQ was what every self-respecting geek used. That was six years ago, and it's still going strong.

Author:  rizzix [ Sat Sep 04, 2004 11:45 am ]
Post subject: 

omg please stop.. heh... there are limits u know Laughing

Author:  Paul [ Sun Sep 05, 2004 9:18 am ]
Post subject: 

Trillian is nice, I use it for the sake of ppl who don't use MSN though.

Author:  the_short1 [ Mon Sep 06, 2004 9:09 am ]
Post subject: 

everything is changing this year!


a new website http://www.e-messenger.net/ .. . lets u sign in and msg ppl from a website! .. unless ur school knows and has already blocked the site... ull be able to MSN during clas Razz

Author:  rdrake [ Mon Sep 06, 2004 9:42 am ]
Post subject: 

Or you could just use http://webmessenger.msn.com/ instead. It works with Firefox too as long as the popup blocker is turned off to let it launch.

Author:  rizzix [ Mon Sep 06, 2004 2:26 pm ]
Post subject: 

wtd wrote:

Yep. The basic form is:

code:
string.gsub(pattern) { |match| <operations> }


The matched substring in the string is replaced by the results of the operations.



if thats the case.. howz that not possible in perl?

code:

$string = "hello a world aa bar aaa baz";
$string =~ s/a/Foo/g;

Author:  wtd [ Mon Sep 06, 2004 3:45 pm ]
Post subject: 

rizzix wrote:
wtd wrote:

Yep. The basic form is:

code:
string.gsub(pattern) { |match| <operations> }


The matched substring in the string is replaced by the results of the operations.



if thats the case.. howz that not possible in perl?

code:

$string = "hello a world aa bar aaa baz";
$string =~ s/a/Foo/g;


It's possibe, but the Perl construct isn't as flexible. I'll post a more complex example later to demonstrate. Smile

Author:  wtd [ Mon Sep 06, 2004 10:58 pm ]
Post subject: 

Take the same example, but if there's one 'a', replace it with "Foo". If there are 2, replace it with "Bar". If there are 4, replace it with "Baz", and anything else, replace it with "Wooble".

code:
raw_string = "a aa aaa aaaa aaaaa"
new_string = raw_string.gsub(/(a+)/i) do |match|
   case match.length
      when 1 then "Foo"
      when 2 then "Bar"
      when 4 then "Baz"
      else "Wooble"
   end
end

Author:  rizzix [ Tue Sep 07, 2004 2:37 pm ]
Post subject: 

code:

$string = "aa aaa aaaa aaaaa";
$string =~ s[(a+)] {
    (length($&) == 1) ? "Foo" :
    (length($&) == 2) ? "Bar" :
    (length($&) == 4) ? "Baz" : "Wooble"
}gxe;

Wink

Author:  wtd [ Tue Sep 07, 2004 3:44 pm ]
Post subject: 

Touché

Author:  wtd [ Tue Sep 07, 2004 3:45 pm ]
Post subject: 

Touché

Mine's easier to read, though. Wink

Plus blocks are useful for lots of other things.

Author:  rizzix [ Tue Sep 07, 2004 3:57 pm ]
Post subject: 

i'll agree ruby is a lot cleaner than perl.. but perl is just not meant to be so clean Wink oh and its possible to include blocks as well.. but i just didn't see the point in this case.

perl 6 is much cleaner and cooler.. its my fav scriping language nywyz

Author:  wtd [ Tue Sep 07, 2004 4:23 pm ]
Post subject: 

Perl6 will be cool. but the syntax will also be much richer than either Perl5 or Ruby's. Remember what I said about Ada95 having a rich syntax and taking a long time to master? Wink

Author:  rizzix [ Tue Sep 07, 2004 9:14 pm ]
Post subject: 

pfft when i have a will. there's no way stopping me.. well unless u kill me. 8)


: