sub greet ($server, $channel, $nick, $address)
Well, that's exactly equivalent to sub greet ($$$$), with the exception that it will break as soon as other symbols are added to the list of meaningful prototype characters. I don't understand why you use this at all. Irssi certainly doesn't require you to use a prototype, and if it does anything, I don't see how it could make anything better.
$address =~ s/\~(.*)\@.*/$1/;
Realise that you will use this with a system call and eventually as a file name. Do not remove what you want gone, but instead throw EVERYTHING away, except what is known to be safe. You should make the ~ optional, by the way. And there is no need to escape it. Try something like:
Note that this is untested. See perldoc -q random\ line for the rand($.) trick and perlvar for $/.my ($fn) = $address =~ /^\W?(\w+)/; return unless defined $fn and length $fn; # I would not test -f or -r or -e manually. # If open failed, the reason is in $!. open my $fh, "~/.quotes/$fn" or do { warn "Cannot open $fn for reading ($!).\n"; return; } local $/ = "\n%\n"; my $quote; rand($.) < 1 && ($quote = $_) while <>; chomp $quote; $window->command("msg $channel $nick> $quote") for split /\n/, $quote;
I have no idea why your code would greet only every other time. It could have to do with the ~, but that's not very likely.
Please note that you should really LEARN PERL BEFORE WRITING PROGRAMS THAT OTHER PEOPLE CAN CONTROL (for example, by joining a channel, visiting a web page or connecting to a daemon you wrote). Several things indicate that you do not know Perl well enough.
Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }
In reply to Re: irssi greeter
by Juerd
in thread irssi greeter
by stuartfreeman
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |