in reply to Problem creating a function

This is the proper syntax:
sub cleaner { my ( $text ) = @_; $text =~ s/\n/<br>/gs; $text =~ s/\t/ /g; return $text; } my $details = cleaner( $clean_me );
Note that function prototypes don't work in perl like in C or PHP code. You can't say sub cleaner( $dirty ) and expect the function to contain a variable called $dirty with your input parameter - you have to pull it off the magic @_ parameter array using shift or the syntax I use here.

Perl does have function prototypes of a sort, but they serve a different purpose than in other languages

Also, if you are matching newlines in your regular expression, you will need the s flag - otherwise the match will stop at the first newline. The s flag tells Perl to treat newlines like any other character, and match to the end of the string.

Update: See below for why that last piece of advice is irrelevant - thanks, jdporter!.

Replies are listed 'Best First'.
Re: Re: Problem creating a function
by jdporter (Paladin) on Dec 24, 2002 at 22:13 UTC
    if you are matching newlines in your regular expression, you will need the s flag - otherwise the match will stop at the first newline.
    No, that's not quite right. /s is only necessary if you want /./ (dot) to match newlines, which it does not normally do. Since the given regex contains no dots, /s has no effect.

    jdporter
    ...porque es dificil estar guapo y blanco.