1
2
use Compress::Raw::Zlib;
my $crc = sprintf( "%x", Compress::Raw::Zlib::crc32( $content ) );
QuoteThe use bytes pragma disables character semantics for the rest of the lexical scope in which it appears.
1
2
3
4
5
my $crc;
{
use bytes;
$crc = sprintf( "%x", Compress::Raw::Zlib::crc32( $content ) );
}
1 2
use Compress::Raw::Zlib; my $crc = sprintf( "%x", Compress::Raw::Zlib::crc32( $content ) );
1
2
3
4
5
6
7
8
9
10
11
12
13
#!/usr/bin/perl
use strict;
use warnings;
use WWW::Mechanize;
use Compress::Raw::Zlib;
my $mech = WWW::Mechanize->new();
$mech->get( 'http://audiologie-phoniatrie.charite.de/forschung/schwerpunkte/phaenotypische_variablitaet_pathologischer_kommunikation/forschungsprojekte/metas/impressum' );
my $crc;
{
use bytes;
$crc = sprintf( '%x', Compress::Raw::Zlib::crc32( $mech->content() ) );
}
print $crc, "\n";
Wide character in subroutine entry at D:\mgress\web\minex.pl line 11.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
This is perl 5, version 12, subversion 2 (v5.12.2) built for MSWin32-86-multi-thread
(with 8 registered patches, see perl -V for more detail)
Copyright 1987-2010, Larry Wall
Binary build 1203 [294165] provided by ActiveState http://www.ActiveState.com
Built Dec 9 2010 04:03:28
Perl may be copied only under the terms of either the Artistic License or the
GNU General Public License, which may be found in the Perl 5 source kit.
Complete documentation for Perl, including FAQ lists, should be found on
this system using "man perl" or "perldoc perl". If you have access to the
Internet, point your browser at http://www.perl.org/, the Perl Home Page.
Guest John DoeEin minimales Beispiel mit fehler-bringender URL:
Quote-CRC32
If set to true, a crc32 checksum of the uncompressed data will be calculated. Use the $d->crc32 method to retrieve this value.
This option defaults to false.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#!/usr/bin/perl -w use strict; use warnings; use WWW::Mechanize; use Compress::Raw::Zlib; my ($d, $status) = new Compress::Raw::Zlib::Deflate ( -CRC32 => 1, ) ; my $mech = WWW::Mechanize->new(); $mech->get( 'http://audiologie-phoniatrie.charite.de/forschung/schwerpunkte/phaenotypische_variablitaet_pathologischer_kommunikation/forschungsprojekte/metas/impressum' ); my $crc; { use bytes; $crc = sprintf( '%x', $d->crc32( $mech->content() ) ); } print $crc, "\n";
Usage: Compress::Raw::Zlib::deflateStream::crc32(s) at test.pl line 12.
no utf8;
QuoteThe use utf8 pragma tells the Perl parser to allow UTF-8 in the program text in the current lexical scope [...] The no utf8 pragma tells Perl to switch back to treating the source text as literal bytes in the current lexical scope.
Do not use this pragma for anything else than telling Perl that your script is written in UTF-8.
Guest John DoeIch bastele derzeit an einem kleinen Webparser, der bestimmte Dateien nach bestimmten Kriterien speichern soll - wenn sie noch nicht gespeichert wurden. Um letzteres zu prüfen, lasse ich die CRC32 berechnen und vergleiche sie mit den CRCs der vorher gespeicherten Seiten.
CRC berechne ich wie folgt ($content wird von WWW::Mechanize mit $mech->content() ausgespuckt):
Code: (dl )1
2use Compress::Raw::Zlib;
my $crc = sprintf( "%x", Compress::Raw::Zlib::crc32( $content ) );
1 2 3
use Encode qw/encode_utf8/; use Compress::Raw::Zlib; my $crc = sprintf( "%x", Compress::Raw::Zlib::crc32( encode_utf8 $content ) );
2011-05-31T10:10:46 moritzAusserdem gilt er nur im lexikalischen Scope, die Funktion die du aufrufst ist aber in einem anderen Scope, daher hat 'use bytes;' in dem Fall keine Auswirkung