[8789] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2406 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Apr 23 21:07:35 1998

Date: Thu, 23 Apr 98 18:00:28 -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           Thu, 23 Apr 1998     Volume: 8 Number: 2406

Today's topics:
    Re: BUG or FEATURE? -- splice() doesn't extend arrays (Jason Gloudon)
    Re: Cron job and Date problem (Alan Voorhees)
    Re: Defending Perl <tchrist@mox.perl.com>
    Re: Defending Perl <tchrist@mox.perl.com>
    Re: formatting localtime output <efinch@cais.com>
        Hash ref slice syntax? (Craig Berry)
    Re: Hash ref slice syntax? <ajh@rtk.com>
    Re: Help with non-text output (Andre L.)
    Re: How do you ignoe characters in <read> (Craig Berry)
    Re: How do you ignoe characters in <read> <br@ndon.com>
    Re: How do you ignoe characters in <read> <"xuming "@ email.unc.edu>
    Re: how to put subject in a email? <rootbeer@teleport.com>
        linefeeds and perl formats jcald@lake.ml.org
    Re: linefeeds and perl formats <rootbeer@teleport.com>
    Re: matching man page lines (Tom Phelps)
    Re: matching man page lines (Tom Phelps)
    Re: Memory usage <robban@it-konsult.com>
        Note: Memory usage <robban@it-konsult.com>
    Re: PC-based editors for Perl? <NOSPAMnagosks@ushc.com>
    Re: Perl5 and IIS4 (on NTworkstation) <rootbeer@teleport.com>
    Re: Regular Expression to match a valid IP address (Nicholas Carey)
    Re: Retrieving input from URL <a-grayson@nwu.edu>
    Re: scalar assignment <rootbeer@teleport.com>
    Re: socket input problems web@calarts.edu
    Re: split... <igor.k@usa.net>
    Re: spoiled noobie <rootbeer@teleport.com>
    Re: techniques for tagging substitution areas in templa <ebohlman@netcom.com>
    Re: Using "require" <rootbeer@teleport.com>
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Thu, 23 Apr 1998 23:05:50 GMT
From: jgloudon@hyssop.bbn.com.bbn.com (Jason Gloudon)
Subject: Re: BUG or FEATURE? -- splice() doesn't extend arrays
Message-Id: <slrn6jvia0.bdr.jgloudon@hyssop.bbn.com>

Tom Phoenix <rootbeer@teleport.com> wrote:
>On Thu, 23 Apr 1998, Mike Clemens wrote:
>
>> I'm trying to use splice() to munge arrays starting at a particular
>> array index, but was surprised to find that it (splice) doesn't
>> automatically extend arrays if you're accessing beyond the end.  
>
>Well, splice has been this way as long as I can remember. :-)  But it
>could still be construed as a bug. The docs say, 
>
>    The array grows or shrinks as necessary.
>
>(...although I'm sure that that wasn't intended to apply here.)
>
>I'd like to see this fixed. The problem I see is that, if we were to fix
>it now, it might cause some older program to break. :-P

This bug means that these are not equivalent:

                   $a[$x] = $y         splice(@a,$x,1,$y);

--
Jason Gloudon


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

Date: Thu, 23 Apr 1998 17:25:54 -0700
From: radio@hotmail.com (Alan Voorhees)
Subject: Re: Cron job and Date problem
Message-Id: <radio-ya02408000R2304981725540001@nntp.best.com>

> Like CGI scripts, cron jobs run in a different environment than you may be
> expecting. 

Here's the code:
  open (DATABASE, "$data_file_path") || &file_open_error
        ("$data_file_path", "Prune Database",  __FILE__, __LINE__);

  while (<DATABASE>)
    {
    $line = $_;
    chop $line;
    @fields = split (/\|/, $line);

($dbmonth,$dbday,$dbyear) = split (/\//, $fields[$index_of_modification_time]);

$julian_day = &jday($dbmonth,$dbday,$dbyear);
($today_month,$today_day,$today_year) = split (/\//, &get_date);
$today = &jday($today_month,$today_day,$today_year);
$posted_days_ago = ($today - $julian_day);

      # Then, foreach item in the delete list, we will delete it
      # if the age of the datestamp id file is greater than the
      # amount specified in the setup file.

    if ($posted_days_ago <= $expiration_days)
      {
      $ignored_rows .= "$line\n";
      }

    else
      {
      $pruned_rows .= "$line\n\n";
      }
    }
  close (DATABASE);

Thanks in advance for any help you might be able to give.

Alan Voorhees


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

Date: 23 Apr 1998 22:15:51 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Defending Perl
Message-Id: <6hoein$ojk$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    ilya@math.ohio-state.edu (Ilya Zakharevich) writes:
:Perl will run 200 times as slow as C for "most" things.  

    +---------------------------------------------------+
    | +-----------------------------------------------+ |
    | | YOU'RE LYING.  VISCIOUSLY.  UNCONSCIONABLY.   | |
    | +-----------------------------------------------+ |
    +---------------------------------------------------+

Ignore that person.

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com

    "I'm sorry, but you just made me lose my sense of humor, which is deeply
    regrettable." --Larry Wall


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

Date: 23 Apr 1998 22:16:51 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Defending Perl
Message-Id: <6hoekj$ojk$2@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    ilya@math.ohio-state.edu (Ilya Zakharevich) writes:
:Perl is not compiled (even if you use perl2c translator).  

And there's another lie.  What the hell are you on today, Ilya?
Or is this just a Russian<=>English mismatch?

--tom
-- 
	Tom Christiansen	tchrist@jhereg.perl.com
There are probably better ways to do that, but it would make the parser
more complex.  I do, occasionally, struggle feebly against complexity...  :-)
            --Larry Wall in <7886@jpl-devvax.JPL.NASA.GOV>


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

Date: Tue, 14 Apr 1998 21:48:15 -0400
From: Ed Finch <efinch@cais.com>
To: falkenl@hotmail.com
Subject: Re: formatting localtime output
Message-Id: <353411DF.FFC4A9E5@cais.com>

Take a look at strftime, in the POSIX module.

Regards,
Ed

Martin Vorlaender wrote:

> Lee Falkenhagen (falkenl@hotmail.com) wrote:
> : YYYYMMDD HHminmin
>
> : if you just return localtime, it truncates the leading zero for the month
> : and date.
>
> : Is there anyway to put it in there besides doing a "if less than 10, add
> : '0' to string" routine?





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

Date: 23 Apr 1998 23:20:56 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Hash ref slice syntax?
Message-Id: <6hoico$gep$1@marina.cinenet.net>

I've banged away at this for a while, but seem to be suffering partial 
brain lock today, so...

Suppose I have a hash reference:

  $hr = { a => 1, b => 2, c => 3 };

Now, suppose I want to obtain two of the values of this hash as a list 
through a hash slice.  With an ordinary hash, I'd use syntax like this:

  %h = ( x => 11, y => 12, z => 13 );
  @xyvals = @h{'x', 'y'};
  print "@xyvals\n";   # Prints:  11 12

What's the equivalent syntax for getting a slice {'a', 'b'} of the hash 
refered to by $hr?  I've tried a number of increasing ugly variants 
without success.  I can't find it in the docs, on or offline.

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: Thu, 23 Apr 1998 17:00:42 -0700
From: "Aaron Harsh" <ajh@rtk.com>
Subject: Re: Hash ref slice syntax?
Message-Id: <6hokpn$p02$1@brokaw.wa.com>

Craig Berry wrote in message <6hoico$gep$1@marina.cinenet.net>...
>I've banged away at this for a while, but seem to be suffering partial
>brain lock today, so...
>
>Suppose I have a hash reference:
>
>  $hr = { a => 1, b => 2, c => 3 };
>
>Now, suppose I want to obtain two of the values of this hash as a list
>through a hash slice.

Either

  @foo = @$hr{a, c};

or

  @foo = @{$hr}{a, c};

work for me.  Out of curiosity, what were you trying that didn't work?

--
Aaron Harsh
ajh@rtk.com




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

Date: Thu, 23 Apr 1998 18:54:35 -0500
From: alecler@cam.org (Andre L.)
Subject: Re: Help with non-text output
Message-Id: <alecler-2304981854350001@dialup-592.hip.cam.org>

In article <alecler-2304981444310001@dialup-89.hip.cam.org>, I,
alecler@cam.org (Andre L.) wrote:

> <SCRATCH object="head">
> Er... maybe I'm being dense, but... isn't a file containing a single byte
> whose value is the ASCII value of "0", the same thing as a file containing
> the actual character "0" ??? I am missing something????
> </SCRATCH>


OK, let me rephrase:

If your data is some text, then simply print the text, as each character
is, by definition, a byte whose value is an ascii code. So, no need waste
time figuring the ascii values of the individual characters.

On the other hand, if what you have is a series of numbers, then you do,
for instance,

for $num (@numbers) { print TOAFILE pack("C",$num) };

A.L.


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

Date: 23 Apr 1998 21:04:01 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: How do you ignoe characters in <read>
Message-Id: <6hoac1$82m$2@marina.cinenet.net>

Brandon Golm (br@ndon.com) wrote:
: 	@array = split(/\w+/,$_);  #\w is whitespace better than '\ '

s/\\w/\\s/g;

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: Thu, 23 Apr 1998 15:34:35 -0400
From: Brandon Golm <br@ndon.com>
To: John Mosey <mosey@alpha3.csd.uwm.edu>
Subject: Re: How do you ignoe characters in <read>
Message-Id: <353F97CB.5FF155B7@ndon.com>

> : John Mosey wrote:
> :> I'm creating a simple file manipulation and display script The problem is that
> :> when I create @array using split and a while (<READ>) command I get stopped.
> :>
> :> The file I'm rading is space delimited (I know, but I didn't create it).
> :> Anyway, one of the fields is a decimal. The "." kicks the process out of the
> :>  loop and I can't finish readin the line.
> :>
> :> Example, the line really is
> :> Jim Jack Joe .25 truck pig man
> :> $array[0] = Jim
> :> $array[1] = Jack
> :> $array[2] = Joe
> :> $array[3] = 25  (no decimal)
> :> $array[4] =
> :> $array[5] =
> :> $array[6] =

-x-

> open (READ,"standing.htm") || die "Can't open file $a
> for reading: $!";
> $count = 1;
> while(<READ>) {
> @array = split(/\.+/, $_);
> 
> if ($count == 13){
> @new = split(/\ +/, $array[0]);
> 
> for($i=0; $i<15; $i++){
> print "cell $i = $new[$i]\n";
> }
> $count++
> }
> }
> close (READ) || die "can't close $a: $!";


I don't understand what you're trying to accomplish.  But the reason
you're losing the '.' is because you're spliting on '\.' which turns:
'Jim Jack Joe .25 truck pig man' into the equivalent of:

@array = ('Jim Jack Joe ', '25 truck pig man');

why don't you just split on whitespace?

while (<READ>) {
	chomp;
	@array = split(/\w+/,$_);  #\w is whitespace better than '\ '
}

does that help?

 .brandon.


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

Date: Thu, 23 Apr 1998 16:46:45 -0400
From: Xuming Wang <"xuming "@ email.unc.edu>
Subject: Re: How do you ignoe characters in <read>
Message-Id: <6ho9p9$l46$1@fddinewz.oit.unc.edu>

I think he wants to print the entries in line 13 but his script has 2 major
problems.  one is split with dot, the other is $count++ is inside if block so it
would never get executed.  besides suggest the llama book, I have this script:

#! perl -w
open (READ, "standing.htm") or die "blah blah";
$count = 1;
while (<READ>) {
    chomp;
    if ($count++ == 13) {
	@array = split;
	foreach $i (o..$#array) {
	    print "cell $i = $array[$i]\n";
	}
	last;
    }
}
close READ or die "oh!";
__END__

now, could you tell me why \s (not \w which is [a-zA-Z_]) is better than space
if he knows the data are space not tab delimited? (also, no need to escape space
or use the + sign in the pattern I believe.)

xuming -- perl newbie

Brandon Golm wrote:
> 
> > : John Mosey wrote:
> > :> I'm creating a simple file manipulation and display script The problem is that
> > :> when I create @array using split and a while (<READ>) command I get stopped.

<snip>

> > open (READ,"standing.htm") || die "Can't open file $a
> > for reading: $!";
> > $count = 1;
> > while(<READ>) {
> > @array = split(/\.+/, $_);
> >
> > if ($count == 13){
> > @new = split(/\ +/, $array[0]);
> >
> > for($i=0; $i<15; $i++){
> > print "cell $i = $new[$i]\n";
> > }
> > $count++
> > }
> > }
> > close (READ) || die "can't close $a: $!";
> 
> I don't understand what you're trying to accomplish.  But the reason
> you're losing the '.' is because you're spliting on '\.' which turns:
> 'Jim Jack Joe .25 truck pig man' into the equivalent of:
> 
> @array = ('Jim Jack Joe ', '25 truck pig man');
> 
> why don't you just split on whitespace?
> 
> while (<READ>) {
>         chomp;
>         @array = split(/\w+/,$_);  #\w is whitespace better than '\ '
> }


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

Date: Thu, 23 Apr 1998 23:42:38 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: tw96 <tw96@email.msn.com>
Subject: Re: how to put subject in a email?
Message-Id: <Pine.GSO.3.96.980423164202.5518S-100000@user2.teleport.com>

On Thu, 23 Apr 1998, tw96 wrote:

> i'm practicing to write a program to send email, but i don't know how to put
> sth. in
>      Subject:
> all i got now is an empty area, will somebody tell me how to do that?

The docs for your mail program should tell you. If you've read them and
you're still not sure, check with a newsgroup about mail programs. Hope
this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 23 Apr 1998 15:31:33 -0600
From: jcald@lake.ml.org
Subject: linefeeds and perl formats
Message-Id: <6ho8f5$am6$1@nnrp1.dejanews.com>

I'm trying to use perl's 'format' to output some text in some columns.  My
problem is that some of the strings are like "foo\nbar\nbaz\n" and my format
looks like this:

format FOO =

Stuff:         ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
               $stuff
               ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<~~
               $stuff
 .


Perl figures "hey, this thing is only one line long." because it ignores the
linefeeds. BUT: it counts them when it is outputting the formatted text, so i
all i see is:



Stuff:         foo


since it only thinks it needs to print out one line.  Any quick way i can fix
this, or am i gonna have to figure something out myself? (ick)


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: Thu, 23 Apr 1998 23:06:44 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: jcald@lake.ml.org
Subject: Re: linefeeds and perl formats
Message-Id: <Pine.GSO.3.96.980423160601.5518L-100000@user2.teleport.com>

On Thu, 23 Apr 1998 jcald@lake.ml.org wrote:

> I'm trying to use perl's 'format' to output some text in some columns. 
> My problem is that some of the strings are like "foo\nbar\nbaz\n"

You may want the @* format. Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: 24 Apr 1998 00:10:21 GMT
From: phelps@ecstasy.CS.Berkeley.EDU (Tom Phelps)
Subject: Re: matching man page lines
Message-Id: <6hol9d$1oj$1@agate.berkeley.edu>


John Erjavec V writes...
> I decided to write a script to strip out the header and footer information
> from man pages, since I was tired of having the header and footer
 ...

Check out PolyglotMan (ne RosettaMan) at 
http://http.cs.berkeley.edu/~phelps/tcltk/


> reinvent more of the wheel)? and 2) Does anyone have any suggestions on how 
> to speed up the regexes (or general advise on the state of the code)?
 ...
> while (<MANUAL>) {
> 	next if (/^ Hewlett-Packard Company/); #for HP footers
> 	next if (/^\s+(.+).+(\1)\s*$/); #for all headers

Stripping based on specific headers won't work--I've tried it and
there are just too many variations.

Tom
-- 
phelps@ACM.org


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

Date: 24 Apr 1998 00:44:23 GMT
From: phelps@ecstasy.CS.Berkeley.EDU (Tom Phelps)
Subject: Re: matching man page lines
Message-Id: <6hon97$2t4$1@agate.berkeley.edu>


John Erjavec V wrote:
> if ($#ARGV == 1) {
> 	if (($ARGV[1] eq "4up") || ($ARGV[1] eq "2up") || ($ARGV[1] eq "2+")) {
> 		@system_args = ("lp", "-t$manpage", "-o$ARGV[1]", "$temp_file");
> 	} 
> } else {
> 	@system_args = ("lp", "-t$manpage", "$temp_file");
> }

Giving this a second look, if you're printing out the pages, you don't
want the pages as formatted for reading on the screen.  Use
troff/groff and the man page source to produce pages specifically
formatted for the printer.

Tom

-- 
phelps@ACM.org


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

Date: 23 Apr 1998 19:19:04 GMT
From: "Robert Friberg" <robban@it-konsult.com>
Subject: Re: Memory usage
Message-Id: <01bd6eec$a190cac0$c82da8c0@robban.ittek.org>

[cc:d to Tom Phoenix]

Tom Phoenix wrote:
> How can you be sure that one of those "other bugs" is not the reason it's
> failing? Fix the known bugs before you try to find the unknown ones! :-)

	Good point. I have done this and now I'm pretty certain.

	CGI-wrap is for some reason offended by my script, my guess
	is that it's consuming too much memory. All I would like
	is a few hints on how I can minimize memory usage. Should I
	avoid anonymous variables in loops? Should I pass references
	to subs and assign there instead of returning something?

 	I cleaned up the script and added some security-features, the
	searchform is at http://www.updateab.se/butik/rsearch.htm
	It's in swedish but simple and somewhat intuitive.
	[Note: The webpages are not done by me]

	It dumps core(~400k) and moans 'internal server error' when the
	linecount exceeds a certain number (always about the same) regardless
	of the number of hits.


> >    $_ = $ENV{'QUERY_STRING'};
> 
> You shouldn't be doing this. Use a module...

	I have	made a choice and am aware of the tradeoff. The 
	gain is probably microscopic but the loss is even smaller.
	There's no intention of being generic; this gets the job
	done for me.

> >    @par = split /&/;
> >    for (@par){ 
> > 	/(.*)=(.*)/;
> > 	$d{$1} = $2;
> >    }
> 
> ...which will do the job right!

	It does what it's supposed to and nothing else. I'm aware
	of 2 cases that could break the code:
		* The script is called with method != GET.
		* Duplicate form field identifiers.
	These will never happen. If I'm missing something else
	please demonstrate!

> 
> > 	      $hitdata[$hits++] = buildrow and last if 
> >                    join( '',(split /\t/)[@fields]) =~ /$w/i;
> 
> I'm not at all sure that that does what you think it does. But maybe
> that's because I'm not sure what you think it does. :-)

	Well, it matches over fieldboundaries, but that's a
	feature! Otherwise I hope it does the equivalent of:

	if (join( '',(split /\t/)[@fields]) =~ /$w/i)
	{
	  	$hitdata[$hits] = buildrow;
		$hits++;
		last;
	}


	Where does the scalar data from the join() go? Will perl allocate
	new memory each time? At worst it will be executed >10000 times!
	What about the split()?

/robban

^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~
'   Robert Friberg
'   robban@it-konsult.com 
'   0708-98 57 01
^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~	


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

Date: 23 Apr 1998 19:28:34 GMT
From: "Robert Friberg" <robban@it-konsult.com>
Subject: Note: Memory usage
Message-Id: <01bd6eed$f8e4f160$c82da8c0@robban.ittek.org>

In case anyone tries it out, the following may be 
of some assistance.

The information searched is computer hardware and software,
therefore try searching for vendornames, productnames 
or comments (in swedish)

 /robban
 
 ^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~
 '   Robert Friberg
 '   robban@it-konsult.com 
 '   0708-98 57 01
 ^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~	
 


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

Date: 23 Apr 1998 18:42:02 GMT
From: "Steve Nagoski" <NOSPAMnagosks@ushc.com>
Subject: Re: PC-based editors for Perl?
Message-Id: <01bd6ee7$863bab00$8a0e799d@w740643.bluebell.aetna.com>


Lee Roth <leeroth-nospamo@worldnet.att.net> wrote in article
<6hnjmg$svs@news1.ee.net>...
> 
> Any suggestions for an editor on a PC that would be 'better suited' to
> writing Perl code than native editors such as Notepad, Wordpad or
> (uck) a word processing package ?
> 
> Now SEDT is not for everyone (and I think the Windows version lacks a
> bit), so here is my question: What editor on a PC supports features
> 1,2, or 3 that I have listed above?

PFE32 has been the most flexible PC-based editor that I've yet to run
across. PFE is short for Programmers File Editor.  It's freeware, does
Keyboard Macros, Auto-indent, pretty printing, handles unix <> dos files,
etc. The only thing on my wish list for it is column-selection, something
I'm not missing in my fave x-windows editor, 'nedit'.



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

Date: Thu, 23 Apr 1998 22:08:16 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Ben Lowery <ben@umich.edu>
Subject: Re: Perl5 and IIS4 (on NTworkstation)
Message-Id: <Pine.GSO.3.96.980423150704.5518I-100000@user2.teleport.com>

On Thu, 23 Apr 1998, Ben Lowery wrote:

> I can run Perl scripts from the command line just fine, with or without
> extension, but cannot figure out how to associate .pl files with either
> Perl.exe or the ActiveState dll. 

If the manual for your server doesn't tell you, get a better one. :-)  Or,
check with the docs and FAQs of a newsgroup about your server. I think
that the Perl-for-Win32 FAQ addresses this as well. Hope this helps! 

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 23 Apr 1998 22:57:50 GMT
From: a-bnc@microsoft.com (Nicholas Carey)
Subject: Re: Regular Expression to match a valid IP address
Message-Id: <353fc132.20321640@newsvr>

On Wed, 22 Apr 1998 15:57:50 GMT, John Porter <jdporter@min.net>
wrote:

>Quentin Fennessy wrote:
>> By using the common
>> dotted-quad representation we can visually (or via regex) check for
>> basic errors.
>
>The regex to test that a number is in (0..255) is far too hairy.
>Regexes can ensure that the components are decimal numbers; but 
>range-checking is better done after the regex.  And this is true
>regardless of whether we're looking at 8.8.8.8, 8.8.16, or 8.24.

Really? Try this on for size. It's a regular expression that will
match any unsigned decimal (base-10) representation of a value between
0 and 255. It's not *that* hairy:

  (0*(1?\d?\d|2[0-4]\d|25[0-5]))

And it's easy to expand this to validate an IP address in the usual
dot notation: nnn.nnn.nnn.nnn as follows:

  (0*(1?\d?\d|2[0-4]\d|25[0-5]))(\.(0*(1?\d?\d|2[0-4]\d|25[0-5]))){3}

Here's a sample program to read a line of data and validate it as an
IP address. Try it out:

#!perl

while ( <> )
  {
    chomp() ;

    last if ( m/^(end|quit|exit|bye)$/i ) ;

    if (   m/^
                (0*(1?\d?\d|2[0-4]\d|25[0-5]))
             (\.(0*(1?\d?\d|2[0-4]\d|25[0-5]))){3}
             $
            /x
    )
      {
        print "    VALID\n" ;
      }
    else
      {
        print "*** INVALID\n" ;
      }

  }

0 ;
# end-of-sample-program

Cheers!

N.
-- 



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

Date: Thu, 23 Apr 1998 18:40:08 -0500
From: Adam Grayson <a-grayson@nwu.edu>
To: Robert Woolley <rwoolley@ottawa.com>
Subject: Re: Retrieving input from URL
Message-Id: <353FD157.4E8F02D@nwu.edu>

Yes, everything after the question mark is part of the
$ENV{"QUERY_STRING"} variable. Once you have that value imported into
your script, you can split it on the plus signs, or ampersands, or
whatever, and then split those subvalues on the equals signs to assign
values to the variables you are bringing in (hope that was
intelligable).

Adam

Robert Woolley wrote:

> How would I go about retrieving the information from the variables
> passed to the script through the URL. i.e.:
>
> http://www.altavista.digital.com/cgi-bin/query?q=%2Bperl+%2B%22query
>
> I believe that it has something to do with QUERY_STRING doesn't it?





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

Date: Thu, 23 Apr 1998 23:40:19 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: tw96 <tw96@email.msn.com>
Subject: Re: scalar assignment
Message-Id: <Pine.GSO.3.96.980423163214.5518Q-100000@user2.teleport.com>

On Thu, 23 Apr 1998, tw96 wrote:

> i tried, but still don't know how to correct these two errors

When you can't understand one of Perl's diagnostic messages, check to see
whether it's listed in the perldiag mainpage, which has detailed
explanations.

> line 3: syntax error near unexpected token
> `open(FILE,"</client/home/webcmo/docs/report.html")'

Even when your script is "just an example" (and perhaps especially in that
case!) you should _always_ check the return value after opening a file.

I'm not completely sure, but I don't think that syntax error is a Perl
error message. 

> `open(FILE,"</client/home/webcmo/docs/report.html")||&return_error(500,"Serv
> er Error","Can not open report file!");'

I don't see the error message, so I don't know what you're complaining
about. :-)  But when reporting an error return from a system call like
open, it's good to include the magical $! variable, which will contain a
human-readable string like "file not found", or "permission denied". 

    open FILE, "</some/file/name"
	or return_error(500, "Server Error",
	    "Can't open /some/file/name: $!";

> Can't modify not in scalar assignment at line 3, near
> "$base = "/client/home/webcmo/docs/";"

There's something more in your code than what you're showing; perldiag
should be helpful. The 'not' that it's talking about is the logical not
operation, represented in Perl by '!' or 'not'. 

>    print <<END;
>    afggutujflgs
> 
> END

> the compiler just can't find the "END", no matter where i put the word,

That diagnostic should also be in perldiag. Be sure that the end-marker
('END') is on a line by itself, with no invisible characters before or
after it (other than the newline at the end of the line, of course). 

Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 23 Apr 1998 17:58:36 -0600
From: web@calarts.edu
Subject: Re: socket input problems
Message-Id: <6hoh2t$nei$1@nnrp1.dejanews.com>

In article <ra2ok3ar.fsf@mailhost.panix.com>,
  Jonathan Feinberg <jdf@pobox.com> wrote:

> You might want to check out perlfaq8, "Can I use perl to run a telnet
> or ftp session?", which has some sample code that's similar to what
> you're trying to do.

Naturally, I checked all the faqs before posting.  There's no sample code in
that faq.  All perlfaq8, "Can I use perl to run a telnet or ftp session?" has
to say is:

"Try the Net::FTP and TCP::Client modules (available from CPAN)."

As I explained in my previous post, I don't want to use CPAN modules for two
reasons:

1.  I'm doing this as much to teach myself about socket programming as
anything else, and

2.  Although I'm currently working on an IRIX system, I'm hoping to port my
finished product to MacPerl, and I doubt that the CPAN modules will work on a
Mac, since MacOS isn't exactly POSIX-compliant...

-jason

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/   Now offering spam-free web-based newsreading


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

Date: Thu, 23 Apr 1998 17:47:33 -0700
From: "Igor Krivokon" <igor.k@usa.net>
Subject: Re: split...
Message-Id: <6hon8c$qiu$1@news.ncal.verio.com>

jcoffey@connectnet.com wrote in message <6hokp7$v2b$1@nnrp1.dejanews.com>...
>Hey, does anybody have any idea how to split a string with a varying number of
>fields?  Let's say (for example...) I have a string from a hashed value of:
>
>blah1,blah2,blah3,blah4 and I want to split it so I can get all of the blahs.
>Okay, so:
>
>($blah1, $blah2, $blah3, $blah4) = split /,/, $_;
>
>fine, BUT what if this is in a while loop and the lines have varying numbers
>of blah?
>
>so I have a file with:
>
>blah1,blah2,blah3,blah4
>poop1,poop2,poop3
>crapola1,crapola2
>
>so...
>
>open (DUMB_FILE, "dumb.file");
>while (<DUMB_FILE>) {
> (????????) = split /,/, $_;
>}



@words = split /,/;


>what the hell do I put in for "???????"  Is there anything built in to perl
>that allows that sort of thing, or am I gonna have to write a sub routine to
>count the number of fields and spit out incremented variables?  Help please
>:).


Arrays allow that sort of things.
Read any good book on Perl (Camel or Llama), it's really worth reading :)

Regards,

Igor Krivokon
<igor.k@usa.net>




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

Date: Thu, 23 Apr 1998 23:04:53 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: "Andrew F. Lee" <andrewf@cp.pathfinder.com>
Subject: Re: spoiled noobie
Message-Id: <Pine.GSO.3.96.980423150835.5518J-100000@user2.teleport.com>

On Thu, 23 Apr 1998, Andrew F. Lee wrote:

> > I grew up? with the trim() function which returns a string with the
> > leading and the trailing space-chars removed.

> sub trim {
> 	my $string = shift;
> 	$string =~ m/\s*(.+)\s*/;
> 	return $1;
> }

If you must answer questions which are answered (or nearly so) in the FAQ,
please ensure that you improve upon the FAQ's answer. This attempt,
unfortunately, is buggy. I encourage you to try it on these strings and
others to see why and how it fails. 

    "    fred and barney    "
    "fred\n and\n barney\n"
    "\t\t\t"
    "\tfred\t "
    "      "

Don't let this discourage you from answering questions, though; we all 
make mistakes sometimes. I hope this can be a learning experience for you.
Cheers!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

Date: Thu, 23 Apr 1998 19:47:50 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: techniques for tagging substitution areas in templates?
Message-Id: <ebohlmanErvtnr.LIB@netcom.com>

dtbaker@flash.net wrote:
: encouraging, but I must be missing something... I checked out the Text::
: module docs and source, and did not find a Text::Template module. I have the
: 5.004_02 GS release, and the modules listed are: Abbrev.pm, ParseWords.pm,
: Soundex.pm, Tabs.pm, Wrap.pm

: I am new to perl, and may be looking in the wrong place? If you could be a
: little more specific about where I can find info on the module, it would
: really help me out...

Text::Template isn't part of the default distribution (which would be way
too big if every possibly useful module was included).  The place to get
standard modules that aren't part of the distribution is the Comprehensive
Perl Archive Network (CPAN), which can be found at
<URL:http://www.perl.com/CPAN/>. 



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

Date: Thu, 23 Apr 1998 23:41:39 GMT
From: Tom Phoenix <rootbeer@teleport.com>
To: Andrew Ho <ag-ho@uiuc.edu>
Subject: Re: Using "require"
Message-Id: <Pine.GSO.3.96.980423164036.5518R-100000@user2.teleport.com>

On Thu, 23 Apr 1998, Andrew Ho wrote:

> How does Perl determine if a library file has already been included? 

The docs for require should explain this. Hope this helps!

-- 
Tom Phoenix       Perl Training and Hacking       Esperanto
Randal Schwartz Case:     http://www.rahul.net/jeffrey/ovs/



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

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

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