[9472] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3066 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Jul 5 22:07:13 1998

Date: Sun, 5 Jul 98 19:00:32 -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           Sun, 5 Jul 1998     Volume: 8 Number: 3066

Today's topics:
    Re: -w on production code (was Re: better way of gettin <zenin@bawdycaste.org>
    Re: [Q] mod_perl <ryan@steelplan.com.au>
        [Q]:  cgi-lib.pl | use strict; | Upload file restrictio <ryan@steelplan.com.au>
        Character  entity for <space>? (Les Jones)
    Re: Character  entity for <space>? <che@debian.org>
    Re: Character  entity for <space>? (Les Jones)
    Re: Determining Users on NT Server with Perl <metcher@spider.herston.uq.edu.au>
    Re: Development / Test Environments (John Springer)
    Re: Editeurs pour Perl? <ryan@steelplan.com.au>
    Re: Editors for Perl? <ryan@steelplan.com.au>
    Re: Extracting a string (easy question) (Mark-Jason Dominus)
    Re: GNUS and cperl-mode conflict? <lmi@gnus.org>
    Re: Help: perl5.00404 and UnixWare 2.1.2 (locale proble <dlgolden@ibm.net>
        NEVER "call warn() and return undef" (Re: question abou <zenin@bawdycaste.org>
    Re: package available to search local HTML pages? Re: l <jdf@pobox.com>
    Re: perl cgi/telnet <rpsavage@ozemail.com.au>
    Re: Perl download (acting as a Browser)<- SOLUTION! (an <douglas@home.com>
    Re: Perl download (acting as a Browser)<- SOLUTION! (an (Josh Kortbein)
    Re: regexp s/// for removing tail end of string <jerry@fitzweb.com>
    Re: regexp s/// for removing tail end of string (Ronald J Kimball)
    Re: setting directory permissions... <ryan@steelplan.com.au>
        shell script and perl script <guest@hantan.postech.ac.kr>
    Re: Substitution-bug? (Ronald J Kimball)
        subtle variations of 'print (&&|and) die;' <danboo@negia.net>
        Web Counters... <davel@mail.aone.com>
    Re: Web Counters... (Josh Kortbein)
    Re: Why no Perl news/mailreader? <Russell_Schulz@locutus.ofB.ORG>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: 6 Jul 1998 00:24:24 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: -w on production code (was Re: better way of getting the last modified file?)
Message-Id: <899685210.339889@thrush.omix.com>

Daniel Grisinger <dgris@rand.dimensional.com> wrote:
: >Do you believe everything you read? :-(
:
: No, only those things that make sense.  Not introducing
: unnecessary panic among my users makes sense.

	If using -w reports a warning in a user's environment, there
	is a chance it's caused by a bug that you should probably be
	made aware of.  The user sees the warning, reports it, and
	you can check it out.  If -w isn't used, you may lose critical
	information needed to fix the bug.

	But if you're creating CGI code on a Netscape server, ignore
	all the above and lose -w since in that particular setting
	you can trash your entire site by simply upgrading perl as
	a new warning could cause Netscape to think that the CGI
	is broken (read: Netscape servers are braindead).

-- 
-Zenin
 zenin@archive.rhps.org


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

Date: Mon, 6 Jul 1998 08:11:02 +0800
From: "Ryan Snowden" <ryan@steelplan.com.au>
Subject: Re: [Q] mod_perl
Message-Id: <6np4rf$poa$1@news.iinet.net.au>

Cheers!

Bekman Stanislav wrote in message 
|You are envited to visit http://perl.apache.org to learn more about
|mod_perl . You have FAQs and complete modules documentation at this URL.
|Most of your answers are covered in the FAQs, the rest can be asked at
|the mod_perl mailing list available from the same place or by browsing
|its archives.




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

Date: Mon, 6 Jul 1998 08:32:43 +0800
From: "Ryan Snowden" <ryan@steelplan.com.au>
Subject: [Q]:  cgi-lib.pl | use strict; | Upload file restrictions
Message-Id: <6np647$sna$1@news.iinet.net.au>

I was using cgi-lib.pl, and an upload file example that came with it.  I
modified the necessary bits to fit in, and it worked! hooray! but only for
small files it seemed.

Sooo.. I re-wrote the upload script, but kept on using cgi-lib.pl - still
didn't fix the problem.

Iiii...  then removed the line use strict; and now my upload limit is not
restricted.

I know I should have been using CGI.pm, but at the time cgi-lib.pl was
available.  Has anyone else the same problem?



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

Date: Sun, 05 Jul 1998 18:28:51 -0400
From: lesONAYAMSPAYjones@usit.net (Les Jones)
Subject: Character  entity for <space>?
Message-Id: <lesONAYAMSPAYjones-ya023480000507981828510001@news.usit.net>


Clueless Perl newbie alert.

I've found regexp equivalents for tab (\t), new line (\n), etc., but
nothing for the space character. I've consulted three books and two online
resources, but they all avoid the space character. What's up with that?

Just as background, I'm writing a script to remove spaces from the
beginning of lines. I've tried ^\s+, but that gets rid of blank lines and
makes a mess of the file.

Any help appreciated.

-- 
+  Les Jones  +  56K Modem Home Page   + http://www.56k.com/  +

         -= email address modified. with Pig Latin! =-


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

Date: 05 Jul 1998 15:35:56 -0700
From: Ben Gertzfield <che@debian.org>
Subject: Re: Character  entity for <space>?
Message-Id: <ytthg0w7woj.fsf@gilgamesh.cse.ucsc.edu>

>>>>> "Les" == Les Jones <lesONAYAMSPAYjones@usit.net> writes:

    Les> Clueless Perl newbie alert.

    Les> I've found regexp equivalents for tab (\t), new line (\n),
    Les> etc., but nothing for the space character. I've consulted
    Les> three books and two online resources, but they all avoid the
    Les> space character. What's up with that?

Have you tried using a space?

$string =~ s/^ +//;

Ben

-- 
Brought to you by the letters V and U and the number 3.
"I'm calling from the plane. I'll call you when I get there." -- TMBG
Debian GNU/Linux -- where do you want to go tomorrow? http://www.debian.org/
I'm on FurryMUCK as Che, and EFNet and YiffNet IRC as Che_Fox.


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

Date: Sun, 05 Jul 1998 21:19:46 -0400
From: lesONAYAMSPAYjones@usit.net (Les Jones)
Subject: Re: Character  entity for <space>?
Message-Id: <lesONAYAMSPAYjones-ya023480000507982119460001@news.usit.net>

In article <ytthg0w7woj.fsf@gilgamesh.cse.ucsc.edu>, Ben Gertzfield
<che@debian.org> wrote:

> >>>>> "Les" == Les Jones <lesONAYAMSPAYjones@usit.net> writes:
> 
>     Les> Clueless Perl newbie alert.
> 
>     Les> I've found regexp equivalents for tab (\t), new line (\n),
>     Les> etc., but nothing for the space character. I've consulted
>     Les> three books and two online resources, but they all avoid the
>     Les> space character. What's up with that?
> 
> Have you tried using a space?
> 
> $string =~ s/^ +//;

Boy, am I glad I confessed to being a clueless Perl newbie right up front. :-)

Thanks! That worked.

-- 
+  Les Jones  +  56K Modem Home Page   + http://www.56k.com/  +

         -= email address modified. with Pig Latin! =-


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

Date: Mon, 06 Jul 1998 11:28:46 +1000
From: Jaime Metcher <metcher@spider.herston.uq.edu.au>
Subject: Re: Determining Users on NT Server with Perl
Message-Id: <35A0284E.ACC1B707@spider.herston.uq.edu.au>

How about:

@sessions = `net session`;

-- 
Jaime Metcher

Dave Wright wrote:
> 
> Is there a way to determine all of the logged in users on a NT
> server using Perl/Win32? Thanx.
> 
> Dave
> dhwright@mindspring.com


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

Date: Sun, 05 Jul 1998 15:33:38 -0700
From: john@digitalmx.com (John Springer)
Subject: Re: Development / Test Environments
Message-Id: <john-0507981533380001@204.202.49.162>

In article <3587D647.6046D381@ams.org>, Daniel Pelton <dnp@ams.org> wrote:

>Has anyone else had any experience doing this and how should I 
>handle absolute paths in Perl CGIs and html pages?

The easiest way is to get the environments set up so the paths are the
same.  This can be done with aliasing sometimes.  If that isn't possible,
then minimize the number of absolute paths you have to deal with by using
mostly relative path names.  Where you have to have a path, specify the
variable portion of the path in a variable, not the entire name down to
the file.

So like:

$path='dev1/users/web';
and later
$FILE1="$path/MYFILE";

Hopefully, you can create the $path variable by computing it based on an
envirnomental variable or based on the path to the script.  Then the code
can actually be the same all the time.

-- 
      John Springer
      http://www.digitalmx.com/john
        


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

Date: Mon, 6 Jul 1998 08:34:08 +0800
From: "Ryan Snowden" <ryan@steelplan.com.au>
Subject: Re: Editeurs pour Perl?
Message-Id: <6np66t$ss0$1@news.iinet.net.au>

yeah, what he said.

 ... <snip> ..
|>un bon editeur pour Perl, si possible freeware, ou il y aurait une aide
|>en ligne sur les mots clis de Perl (ex: Shift F1 sur le mot cle GREP).
|>
|There are plenty of good editors out there, some of which might make a
|fair fist of syntax highlighting but as far as I know there are none
|that will be able to provide assistance in that manner although it
|might be possible with some of the more configurable editors available
|to write a macro to do that.
|
|>Merci de votre aide,
|>Dominique Cretel
|




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

Date: Mon, 6 Jul 1998 08:22:45 +0800
From: "Ryan Snowden" <ryan@steelplan.com.au>
Subject: Re: Editors for Perl?
Message-Id: <6np5hf$rbr$1@news.iinet.net.au>

Emacs or XEmacs is rather good also.

Sitaram Chamarty wrote in message ...
|VIM is an editor that is a "clone" of vi.  Like all vi-clones, it
|extends the functionality *tremendously* - I am a big fan.

 ...
|
|HTH



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

Date: 5 Jul 1998 21:49:41 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Extracting a string (easy question)
Message-Id: <6npafl$sk2$1@monet.op.net>
Keywords: eccentric grandeur sonant vocable


In article <359EFAF1.9FD35A1A@melbpc.org.au>,
David Hamilton  <hamilton@melbpc.org.au> wrote:
>Howdy,
>
>Can someone please tell me how to extract the first set of characters in
>a line before a space,


awk '{print $1}'   <input >output



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

Date: 06 Jul 1998 00:55:18 +0200
From: Lars Magne Ingebrigtsen <lmi@gnus.org>
Subject: Re: GNUS and cperl-mode conflict?
Message-Id: <m3lnq7lxgp.fsf@sparky.gnus.org>

jzawodn@wcnet.org (Jeremy D. Zawodny) writes:

>   Wrong type argument: buffer-or-string-p, t
> 
> The last line, of course, being the clincher.
> 
> Is this a known problem?

Nope.

> How can I diagnose/fix it?

`(setq debug-on-error t)', repeat the bug and mail me the resulting
backtrace.

-- 
(domestic pets only, the antidote for overdose, milk.)
  lmi@gnus.org * Lars Magne Ingebrigtsen


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

Date: Sun, 05 Jul 1998 18:00:12 -0500
From: Dennis Golden <dlgolden@ibm.net>
Subject: Re: Help: perl5.00404 and UnixWare 2.1.2 (locale problem)
Message-Id: <35A0057C.20E6@ibm.net>

Sitaram Chamarty wrote:
> 
> On Tue, 30 Jun 1998 15:36:56 -0500, Dennis Golden
> <dlgolden@ibm.net> wrote:
> 
> >This is a multi-part message in MIME format.
> 
> Dont do that.  The second M in "MIME" stands for mail.  This is
> usenet, not email.
> 
> >perl: warning: Please check that your locale settings:
> >       LC_ALL = (unset),
> >       LC_MESSAGES = "/etc/inst/locale/C",
> >       LANG = "C"
> >    are supported and installed on your system.
> 
> Seems pretty clear to me.  Have you tried comparing the output of
> the %ENV printouts for both cases.  I did - from your post:
> 
> The following line was extra in your failing case.
> 
>     LC_MESSAGES=/etc/inst/locale/C
> 
> Figure out how that's getting set in your failing case, or unset
> it forcibly and try again.

Yes I did notice this and I have no control over the environment because
it is set by lpsched.  The directory is there and looked okay; however,
after your response, I found that it is missing the LC_MESSAGES
subdirectory.  I am looking for the cause in UnixWare.

Thanks for your response.

Dennis


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

Date: 6 Jul 1998 00:17:22 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: NEVER "call warn() and return undef" (Re: question about objects)
Message-Id: <899684788.742259@thrush.omix.com>

John Porter <jdporter@min.net> wrote:
: Here's a tip: if your constructor won't returned a properly blessed
: reference, have it call warn, and return undef.
                          ^^^^
	Ack!  No!  DO **NOT** DO THIS!

	Call warn() for "questionable" code usages, as perl does, but do
	*not* call warn() for *error* conditions.  That's *NOT* what
	it's for!

	To do this almost completely eliminates any possibility of the
	application doing something useful with the error condition. -Sure,
	they can set $SIG{__WARN__} but that's very kludgey at best and
	leads to almost no reusability (stacking $SIG{__WARN__} handlers
	is a nightmare).

	A *MUCH* better method is to set a package global (say,
	$MyPackage::Error) and return undef (as the DBI module and many
	others use).  Or if you must, throw an exception via confess, croak,
	or die (in that order), but do *not* call warn() and think that
	all will be happy with the world.

	Whatever you do, documenting it is rule #1.  The IO::Socket module
	constructor for instance, sets $@ (why this var, I have no idea.
	It's just a bad idea altogether...), calls warn(), and returns
	undef. The warn() should never be there (who's to say that there is
	someone sitting at the console to see that warn() fly by?), and $@
	is not only a bad choice ($IO::Socket::Errstr would be much, much
	better) it's not documented at all.  What if I wanted to print a
	clean error message to a log file with time stamp? I guess I'm out
	of luck, unless I want to do some hackery with stderr or
	$SIG{__WARN__}...

	More over, by the perl convention of nothing existing unless it's
	documented, IO::Socket has absolutely no error handling whatsoever.
	-Nether the warn() or the setting of $@ is documented anywhere
	in IO::Socket.

	Errors are *useless* unless the calling environment can act on
	them.  It's the same reasons why open(args) or die "error" is
	more often then not less then useless simply because $! isn't
	there.
	
	"Doctor, something hurts.  Well, where does it hurt?  Sorry, but
	I'm just too lazy to tell you, can't you just guess and try to
	fix it?".  It's a damn shame sometimes that software "engineers"
	can't be sued for malpractice...

	Sorry to be so long winded, but advice like "call warn and return
	undef" has lead to many, many useless modules being created. -IMO,
	any code that can't inform its caller about the nature of an error
	is less then useless.

	BTW, for the still awake, here's a simple example of good error
	reporting code:

	=pod

	  my $obj = new My::Object ($foo, $bar)
	      or die "Can't create new My::Object: $My::Object::Error, stopped";

	=cut

	use vars qw($Error);
	sub new {
	    my $class   = shift;
	    $class      = ref ($class) || $class;

	    my $self    = bless {}, $class;
	    
	    my $file    = "Some_File";
	    $self->{FH} = new IO::File ("$file")
	        or ($Error = "Can't open '$file' for reading: $!", return);
	
	    return $self;
	}

	We document our error reporting interface, and when we issue the
	error message we give the caller as much information as we can
	about the problem that caused the error.  This includes the action
	that was being attempted, "Can't open", the data that it was trying
	to work on, "'$file'" (Note: We also put it in quotes so we can
	tell if extra spaces where the cause, etc), we tell the exact type of
	action, "for reading", and any other error messages we can get, "$!".
	We also NEVER append a newline, "\n", to the end so that the caller
	knows exactly the line number of the code where the error took place.

	Any code that just calls, "warn $! and return" should be burned,
	along with the programmer that wrote it.

-- 
-Zenin
 zenin@archive.rhps.org


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

Date: 05 Jul 1998 21:31:02 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: dtbaker@flash.net
Subject: Re: package available to search local HTML pages? Re: limits of glob() ?
Message-Id: <u34vyal5.fsf@mailhost.panix.com>

Dan Baker <dtbaker_@flash.net> writes:

> Bob Trieger wrote:
>> If you have the standard port of perl for win32, you have all the
>> documentation in html format. You can combine them all into one
>> document and then use `cntl-f' to search that document in your
>> browser.

> not a bad idea.... but it must make a MONSTER HTML page!  I'm
> thinking that it may be a good project to build a little search
> engine to zip thru the docs looking for a word or phrase. Unless of
> course someone else has already done it and has a package they would
> like to share?!

The following is provided without warranty or anything, etc.  It uses
a free Win32-compatible grep, as indicated in the source.  Enjoy.
Umm, looking over it, I see that it's not taint-safe.  Caveat
webmastor.

   #!/usr/bin/perl -w

   #
   # This script was written by Jonathan Feinberg.
   # It's in the public domain; you may do with it what you wish.
   #

   use CGI qw/ :standard :nph /;
   use CGI::Carp qw/ fatalsToBrowser /;

   require HTML::FormatText;
   use HTML::Parse;

   $|=1;

   #http://www.geocities.com/SiliconValley/Lakes/4889/agrep.html
   $AGREP = '/agrep/agrepw32.exe';
   $PERLDOC_ROOT = '/webroot/perl';
   $PERLDOC_URL = 'http://localhost/perl';

   my $search_string = param('search_string');

   my $last_search = cookie('last_search') || 'Randal';
   my $cookie = cookie( -NAME => 'last_search',
			-VALUE => $search_string || $last_search,
			-EXPIRES => '+10y',
		      );

   print header(-COOKIE => $cookie), start_html();

   do_form();

   if (defined $search_string) {
      do_results();
      do_form();
   }

   print end_html();

   sub do_form()
   {
      print start_form();
      print "<table>\n";
      print qq(<tr><td align="left" colspan="3">);
	 print "Search for:";
	 print textfield( -NAME => 'search_string',
			  -DEFAULT => $last_search,
			  -SIZE => 50
			);
      print qq(</td></tr>\n);

      print qq(<tr><td colspan="3" align="center">),
	    submit,
	    qq(</td></tr>\n);
      print qq(</table>\n);
      print end_form();
   }

   sub do_results
   {
      $formatter = new HTML::FormatText or die "$!";
      open (GREP, qq{$AGREP -ir "$search_string" $PERLDOC_ROOT |})
	 or die "$!";
      my $current_page = '';
      my $examples = 0;
      while (<GREP>) {
	 next if /^Grand Total/;
	 chomp;
	 my($page, $text) = split ':', $_, 2;
	 $page =~ s{\\}{/}g;
	 $page =~ s/^$PERLDOC_ROOT/$PERLDOC_URL/;
	 if ($page ne $current_page) {
	    $current_page = $page;
	    $examples = 0;
	    print qq( </ul><a href="$page">$page</a><ul> \n);
	 }
	 next if $examples++ > 4;
	 my $html = parse_html($text);
	 $text = $formatter->format($html);
	 $text =~ s{($search_string)}{<b>$1</b>}g;
	 print qq(<li><code>$text</code>\n);
      }
      close GREP;
   }

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
http://pobox.com/~jdf/


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

Date: 5 Jul 1998 23:05:09 GMT
From: "Ron Savage" <rpsavage@ozemail.com.au>
Subject: Re: perl cgi/telnet
Message-Id: <01bda86a$4b7c9ee0$43ea1286@steelres-pcm657.resmel.bhp.com.au>

# Name:
#	sgi.pl.
#
# Purpose:
#	Start an XTerm on dilbert.
#

use integer;
use strict;

use Net::Telnet;

#---------------------------------------------------------------------------
---

my($host, $username, $password, $prompt, $logFileName) =
(
	'dilbert',
	'rons',
	'password',
	'/rons\@dilbert\[.+\]\[\d+\] /',
	'sgi.log',
);

my($session);

$session = new Net::Telnet
(
	Timeout	=> 10,
	Prompt	=> $prompt
);

$session -> input_log($logFileName);
$session -> open($host);
$session -> login($username, $password);
$session -> cmd('red');		# XTerm
$session -> cmd('blue');		# XTerm
$session -> cmd('yellow');	# XTerm
$session -> cmd('green');	# XTerm
$session -> close();
exit(0);


dmorel <emorel@stny.lrun.com> wrote in article
<359FC4ED.9C4958AE@stny.lrun.com>...
> Hi,
> does anyone know how to send a list of commands to a telnet client via a
> perl/cgi script?
> I have been able to implement a script that will launch the servers
> telnet app (using a bat file) and
> connect to the proper port. After that I am failing, I need to be able
> to send a few comands (or lines
> of text from a file) which would work using -S: textfilename.txt if I
> was using an FTP client, but I have
> had no luck with telnet.
> tia,
> dmorel@stny.lrun.com
> 
> 


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

Date: Sun, 05 Jul 1998 22:26:24 GMT
From: Douglas Galbraith <douglas@home.com>
Subject: Re: Perl download (acting as a Browser)<- SOLUTION! (and another problem)
Message-Id: <359FFD72.D2413BC0@home.com>

Thank you Jonathan and Bill for the pointers! ... I was able to solve my
problem with your help (after just a little teeth pulling).

To recap: my problem was how do you download information off of the web
with perl?

In case there are others with this problem, I'm posting the solution
below.


#!/usr/bin/perl
use LWP::UserAgent;

$ua = LWP::UserAgent->new;
$request = HTTP::Request->new(GET => 'http://www.yahoo.com');
$response = $ua->request($request);
$content = $response->content();
print $content . "\n";


I would also recommend that you install the new version of perl for
Windows95 from:
  http://www.activestate.com/ActivePerl/download.htm 
This new software from activeware comes with the CPAN libraries ready to
go, so that YOU don't have to hassle with getting and installing them
(one stop shop) -- a big plus for Windows95 users who don't want to
become system managers ;) (sigh of relief).

Now ... for my next problem.  The variable "content", in the script
above, appears to be just one big string, instead of an array of lines. 
So it can not be parsed line by line in its present form.  

So ... how do I convert it into an array of lines so that I can parse it
line by line?

Stay tuned ... same Bat Time ... same Bat Channel ...


Douglas Galbraith wrote:
> 
> Hello,
> 
> Does someone have an example perl script which downloads information off
> the web using a Window95 machine?  (For example: how would you download
> a web page from "http://www.yahoo.com" and pull information from it?)
> 
> I'm asking for this help because my perl manuals focus on server side
> uses, not the client side (just the opposite of what I need).
> 
> I'd like to use a perl script to download information off of the net and
> process it on my local Windows95 machine.  (For example, downloading
> news articles and stock quotes).  I've installed perl and run some test
> scripts successfully.  I do NOT have a server installed on my machine.
> But since my browsers access web sites without a local server, I would
> assume that perl scripts should also be able to access those same sites.
> 
> Below is my system configuration:
>  system:        Windows95 (4.00.950a)
>  perl version:  perl 5.003_07
>  perl download:
> ftp://ftp.activestate.com/Perl-Win32/Release/Pw32i316.exe
>  browsers:      Internet Explorer 3.02
>  browsers:      Netscape Communicator 4.02
> 
> thanks for the help in advance;
> DGalbra862@aol.com


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

Date: 5 Jul 1998 22:42:08 GMT
From: kortbein@iastate.edu (Josh Kortbein)
Subject: Re: Perl download (acting as a Browser)<- SOLUTION! (and another problem)
Message-Id: <6novg0$2qb$1@news.iastate.edu>

Douglas Galbraith (douglas@home.com) wrote:
: So ... how do I convert it into an array of lines so that I can parse it
: line by line?

Try

@content = split(/\n/, $content);

Though if this is hairy HTML you might rather use the HTML::Parse module
to get at the content of the page.


cheers,
Josh

--

__________________________________________
She had heard all about excluded middles;
they were bad shit, to be avoided.
            - Thomas Pynchon



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

Date: Sun, 5 Jul 1998 18:12:55 -0500
From: "Fitz" <jerry@fitzweb.com>
Subject: Re: regexp s/// for removing tail end of string
Message-Id: <6np19m$fcd$1@news.iquest.net>

Thanks Ryan, works like a charm.  Now I just have to understand why, LOL.  I
enjoy figuring out regexp's; haven't had as much fun since learning
calculus.

Thanks again
Fitz

Ryan Gendron wrote in message <359FF76B.F93E9140@secretshopnet.com>...
>Hi Jerry
>$path =~ s/[^\/]*$//;
>Try:
>





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

Date: Sun, 5 Jul 1998 21:56:16 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: regexp s/// for removing tail end of string
Message-Id: <1dbprap.1dyhmou11s0hooN@bos-ip-1-99.ziplink.net>

Jerry <jerry@fitzweb.com> wrote:

> I have a string that is a full path to a file, i.e.
> dir/subdir/subsubdir/file.ext  What I want to do is strip off the file name,
> leaving just the path info (with the final / ) in a string.  The paths will
> have a varying number of directories, so I don't think I can use split to
> just grab all the dirs, throw out the last one, and join the remainder
> together. (If this is the way to go, please show me I can't see it).

($file) = $path =~ m{([^/]*)$};

use File::Basename;
$file = basename($path);

> I tried substitution, using this:
> $path =~ s/\/.*?$//;
> but it strips off everything after the first '/'.  I thought the '.*?' would
> give  me the minimal match, and the '$' would make the match start at the
> end of the string, but I'm wrong.

Regardless of greediness, the regex will always match the *leftmost*
string.  With greedy matching, it's the longest leftmost, and with
non-greedy matching the shortest leftmost, but it's still the leftmost.
Similarly, '$' doesn't make the match start at the end of the string, it
makes it *end* at the end of the string.  Regex matching always proceeds
from left to right.

_Mastering Regular Expressions_, by Jeffrey Friedl, includes an
excellent explanation of this and just about every other aspect of
regular expressions.

> Checked the FAQ, newsgroup, manpages, several books.  All to no avail.  I
> know I'm missing something elementarily simple....

Did you check dejanews?  This question was answered just last week.
(Not to mention all the times before that.  :-)

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Mon, 6 Jul 1998 08:28:28 +0800
From: "Ryan Snowden" <ryan@steelplan.com.au>
Subject: Re: setting directory permissions...
Message-Id: <6np5s9$rom$1@news.iinet.net.au>

Oh! So is that how people use help documents! *slaps forehead* ;-)

Matt Knecht wrote in message ...
|
|Hmmm... I'm not sure.  Let me check 'perldoc -f mkdir'


|That doesn't seem to be much help.  I wonder what it means by umask... I
|better check 'perldoc -f umask'!
|
|Hmmm... looks like I need to check 'perldoc -f oct' next.
|

|Matt Knecht - <hex@voicenet.com>
|"496620796F752063616E207265616420746869732C20796F7520686176652066
|617220746F6F206D7563682074696D65206F6E20796F75722068616E6473210F"



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

Date: 6 Jul 1998 01:33:04 GMT
From: <guest@hantan.postech.ac.kr>
Subject: shell script and perl script
Message-Id: <6np9gg$b3k$2@news.postech.ac.kr>



Here is all I tried so far.

---this is pktgrab.cgi---
#!/bin/sh

echo $$ > /var/run/pktgrab.pid

touch ./flag

 ./ipgrab > logfile &
echo $! > /var/run/ipgrab.pid

sleep $1

rm ./flag
rm ./logfile

kill -9 $(cat /var/run/ipgrab.pid)
kill -9 $(cat /var/run/pktgrab.pid)

---this is test.cgi that calls pktgrab.cgi above---
#!/usr/bin/perl

#this is the general cgi-lib.pl
require "cgi-lib.pl";

#parse user input form data
&ReadParse;

#I suspect this line....is it correct?
$TIME = $in{'time'}*60;

print "Content-type: text/html\n";
print "\n";
print "\n";

#execute pktgrab.cgi that grabs packet
#"0<&- 1>&- 2>&- &" is not to wait until pktgrab.cgi ends
system("./pktgrab.cgi $TIME 0<&- 1>&- 2>&- &");

open(html, "../html/analysis.html");
while(<html>)
{
print STDOUT $_ ;
}




When I make a html page that calls test.cgi(test.cgi calls pktgrab.cgi)
and pass an argument named "time", "&ReadParse;" parses it and
can be used using "$in{'time'}".

But I failed constantly.

the apache error log is
----------------------------------------
sleep: too few arguments
Try `sleep --help' for more information.
[Mon Jul  6 03:33:03 1998] access to /home/httpd/cgi-bin/pktgrab.cgi failed for 141.223.82.4, reason: Premature end of script headers
----------------------------------------

This is all I tried so far....
I think the sleep in pktgrab.cgi is the problem.....

anyone could kindly help me to make this stupid program go?



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

Date: Sun, 5 Jul 1998 21:44:26 -0400
From: rjk@coos.dartmouth.edu (Ronald J Kimball)
Subject: Re: Substitution-bug?
Message-Id: <1dbppte.ekdspk1r34mfoN@bos-ip-1-99.ziplink.net>

[posted and mailed]

First off, let me answer your subject.  No, it's not a bug.

Mark <admin@asarian-host.org> wrote:

> while (<STDIN>) {
>     push(@header, $_);
> }

@header = <STDIN>;

> $number = "0";

Why do you assign a number as a string?

> foreach $whatever (@header) {

You never use $whatever.  Whatever are you doing?

>     if (@header[$number] =~

You are referring to a single element of @header, not a slice.  You
meant $header[$number].  It's an important distinction that will bite
you later on.

> /(\D|\b)\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(\D|\b)/i) {

/i?  So you can match all those uppercase numbers, right?

>         $middle = $&;

Do you really want $middle to include the non-digit characters before
and after the IP number?

Try to avoid using $&.  Put parentheses around the whole regex and use
$1 instead.  

>         $& =~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/i;

Okay, you don't want to keep the non-digit characters.  Repeating the
original match is a silly way to do it, though.

>         $new = $`.'[IP-address.masked]'.$';

Try to avoid $` and $' too.  All three of these variables slow down
every regex in your entire script.

>         @header[$number] =~ s/$middle/$new/;

Hmm...  All that for a simple substitution.

Replace the whole dang if block with the following:

$header[$number] =~
    s/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/[IP-address.masked]/;

>     }
> 
>     if (@header[$number] =~
> /(\D|\b)\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}(\D|\b)/i) {
>         $middle = $&;     
>         $& =~ /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/i;
>         $new = $`.'[IP-address.masked]'.$';
>         @header[$number] =~ s/$middle/$new/;
>     }

Hmm, this looks familiar...  Why do you do the same thing all over
again?

If you want to replace all instances, use the /g modifier.

$header[$number] =~
    s/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/[IP-address.masked]/g;


>     $number++;

Either do a proper for loop, or redo the foreach loop as

foreach $header (@header) {
  $header =~
    s/\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b/[IP-address.masked]/g;
}

> }
> 
> The routine looks for an IP-number, preceded by either a non-digit
> character or a boundary (like start-of-line,) and that either ends with
> a boundary or a non-digit too.

That's redundant.  A word boundary is the position between a word
character and a non-word character (or the beginning or end of the
string).  Digits are word characters, so in your regex any character
that would match \D would also cause \b to match.

> Then it replaces the true IP-number with
> a text, then replaces the originally found IP-number and its possible
> boundaries for what it found around the true IP numer with the new text
> inserted. So, from the following string:
> 
>   embed101.101.101.101embed
> 
> $& ($middle) becomes:
> 
>   d101.101.101.101e
> 
> Then it looks in here for the true IP; $& becomes:
> 
>   101.101.101.101
> 
> Then it sets $new to:
> 
>   'd'.'[IP-address.masked]'.'e' ($new = $`.'[IP-address.masked]'.$')
> 
> Finally, in the original string, it attempts to translate $middle
> (d101.101.101.101e) to d[IP-address.masked]e.

Alternatively, just match an IP address, and replace it.  Skip all this
mucking about with special variables and temporary variables and
repeated regexes and so on.

> The process seems rather
> lengthy, but it is really necessary to ensure that we really replace a
> properly identified IP-address.

The process is rather lengthy because you made it so contrived.  :-)

> Okay, nothing too fancy, except that is goes incredibly wrong. :) The
> iteration caused the prog to hang in a while-loop, hence the manual
> repetition. So, after feeding it this line:
> 
> Received: from anybody (ldn-p188.worldonline.nl [101.101.101.101])...
> 
> This came out (two-times iteraton):
> 
> Received: from anybody
> (ldn[IP-address[[IP-address.masked]]masked]-p188.worldonline.nl
> [101.101.101.101])...

$middle is [101.101.101.101].  In a regex, this is a character class
which matches a one, a zero, or a period.  Thus, when you do the
substitution s/$middle/$new/, you are replacing the 1 in Idn-p188 with
the contents of $new.  You probably meant s/\Q$middle/$new/, so that the
regex metacharacters would be quoted with backslashes.

> Eh??? Something (or me) screws up incredibly with the substitution:
> "s/$middle/$new/".

Sorry, it's you.  I hope this message helped explain things.  I would
suggest reading the perlre documentation as the next step in fixing your
program.

By the way, your signature is about 20 lines too long.

-- 
 _ / '  _      /         - aka -         rjk@coos.dartmouth.edu
( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
    /                                  http://www.ziplink.net/~rjk/
        "It's funny 'cause it's true ... and vice versa."


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

Date: Sun, 05 Jul 1998 21:35:21 -0400
From: Dan Boorstein <danboo@negia.net>
Subject: subtle variations of 'print (&&|and) die;'
Message-Id: <35A029D9.A6D93629@negia.net>

hello all,

i surprised myself with some unexpected behavior that i thought
was subtle enough to share, and confusing enough to request
clarifications/explanations.

my guess would have been that they all print 'money' to STDOUT
(and that it would actually appear on screen) before dying.
one version does not. can you guess which one?

print 'money' and die 'in jail';
__END__

print 'money' && die 'in jail';
__END__

$_ = 'money';
print && die 'in jail';
__END__

&print('money') && die 'in jail';
sub print { print @_ }
__END__

confusedly yours,

-- 
Dan Boorstein   home: danboo@negia.net  work: danboo@y-dna.com

 "THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER."
                         - Cosmic AC


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

Date: Sun, 05 Jul 1998 17:25:49 -0700
From: David LaPierre <davel@mail.aone.com>
Subject: Web Counters...
Message-Id: <35A0198D.F9702A56@mail.aone.com>

Does anyone know of a tutorial for retarted people that will help we put
a web counter on my web page? One that will walk me throught it step by
step. I have now pior programming
experience. My server thinks I am a programmer.

Thank You in advance, Dave LaPierre



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

Date: 6 Jul 1998 01:18:21 GMT
From: kortbein@iastate.edu (Josh Kortbein)
Subject: Re: Web Counters...
Message-Id: <6np8kt$eau$1@news.iastate.edu>

David LaPierre (davel@mail.aone.com) wrote:
: Does anyone know of a tutorial for retarted people that will help we put
: a web counter on my web page? One that will walk me throught it step by
: step. I have now pior programming
: experience. My server thinks I am a programmer.

FYI, this is not a perl-specific question. You will be much better-served
in the future by posting to one of the WWW newsgroups, or by checking
the web first (counter CGIs should be readily available there).

You should search around for a pre-made counter CGI, or use one of
the many free counter-servers out there. Your ISP may even have one
ready for you to use, since it's a commonly requested feature.

I could be wrong, but I think you'll find those options preferable to
actually learning how to do it yourself. Doing it yourself will probably
not be very enlightening unless you start learning programming from the
beginning.

Josh

--

__________________________________________
She had heard all about excluded middles;
they were bad shit, to be avoided.
            - Thomas Pynchon



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

Date: Mon, 6 Jul 1998 01:46:15 +0100
From: Russell Schulz <Russell_Schulz@locutus.ofB.ORG>
Subject: Re: Why no Perl news/mailreader?
Message-Id: <19980706.014615.9g4.rnr.w164w@locutus.ofB.ORG>

the Subject: header makes an invalid assumption; I know of at least
two newsreaders written in perl.

brn           ftp.ee.umanitoba.ca:/pub/msdos/waffle/brn*
5061. brn - waffle news; in perl

the other was simply called `prn', and was from someone who at the time
had a sun.com address, I think.  I never saw an archive site posted.
-- 
Russell_Schulz@locutus.ofB.ORG  Shad 86c


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

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 3066
**************************************

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