Friday, September 10th, 2010
Perl File Handling

Check for Acceptable File Types during upload in Perl

When a file with a Content-Type that isn’t text/html is uploaded to this CGI script, its output indicates that only HTML types are allowed.#!/usr/bin/perluse strict; use CGI ...

More Perl File Handling

Display the Content-Type of an Uploaded File in Perl

#!/usr/bin/perl use strict; use CGI qw/:standard/; my $q = new CGI; my $filename = $q->param('uploaded_file'); my $contenttype = $q->uploadInfo($filename)->{'Content-Type'}; print header; print start_html; print "Type is $contenttype"; print end_html;

Closing filehandles in Perl

Perl automatically closes the filehandle when the program exits or if the file is opened again. We can explicitly close it ...

Writing to filehandles in PERL

To write to a filehandle, place the filehandle after the print function call.open (NEWFILE, ">/tmp/thenewfile"); print NEWFILE "Printing to the new file ...

Using die() to trap errors in Perl

The easiest way to use the die() function is with a logical OR when opening a file.open (MYFILE, ">thefilename") or die ...

Reading from Filehandles in Perl

open (FILE, "/tmp/file") or die("Cannot open file: $!"); while () { chomp; print "The line just read was: $_\n"; }

FileHandles in Perl

There are three global filehandles that are already opened when a program starts in Perl.1.STDIN 2.STDOUT 3.STDERR.STDIN (standard input) is the ...

Read file using IO::File module in Perl

Here's how we would write a program to find specific words in a file using the IO::File module using purely object-oriented ...

Find specific words in file using Perl

open (INPUT, "< C:\\data\\test.txt") or die "Couldn't open C:\\data\\test.txt for reading: $!\n"; $char = "thisword"; while () { ...

eXTReMe Tracker