Perl Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Perl Examples

Quick Start
Perl Unicode
Perl Byte Array
Perl Certs
Perl Email
Perl Encryption
Perl FTP
HTML-to-XML
Perl HTTP
Perl IMAP
Perl MHT
Perl MIME
Perl RSA
Perl S/MIME
Perl Signatures
Perl Socket
Perl Spider
Perl Tar
Perl Upload
Perl XML
Perl XMP
Perl Zip

More Examples...
String
Email Object
POP3
SMTP
RSS
Atom
Self-Extractor

Unreleased...
Service
PPMD
Deflate
Bzip2
LZW
Bz2
DH Key Exchange
DSA
Icon

 

 

 

 

 

 

 

beginsWith -- Check if Byte Array Begins with Byte Sequence

Determine if a byte array begins with a specific byte sequence.

Download Chilkat Perl Module

use chilkat;

$zipData = new chilkat::CkByteData();
$gifData = new chilkat::CkByteData();

#  Zip files begin with these 4 bytes:
$zipBegin_bytes = pack "C4", 0x50, 0x4B, 3, 4;
$zipBegin = new chilkat::CkByteData();
$zipBegin->append($zipBegin_bytes,4);

#  GIF files begin with "GIF89", which is this byte sequence:
$gifBegin_bytes = pack "C5", 0x47, 0x49, 0x46, 0x38, 0x39;
$gifBegin = new chilkat::CkByteData();
$gifBegin->append($gifBegin_bytes,5);

$success = $zipData->loadFile("dude.zip");
if ($success == 1) {
    if ($zipData->beginsWith($zipBegin)) {
        print "Yes, this is a .zip archive!" . "\r\n";
    }
    else {
        print "No, this is not a .zip archive." . "\r\n";
    }

}
else {
    print "Failed to load dude.zip" . "\r\n";
}

$success = $gifData->loadFile("dude.gif");
if ($success == 1) {
    if ($gifData->beginsWith($gifBegin)) {
        print "Yes, this is a GIF image!" . "\r\n";
    }
    else {
        print "No, this is not a GIF image." . "\r\n";
    }

}
else {
    print "Failed to load dude.gif" . "\r\n";
}

 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2007 Chilkat Software, Inc. All Rights Reserved.