Re: marine subroutine

2007-08-30 Thread Amichai Teumim
Yeah that works now. Great. Finally I'm getting this...after months. Thank you. On 8/30/07, Jeff Pang <[EMAIL PROTECTED]> wrote: > > 2007/8/30, Amichai Teumim <[EMAIL PROTECTED]>: > > > > I get the error: > > > > sub-lib.pl did not return a true val

marine subroutine

2007-08-30 Thread Amichai Teumim
i am trying to figure out how to use the subroutine in a library now. so I did this. I name one script sub.pl and the library sub-lib-pl: the script.pl contains: #!/usr/bin/perl use strict; require 'sub-lib.pl'; marine(); The sub-lib.pl contains: #!/usr/bin/perl sub marine { $n += 1;

marine subroutine

2007-08-30 Thread Amichai Teumim
Oh that curly! Ignore my previous message. Thank you.

marine subroutine

2007-08-30 Thread Amichai Teumim
Hi I'm trying to understand subroutines. #!/usr/bin/perl &marine() sub marine { $n += 1; #Global variable $n print "Hello, sailor number $n!\n"; } This doesn't work. Is &marine() incorrect? How would I call the sub marine? Thanks Amichai

library (random numbers)

2007-08-07 Thread Amichai Teumim
Does this make any sense? Here is the script again: #!/usr/bin/perl use strict; use warnings; require 'obj13-lib.pl'; my @userArray = ; my $sum = sumIt(@userArray); print $sum; And here is the library: sub sumIt{ my $total; $total += $_ for @_; warn "@_ was empty, total undefined!\n" i

Re: library (random numbers)

2007-08-07 Thread Amichai Teumim
Yeah I think it was a comment. I removed it now. Thanks ;) Jeff Pang wrote: > -Original Message- > >> From: Amichai Teumim <[EMAIL PROTECTED]> >> Sent: Aug 6, 2007 10:34 AM >> To: "Mr. Shawn H. Corey" <[EMAIL PROTECTED]> >> Cc: beginn

library (random numbers)

2007-08-07 Thread Amichai Teumim
Line 11 n obj13-lib.pl is: (last index). Double check I don't know what could be wrong with this syntax, as I have never used these commands before. I thought it migh need a curly, but I get the same error. Mr. Shawn H. Corey wrote: > Amichai Teumim wrote: >> I get: &g

Re: library (random numbers)

2007-08-07 Thread Amichai Teumim
So that makes sense. (last index). Double check shouldn't even be there. I must have incompletely removed the comment. So I should just delete it or comment it out? Chas Owens wrote: > On 8/6/07, Amichai Teumim <[EMAIL PROTECTED]> wrote: > snip > >> sub sumIt{

Re: library (random numbers)

2007-08-06 Thread Amichai Teumim
guments for index at obj13-lib.pl line 11, near "index)" Compilation failed in require at obj13-1.pl line 6. What is this index error? Mr. Shawn H. Corey wrote: > Amichai Teumim wrote: >> No it was commented out. Now it's changed. I still don't know how to use >> i

Re: library (random numbers)

2007-08-06 Thread Amichai Teumim
No it was commented out. Now it's changed. I still don't know how to use it. What would a good way to test it be? echo 1234 | ./script.pl obviously won't do much. I wad told ./obj13-1.pl < Paul Lalli wrote: >> Yes, it would have, if that's what you had. But you didn't. You had >> the line: >> #

Re: library (random numbers)

2007-08-06 Thread Amichai Teumim
When I do this, I get : ./script.pl < line 3. #!/usr/bin/perl #require 'script.pl'; @userArray = ; $sum = sumIt(@userArray); print $sum; Mr. Shawn H. Corey wrote: > Amichai Teumim wrote: >> ./script.pl | echo 1234 >> >> Or is this nonsensical? Very very

Re: library (random numbers)

2007-08-06 Thread Amichai Teumim
I thought that require 'lib.pl'; was telling Perl where to find it. Mr. Shawn H. Corey wrote: > Amichai Teumim wrote: >> When I do this, I get : >> >> ./script.pl <> 1234 >> 5678 >> 90 >> EOD >> >> Undefined subroutine &main

Re: library (random numbers)

2007-08-06 Thread Amichai Teumim
What command should I use to try this out? Thanks Amichai P.S. echo 1234 | ./script.pl doesn't do anythign exciting. On 8/3/07, Paul Lalli <[EMAIL PROTECTED]> wrote: > > On Aug 3, 6:03 am, [EMAIL PROTECTED] (Amichai Teumim) > wrote: > > After some friendly input

library (random numbers)

2007-08-03 Thread Amichai Teumim
After some friendly input from yitzle I might have moved further with my library. This is my script. script.pl #!/usr/bin/perl #require 'lib.pl'; @userArray = ; $sum = sumIt(@userArray); print $sum; And this is my library according to yitzle: sub sumIt(@) { my $total = 0; $total += $_

library (random numberS)

2007-07-27 Thread Amichai Teumim
OK. I think I moved further. So this is my library. ub sumIt(){ @functionArray = @_; foreach $line(@functionArray){ $functionSum += $line; } return $functionSum; } 1; What do I add here to calculate the average of the numbers? thanks Amichai -- To unsubscribe, e-mail: [EMAIL

library (random numbers)

2007-07-27 Thread Amichai Teumim
OK I figured most of this out I think. I want to create a library that contains a function which takes in an array of numbers (random numbers). This function will then calculate the average of these numbers, the total of all these numbers added together, and a new array of numbers which is the oth

homework

2007-07-19 Thread Amichai Teumim
Hi This is my homework: "Write a script called *obj13-1.pl* and a library called *obj13-lib.pl*. The library should contain a function that takes in an array of numbers (of arbitrary size). The function will then calculate the average of the numbers, the total of all of the numbers added togethe

Re: Still stuck with my cards

2007-07-12 Thread Amichai Teumim
to change the 99 to something else to get a more RANDom seeming shuffle but you said this was a snippet so that may be taken care of in the real code. -Original Message- From: Amichai Teumim [mailto:[EMAIL PROTECTED] Sent: Thursday, July 12, 2007 10:34 AM To: beginners@perl.org Subject: S

Still stuck with my cards

2007-07-12 Thread Amichai Teumim
There we go...my print statement was stuck in my loop. Thanks! push @startingdeck, @shuffle; } print "@startingdeck[0 .. 4]\n";

Still stuck with my cards

2007-07-12 Thread Amichai Teumim
I'm still stuck with this. It shuffles the cards, then replaces the letter representing the card (such as H = heart) with the word. Then it's meant to print the top five cards (meanign the five cards that come first after the shuffling). Somethign like: 9 Heart 10 Heart J Heart Queen Heart King H

deck of cards the saga

2007-07-09 Thread Amichai Teumim
Hi In my deck of cards I want to replace the letter of the card with the name( e.g. A = Ace). So I tried to implement the following snippet into my code: while @startingdeck{ $_ =~ s/A/Ace/; print NEW; } The code is as follows (including snippet): #!/usr/bin/perl use strict; use warnings;

query about code

2007-07-04 Thread Amichai Teumim
Can someone explain to me what this script really does? I mean I see that it lists dir within dir. But what is the code doing? For example all the blue highlighted stuff, what is it doing? #!/usr/bin/perl $startdir = "/lib"; $level = 0; list_dirs($startdir,$level); sub list_dirs(){ my $dir

TWO loops and ONE

2007-07-03 Thread Amichai Teumim
OK. So I removed $tmp. Now my code looks like this: #!/usr/bin/perl use strict; use warnings; my @array = (5,3,2,1,4); my $n = @array; for my $i (0 .. $n-1) { for my $j (0 .. $n-1) { if ($array[$j+1] < $array[$j]) { #compare the two neighbors @array[$j, $j+1] = @array[$j+1,

Fwd: TWO loops and ONE if statement

2007-07-03 Thread Amichai Teumim
I forgot to add what I have done so far. I did: #!/usr/bin/perl use strict; use warnings; my @array = (5,3,2,1,4); my $n = @array; for my $i (0 .. $n-1) { for my $j (0 .. $n-1) { if ($array[$j+1] < $array[$j]) { #compare the two neighbors $tmp = $array[$j]; # swap

TWO loops and ONE if statement

2007-07-03 Thread Amichai Teumim
Hi guys You guys have been giving me some very good ideas. Very efficent ways of doing things. For this excercise that I'm trying to figure out I actually need the following inefficient way: #!/usr/bin/perl @array = (5,3,2,1,4); ## include your code here ## foreach $elem (@array){ print "$

my deck of cards (once again)

2007-07-03 Thread Amichai Teumim
The following shuffles up my deck of card and then prints out the top five cards. I need it to work somehwhat differently. When I shift or pop an element, I need to store it as a variable, then push it on to the array in a different order from the original order. Any suggestions? (See code below)

missing curly - brain fried

2007-06-28 Thread Amichai Teumim
Where is the open curly missing here? #!/usr/bin/perl @array = (5,3,2,1,4); for ($i=0; $i<$n-1; $i++) { ( for ($j=0; $j<$n-1-$i; $j++) if ($array[$j+1] < $array[$j]) { /* compare the two neighbors */ $tmp = $array[$j]; /* swap $array[j] and $array[j+1] */ $array[$j] = $a

don't understand working script

2007-06-28 Thread Amichai Teumim
I have this script, If you run it you can see how it nicely idents the directories. I don't understand everything in this script. Please see my comments. #!/usr/bin/perl $startdir = "/lib"; $level = 0;#WHAT DOES THIS DO? list_dirs($startdir,$level); #WHAT DOES THIS DO? sub list_dirs(){ m

More loops

2007-06-28 Thread Amichai Teumim
I need to use two loops and an if statement to sort the contents of this array so that the number go from lowest to highest. #!/usr/bin/perl @array = (5,3,2,1,4); ## include your code here ## foreach $elem (@array){ print "$elem"; } Looking further into this it was revealed to me that I shou

shuffling cards

2007-06-28 Thread Amichai Teumim
Thanks for all the answers. I know there are other better ways of doing this shuffle. I must however, use pop shift ans push. #!/usr/bin/perl @startingdeck = ("A H","2 H","3 H","4 H","5 H","6 H","7 H","8 H", "9 H","10 H","J H","Q H","K H", "A D","2 D","3 D","4 D",

shuffling cards

2007-06-28 Thread Amichai Teumim
I want to shuffle a deck of cards and then print out the top five cards. #!/usr/bin/perl @startingdeck = ("A H","2 H","3 H","4 H","5 H","6 H","7 H","8 H", "9 H","10 H","J H","Q H","K H", "A D","2 D","3 D","4 D","5 D","6 D","7 D","8 D", "9 D","10 D"

printing content of found file

2007-06-28 Thread Amichai Teumim
I'm trying to do the following: I want to search for a specific file/s in my current dir and when it finds it, print its contents. So I did the following: #!/usr/bin/perl opendir(CURRENT,"."); @list = readdir(CURRENT); closedir(CURRENT); foreach $item (@list){ if($item =~ /notes/){ open(FI

regular expressions issue

2007-06-27 Thread Amichai Teumim
I created a file called data.txt which contains a bunch of junk, including some IPs. I want $line to be stored in $ip . It works, except for the regular expressions which should find only IPs. If I use the regular expression with the gr