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:

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;
Note that this is untested. See perldoc -q random\ line for the rand($.) trick and perlvar for $/.

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.