I fixed it. I needed to use this line before the loop.
binmode STDOUT;
I'm still confused why this affects the explicit output of specific characters rather than simply affecting aliases like "\n" is something I'd be interested in finding out.
I'm looking for a simple (or simple-minded) way to convert a text file from DOS-ish CR/LF end-of-line pairs to Unix-ish LF end-of-line characters. It should be pretty straightforward, since Perl contains a robust pattern matching facility. So here's my code.
#! /usr/bin/perl
while($line =...
At one time, I needed to create PDFs from HTML to deliver on an intranet. Because I'm a big fan of TMTOWTDI, I did the following steps. (Keep in mind that I was more of a neonate at the time.)
1. Use my CGI Perl script to create the HTML.
2. Write the same HTML to a file.
3. Use html2ps...
You can also use the ceil() and floor() functions in the POSIX module.
Example:
=========
use POSIX;
print floor(3/2) . "\n" . ceil(3/2) . "\n";
=========
This doesn't exactly round the number, but it does return the floor and ceiling.
If the file is too big to fit in memory at one time, you can try this solution.
==================
$firstline = "";
$lastline = "";
open IPF, "filename" or die "Error opening input file: $!";
$firstline = <IPF>;
while(<IPF>) {$lastline = $_;}...
You could try something like splitting the date string on the space character, then pop the last element off the existing array, then join the array back together with spaces, then print the string. It's a little messy, but it works.
============
$thetime = scalar localtime;
@timearray = split...
If the $date variable exists in a block that also includes the format_date() function, you should be able to modify $date directly within the function. All of the object lovers out there are cringing right now, though.
The OO way to do it would be to make an object that had a format_date()...
Perl 5.6 and higher support large files. Here's an excerpt from the perl56delta documentation file.
===========
Large file support
If you have filesystems that support ``large files'' (files larger than 2 gigabytes), you may now also be able to create and access them from Perl.
NOTE: The...
Is there any extension to HTML that Mozilla uses to open pages in a new tab? This would be analagous to the <A HREF='whatever' target='_new'> construction that's commonly used to open pages in a new window. Oddly, though, a quick read of the HTML 4.01 spec didn't show me _new.
Thanks!
Generally, Perl is designed to accomplish easy tasks in very few lines of code. For example, in a UNIX-ey type of environment, this code emulates the cat utility, assuming you redirect the input.
====
#! /usr/local/bin/perl
while(<>) {
print;
}
====
For active web content, there are reasons...
Heh. Plan B is usually RTM again. In my first attempt at this, I wrote a message handler in C, and wrote some functionality in Perl. The C program launched the Perl program at the time of shutdown. I may have to revert back to that plan.
Thnaks for the help. If I do ever figure out the...
===
while(<IMAGES>) {...}
===
The <> operator expects a filehandle, not a directory handle (I think - I couldn't find a definitive reference in 60 seconds of searching).
Keep in mind that there's more than one way to do it, but when I have to process all files of a particular type in a...
You know, that's a really good question. I wrote another script that uses Win32::Event->pulse() to send an arbitrarily named Windows event, and an appropriately configured script caught that event, but I'm guessing Windows doesn't pass events around by name.
I got it from <I>Programming Windows 95</I>, by Charles Petzold (ISBN: 1-55615-676-6), and it also exists in the Cygwin WINDOWSX.H file.
From the text of the book:
======
Windows begins sending every window procedure a WM_QUERYENDSESSION message when the user ends a Windows session. If any...
I want to write a program in Perl that sits and waits for Windows to shut down, then does something. I know that I have to use the Win32::Event module, and I have some code that I've written here.
========
use Win32::Event;
$manual = 0;
$initial = 0;
$name = "WM_QUERYENDSESSION"...
You mention that you can't start an applet by double-clicking and that there are VM-imposed restrictions on file access for applets. The first point is true for both Java applets and applications, but the second point isn't true for Java applications. Java applications running on the local...
I'm not quite sure about that. It might be possible to open the parallel port twice - once for reading, and once for writing. I'll see if I can try that out today. If you have any success before I post, please post a reply.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.