Perl command or module, for example Linux command "file"

I have a script that downloads files, but these files do not have any information about them until they are downloaded. At the time of writing for Linux, I just called qx{ 'file ' . $filename }to see if it is a JPEG image, and if not delete it. However, now I'm trying to rewrite an independent and clean Perl form onto the platform. I went over all the calls to system{ 'curl', $image_website }the LWP :: UserAgent calls, and I was hoping there was a way to replace the calls with a file with something.

+3
source share
1 answer

File::TypeThe CPAN module can help you - its description "determines the type of file using magic," which the Unix team does type.

my $ft = File::Type->new();
my $type_from_file = $ft->checktype_filename($file);

File::LibMagic (Perl- libmagic; file-4.x file-5.x)

+6

Source: https://habr.com/ru/post/1787589/


All Articles