Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Dhcpclient module

by drip (Beadle)
on Apr 01, 2008 at 03:27 UTC ( [id://677684]=note: print w/replies, xml ) Need Help??


in reply to Dhcpclient module

so should i do it like this?
set_serverid{ my $self=shift; if(@_) {$self->{SERVER} = shift} } getserverid{ $self->{SERVER}; } $serverid=getserverid();

dont know much about the correct indentation..i'll read more on that...

Replies are listed 'Best First'.
Re^2: Dhcpclient module
by tachyon-II (Chaplain) on Apr 02, 2008 at 05:07 UTC

    You could but it should look like this with "standard/common" perl indentation and some error checking. Also if you are going to set_xxx you should get_xxx, not getxxx or getXxx to be conSistent:

    set_serverid { my $self = shift; if (@_) { $self->{SERVER} = shift; } else { die "No argument passed to set_serverid!\n"; } } get_serverid { my $self = shift; $self->{SERVER}; }

    shift syntax works fine for $self but often you might like to do a bit more error checking in your setters:

    set_serverid { my ($self,$id) = @_; if (defined $id) { die "Invalid value for id '$id' in set_serverid!\n" unless $id > 0 and $id < 255; $self->{SERVER} = $id; } else { die "No argument passed to set_serverid!\n"; } }

    As noted I like to start off with very simple accessors like:

    sub get_serverid { $_[0]->{SERVER} } sub set_serverid { $_[0]->{SERVER} = $_[1] } sub get_requestip { $_[0]->{REQIP} } sub set_requestip { $_[0]->{REQIP} = $_[1] }

    The thing I like about this is that you can see typos in the hash key names very easily. Unless you are doing formal error checking on the set side you don't really need more.

      Thank you very much...i learned a great deal from you...
      i will post the revised code later after i finish my other task...
      and hope you will check it out...
      just to make sure if everything is in the right place... ;) thanks....

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2025-02-07 04:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which URL do you most often use to access this site?












    Results (94 votes). Check out past polls.