I few days ago i posted here looking for support to my new project WWW::SMS: thank you for suggestions.
Anyway the new() method is now more beautiful and standardized as it allows for free optional parameters in hash fashion.
Now it's coded like this:
sub new { my ($self, $key, $value); my $class = shift; my ($intpref, $prefix, $telnum, $smstext, %hash) = @_; $self = bless { 'intpref' => $intpref, 'prefix' => $prefix, 'telnum' => $telnum, 'smstext' => $smstext, 'cookie_jar' => exists $hash{cookie_jar} ? delete $hash{cookie_jar} : "lwpcookies.txt", }, $class; for (($key, $value) = each %hash) { $self->{$key} = $value; } $self; }
Is there any better way to code the last part of the method where i just put every remaining hash value into the object?
Is there a way to do it without cycling over the hash?
Bye and thanks.
Giulio

In reply to Optional parameters in new() method by giulienk

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.