Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^5: writing a pragma

by tobyink (Canon)
on Apr 26, 2014 at 07:18 UTC ( [id://1083903]=note: print w/replies, xml ) Need Help??


in reply to Re^4: writing a pragma
in thread writing a pragma

That really depends on exactly what you want to do at compile time, doesn't it? Some things are easier than others.

use Moops; class Cow :rw { has name => (default => 'Ermintrude') }; say Cow->new->name

Replies are listed 'Best First'.
Re^6: writing a pragma
by karthikasasanka (Acolyte) on Apr 27, 2014 at 09:16 UTC

    I want to write a pragma, which reads the contents of file where it is imported.

    1. use mypragma;

    2. use Data::Dumper;

    3. my $hash = {1,2,3,4,5,6}

    4. print Dumper $hash;

    I want to get the lines from 2,3,4 into the mypragma which was loaded into memory for this program.

    I am not sure that this is possible, I just want to try.

      sure its possible, but such a thing shouldn't be a pragma :) see caller and open and import and splice and zentara package/module tutorial....

      use NotAPragma; ...

      NotAPragma.pm

      package NotAPragma; sub import { my ($package, $filename, $line) = caller; open my($infh), '<:raw', $filename or die "Can't open caller $filename : $!"; my @lines = ( 'pad', readline $infh ); close $infh; splice @lines, 0, $line; print "@lines\n"; ## << this is the ... after use NotAPragma; } 1;
        Thank you the solution.
        can you please explain y it should not be pragma.

        does it affect anything if we write it as pragma.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2024-04-19 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found