Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Is this code correct

by hax0id
on Jan 28, 2009 at 15:20 UTC ( #739601=perlquestion: print w/replies, xml ) Need Help??

hax0id has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Is this code correct
by moritz (Cardinal) on Jan 28, 2009 at 15:22 UTC
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Is this code correct
by talexb (Canon) on Jan 28, 2009 at 17:37 UTC

    After I run your code through perltidy, I get the following:

    sub info() { my $nick = $_[0]; my $reply = $_[1]; my $val = admin($nick); if ( $reply =~ /a/ ) { if ( $val == 1 ) { @info; foreach my $n (@info) { writ1("$n"); } } } else { if ( $val == 1 ) { @info; foreach my $n (@info) { writ1("$n"); } } else { pm( $nick, "^B^C4,1[x] Not auhtorized to see this!^C^B" ); } } }

    There are some problems with your code. First of all, I consider it bad form to access elements of @_; it's more natural for your prologue to be my ( $nick, $reply ) = @_.

    As has already been pointed out, the lines with just @info; are meaningless. What are you trying to do there?

    There's no need to put $n inside quotes. That line can just be writ1($n);, and I would probably just do foreach (@info) { writ1($_); }.

    Finally, we have no idea whether the code works (that is, whether it's correct) because we have no idea what it's trying to accomplish -- there are no comments, nor have you provided anything to guide us as to what the inputs are (nickname and reply, but what's the context?). There's also no clue as to what the admin, writ1 or pm routines do.

    Alex / talexb / Toronto

    "Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

No, it is not
by Joost (Canon) on Jan 28, 2009 at 16:40 UTC

      "auhtorized" is spelled wrong.

      <span lang="en-CA">
      Right... The zed should be an "s". :)
      </span>

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Is this code correct
by borisz (Canon) on Jan 28, 2009 at 15:31 UTC
    Looks wrong to me $_1 is always undefined and @info; seems senseless too.
    Boris
      The OP actually typed $_[1] and PM interpolated that into $_1, so that's no problem. Looping over an undefined array, on the other hand... Perhaps it's a global...
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Is this code correct
by linuxer (Curate) on Jan 29, 2009 at 23:20 UTC
    sub info() { my ( $nick, $reply ) = @_; }

    That doesn't make sense. sub info() declares info as a subroutine, which doesn't accept any arguments. Inside that subroutine you want to pass arguments to $nick and $reply.

    See:

    #!/usr/bin/perl use strict; use warnings; sub foobar() { my ( $foo, $bar ) = @_; print "foo: $foo\nbar: $bar\n"; } foobar( 1, 2 );

    This results in:

    Too many arguments for main::foobar at prot.pl line 11, near "2 )" prot.pl had compilation errors.

    Please see perldoc perlsub; section Prototypes for details.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://739601]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (5)
As of 2021-10-19 15:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (77 votes). Check out past polls.

    Notices?