[comp.lang.perl] Help for a new-born perl user....

eillihca@embezzle.StanFord.EDU ( Achille Hui, the Day Dreamer ) (01/15/91)

    I have just compiled perl3.0@44 on our dept. machines and start to
write perl-scripts, then I encounter the following two problems:

  1) consider the following pieces of codes:

        if(open(pp,"|less")){
		while($_ = <>){
			printf(pp "%s",$_);
		} close(pp);
	}

    If I pump a lot of data into <pp> and exit the program ( less in this
    case ) before it exhausts all those data, the perl script simply die
    prematurely...  I discover when I try to close the pipe in the script
    , perl will try to flush remaining data onto the pipe. If the other
    end close the pipe first, a SIGPIPE will be generated.... Is it
    more sensible that `` close '' will return will an indication of error
    instead of simply bumping me out ???? Of course, I can avoid this by
    sandwiching the while loop and the close statement with a signal
    handler on SIGPIPE. But this is sort of gloss ... Is there more
    elegant way to handle this ?

   2) how to tell a given string is a valid regular expression or not ?
      Basically, I want to get a regular expression $pattern   from an
      user and matches it with a fixed list of strings and do something
      on them..

	while($_ = shift(@strings)){
		if ( $_ =~ /^$pattern/ ){
			... doing something .....
		}
	}

      However, if the user accidentally type in a malformed regular
      expression, perl will kick me out again....

In general, is there a way to make perl ignore such ``fatal'' error ?

                                           +--------------------------------+
+------------------------+                 | eillihca@embezzle.StanFord.EDU |
|  Achille Hui        +--------------------|           -01/15/91-           |
|  The Day Dreamer... |  Dept. of Physics, +--------------------------------+
+---------------------|  Stanford University. |
                      +-----------------------+