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

Re: including modules during runtime and dealing with OS specific (constants) code block

by Khen1950fx (Canon)
on Aug 02, 2011 at 04:28 UTC ( #917969=note: print w/ replies, xml ) Need Help??


in reply to including modules during runtime and dealing with OS specific (constants) code block

First, the functions, SetAttributes and GetAttributes, must be specifically requested:

use Win32::File qw(:DEFAULT SetAttributes GetAttributes);
Second, since you're using Win32::File, it doesn't do any good to try darwin. I eliminated darwin, and I deleted the eval. There was also a problem with &error_dialog being undefined, so I deleted that. Here's what I have so far:
#!perl BEGIN { $| = 1; $^W = 1; } use strict; use warnings; use Win32::File qw( :DEFAULT SetAttributes GetAttributes ); my $name = '/root/Desktop/foo.txt'; my $attr = 0; Win32::File::SetAttributes( $name, $attr ); Win32::File::GetAttributes( $name, $attr ); if ( $attr & SYSTEM ) { print "$name has SYSTEM set.\n"; } if ( $attr & HIDDEN ) { print "$name is hidden.\n"; }


Comment on Re: including modules during runtime and dealing with OS specific (constants) code block
Select or Download Code
Re^2: including modules during runtime and dealing with OS specific (constants) code block
by armstd (Friar) on Aug 02, 2011 at 17:26 UTC
    First, the functions, SetAttributes and GetAttributes, must be specifically requested:
    use Win32::File qw(:DEFAULT SetAttributes GetAttributes);

    That would not actually make any difference here. The only difference it would make is allowing this syntax:

    GetAttributes()

    Instead of this:

    Win32::File::GetAttributes()

    ...which is not being attempted here. That specification just tells import() what to bring into the current package namespace from the module.

    The issue in play here is the 'eval', which gives the compiler no idea what will be available at runtime. So it fails at compile time. In your 'fixed' example, it's working not because of your added imports, its working because you removed the 'eval'.

    --Dave

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2014-04-20 09:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (485 votes), past polls