[6883] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 508 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 21 15:17:41 1997

Date: Wed, 21 May 97 12:00:21 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 21 May 1997     Volume: 8 Number: 508

Today's topics:
     Arpanet's "Perl Shop" shopping cart program webfoot2@iwshome.com
     Re: File Exsists & get all files (Jeff Stampes)
     Find Data in File and Add?  Simple? <stevek@unidial.com>
     Re: Form POST Vs. GET <--Need help <burleigh@hackberry.chem.niu.edu>
     Re: GnuEmacs, ActiveWare Perl and debugging <jay@rgrs.com>
     Re: New Perl User Question <flg@vhojd.skovde.se>
     Passing Variables between Programs joet@miles33.com
     Re: Perl and CGI <burleigh@hackberry.chem.niu.edu>
     Perl and ms-access (Sasha Higer)
     PGP::Pipe (Can't locate new) (Peter Makholm)
     Problems with form handling <P.Smits@stud.frw.ruu.nl>
     Re: timelocal.pl ? (Clay Irving)
     Variables In Data Structures. (Ron Picker)
     Re: Variables In Data Structures. (Nathan V. Patwardhan)
     Re: winnuke (Erik Braun)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 21 May 1997 09:02:52 -0600
From: webfoot2@iwshome.com
Subject: Arpanet's "Perl Shop" shopping cart program
Message-Id: <864222804.11218@dejanews.com>

Ola,

I'm would like to talk with someone who has used Arpanet's "Perl Shop"
shopping cart program.

I dont have experience with cgi scripts and would like some help getting
the thing set up so I can get some practice.

All assistance will be appreciated!

thanx a bunch
bill

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


------------------------------

Date: 21 May 1997 15:56:10 GMT
From: stampes@xilinx.com (Jeff Stampes)
Subject: Re: File Exsists & get all files
Message-Id: <5lv5ur$evq$1@neocad.com>

Lauri Laakso (lauri@nettipaja.clinet.fi) wrote:
: 1) How I can check if file Exsists ?

I'd suggest looking into the file tests, such as -e

: 2) How I can get all files in directory to @files() for reading them.

Using opendir, readdir and closedir is my favorite way.

See the man pages or FAQ for details

--
Jeff Stampes -- Xilinx, Inc. -- Boulder, CO -- jeff.stampes@xilinx.com


------------------------------

Date: Wed, 21 May 1997 13:33:19 GMT
From: Steve Karr <stevek@unidial.com>
Subject: Find Data in File and Add?  Simple?
Message-Id: <3382F99F.5C02@unidial.com>

Hello hello!  I've helped others out a few times, but now it's
my turn to ask for help.  My brain has turned to mush and I
cannot think.  I need a (simple?) routine to do the following
and I'm stumped:

I've created a data file in this format (account+name):

2000 Ron Allen
2001 Steve Simms
2002 Bob Jones
2003 Dan Bryan

I need a routine to read in the last line, find (figure) out that the
last
entered account number was, say, 2003 and take my data ($name) and
create the next consecutive account number (acc + 1 = 2004) an
write the info so it now is:

2000 Ron Allen
2001 Steve Simms
2002 Bob Jones
2003 Dan Bryan
2004 new name here

Hard?  Simple?  Help?  Thanks!

Please post here but cc to me in email.  I would really appreciate
it.

Steve


-- 

-{ Steve Karr               Internet Services Coordinator }-
-{ UniDial Communications, Inc.    http://www.unidial.com }-
-{ Voice +1.502.244.6666 ext. 1147   Fax  +1.502.244.4810 }-


------------------------------

Date: Wed, 21 May 1997 11:19:46 -0500
From: Darin Burleigh <burleigh@hackberry.chem.niu.edu>
Subject: Re: Form POST Vs. GET <--Need help
Message-Id: <338320A2.76AF@hackberry.chem.niu.edu>

gannon wrote:
> 
> Question....
> I know to post to a cgi script using the "GET" command, you just do the
> http://www.whatever.com/something.cgi?somestring=something&somethingelse=something
> 
> and like that... how to you do it for a "POST"..because I'm writing a
> script and I really cannot do the "?" and "&" sign things..they are not
> working..
> 
> I need help..
> Please email at brian@gannon.com or reply if you can help...

hmm, i don't see any POST or GET commands in my camel...
oh, I get it: this is a CGI question! 
you want comp.infosystems.www.authoring.cgi,
right?
or maybe just:
http://hoohoo.ncsa.uiuc.edu/cgi/primer.html

-- 
==========================================================
 - darin
burleigh@hackberry.chem.niu.edu
\\//\\//.\\//\\//.\\//\\//. http://hackberry.chem.niu.edu/HOME/dcb/
 '2 kinds of green, look out!' - dieter rot


------------------------------

Date: 21 May 1997 10:20:33 -0400
From: Jay Rogers <jay@rgrs.com>
To: Per <per@mogul.no>
Subject: Re: GnuEmacs, ActiveWare Perl and debugging
Message-Id: <82vi4cc3f2.fsf@shell2.shore.net>

Per <per@mogul.no> writes:

> Hallo, I installed the perl5 distribution for winNT from ActiveWare on a
> NT4 workstation. I also installed GNU Emacs 19.34.1.
>  What I'm trying to do is to run the debugger from inside emacs 
> (M-x perldb) and use it as I do on unix.
>  Even though Perl for Win32 supports the debugger and Emacs seems to
> recognize the M-x perldb command, the two applications do not appear to
> be integrated as they are under UNIX (the only result I was able to
> achieve was crashing emacs). So I would like to know which of the
> following three holds:
> 
> 1) Emacs for windows supports Perl and I'm probably getting something
> wrong
> 
> 2) Integration of debugging and emacs has never been attempted (M-x
> perldb is not actually supported)
> 
> 3) Doesn't work yet, but someone is working on it.

Number 3.  It's an NT or Emacs problem depending on how you want to
look at it.  It will probably be fixed in Emacs 19.35.  Emacs
specifies that a debugger send it info separated by a ^Z.  Reading a
^Z without binmode is a problem with NT.

Here's a version of perldb.el that works.  It has an extra function to
position at the locus of a compilation error.  I really should post
this to CPAN.

Also see the installation comments in perldb.el.

--
Jay Rogers
jay@rgrs.com


;;; perldb.el --- specialized mode for compiling and debugging perl code

;; Run perl -d under Emacs
;; Based on gdb.el, as written by W. Schelter, and modified by rms.
;; Modified for Perl by Ray Lischner (uunet!mntgfx!lisch), Nov 1990.
;; Modified by Jay Rogers <jay@rgrs.com>, March 1997
;;   .  support for next compilation error or warning `C-x `'
;;      (note: this comes from an old posting to comp.lang.perl by
;;      ted@evi.com <Ted Stefanik>)
;;   .  Win32 work around for can't read ^Z problem.

;; This file is part of GNU Emacs.
;; Copyright (C) 1988,1990,1997 Free Software Foundation, Inc.

;; GNU Emacs is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
;; to anyone for the consequences of using it or for whether it serves
;; any particular purpose or works at all, unless he says so in writing.
;; Refer to the GNU Emacs General Public License for full details.

;; Everyone is granted permission to copy, modify and redistribute GNU
;; Emacs, but only under the conditions described in the GNU Emacs
;; General Public License.  A copy of this license is supposed to have
;; been given to you along with GNU Emacs so you can know your rights and
;; responsibilities.  It should be in a file named COPYING.  Among other
;; things, the copyright notice and this notice must be preserved on all
;; copies.

;; Description of perl -d interface:

;; A facility is provided for the simultaneous display of the source code
;; in one window, while using perldb to step through a function in the
;; other.  A small arrow in the source window, indicates the current
;; line.

;; Installation:
;;
;; Put in your ~/.emacs:
;;
;;  (autoload 'perldb "perldb" "Major mode for running the Perl debugger." t)
;;  (add-hook 'gud-mode-hook '(lambda () (load "perldb" t t)))
;;  (defvar perldb-command-name "perl" "*Pathname of the Perl interpreter.")

;; Starting up:

;; In order to use this facility, invoke the command PERLDB to obtain a
;; shell window with the appropriate command bindings.  You will be asked
;; for the name of a file to run and additional command line arguments.
;; Perldb will be invoked on this file, in a window named *perldb-foo*
;; if the file is foo.

;; C-x ` visits the locus of the next compiler error or warning message

;; M-s steps by one line, and redisplays the source file and line.

;; You may easily create additional commands and bindings to interact
;; with the display.  For example to put the perl debugger command n on \M-n
;; (def-perldb n "\M-n")

;; This causes the emacs command perldb-next to be defined, and runs
;; perldb-display-frame after the command.

;; perldb-display-frame is the basic display function.  It tries to display
;; in the other window, the file and line corresponding to the current
;; position in the perldb window.  For example after a perldb-step, it would
;; display the line corresponding to the position for the last step.  Or
;; if you have done a backtrace in the perldb buffer, and move the cursor
;; into one of the frames, it would display the position corresponding to
;; that frame.

;; perldb-display-frame is invoked automatically when a
;; filename-and-line-number appears in the output.

;; Note: For Windows 95/NT, the perl debugger with version 5.001 or
;; less doesn't work with emacs.  To fix: locate and change the
;; following code in lib/perl5db.pl
;;
;;    if (-e "/dev/tty") {
;;    	  $console = "/dev/tty";
;;    	  $rcfile=".perldb";
;;    }
;;    elsif (-e "con") {
;;    	  $console = "";                 <---- change "con" to ""
;;    	  $rcfile="perldb.ini";
;;    }
;;    else {
;;    	  $console = "sys\$command";
;;    	  $rcfile="perldb.ini";
;;    }

(require 'shell)

(defvar perldb-command-name "perl"
  "*Pathname of the Perl interpreter.")

(defvar perldb-command-args "-dw"
  "*Start perl with these command line options.")

(defvar perldb-dos-binmode (and (string= system-type "windows-nt")
				(boundp 'emacs-major-version)
				(= emacs-major-version 19)
				(<= emacs-minor-version 34))
  "*This flag turns on a work around for a problem on Win32 machines
   where emacs hangs before displaying a debugger prompt.  This
   problem is caused by the Win32 I/O routines interpreting ^Z as
   end-of-file.  I'm told Emacs 19.35 will fix the ^Z problem in
   the routines that interface with the Win32 I/O routines.")

(defvar perldb-prompt-pattern "^  DB<[0-9]+> "
  "A regexp to recognize the prompt for perldb.")

(defvar perldb-mode-map nil
  "Keymap for perldb-mode.")

(if perldb-mode-map
    nil
  (setq perldb-mode-map (copy-keymap comint-mode-map))
  (define-key perldb-mode-map "\C-c\C-l" 'perldb-refresh))

(define-key ctl-x-map " " 'perldb-break)
(define-key ctl-x-map "&" 'send-perldb-command)
(define-key ctl-x-map "~" 'perldb-next-error)
(define-key perldb-mode-map "\M-n" 'comint-next-matching-input-from-input)
(define-key perldb-mode-map "\M-p" 'comint-previous-matching-input-from-input)
(define-key perldb-mode-map "\C-x`" 'perldb-next-error)
(if (boundp 'perl-mode-map)
    (define-key perl-mode-map "\C-x`" 'perldb-next-error)
  (add-hook 'perl-mode-hook
	    '(lambda ()
	       (define-key perl-mode-map "\C-x`" 'perldb-next-error))))

;;Of course you may use `def-perldb' with any other perldb command, including
;;user defined ones.

(defmacro def-perldb (name key &optional doc)
  (let* ((fun (intern (concat "perldb-" name))))
    (` (progn
	 (defun (, fun) (arg)
	   (, (or doc ""))
	   (interactive "p")
	   (perldb-call (if (not (= 1 arg))
			    (concat (, name) arg)
			  (, name))))
	 (define-key perldb-mode-map (, key) (quote (, fun)))))))

(def-perldb "s"   "\M-s" "Step one source line with display")
(def-perldb "n"   "\M-n" "Step one source line (skip functions)")
(def-perldb "c"   "\M-c" "Continue with display")
;;(def-perldb "r"   "\C-c\C-r" "Return from current subroutine")
;;(def-perldb "A"   "\C-c\C-a" "Delete all actions")

(defun perldb-mode ()
  "Major mode for interacting with an inferior Perl debugger process.
The following commands are available:

\\{perldb-mode-map}

You can then use the command \\[perldb-next-error] to find the next error
or warning message and move to the source code that caused it.

\\[perldb-display-frame] displays in the other window
the last line referred to in the perldb buffer.

\\[perldb-s],\\[perldb-n], and \\[perldb-n] in the perldb window,
call perldb to step, next or continue and then update the other window
with the current file and position.

If you are in a source file, you may select a point to break
at, by doing \\[perldb-break].

Commands:
Many commands are inherited from shell mode.
Additionally we have:

\\[perldb-display-frame] display frames file in other window
\\[perldb-s] advance one line in program
\\[perldb-n] advance one line in program (skip over calls).
\\[send-perldb-command] used for special printing of an arg at the current point.
C-x SPACE sets break point at current line.

Variable `perldb-command-name' specifies which perl to run.

Variable `perldb-command-args' specifies perl command line args. It should
at least contain -d
"
  (interactive)
  (kill-all-local-variables)
  (setq major-mode 'perldb-mode)
  (setq mode-name "Inferior Perl")
  (setq mode-line-process '(": %s"))
  (setq comint-last-output-start (make-marker))
  (use-local-map perldb-mode-map)
  (make-local-variable 'comint-last-input-start)
  (setq comint-last-input-start (make-marker))
  (make-local-variable 'comint-last-input-end)
  (setq comint-last-input-end (make-marker))
  (make-local-variable 'perldb-last-frame)
  (setq perldb-last-frame nil)
  (make-local-variable 'perldb-last-frame-displayed-p)
  (setq perldb-last-frame-displayed-p t)
  (make-local-variable 'perldb-delete-prompt-marker)
  (setq perldb-delete-prompt-marker nil)
  ;;  (make-local-variable 'perldb-filter-accumulator)
  (setq perldb-filter-accumulator nil)
  (make-local-variable 'comint-prompt-regexp)
  (setq comint-prompt-regexp perldb-prompt-pattern)
  (run-hooks 'comint-mode-hook 'perldb-mode-hook))

(defvar current-perldb-buffer nil)

(defun end-of-quoted-arg (argstr start end)
  (let* ((chr (substring argstr start (1+ start)))
	 (idx (string-match (concat "[^\\]" chr) argstr (1+ start))))
    (and idx (1+ idx))
    )
  )

(defun parse-args-helper (arglist argstr start end)
  (while (and (< start end) (string-match "[ \t\n\f\r\b]"
					  (substring argstr start (1+ start))))
    (setq start (1+ start)))
  (cond
   ((= start end) arglist)
   ((string-match "[\"']" (substring argstr start (1+ start)))
    (let ((next (end-of-quoted-arg argstr start end)))
      (parse-args-helper (cons (substring argstr (1+ start) next) arglist)
			 argstr (1+ next) end)))
   (t (let ((next (string-match "[ \t\n\f\b\r]" argstr start)))
	(if next
	    (parse-args-helper (cons (substring argstr start next) arglist)
			       argstr (1+ next) end)
	  (cons (substring argstr start) arglist))))
   )
  )

(defun parse-args (args)
  "Extract arguments from a string ARGS.
White space separates arguments, with single or double quotes
used to protect spaces.  A list of strings is returned, e.g.,
(parse-args \"foo bar 'two args'\") => (\"foo\" \"bar\" \"two args\")."
  (nreverse (parse-args-helper '() args 0 (length args)))
  )

(defun perldb (path args)
  "Run perldb on program FILE in buffer *perldb-FILE*.
The default directory for the current buffer becomes the initial
working directory, by analogy with  gdb .  If you wish to change this, use
the Perl command `M-x cd'."
  (interactive (list (read-file-name (format "Run %s %s on file: "
					     perldb-command-name
					     perldb-command-args)
				     nil "" t)
		     (read-from-minibuffer "Command line arguments: " "")))
  (setq path (expand-file-name path))
  (let ((file (file-name-nondirectory path))
	(dir default-directory)
	(binary-process-output perldb-dos-binmode))
    (switch-to-buffer (concat "*perldb-" file "*"))
    (setq default-directory dir)
    (or (bolp) (newline))
    (insert "Current directory is " default-directory "\n")
    (apply 'make-comint
	   (concat "perldb-" file)
	   perldb-command-name nil perldb-command-args path "-emacs"
	   (parse-args args))
    (perldb-mode)
    (set-process-filter (get-buffer-process (current-buffer)) 'perldb-filter)
    (set-process-sentinel (get-buffer-process (current-buffer)) 'perldb-sentinel)
    (perldb-set-buffer)))

(defun perldb-set-buffer ()
  (cond ((eq major-mode 'perldb-mode)
         (cond ((not (eq current-perldb-buffer (current-buffer)))
                (perldb-forget-errors)
                (setq perldb-parsing-end 2));; 2 to defeat grep defeater
               (t
                (if (> perldb-parsing-end (point-max))
                    (setq perldb-parsing-end (max (point-max) 2)))))
         (setq current-perldb-buffer (current-buffer)))))

;; This function is responsible for inserting output from Perl
;; into the buffer.
;; Aside from inserting the text, it notices and deletes
;; each filename-and-line-number;
;; that Perl prints to identify the selected frame.
;; It records the filename and line number, and maybe displays that file.
(defun perldb-filter (proc string)
  (let ((inhibit-quit t))
    (if perldb-dos-binmode
	(while (string-match "\r\n" string)
	  (setq string (replace-match "\n" t t string))))
    (if perldb-filter-accumulator
	(perldb-filter-accumulate-marker proc
					 (concat perldb-filter-accumulator
						 string))
      (perldb-filter-scan-input proc string))))

(defun perldb-filter-accumulate-marker (proc string)
  (setq perldb-filter-accumulator nil)
  (if (> (length string) 1)
      (if (= (aref string 1) ?\032)
	  (cond ((string-match "\\([^\032\n]+\\):\\([0-9]+\\):[0-9]+\n" string)
		 (setq perldb-last-frame
		       (cons
			(substring string (match-beginning 1)(match-end 1))
			(string-to-int (substring string
						  (match-beginning 2)
						  (match-end 2)))))
		 (setq perldb-last-frame-displayed-p nil)
		 (perldb-filter-scan-input proc
					   (substring string (match-end 0))))
		(t (setq perldb-filter-accumulator string)))
	(perldb-filter-insert proc "\032")
	(perldb-filter-scan-input proc (substring string 1)))
    (setq perldb-filter-accumulator string)))

(defun perldb-filter-scan-input (proc string)
  (if (equal string "")
      (setq perldb-filter-accumulator nil)
    (let ((start (string-match "\032" string)))
      (if start
	  (progn (perldb-filter-insert proc (substring string 0 start))
		 (perldb-filter-accumulate-marker proc
						  (substring string start)))
	(perldb-filter-insert proc string)))))

(defun perldb-filter-insert (proc string)
  (let ((moving (= (point) (process-mark proc)))
	(output-after-point (< (point) (process-mark proc)))
	(old-buffer (current-buffer))
	start)
    (set-buffer (process-buffer proc))
    (unwind-protect
	(save-excursion
	  ;; Insert the text, moving the process-marker.
	  (goto-char (process-mark proc))
	  (setq start (point))
	  (insert string)
	  (set-marker (process-mark proc) (point))
	  (perldb-maybe-delete-prompt)
	  ;; Check for a filename-and-line number.
	  (perldb-display-frame
	   ;; Don't display the specified file
	   ;; unless (1) point is at or after the position where output appears
	   ;; and (2) this buffer is on the screen.
	   (or output-after-point
	       (not (get-buffer-window (current-buffer))))
	   ;; Display a file only when a new filename-and-line-number appears.
	   t))
      (set-buffer old-buffer))
    (if moving (goto-char (process-mark proc)))))

(defun perldb-sentinel (proc msg)
  (cond ((null (buffer-name (process-buffer proc)))
	 ;; buffer killed
	 ;; Stop displaying an arrow in a source file.
	 (setq overlay-arrow-position nil)
	 (set-process-buffer proc nil))
	((memq (process-status proc) '(signal exit))
	 ;; Stop displaying an arrow in a source file.
	 (setq overlay-arrow-position nil)
	 ;; Fix the mode line.
	 (setq mode-line-process
	       (concat ": "
		       (symbol-name (process-status proc))))
	 (let* ((obuf (current-buffer)))
	   ;; save-excursion isn't the right thing if
	   ;;  process-buffer is current-buffer
	   (unwind-protect
	       (progn
		 ;; Write something in *perldb-<foo>* and hack its mode line,
		 (set-buffer (process-buffer proc))
		 ;; Force mode line redisplay soon
		 (set-buffer-modified-p (buffer-modified-p))
		 (if (eobp)
		     (insert ?\n mode-name " " msg)
		   (save-excursion
		     (goto-char (point-max))
		     (insert ?\n mode-name " " msg)))
		 ;; If buffer and mode line will show that the process
		 ;; is dead, we can delete it now.  Otherwise it
		 ;; will stay around until M-x list-processes.
		 (delete-process proc))
	     ;; Restore old buffer, but don't restore old point
	     ;; if obuf is the perldb buffer.
	     (set-buffer obuf))))))


(defun perldb-refresh ()
  "Fix up a possibly garbled display, and redraw the arrow."
  (interactive)
  (redraw-display)
  (perldb-display-frame))

(defun perldb-display-frame (&optional nodisplay noauto)
  "Find, obey and delete the last filename-and-line marker from PERLDB.
The marker looks like \\032\\032FILENAME:LINE:CHARPOS\\n.
Obeying it means displaying in another window the specified file and line."
  (interactive)
  (perldb-set-buffer)
  (and perldb-last-frame (not nodisplay)
       (or (not perldb-last-frame-displayed-p) (not noauto))
       (progn (perldb-display-line (car perldb-last-frame) (cdr perldb-last-frame))
	      (setq perldb-last-frame-displayed-p t))))

;; Make sure the file named TRUE-FILE is in a buffer that appears on the screen
;; and that its line LINE is visible.
;; Put the overlay-arrow on the line LINE in that buffer.

(defun perldb-display-line (true-file line)
  (let* ((buffer (find-file-noselect true-file))
	 (window (display-buffer buffer t))
	 (pos))
    (save-excursion
      (set-buffer buffer)
      (save-restriction
	(widen)
	(goto-line line)
	(setq pos (point))
	(setq overlay-arrow-string "=>")
	(or overlay-arrow-position
	    (setq overlay-arrow-position (make-marker)))
	(set-marker overlay-arrow-position (point) (current-buffer)))
      (cond ((or (< pos (point-min)) (> pos (point-max)))
	     (widen)
	     (goto-char pos))))
    (set-window-point window overlay-arrow-position)))

(defun perldb-call (command)
  "Invoke perldb COMMAND displaying source in other window."
  (interactive)
  (goto-char (point-max))
  (setq perldb-delete-prompt-marker (point-marker))
  (perldb-set-buffer)
  (send-string (get-buffer-process current-perldb-buffer)
	       (concat command "\n")))

(defun perldb-maybe-delete-prompt ()
  (if (and perldb-delete-prompt-marker
	   (> (point-max) (marker-position perldb-delete-prompt-marker)))
      (let (start)
	(goto-char perldb-delete-prompt-marker)
	(setq start (point))
	(beginning-of-line)
	(delete-region (point) start)
	(setq perldb-delete-prompt-marker nil))))

(defun perldb-break ()
  "Set PERLDB breakpoint at this source line."
  (interactive)
  (let ((line (save-restriction
		(widen)
		(1+ (count-lines 1 (point))))))
    (process-send-string (get-buffer-process current-perldb-buffer)
			 (concat "b " line "\n"))))

(defun perldb-read-token ()
  "Return a string containing the token found in the buffer at point.
A token can be a number or an identifier.  If the token is a name prefaced
by `$', `@', or `%', the leading character is included in the token."
  (save-excursion
    (let (begin)
      (or (looking-at "[$@%]")
	  (re-search-backward "[^a-zA-Z_0-9]" (point-min) 'move))
      (setq begin (point))
      (or (looking-at "[$@%]") (setq begin (+ begin 1)))
      (forward-char 1)
      (buffer-substring begin
			(if (re-search-forward "[^a-zA-Z_0-9]"
					       (point-max) 'move)
			    (- (point) 1)
			  (point)))
      )))

(defvar perldb-commands nil
  "List of strings or functions used by send-perldb-command.
It is for customization by the user.")

(defun send-perldb-command (arg)
  "Issue a Perl debugger command selected by the prefix arg.  A numeric
arg selects the ARG'th member COMMAND of the list perldb-commands.
The token under the cursor is passed to the command.  If COMMAND is a
string, (format COMMAND TOKEN) is inserted at the end of the perldb
buffer, otherwise (funcall COMMAND TOKEN) is inserted.  If there is
no such COMMAND, then the token itself is inserted.  For example,
\"p %s\" is a possible string to be a member of perldb-commands,
or \"p $ENV{%s}\"."
  (interactive "P")
  (let (comm token)
    (if arg (setq comm (nth arg perldb-commands)))
    (setq token (perldb-read-token))
    (if (eq (current-buffer) current-perldb-buffer)
	(set-mark (point)))
    (cond (comm
	   (setq comm
		 (if (stringp comm) (format comm token) (funcall comm token))))
	  (t (setq comm token)))
    (switch-to-buffer-other-window current-perldb-buffer)
    (goto-char (point-max))
    (insert-string comm)))

(defvar perldb-error-list nil
  "List of error message descriptors for visiting erring functions.
Each error descriptor is a list of length two.
Its car is a marker pointing to an error message.
Its cadr is a marker pointing to the text of the line the message is about,
  or nil if that is not interesting.
The value may be t instead of a list;
this means that the buffer of error messages should be reparsed
the next time the list of errors is wanted.")

(defvar perldb-parsing-end nil
  "Position of end of buffer when last error messages parsed.")

(defvar perldb-error-message "No more fatal Perl errors"
  "Message to print when no more matches for compilation-error-regexp are found")

(make-local-variable 'compilation-error-regexp)
(defvar compilation-error-regexp
  "\\([^ :\n]+\\(: *\\|, line \\|(\\)[0-9]+\\)\\|\\([0-9]+ *of *[^ \n]+\\|[^ \n]+ \\(at \\)*line [0-9]+\\)"
  "Regular expression to recognize perl compilation errors")

(defun perldb-next-error (&optional argp)
  "Visit next perldb error message and corresponding source code.
This operates on the output from the \\[perldb] command.
If all preparsed error messages have been processed,
the error message buffer is checked for new ones.
A non-nil argument (prefix arg, if interactive)
means reparse the error message buffer and start at the first error."
  (interactive "P")
  (if (or (eq perldb-error-list t)
	  argp)
      (progn (perldb-forget-errors)
	     (setq perldb-parsing-end 2)));; 2 to defeat grep defeater
  (if perldb-error-list
      nil
    (save-excursion
      (switch-to-buffer current-perldb-buffer)
      (perldb-parse-errors)))
  (let ((next-error (car perldb-error-list)))
    (if (null next-error)
	(error (concat perldb-error-message
		       (if (and (get-buffer-process current-perldb-buffer)
				(eq (process-status
                                     (get-buffer-process
                                      current-perldb-buffer))
				    'run))
			   " yet" ""))))
    (setq perldb-error-list (cdr perldb-error-list))
    (if (null (car (cdr next-error)))
	nil
      (switch-to-buffer (marker-buffer (car (cdr next-error))))
      (goto-char (car (cdr next-error)))
      (set-marker (car (cdr next-error)) nil))
    (let* ((pop-up-windows t)
	   (w (display-buffer (marker-buffer (car next-error)))))
      (set-window-point w (car next-error))
      (set-window-start w (car next-error)))
    (set-marker (car next-error) nil)))

;; Set perldb-error-list to nil, and
;; unchain the markers that point to the error messages and their text,
;; so that they no longer slow down gap motion.
;; This would happen anyway at the next garbage collection,
;; but it is better to do it right away.
(defun perldb-forget-errors ()
  (if (eq perldb-error-list t)
      (setq perldb-error-list nil))
  (while perldb-error-list
    (let ((next-error (car perldb-error-list)))
      (set-marker (car next-error) nil)
      (if (car (cdr next-error))
	  (set-marker (car (cdr next-error)) nil)))
    (setq perldb-error-list (cdr perldb-error-list))))

(defun perldb-parse-errors ()
  "Parse the current buffer as error messages.
This makes a list of error descriptors, perldb-error-list.
For each source-file, line-number pair in the buffer,
the source file is read in, and the text location is saved in perldb-error-list.
The function next-error, assigned to \\[next-error], takes the next error off the list
and visits its location."
  (setq perldb-error-list nil)
  (message "Parsing error messages...")
  (let (text-buffer
	last-filename last-linenum)
    ;; Don't reparse messages already seen at last parse.
    (goto-char perldb-parsing-end)
    ;; Don't parse the first two lines as error messages.
    ;; This matters for grep.
    (if (bobp)
	(forward-line 2))
    (while (re-search-forward compilation-error-regexp nil t)
      (let (linenum filename
		    error-marker text-marker)
	;; Extract file name and line number from error message.
	(save-restriction
	  (narrow-to-region (match-beginning 0) (match-end 0))
	  (goto-char (point-max))
	  (skip-chars-backward "[0-9]")
	  ;; If it's a lint message, use the last file(linenum) on the line.
	  ;; Normally we use the first on the line.
	  (if (= (preceding-char) ?\()
	      (progn
		(narrow-to-region (point-min) (1+ (buffer-size)))
		(end-of-line)
		(re-search-backward compilation-error-regexp)
		(skip-chars-backward "^ \t\n")
		(narrow-to-region (point) (match-end 0))
		(goto-char (point-max))
		(skip-chars-backward "[0-9]")))
	  ;; Are we looking at a "filename-first" or "line-number-first" form?
	  (if (looking-at "[0-9]")
	      (progn
		(setq linenum (read (current-buffer)))
		(goto-char (point-min)))
	    ;; Line number at start, file name at end.
	    (progn
	      (goto-char (point-min))
	      (setq linenum (read (current-buffer)))
	      (goto-char (point-max))
	      (skip-chars-backward "^ \t\n")))
	  (setq filename (perldb-grab-filename)))
	;; Locate the erring file and line.
	(if (and (equal filename last-filename)
		 (= linenum last-linenum))
	    nil
	  (beginning-of-line 1)
	  (setq error-marker (point-marker))
	  ;; text-buffer gets the buffer containing this error's file.
	  (if (not (equal filename last-filename))
	      (setq text-buffer
		    (and (file-exists-p (setq last-filename filename))
			 (find-file-noselect filename))
		    last-linenum 0))
	  (if text-buffer
	      ;; Go to that buffer and find the erring line.
	      (save-excursion
		(set-buffer text-buffer)
		(if (zerop last-linenum)
		    (progn
		      (goto-char 1)
		      (setq last-linenum 1)))
		(forward-line (- linenum last-linenum))
		(setq last-linenum linenum)
		(setq text-marker (point-marker))
		(setq perldb-error-list
		      (cons (list error-marker text-marker)
			    perldb-error-list)))))
	(forward-line 1)))
    (setq perldb-parsing-end (point-max)))
  (message "Parsing error messages...done")
  (setq perldb-error-list (nreverse perldb-error-list)))

(defun perldb-grab-filename ()
  "Return a string which is a filename, starting at point.
Ignore quotes and parentheses around it, as well as trailing colons."
  (if (eq (following-char) ?\")
      (save-restriction
	(narrow-to-region (point)
			  (progn (forward-sexp 1) (point)))
	(goto-char (point-min))
	(read (current-buffer)))
    (buffer-substring (point)
		      (progn
			(skip-chars-forward "^ ,\n\t(")
			(point)))))


------------------------------

Date: 21 May 97 14:11:36 GMT
From: "Fredrik Lindberg" <flg@vhojd.skovde.se>
Subject: Re: New Perl User Question
Message-Id: <01bc65f0$e54cbfe0$e20f10c2@odens.di.vhojd.skovde.se>

Troy Bull <troy@pop.uni.edu> wrote in article <5lsvm0$pbr@news.uni.edu>...
> I am new to perl and I have a question.
> I am trying to write a perl program that will open a file, search for a
> word, then return the next word in the file and write the output to yet
> another file.

Hi!

Here is one way of doing it (I only tested it with your example file, and
the
program reads the entire file into memory):

#!/usr/bin/perl -w
#
my($word, $content);

$word = shift;  # Get regexp from commandline first.

# Then loop through each remaining argument, setting $filename

foreach $filename (@ARGV) {

   # Try to open the file, or die if unsuccessful

    open(FILE, "<$filename") or die("Unable to open $filename: $!\n");

   # the <FILE> construct is used in a LIST context, which causes the 
   # entire file to be read in one big slurp. The various lines are then 
   # joined together with the null string ('') and assigned to the $content
variable

    $content = join '', <FILE>;  # slurp

   # Now try to find the word inside the content, and loop over the string
   # until no more matches are found (the /g modifier is used for this)
   #
   # The regexp used says we want to find 1 or more nonword characters
   # followed by one or more word characters after the found string.
   # The word characters are captured with the paranthesis and stored 
   # by perl in the $1 variable

    while ($content =~ /$word\W+(\w*)/go) {
        print "$filename: $1\n";
    }
} 

__END__

You might want to check out the perlre man page for more information about
the regexp's, and the perlfunc pages for more information about join() and
open() function. For information about scalar and list (array) context,
check out
the perldata man page.

Hope this helps

/Fredrik


------------------------------

Date: Wed, 21 May 1997 11:12:31 -0600
From: joet@miles33.com
Subject: Passing Variables between Programs
Message-Id: <864230115.17762@dejanews.com>

    I'm new to Perl programming, so my apologies if this is trite.
I have a Perl wrapper which will execute two separate Perl scripts.
The first script, when finished, needs to pass one of it's variables
to the second script. I tried to use the return() function, but it is
only valid between subroutines. I have looked at the Perl FAQ, but to
no avail.

I could do this by writing the data to a temporary disk file, or
setting up a shared memory area (the script will run under Solaris),
but is this the best way?

Does anyone have any suggestions on the best way of doing this in Perl?

Any guidance is appreciated.

Thanks in advance,
Joe

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


------------------------------

Date: Wed, 21 May 1997 11:14:03 -0500
From: Darin Burleigh <burleigh@hackberry.chem.niu.edu>
Subject: Re: Perl and CGI
Message-Id: <33831F4B.670C@hackberry.chem.niu.edu>

Kendal Van Dyke wrote:
> 
> I'm new to the newsgroup (and perl actaully), so forgive me if this is
> off-subject (not sure which of the perl newsgroups was the correct one
> for this), but I need a quick bit of programming help.

have your read:
The Idiot's Guide to Solving Perl CGI Problems, yet?
http://www.perl.com/perl/faq/idiots-guide.html


-- 
==========================================================
 - darin
burleigh@hackberry.chem.niu.edu
\\//\\//.\\//\\//.\\//\\//. http://hackberry.chem.niu.edu/HOME/dcb/
 '2 kinds of green, look out!' - dieter rot


------------------------------

Date: Wed, 21 May 1997 12:52:00 GMT
From: sash@nite.org.il (Sasha Higer)
Subject: Perl and ms-access
Message-Id: <3382ef40.16915212@news.netvision.net.il>

Does anybody have a experience of connecting Perl with
microsoft access database.
I saw the activeware's faq (9.4) but it's not detailed enough.
thanks.


------------------------------

Date: 21 May 1997 14:19:02 GMT
From: brother@diku.dk (Peter Makholm)
Subject: PGP::Pipe (Can't locate new)
Message-Id: <5lv08m$1ke@vidar.diku.dk>

I'm using the module PGP::Pipe for an automatic moderator.

I have a script beginning with the following:

	#!/pack/perl/bin/perl

	use lib 'home/brother/perl';
	use PGP::Pipe;

	$pgp = new PGP "/home/brother/.pgp", "/pack/pgp/lib/";

When I tries to run it Perl says:

	Can't locate object method "new" via package "PGP" at testpgp line 6.

Any ideas?
-- 
      Peter Makholm       |       E-mail:     |    Adresse:
 Computer Science & Math  |  brother@diku.dk  | Aamosevej 44
 University of Copenhagen |       Phone:      | 2610 Rodovre
                          | (+45) 42 84 55 82 | Danmark


------------------------------

Date: 21 May 1997 14:24:04 GMT
From: "Petra Smits" <P.Smits@stud.frw.ruu.nl>
Subject: Problems with form handling
Message-Id: <01bc65f3$22e7b4c0$4a40d383@klaveren.frw.ruu.nl>

Hello

I am making a test about geography on the WWW. For this test I made an
ascii file with the questions and answers. A PERL script randomly chooses
questions and answers from this "database" and writes these to a HTML form.
The numbers of the randomly picked questions are sent to the HTML form as
an hidden field, so afterwards it  is possible to see which questions are
asked, for example questionnumbers 8, 10 and 49, with the names in the HTML
form question8, question10 and question49.
I have two problems with reading the given answers:

-The questionnumbers are sent with one name (question_number) and the
number PERL gives back is not 8 and 10 and 49, but 81049

-I only know to read each name-value pair. So my script will be very
long...
$anwer_question1=$in{question1}
$anwer_question2=$in{question2}
$anwer_question3=$in{question3}
and so on...
 
Does anybody know how I can only look at the randomly picked questions.
Something like 
@i=(8,10,49)
$answer$i=$in{$i}


Thank you very much,

Petra Smits


------------------------------

Date: 21 May 1997 10:17:17 -0400
From: clay@panix.com (Clay Irving)
Subject: Re: timelocal.pl ?
Message-Id: <5lv05d$2l6@panix.com>

In <strider-ya02408000R2005971558080001@news.winternet.com> strider@ShadowMAC.org (Raul Almquist) writes:

>  I am using perl 5.003 on a Sun Sparc with Solaris OS.

>  I have been trying to utilize perl's time and date capabilities, but so
>far I can't get it to function as it states in Programming Perl states it
>should function, below is my little test script


>>>
>#!/usr/local/bin/perl5

>use Time::Local;

>$time = timelocal($sec,$min,$hours,$mday,$mon,$year);

>print $time
><<

Using Perl 5.003 on a Solaris 2.3 machine, this works fine:

#!/usr/local/bin/perl

	$time = localtime();

	print $time;


>  All I need is to get localtime and local date into a related pair of
>variables for another script...

>$Ldate    (in yyyy-mm-dd format)
>$Ltime    (in 24 hour hh:mm:ss format)

Oh! Perl Modules are your friend -- The Date::Format module is ideal for 
this. Why bang your head on the wall when you can do something simple 
like:

#!/usr/local/bin/perl -w

        use Date::Format;

	$Ldate = time2str("%Y-%m-%d", time);
	$Ltime = time2str("%T", time);

	print "$Ldate\n";
	print "$Ltime\n";

The output is:

	1997-05-21
	10:17:49

See: http://www.panix.com/~clay/perl/module.cgi?Date::Format

[ mailed and posted ]

-- 
Clay Irving                                        See the happy moron,
clay@panix.com                                     He doesn't give a damn,
http://www.panix.com/~clay                         I wish I were a moron,
                                                   My God! Perhaps I am!


------------------------------

Date: Wed, 21 May 1997 12:52:29 GMT
From: dharma@msys.net (Ron Picker)
Subject: Variables In Data Structures.
Message-Id: <5lur6b$sb9@snews5.zippo.com>

I'm attempting to use variables, without success, in data structures
as demonstrated in the following trivial test case.

#!/usr/bin/perl
%dom = (
  "Var1"   => "bar",
  "Var2"   => "foo $dom{Var1}"
);

print "$dom{Var1}\n"; #case 1
print "$dom{Var2}\n"; #case 2

I expected to have "foo bar" printed for print case 2 but only get
foo.

Please provide suggestions.

Thank you.


Ron Picker
DharmaSystems
dharma@msys.net
Druid Hollow
French Creek, WV.



------------------------------

Date: 21 May 1997 14:19:12 GMT
From: nvp@shore.net (Nathan V. Patwardhan)
Subject: Re: Variables In Data Structures.
Message-Id: <5lv090$h8d@fridge-nf0.shore.net>

Ron Picker (dharma@msys.net) wrote:

: I expected to have "foo bar" printed for print case 2 but only get
: foo.

: Please provide suggestions.

Use perl -w as something seems to be fishy in Denmark (or at very least 
in the hash).

--
Nathan V. Patwardhan
nvp@shore.net



------------------------------

Date: 21 May 1997 14:11:39 GMT
From: erik@paxp01.mipool.uni-jena.de (Erik Braun)
Subject: Re: winnuke
Message-Id: <slrn45o60kr.bfl.erik@paxp01.mipool.uni-jena.de>

On 16 May 1997 00:26:39 GMT, Zachary Fisk <fisk@homarus.ccsu.ctstateu.edu> wrote:

>Has anyone gotten the perl version of winnuke to work?

yeah, no problem. Please learn enough perl to be a "knowledgable people",
and so you should not have a problem. But maybe then there is the bug
in WinNT removed...

erik
-- 
erik@minet.uni-jena.de


------------------------------

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 508
*************************************

home help back first fref pref prev next nref lref last post