The Forum is up for sale: XeNTaX Forum looking for new owner
Call Perl function (help with code)
Call Perl function (help with code)
Hi there!
Well, I have a perl script downloaded from here: http://pastebin.com/b3EHJJ2g or this link http://www.mediafire.com/?a451ee6h6egzqo8 that uncompress some type of LZE compressed files (like the LZE file that I have). This script has two functions, unlze(); and compress_lze(); I haven't got any perl knowledges, but I need to decompress that LZE file no matter what.
So, here are my questions:
1º- How can I call a function in perl? I suppose that is writing "unlze();", no?
2º- In this script, how/where can I indicate the path of compressed file?
3º- Could someone write those functions in C please?
Greetings.
Well, I have a perl script downloaded from here: http://pastebin.com/b3EHJJ2g or this link http://www.mediafire.com/?a451ee6h6egzqo8 that uncompress some type of LZE compressed files (like the LZE file that I have). This script has two functions, unlze(); and compress_lze(); I haven't got any perl knowledges, but I need to decompress that LZE file no matter what.
So, here are my questions:
1º- How can I call a function in perl? I suppose that is writing "unlze();", no?
2º- In this script, how/where can I indicate the path of compressed file?
3º- Could someone write those functions in C please?
Greetings.
Re: Call Perl function (help with code)
It seems that the two functions expect a reference to a bytestring as input. So you could write a perl script like this (I added some comments (#) to make things a little more clearer...)
Name this script for example lze.pl and start it from the command line prompt with e.g.
lze.pl c:\mydata\mycompressedfile
Of course, you got to have a perl interpreter installed...
To all Perl experts: I know I should have used "use warnings" and strict and File:Slurp and stuff, but I wanted to keep it as simple /understandable as possible and without extra modules...
Code: Select all
#!/usr/bin/perl
open FILE, $ARGV[0] or die "Couldn't open file: $!"; #opens the file you want to decompress
binmode FILE; #use binary mode
read (FILE, $string, -s $ARGV[0]); #read the whole file into the string variable $string
$decompressed=unlze(\$string); #if you want compression: $compressed=compress_lze(\$string);
#.....do things with $decompressed here....
close FILE;
#copy here the functions from your link
sub unlze {
#....
}
sub compress_lze {
#....
}lze.pl c:\mydata\mycompressedfile
Of course, you got to have a perl interpreter installed...
To all Perl experts: I know I should have used "use warnings" and strict and File:Slurp and stuff, but I wanted to keep it as simple /understandable as possible and without extra modules...
-
Vash
- mega-veteran

- Posts: 183
- Joined: Fri Apr 29, 2005 2:39 pm
- Has thanked: 5 times
- Been thanked: 26 times
Re: Call Perl function (help with code)
Just for curiosity i wrote
where you put #.....do things with $decompressed here....
but it doesn't do anything, even if it seems to work becuase it doesn't give errors...suggestions?
Code: Select all
open DEC, $ARGV[1] or die "Couldn't open file: $!";
binmode DEC;
print DEC $decompressed;
close DEC;
but it doesn't do anything, even if it seems to work becuase it doesn't give errors...suggestions?
Re: Call Perl function (help with code)
Looks good...I think you just forgot to open the output file explicitly for writing (strange that you didn't receive an error message from the 'print' command). Just try instead:Vash wrote:Just for curiosity i wrote
where you put #.....do things with $decompressed here....Code: Select all
open DEC, $ARGV[1] or die "Couldn't open file: $!"; binmode DEC; print DEC $decompressed; close DEC;
Code: Select all
open (DEC,'>' ,$ARGV[1]) or die "Couldn't open output file: $!"; #'>' means: open for writing
binmode DEC;
print DEC $decompressed;
close DEC;
lze.pl compressedInputFile decompressedOutputFile
This should work...
I just tried compressing a 35KB text file. The compressed output file had 17 KB. Decompressing the output file again delivered the original file
Re: Call Perl function (help with code)
Good idea, thanks VashVash wrote:I compiled a compressor and a decompressor if someone need them:
Re: Call Perl function (help with code)
So that means: "Pay more - get less"Vash wrote:the pro version make an even little executbale, or so they say...
