Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Include data in a perl program?

Reply
Thread Tools

Include data in a perl program?

 
 
David O in Seattle
Guest
Posts: n/a
 
      02-09-2004
Hi,

I'm not sure out to do this, and Google searches didn't seem to yield
well for me (perhaps I used the wrong terms) so I thought I'd see if
someone can point me in the right direction.

I'm writing a PERL script to use the Win32::TieRegistry module and
Win32API::Registry module. I noticed in Registry that there are calls
to load registry hive data into a module. What I would LIKE to do is
include that hive data in a scalar or similar object for use by the
"RegLoadKey" call so I don't have to include a separate .reg file when
I distribute my code.

Suggestions/Guidence would be very appreciated.. TIA.

 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      02-09-2004

David O in Seattle <(E-Mail Removed)> wrote:
> I'm writing a PERL


Perl or perl.

> script to use the Win32::TieRegistry module and
> Win32API::Registry module. I noticed in Registry that there are calls
> to load registry hive data into a module. What I would LIKE to do is
> include that hive data in a scalar or similar object for use by the
> "RegLoadKey" call so I don't have to include a separate .reg file when
> I distribute my code.


If you can load a .reg file from a filehandle, then you can include
the file at the end of your module after a __DATA__ token. This will
then be available as the DATA filehandle. See perldoc perldata.

If you can't, you want to do the same thing but write some code to
parse the .reg format yourself: it's pretty simply .

Ben

--
"The Earth is degenerating these days. Bribery and corruption abound.
Children no longer mind their parents, every man wants to write a book,
and it is evident that the end of the world is fast approaching."
-Assyrian stone tablet, c.2800 BC http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
David O in Seattle
Guest
Posts: n/a
 
      02-10-2004
On Mon, 9 Feb 2004 22:31:36 +0000 (UTC), Ben Morrow
<(E-Mail Removed)> wrote:

>
>David O in Seattle <(E-Mail Removed)> wrote:
>> I'm writing a PERL

>
>Perl or perl.


Umm.. ok...


>
>If you can't, you want to do the same thing but write some code to
>parse the .reg format yourself: it's pretty simply .
>
>Ben


Turns out the file that's created by the Perl modules is a binary
"save" file and not the text-based 'reg' export file. So to use the
text file, I'd have to write the code to insert every key. While
that's certainly doable, I'm under a bit of a time contraint.

Thanks tho. I appreciate your input.


 
Reply With Quote
 
Thomas Kratz
Guest
Posts: n/a
 
      02-11-2004
David O in Seattle wrote:
> Hi,
>
> I'm not sure out to do this, and Google searches didn't seem to yield
> well for me (perhaps I used the wrong terms) so I thought I'd see if
> someone can point me in the right direction.
>
> I'm writing a PERL script to use the Win32::TieRegistry module and
> Win32API::Registry module. I noticed in Registry that there are calls
> to load registry hive data into a module. What I would LIKE to do is
> include that hive data in a scalar or similar object for use by the
> "RegLoadKey" call so I don't have to include a separate .reg file when
> I distribute my code.
>
> Suggestions/Guidence would be very appreciated.. TIA.
>


What about using Data:umper to dump a complete Win32::TieRegistry tree
to text and store that below the __DATA__ token? Later you can eval the
text data back to a hash and feed it again to Win32::TieRegistry.
Perhaps you'll have to set a few of the Win32::TieRegistry options like
'ArrayValues' or 'DualBinVals' to get a true 1:1 save nad restore.
I haven't tested it myself, but it should be possible.

Thomas

--
open STDIN,"<&DATA";$=+=14;$%=50;while($_=(seek( #J~.> a>n~>>e~.......>r.
STDIN,$:*$=+$,+$%,0),getc)){/\./&&last;/\w| /&&( #.u.t.^..oP..r.>h>a~.e..
print,$_=$~);/~/&&++$:;/\^/&&--$:;/>/&&++$,;/</ #.>s^~h<t< ..~. ...c.^..
&&--$,;$:%=4;$,%=23;$~=$_;++$i==1?++$,:_;}__END__#.... >>e>r^..>l^...>k^..
 
Reply With Quote
 
davido@codethought.nospamforme.com
Guest
Posts: n/a
 
      02-11-2004
On Wed, 11 Feb 2004 17:20:18 +0100, Thomas Kratz
<(E-Mail Removed)> wrote:

>What about using Data:umper to dump a complete Win32::TieRegistry tree
>to text and store that below the __DATA__ token? Later you can eval the
>text data back to a hash and feed it again to Win32::TieRegistry.


I'll look into that. Thanks for the suggestion.


 
Reply With Quote
 
davido@codethought.nospamforme.com
Guest
Posts: n/a
 
      02-12-2004
On Wed, 11 Feb 2004 17:20:18 +0100, Thomas Kratz
<(E-Mail Removed)> wrote:

>What about using Data:umper to dump a complete Win32::TieRegistry tree
>to text and store that below the __DATA__ token? Later you can eval the
>text data back to a hash and feed it again to Win32::TieRegistry.
>Perhaps you'll have to set a few of the Win32::TieRegistry options like
>'ArrayValues' or 'DualBinVals' to get a true 1:1 save nad restore.
>I haven't tested it myself, but it should be possible.



Well, so far I keep running into the same problem. I get my hash
reference and all that gets written to the registy is a 'text'
representation of the TieRegistry data. Any other ideas would be
appreciated...

Example: Win32::TieRegistry=HASH(0x207d420)


Code:
my %filetypes;
my $hashref;

$Registry->Delimiter("/");
$Registry->AllowLoad(1);
$Registry->ArrayValues(1);

my $eol = undef $/;
eval <DATA>;

$Registry->{"CUser/Software/VanDyke/SecureFX/File
Types"}=\%filetypes
or die "Can't set the File Types: $^E\n";
$/ = $eol;


 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      02-12-2004

"(E-Mail Removed)" <(E-Mail Removed)> wrote:
>
> Well, so far I keep running into the same problem. I get my hash
> reference and all that gets written to the registy is a 'text'
> representation of the TieRegistry data. Any other ideas would be
> appreciated...
>
> Example: Win32::TieRegistry=HASH(0x207d420)
>
>
> Code:
> my $eol = undef $/;


Let Perl remember the old value for you. It's much more reliable.

{
local $/; # by default set to undef

> eval <DATA>;


}

>
> $Registry->{"CUser/Software/VanDyke/SecureFX/File
> Types"}=\%filetypes
> or die "Can't set the File Types: $^E\n";


Try
$Registry->{...}{$_} = $filetypes{$_}
for keys %filetypes;

If %filetypes is a deep structure, then you'll probably have to
recurse over it: it looks like the tied hash stringifies everything,
so references will be destroyed.

Alternatively, you could take your binary dump that you had before and
Base64 encode it. Stick that at the end of your module, then load it
from DATA, decode it and use TieRegistry's load function (with
IO::Scalar if necessary).

Ben

--
Heracles: Vulture! Here's a titbit for you / A few dried molecules of the gall
From the liver of a friend of yours. / Excuse the arrow but I have no spoon.
(Ted Hughes, [ Heracles shoots Vulture with arrow. Vulture bursts into ]
/Alcestis/) [ flame, and falls out of sight. ] (E-Mail Removed)
 
Reply With Quote
 
davido@codethought.nospamforme.com
Guest
Posts: n/a
 
      02-13-2004
On Thu, 12 Feb 2004 23:18:29 +0000 (UTC), Ben Morrow
<(E-Mail Removed)> wrote:

>
>"(E-Mail Removed)" <(E-Mail Removed)> wrote:
>>
>> Well, so far I keep running into the same problem. I get my hash
>> reference and all that gets written to the registy is a 'text'
>> representation of the TieRegistry data. Any other ideas would be
>> appreciated...
>>
>> Example: Win32::TieRegistry=HASH(0x207d420)
>>
>>
>> Code:
>> my $eol = undef $/;

>
>Let Perl remember the old value for you. It's much more reliable.
>
> {
> local $/; # by default set to undef
>
>> eval <DATA>;

>
> }
>


Oh cool! Thanks for that tip!

>>
>> $Registry->{"CUser/Software/VanDyke/SecureFX/File
>> Types"}=\%filetypes
>> or die "Can't set the File Types: $^E\n";

>
>Try
> $Registry->{...}{$_} = $filetypes{$_}
> for keys %filetypes;
>
>If %filetypes is a deep structure, then you'll probably have to
>recurse over it: it looks like the tied hash stringifies everything,
>so references will be destroyed.



Er... You might have something there... He's a sample:

%filetypes = bless( (
'Access.Fragment/' => bless( {
'/Default Icon Path' => '',
'/Default Icon Index' => '0x00000000',
'/Application' => '',
'/Extensions' => '',
'/Transfer Type' => '0x00000002',
'/Remote File Open Action' => '0x00000001'
}, 'Win32::TieRegistry' )
),'Win32::TieRegistry' );

>
>Alternatively, you could take your binary dump that you had before and
>Base64 encode it. Stick that at the end of your module, then load it
>from DATA, decode it and use TieRegistry's load function (with
>IO::Scalar if necessary).
>


I like this idea better. Would the MIME::Base64 module be the one I'd
use to encode the original binary file?

It's looking like I might end up just 'punting' and including the SAV
file has a binary - tho I'd rather *not* since that creates another
distributable that needs to be managed...

Ben/Thomas - I just wanted to say thank you for your help thus far.
While this is a deliverable that I have to finish, you guys have
helped me learn some cool stuff and I appreciate that.


 
Reply With Quote
 
davido@codethought.nospamforme.com
Guest
Posts: n/a
 
      02-13-2004
In the spirit of "There's more than one way to do it." I decided to
find another way, and I did.

In WinXP/Win2k3 (the platforms this tool is targeted for) there is a
command-line version of RegEdit - simply called REG. It does the work
for me and I just pass a call to it from my perl script. The registry
data itself is in a __DATA__ block that I write to a temporary file
and then use for the REG IMPORT command.

Another problem solved. Thank you for taking the time to help me tho!

*returns to lurk and interject mode*


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Perl / cgi / include file a la #include me Perl Misc 10 03-26-2010 10:21 PM
/* #include <someyhing.h> */ => include it or do not include it?That is the question .... Andreas Bogenberger C Programming 3 02-22-2008 10:53 AM
Re: the use of #include <a_file.h> v/s #include"a_file.cpp" Elie Nader C++ 1 11-28-2003 03:12 PM
Re: the use of #include <a_file.h> v/s #include"a_file.cpp" Rolf Magnus C++ 2 11-28-2003 12:26 PM
#include "bar" negates #include <string> ; how to fix? Danny Anderson C++ 5 08-15-2003 06:38 PM



Advertisments