in reply to Re: Functions (Return V Print)
in thread Functions (Return V Print)

I am using Strict (like I said in the post!). But there is no error. That's what I don't understand. Is it bad practice to use "our $title" in the function so I can reuse it in the script?

Replies are listed 'Best First'.
Re^3: Functions (Return V Print)
by Anonymous Monk on Feb 04, 2011 at 11:26 UTC
    I am using Strict (like I said in the post!). But there is no error.

    ah, post a complete program :) How do I post a question effectively?

    Is it bad practice to use "our $title" in the function so I can reuse it in the script?

    Yes. Having trouble getting it to work should be convincing :) Variables and Scoping

Re^3: Functions (Return V Print)
by cjb (Friar) on Feb 04, 2011 at 11:05 UTC
    If you're returning title are you assigning it to a variable on it's return?
    #!/opt/perl/bin/perl use strict; use warnings; my $title="name"; print "$title\n"; $title = &function64("name"); print "$title\n"; sub function64 { my ($title) = @_; $title="$title " x 3; return ($title); }

      Ignore me, you are, just re-read your original post.

      Errr, ignore my ignore, you've not shown enough code. Could you show us where you're calling the function?

      Updated: 20110204 11:53 GMT

Re^3: Functions (Return V Print)
by jethro (Monsignor) on Feb 04, 2011 at 14:10 UTC
    But there is no error.

    Strict can only warn about some bugs, not all of them. Otherwise you could trivially write perl scripts without any bugs.

    If you don't have really compelling reasons, functions should return values only through 'return'. Note that you can return more than one value in perl, different from languages like C. In C this is often the reason why other means are used to return values.