[18786] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 954 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 21 21:21:39 2001

Date: Mon, 21 May 2001 18:10:17 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <990493817-v10-i954@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 21 May 2001     Volume: 10 Number: 954

Today's topics:
        Regexp to match IP Address <centreman_19@NOSPAMyahoo.com>
    Re: Regexp to match IP Address <centreman_19@NOSPAMyahoo.com>
    Re: Regexp to match IP Address <chok@ece.gatech.edu>
    Re: Regexp to match IP Address (Craig Berry)
    Re: scientific notation <todd@ti.com>
    Re: SET-UP (free) (Bob Moose)
    Re: Simple sorting problem <abe@ztreet.demon.nl>
    Re: Simple sorting problem <jurgenex@hotmail.com>
    Re: Slight problems with rounding. <iltzu@sci.invalid>
    Re: Sorting (Joe Smith)
    Re: Stubborn regex won't work <mischief@velma.motion.net>
    Re: System calls in Windows NT <mischief@velma.motion.net>
    Re: unlinking files under -T <Juha.Laiho@iki.fi>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 21 May 2001 16:51:35 -0700
From: "Brandon Thornburg" <centreman_19@NOSPAMyahoo.com>
Subject: Regexp to match IP Address
Message-Id: <9ec9mj$ncq$1@fremont.ohsu.edu>

I have read others on other newsgroups claiming that matching any IP address
with a regular expression would be ridiculously obfuscated. I have tried
what I thought was a simple expression that should work...and it doesn't, as
they said. Can anyone help me with why this:

(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})

isn't matching an IP address?

Thanks...




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

Date: Mon, 21 May 2001 16:53:28 -0700
From: "Brandon Thornburg" <centreman_19@NOSPAMyahoo.com>
Subject: Re: Regexp to match IP Address
Message-Id: <9ec9vl$nev$1@fremont.ohsu.edu>

Please, PLEASE ignore the previous example of complete newbie drek.

I apologize, I really, really do.

No, really.





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

Date: Mon, 21 May 2001 20:04:42 -0400
From: ChokSheak Lau <chok@ece.gatech.edu>
Subject: Re: Regexp to match IP Address
Message-Id: <3B09AD1A.6CD8F7FA@ece.gatech.edu>

it does work, i tried:
$a = '1.1.1.1' =~ m/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/;
print $a;   # prints 1

if you want to get the whole ip, just put ( ) around the whole thing.
right now, $IP = "$1.$2.$3.$4";

chok

Brandon Thornburg wrote:

> I have read others on other newsgroups claiming that matching any IP address
> with a regular expression would be ridiculously obfuscated. I have tried
> what I thought was a simple expression that should work...and it doesn't, as
> they said. Can anyone help me with why this:
>
> (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})
>
> isn't matching an IP address?
>
> Thanks...



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

Date: Tue, 22 May 2001 00:54:51 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Regexp to match IP Address
Message-Id: <tgje6rrb7arjf3@corp.supernews.com>

Brandon Thornburg (centreman_19@NOSPAMyahoo.com) wrote:
: I have read others on other newsgroups claiming that matching any IP address
: with a regular expression would be ridiculously obfuscated. I have tried
: what I thought was a simple expression that should work...and it doesn't, as
: they said. Can anyone help me with why this:
: 
: (\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})
: 
: isn't matching an IP address?

  $_ = '123.244.111.009';
  m/(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/ and print "IP!";

That prints out "IP!" on my system, so it is matching an IP address.
The problem with your regex is that it also matches invalid addresses,
like 999.999.999.999.

See Friedl's _Mastering Regular Expressions_ for a great discussion of
this very problem.  In brief, you can write a reasonably compact regex
that will match only valid IP addresses, but it's easier to do it using
numeric range comparisons on the dotted-quad components.

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "God becomes as we are that we may be as he is."
   |               - William Blake


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

Date: Mon, 21 May 2001 17:19:41 -0500
From: Todd Bair <todd@ti.com>
Subject: Re: scientific notation
Message-Id: <3B09947D.1FD83D8E@ti.com>

Thanks Greg.


    Answer for reference:
    print sprintf("%e",22534238432.3955);

    # 2.253424e+10


Todd


Greg Bacon wrote:

> In article <3B0984B4.6A03458F@ti.com>,
>     Todd Bair  <todd@ti.com> wrote:
>
> : How do format number like 22534238432.3955 to 2.2534e+10.  I
> : have tried Convert-SciEng-0.90, but it gives me 22.5342G.  Any
> : suggestions??
>
> % man perlfunc
> [...]
>         Perl's `sprintf' permits the following universally-known
>         conversions:
>
> [...]
>             %e   a floating-point number, in scientific notation
> [...]
>
> Hope this helps,
> Greg
> --
> The war . . . has tended, more than any other event in the history of the
> country to militate against the Jeffersonian idea, that "the best government
> is that which governs least."
>     -- Illinois Governor Richard Yates, 1865

--
Todd A. Bair
Mixed Signal Process Development
PHONE:    972-995-1950
PAGER:    972-598-6253
MSGID:    TDDB
E-MAIL:   todd@ti.com




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

Date: 21 May 2001 18:04:08 -0700
From: yogibearxx@bobmoose.com (Bob Moose)
Subject: Re: SET-UP (free)
Message-Id: <4ec914b1.0105211704.7bc41d57@posting.google.com>

"flash" <bop@mypad.com> wrote in message news:<RlVN6.4790$eF6.368361@news20.bellglobal.com>...
> No one will do that for you.
> 
> You should learn to do stuff on your own.
> "Bob Moose" <yogibearxx@bobmoose.com> wrote in message
> news:4ec914b1.0105200757.2302ca2c@posting.google.com...
> > Can somebody set up http://www.kastle.net/products/URLredirect/
> > For FREE,
> > set up at http://www.bobmoose.com,
> > when done send it to http://bobmoose.com/publicftpspace,
> > then i will chmod it and put it in the CGI-BIN

Well, I'll ask again. Can somebody?


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

Date: Tue, 22 May 2001 02:06:31 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: Simple sorting problem
Message-Id: <ni8jgtsglmut9mhom805o3g2p4b1mhemic@4ax.com>

On Wed, 16 May 2001 15:26:35 -0400, Young Chi-Yeung Fan
<yf32@cornell.edu> wrote:

> Hi,
> 
> I'm trying to sort key-value pairs read in from a DBM file. The keys
> are:
> 1, 2, 3, ..., 14, 15, 16, A, B
> 
> Using this loop:
> 
> for $trip (sort { $a <=> $b } keys %DATA) { ... }
> 
> I get this sorted result:
> B, A, 1, 2, ..., 15, 16

[ snip ]

> What I want is this:
> 1, 2, 3, ..., 14, 15, 16, A, B

So, my first thought was to use GRT to sort the keys for the general
case where (natural) numbers come before (other) strings.

This was the point where I went back to reading appendix B of "A Fresh
Look at Efficient Perl Sorting"[1] and usually find an answer as to
how-to pack/unpack the data for GRT.

Although I found a solution for this example data, I didn't find a
answer for the general case I stated above.

The appendix suggests using 

	pack( 'A* x' => "$string\0" ) 

for ascending varying-length string sort, but I couldn't get it to work.

How should I change the following code?

#!/usr/bin/perl -w
use strict;

my %data = (
	1 => 1, 2 => 2, 6 => 3, 9 => 4, 11 => 5,
	A => 6, B => 7,
);

# assuming numbers >= 0
my @s_keys = map { ( unpack 'N A2  A*' =>  $_ )[-1] } sort
	map {
		/^(\d+)$/
			? pack( "N A2" => $1, "\0" ) . $_
			: pack( "N A2" => -1, "$_\0" ) . $_
	} keys %data;

for my $key ( @s_keys ) {
	print "$key ==> $data{ $key }\n";
}
__END__

[1] http://www.sysarch.com/perl/sort_paper.html

-- 
Good luck, Abe
Amsterdam Perl Mongers http://amsterdam.pm.org
perl -e '$_=sub{split//,pop;print pop while@_};&$_("rekcah lreP rehtona tsuJ")'


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

Date: Mon, 21 May 2001 17:39:56 -0700
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Simple sorting problem
Message-Id: <3b09b577@news.microsoft.com>

> On Wed, 16 May 2001 15:26:35 -0400, Young Chi-Yeung Fan
> <yf32@cornell.edu> wrote:
>
> > Hi,
> >
> > I'm trying to sort key-value pairs read in from a DBM file. The keys
> > are:
> > 1, 2, 3, ..., 14, 15, 16, A, B
> >
> > Using this loop:
> >
> > for $trip (sort { $a <=> $b } keys %DATA) { ... }
> >
> > I get this sorted result:
> > B, A, 1, 2, ..., 15, 16

Well, yeah, quite understandable. "<=>" is a numerical compare and all
'string values' (e.g. "A", "B:" etc.) have a numerical value of 0. Their
internal order is undetermined, all actual numbers will be sorted after
them.

> > What I want is this:
> > 1, 2, 3, ..., 14, 15, 16, A, B

Easy enough: write your own compare function.
Something in the line of
- if both arguments are numbers then return the result of "<=>"
- if both arguments are text pieces then return the result of "cmp".
- if one argument is a number, the other text then return -1 or 1, depending
on if $a or $b is the number (and if you want the text first or the numbers
first).

jue




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

Date: 21 May 2001 22:31:41 GMT
From: Ilmari Karonen <iltzu@sci.invalid>
Subject: Re: Slight problems with rounding.
Message-Id: <990483658.5535@itz.pp.sci.fi>

In article <tgj2jhskmmsc05@corp.supernews.co.uk>, Nick wrote:
>mostly works okay, but I've noticed that certain results combinations
>produce percentages that do not add up to 100, and wondered if anyone
>could see the flaw in my "rounding" logic.

That's inevitable.  Imagine you have three choices that have each
received the same number of votes.  Each has therefore received one
third of the votes, or approximately 33%, producing a total of 99%.

The fact that round(100 / 3) equals 33 is independent of the rounding
scheme.  Even if you add more significant digits, the total will never
be exactly 100%.

-- 
Ilmari Karonen - http://www.sci.fi/~iltzu/
Please ignore Godzilla / Kira -- do not feed the troll.


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

Date: Tue, 22 May 2001 00:02:00 +0000 (UTC)
From: inwap@best.com (Joe Smith)
Subject: Re: Sorting
Message-Id: <9eca9o$2loj$1@nntp1.ba.best.com>

In article <8PVJ6.2$fi2.343@news.cpqcorp.net>, Eter4 <eter4@hotmail.com> wrote:
>I have a Tab Delimited file that stores information on files that I am
>offering on my website.
>The formatting is as follows
>
># of times downloaded    Name Of File    Location Of File( URL)     File ID#
>
>I want my script to sort out all the files and show me only the top 5
>downloaded..

Read file a line at a time.
Split the line on tabs, storing results in an anonymous array, and pushing
that onto a named array.
Sort the named array, using {$a->[0] <=> $b->[1]} as the sort routine.
Select the top 5, dereference and print.

For details, go to http://www.perl.com/, locate the pull-down box that
says "binaries" and select "sorting", then click "Go!".  Look at
"Far More Than Everything You've Ever Wanted to Know About Sorting"
or http://www.sysarch.com/perl/sort_paper.html .

--
See http://www.inwap.com/ for PDP-10 and "ReBoot" pages.


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

Date: Tue, 22 May 2001 00:11:34 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Stubborn regex won't work
Message-Id: <tgjblmmoi8pb6a@corp.supernews.com>

William Cardwell <EUSWMCL@am1.ericsson.se> wrote:
> In the following, I'm trying to pull the "ERI000001" in every case, but
> I can't get it.
> Can anyone help?


> $x='DISK02:[USERS.EUSWILC]ERI000001.INO;1';
> $y='DISK02:[USERS.EUSWILC]ERI000001.;1';
> $z='DISK02:[USERS.EUSWILC]ERI000001.';
> $w='DISK02:[USERS.EUSWILC]ERI000001.INO';

> # Last word string terminated by a period

    my $string = 'DISK02:[USERS.EUSWILC]ERI000001.INO;1';
    my $foo = reverse $string;
    $foo =~ /\.(\w+)\]/;
    my $result = reverse $1;

There's even an article about this method on http://www.perl.com,
where useful things can often be found.

I'm basing the idea that my example provides correct results
based upon q{I'm trying to pull the "ERI000001" in every case}
and q{Last word string terminated by a period} and what I
understand those to mean in the context of the post.

This method should benchmark pretty well, using the q{reverse}
builtin. It has for every other reverse regex match I've needed
when compared to methods which throw away the beginning of the
string just to match the end.

Chris

-- 
It's not the U in UBE that pisses people off. It's the B.
  -- Martien Verbruggen in clp.misc



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

Date: Mon, 21 May 2001 23:51:59 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: System calls in Windows NT
Message-Id: <tgjagv7hgnspb0@corp.supernews.com>

Dominic Hibbs <mtx064@coventry.ac.uk> wrote:
> In my UNIX script I accept a password without echo to the screen using 

> system 'stty','-echo';
> my $pass = <STDIN>;
> system 'stty','echo';

This is nonportable, even among some Unix flavors.

> What is the Win NT equivalent to suppress echo?

Term::Readkey should do the trick in a more protable manner,
and the CPAN testers say it works on Windows. Too bad you
missed it when you searched CPAN yourself, because you
could have been using by now instead of waiting for an
answer on the newsgroup.

Chris
-- 
For the pleasure of others, please adhere to the following
rules when visiting your park:
    No swimming.  No fishing.  No flying kites.  No frisbees.
    No audio equipment. Stay off grass.  No pets. No running.



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

Date: 21 May 2001 15:51:40 GMT
From: Juha Laiho <Juha.Laiho@iki.fi>
Subject: Re: unlinking files under -T
Message-Id: <9ebdic$4lp$1@ichaos.ichaos-int>

"Scott R. Godin" <webmaster@webdragon.unmunge.net> said:
># During-Usage Cleanup of old user-created files, but save our samples.
>opendir(DIR, $output_path) or die "Cannot Open Output Dir $output_path 
>-- $!";
>my @oldfiles = readdir(DIR);
>closedir(DIR) or die "closing read on $output_path directory failed: $!";
>
>foreach my $oldfile (@oldfiles) 
>{
 ...
>        unlink "$output_path$oldfile"; #older than 24 hours
 ...
>}
>
>I get an "Insecure dependency" warning about the unlink. Now, none of 
>this information is user-generated, so I don't quite understand why I 
>get a warning of this nature unless it's because ANY unlink operation is 
>considered unsecure (which seems to be the case, from my perusal of 
>perlsec.pod).

I'd claim that filenames read off from directory are the reason for that
insecure dependency. As your program doesn't actually know what generated
the filenames it's reading off the directory, perl throws the "insecure
dependency" at you.
-- 
Wolf  a.k.a.  Juha Laiho     Espoo, Finland
(GC 3.0) GIT d- s+: a C++ UH++++ UL++++$ P++@ L+++ E(-) W+$@ N++ !K w !O
         !M V PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h--- r+++ y+++
"...cancel my subscription to the resurrection!" (Jim Morrison)


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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
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.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.

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 V10 Issue 954
**************************************


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