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

Re: marshalling data

by thomas895 (Deacon)
on Mar 12, 2013 at 03:36 UTC ( [id://1022912]=note: print w/replies, xml ) Need Help??


in reply to marshalling data

There's one big flaw: you don't declare packages using braces. Instead, it goes like:

package Foo; sub method { ... }

Notice the difference.
Next, you've used warnings -- this is great, since many people tend to forget that -- but you should also try strict. Many other problems are quickly found that way.
Also, you don't print to file handles like you did. Rather, it goes more like:

print $FH Data::Dumper->dump(...);

Try that, see if it helps.

~Thomas~ 
"Excuse me for butting in, but I'm interrupt-driven..."

Replies are listed 'Best First'.
Re^2: marshalling data (braces)
by tye (Sage) on Mar 12, 2013 at 03:58 UTC

    Actually, both of the uses of braces are valid alternatives (one only for moderately modern versions of Perl) to the methods you proposed. You can write "package main; ..." or "package main { ... }" (as of some non-ancient Perl version) and you can do "print $FH ..." or "print {$FH} ..." (since at least Perl 3).

    - tye        

      Huh, interesting.
      Well I have to admit I've never seen it used before. Oh well, I guess I learn something new every day.

      ~Thomas~ 
      "Excuse me for butting in, but I'm interrupt-driven..."
Re^2: marshalling data
by Anonymous Monk on Mar 12, 2013 at 03:55 UTC

    There's one big flaw: you don't declare packages using braces . Instead, it goes like:

    On an old perl -- it depends on your perl vrsion, see package

Re^2: marshalling data
by BillKSmith (Monsignor) on Mar 12, 2013 at 03:58 UTC
    Package Blocks were introduced in perl 5.12. They have the advantage of limiting the scope of lexical variables to the package. I did not use strict in this example because the the concept that I am trying to learn makes changes to the symbol table. The hashes and the the string $marshalling_data must be global variables. Explicitly specifing all the exceptions to strict would mask my intention.
    Bill

      Perl 5.14 actually. Perl 5.12 introduced the package Foo 1.23 syntax.

      package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-03-19 07:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found