The Forum is up for sale: XeNTaX Forum looking for new owner

Call Perl function (help with code)

Read or post about compression. And decompression. Or ask questions how to decompress your files.
Post Reply
Eldinen
n00b
Posts: 12
Joined: Mon Nov 09, 2009 7:26 pm
Has thanked: 1 time
Been thanked: 4 times

Call Perl function (help with code)

Post by Eldinen »

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.
Liandril
advanced
Posts: 55
Joined: Mon Aug 02, 2010 4:11 pm
Been thanked: 4 times

Re: Call Perl function (help with code)

Post by Liandril »

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...)

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 {
  #....
}
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...
Vash
mega-veteran
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)

Post by Vash »

Just for curiosity i wrote

Code: Select all

open DEC, $ARGV[1] or die "Couldn't open file: $!";
binmode DEC;
print DEC $decompressed;
close DEC;  
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?
Liandril
advanced
Posts: 55
Joined: Mon Aug 02, 2010 4:11 pm
Been thanked: 4 times

Re: Call Perl function (help with code)

Post by Liandril »

Vash wrote:Just for curiosity i wrote

Code: Select all

open DEC, $ARGV[1] or die "Couldn't open file: $!";
binmode DEC;
print DEC $decompressed;
close DEC;  
where you put #.....do things with $decompressed here....
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:

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;  
Now the script can be called like this:
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 :)
Eldinen
n00b
Posts: 12
Joined: Mon Nov 09, 2009 7:26 pm
Has thanked: 1 time
Been thanked: 4 times

Re: Call Perl function (help with code)

Post by Eldinen »

Thanks for all!!! Now all work!!

Liandril, Vash, thanks ^^.
Vash
mega-veteran
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)

Post by Vash »

The contents of this post was deleted because of possible forum rules violation.
Liandril
advanced
Posts: 55
Joined: Mon Aug 02, 2010 4:11 pm
Been thanked: 4 times

Re: Call Perl function (help with code)

Post by Liandril »

Vash wrote:I compiled a compressor and a decompressor if someone need them:
Good idea, thanks Vash :) And hey: only 450KB for each file... Perl2Exe seems to produce very small executables (I tried Activstates Perl Dev Kit.. the resulting binaries were at least 1.3 MB). Unfortunately, Perl2Exe won't compile the Perl script I'm currently working on... but that's a different topic.
Vash
mega-veteran
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)

Post by Vash »

the pro version make an even little executbale, or so they say...
Liandril
advanced
Posts: 55
Joined: Mon Aug 02, 2010 4:11 pm
Been thanked: 4 times

Re: Call Perl function (help with code)

Post by Liandril »

Vash wrote:the pro version make an even little executbale, or so they say...
So that means: "Pay more - get less" :D
Post Reply