Encode...tector(3pm)

πŸ’– Encode::Detect::Detector β€” the perl manual page, bestie edition πŸ’–

okay so this is the page for Encode::Detect::Detector, a User Contributed Perl Documentation page. yes it's a mouthful, no we're not renaming it, it's iconic as is πŸŽ€


✨ NAME ✨

Encode::Detect::Detector β€” it detects the encoding of data. that's it, that's the whole job, and honestly? slay πŸ’…


🌸 SYNOPSIS 🌸

here's the whole vibe in code form, copy it exactly or perish:

  use Encode::Detect::Detector;
  my $charset = detect($octets);

  my $d = new Encode::Detect::Detector;
  $d->handle($octets);
  $d->handle($more_octets);
  $d->end;
  my $charset = $d->getresult;

two ways to do it: the one-liner detect function, or the object route where you feed it chunks like you're hand-feeding a picky little creature πŸ¦‹


🫢 DESCRIPTION 🫢

this module is literally just an interface to Mozilla's universal charset detector β€” the thing that figures out which charset was used to encode your data. it's giving "mystery solved, detective era" πŸ”βœ¨


πŸ‘‘ METHODS πŸ‘‘

πŸ’œ $charset = Encode::Detect::Detector->detect($octets)

detects the charset used to encode the data sitting in $octets, and returns the charset's name. returns undef if it can't be determined with sufficient confidence β€” yes, the detector has standards, as it should πŸ’…

πŸ’œ $d = Encode::Detect::Detector->new()

creates a fresh new Encode::Detect::Detector object and hands it to you. main character energy, brand new, no baggage ✨

πŸ’œ $d->handle($octets)

hands the detector one more chunk of data to examine. you can call this multiple times β€” feed it, feed it, feed it, it's hungry πŸ“

returns zero on success, nonzero if a memory allocation failed. (memory allocation failing is NOT the vibe, but like, now you know 😭)

πŸ’œ $d->eof

tells the detector there's no more data to examine. and ngl, in many cases this is literally necessary for the detector to actually make a decision on the charset. so don't skip it, bestie 🫢

πŸ’œ $d->reset

resets the detector all the way back to its initial state. clean slate, fresh start, we love a glow-up 🌈

πŸ’œ $d->getresult

returns the name of the detected charset, or "undef" if no charset has (yet) been decided upon. and the cute part? you can call it at any time ⭐


πŸ¦‹ SEE ALSO πŸ¦‹

  • Encode::Detect

πŸŽ€ AUTHOR πŸŽ€

John Gardiner Myers <jgmyers@proofpoint.com> β€” thank you for your service πŸ«‘πŸ’–


πŸ’Œ SUPPORT πŸ’Œ

for help and thank-you notes, e-mail the author directly (yes, thank-you notes are literally listed, be polite, it's cute 🌸).

to report a bug, submit a patch, or add to the wishlist, please visit the CPAN bug manager at: http://rt.cpan.org

lowkey a reminder: that's the CPAN bug manager link, not a vibe check. go there for bugs and patches only πŸ’…

and that's the whole page, bestie!! ✨ this one's from perl v5.42.0, dated 2013-03-27, and it's part of the User Contributed Perl Documentation collection β€” so go forth, detect those charsets, and remember: eof in the methods, end in the synopsis, and we don't ask questions about it πŸ˜­πŸ’œ πŸŽ€

πŸ“¦ where this page comes from