Beefy Boxes and Bandwidth Generously Provided by pair Networks vroom
There's more than one way to do things
 
PerlMonks  

Re^3: What I Most Recently Learned in Perl, But Should Have Already Known

by GrandFather (Cardinal)
on Aug 16, 2006 at 23:19 UTC ( #567792=note: print w/ replies, xml ) Need Help??


in reply to Re^2: What I Most Recently Learned in Perl, But Should Have Already Known
in thread What I Most Recently Learned in Perl, But Should Have Already Known

I learned something about pack/unpack writing Updated QuickTime format movie file dumper. But the cool thing I learned writing that code was using can to assist in the context of a "dispatch by name":

my $member = "dump_$key"; my $name = "name_$key"; $name = $self->can($name) ? $self->$name () . ' ' : ''; ... if ($self->can($member)) { $self->$member ($pos, $len);

$key is an "atom" code from the file being parsed. If there is a handler for the atom $self->$member dispatches to the code to handle it. One neat thing about this is that a derived class can add handlers and the parser just takes it all in its stride. I reckon that's pretty cool - perhaps even elegant. :)

One way to do a binary conversion is:

my $str = '001100010011001100110001'; my $value = pack ('B*', $str); print $value;

DWIM is Perl's answer to Gödel


Comment on Re^3: What I Most Recently Learned in Perl, But Should Have Already Known
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://567792]
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: (10)
As of 2014-04-16 06:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (414 votes), past polls