Thursday, October 28, 2004

Installing perl modules

from http://www.brandonhutchinson.com/installing_perl_modules.html

perl -MCPAN -e shell (to get an interactive CPAN shell)
perl -MCPAN -e 'install Time::JulianDay' (if you know the name of the module, you can install it directly without interacting with the CPAN shell)

Within the CPAN shell:
i /expression/ will search for a Perl module containing expression, and
install module will install the module.

Example:
perl -MCPAN -e shell
i /JulianDay/
install Time::JulianDay

Note: if you are behind a firewall, you may wish to use passive FTP with Perl's Net::FTP module. Set the environment variable FTP_PASSIVE 1 (or any non-zero value) to use passive FTP when downloading Perl modules through CPAN.


To manually install a Perl module:

1. Download the Perl module from CPAN or other site.
2. Extract the tarball.
3. Run perl Makefile.PL
4. Run make
5. Run make test
6. Run make install

Note: you should use the same compiler to build Perl modules that you used to build Perl. For example, if you are building Perl modules with gcc and are using a version of Perl that was supplied with your distribution (ex. Solaris 8 includes Perl 5.005_03), you may run into errors.

Tuesday, October 05, 2004

fflush(stdin)

from http://www.eskimo.com/~scs/C-faq/q12.26.html

How can I flush pending input so that a user's typeahead isn't read at the next prompt? Will fflush(stdin) work?


fflush is defined only for output streams. Since its definition of ``flush'' is to complete the writing of buffered characters (not to discard them), discarding unread input would not be an analogous meaning for fflush on input streams.

There is no standard way to discard unread characters from a stdio input stream, nor would such a way be sufficient unread characters can also accumulate in other, OS-level input buffers.

References: ANSI Sec. 4.9.5.2
ISO Sec. 7.9.5.2
H&S Sec. 15.2



dired to open new directories in same buffer

From http://list-archive.xemacs.org/xemacs-beta/200006/msg00277.html

Pasting the entire mail

Recently, there was some discussion in the comp.emacs newsgroup

regarding dired and the way `dired-find-file' handles directories.
`dired-find-file' will always create a new buffer for each directory.
If you work in many directories, these dired buffers can accumulate
and quickly become unwieldy.

The original post asked for a way to reuse the same dired buffer when
changing directories. Someone suggested using 'i',
`dired-maybe-insert-subdir', instead of 'RET'. This isn't ideal,
however, because it simply inserts the contents of the subdirectory
into the current dired buffer and doesn't remove the old directory's
contents. It also forces users to use two different keys to navigate
through directories and select files, 'i' and 'RET', instead of just
being able to use 'RET'.

I would really like to have the new directory contents replace the old
in a dired buffer. If my cursor is positioned over a file, however, I
want dired to do the normal thing: open the file in a new buffer.
This seems to me like the most intuitive behavior. I hacked out some
lisp code that does this:


(defun dired-follow-file ()
"In dired, visit the file or directory on this line.
If a directory is on the current line, replace the current
dired buffer with one containing the contents of the directory.
Otherwise, invoke `dired-find-file' on the file."
(interactive)
(let ((filename (dired-get-filename)))
;; if the file is a directory, replace the buffer with the
;; directory's contents
(if (file-directory-p filename)
(find-alternate-file filename)
;; otherwise simply perform a normal `dired-find-file'
(dired-find-file))))


Now, I simply need to remap the dired keys


(add-hook
'dired-mode-hook
(lambda ()
(local-set-key "\C-m" 'dired-follow-file)
(local-set-key "e" 'dired-follow-file)
(local-set-key "f" 'dired-follow-file)))


and (abracadabra) dired replaces the old directory with the new one in
the same buffer when I press 'RET'. (Note that it's always easy to
get back to the parent directory because you can just select '..' in
the new directory listing.)

I posted this lisp snippet to comp.emacs and was asked to also send it
to and . Here it
is. I hope this is helpful.

Regards,
Samuel Padgett