On 5/10/05, Larsen, Errin M HMMA/IT <[EMAIL PROTECTED]> wrote: > > -----Original Message----- > > From: Madhur Kashyap [mailto:[EMAIL PROTECTED] > > Sent: Tuesday, May 10, 2005 11:34 AM > > To: beginners@perl.org > > Subject: Urgent Help with functions > > > > > > Can someone help me out with this simple code? It gives an > > error saying: > > > > Illegal division by zero at test.pl line 4. > > Exit 255 > > > > Code: > > --------------------------------------------- > > #!/usr/local/bin/perl > > sub test { > > =09my @[EMAIL PROTECTED]; > > =09my $div=3D$pars[0]/$par[1]; > > =09print "Pars were @{_}\n"; > > } > > > > test (1,2,3,4,5); > > > > PS: I understand that there could be several workarounds to > > write the same code but whatif I do want to divide one of the > > local variable with one of the passed parameters? Its lot > > confusing for me as I have a strong C/C++ background. > > > > Another silly question ... is it possible to use the regular > > expressions capability of perl and combine it with C++ codes > > in some fashion. I mean is it possible to write programs > > having both C++ and perl code snippets. > > > > Regards > > Madhur Kashyap > > > > -- > > I ran the following code: > > #!/usr/bin/perl > > use warnings; > use strict; > # Always use warnings and strict! They are very helpful in finding > bugs! > > sub test { > my @pars = @_; > my $div = $pars[0] / $pars[1]; > print "Pars were @_\n"; > # I don't know why you put the '_' (underscore) in parens '(' ')' in > your code. I took them out. > print "Division was $div\n"; > } > > test (1,2,3,4,5); > > This code ran fine on my machine. I could not reproduce your divide by > zero error. Are you sure you transcribed the function call exactly in > your original email? > > I don't know about using the C++ code snippets. I bet that if you show > us your c++ code snippets, we can show you how to do it in Perl, > though!! > > --Errin
He didn't give us any test data. Perhaps $_[1] == 0. The easiest way I can think of to get a dived by zero error is to try to divide by zero. I can't read make heads or tails of the original post, though: some character translations problem. I'm seeing sub test { =09my @[EMAIL PROTECTED]; =09my $div=3D$pars[0]/$par[1]; =09print "Pars were @{_}\n"; } and I'm seeing curly braces, not parens. If the OP's editor has the same localization issues his email client has, some strange thins may be happening with the variable names, etc. HTH, --jay -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>