[25986] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 8205 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jun 27 09:05:28 2005

Date: Mon, 27 Jun 2005 06:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 27 Jun 2005     Volume: 10 Number: 8205

Today's topics:
        Checking IP addresses against lists of IPs, partial IPs <a24061@yahoo.com>
    Re: Checking IP addresses against lists of IPs, partial (Anno Siegel)
    Re: Checking IP addresses against lists of IPs, partial <a24061@yahoo.com>
        GD trouble  <""alexjaquet\"@[no spam]msn.com">
    Re: GD trouble  <sisyphus1@nomail.afraid.org>
    Re: GD trouble <no@email.com>
        Proxy and LWP::UserAgent <l6445@comcast.net>
    Re: RegEx Help, Please?  (match after n) <dave@nospam.com>
    Re: RegEx Help, Please?  (match after n) <dave@nospam.com>
        regexp to sql wildcard conversion (Neil Shadrach)
        simple upload <""alexjaquet\"@[no spam]msn.com">
    Re: simple upload <no@email.com>
    Re: simple upload <""alexjaquet\"@[no spam]msn.com">
    Re: simple upload <noreply@gunnar.cc>
    Re: UTF-8 to named character entities (Anno Siegel)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 27 Jun 2005 11:22:10 +0100
From: Adam Funk <a24061@yahoo.com>
Subject: Checking IP addresses against lists of IPs, partial IPs, and netmasks.
Message-Id: <d9ok0j$2gdc$1@godfrey.mcc.ac.uk>

I'm trying to write some Perl code to check an IP addresses against a list
of strings containing IP address, partial IP addresses ending in ".",
net/mask pairs and net/masklength pairs.  

In other words, I'd like ip_found("192.168.2.3") to return true if the test
list contains any of the following:
192.168.2.3
192.168.
192.168.2.0/255.255.255.0
192.168.2.0/24

I'm sure someone else has done this already -- any good code to recycle?

Thanks,
Adam



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

Date: 27 Jun 2005 11:07:55 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Checking IP addresses against lists of IPs, partial IPs, and netmasks.
Message-Id: <d9ommb$onj$2@mamenchi.zrz.TU-Berlin.DE>

Adam Funk  <a24061@yahoo.com> wrote in comp.lang.perl.misc:
> I'm trying to write some Perl code to check an IP addresses against a list
> of strings containing IP address, partial IP addresses ending in ".",
> net/mask pairs and net/masklength pairs.  
> 
> In other words, I'd like ip_found("192.168.2.3") to return true if the test
> list contains any of the following:
> 192.168.2.3
> 192.168.
> 192.168.2.0/255.255.255.0
> 192.168.2.0/24
> 
> I'm sure someone else has done this already -- any good code to recycle?

So what have you tried?  Which modules have you considered?

Just throwing specifications at the newsgroup is unlikely to give
useful replies.

Anno


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

Date: Mon, 27 Jun 2005 12:49:27 +0100
From: Adam Funk <a24061@yahoo.com>
Subject: Re: Checking IP addresses against lists of IPs, partial IPs, and netmasks.
Message-Id: <d9op48$2hrh$1@godfrey.mcc.ac.uk>

Anno Siegel wrote:

> Adam Funk  <a24061@yahoo.com> wrote in comp.lang.perl.misc:
>> I'm trying to write some Perl code to check an IP addresses against a
>> list of strings containing IP address, partial IP addresses ending in
>> ".", net/mask pairs and net/masklength pairs.
>> 
>> In other words, I'd like ip_found("192.168.2.3") to return true if the
>> test list contains any of the following:
>> 192.168.2.3
>> 192.168.
>> 192.168.2.0/255.255.255.0
>> 192.168.2.0/24
>> 
>> I'm sure someone else has done this already -- any good code to recycle?
> 
> So what have you tried?  Which modules have you considered?

I had started from scratch using regexps and some other string manipulation,
but fortunately found Net::Netmask, which does a lot of the job for me.

I can read the input file and for each netmask string, create a Net::Netmask
and test with the Net::Netmask->match($ip) method, until it returns true or
I run out of input.

But I'm wondering if there is a more efficient way to do it.



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

Date: Mon, 27 Jun 2005 10:44:11 +0200
From: Alexandre Jaquet <""alexjaquet\"@[no spam]msn.com">
Subject: GD trouble 
Message-Id: <42bfbc6b$0$1159$5402220f@news.sunrise.ch>

I could not open the file 00.jpg
the file exis and it's not in read only mode

#!C:/Perl/bin/perl.exe -w
use strict;
use GD;


     my $filename = '00.jpg';
     open IN, 'C:/Documents and Settings/alexandre/Mes documents/Mes 
images/$filename'  or die "Could not open C:/Documents and 
Settings/alexandre/Mes documents/Mes images/$filename";
     my $srcImage = GD::Image->newFromJpeg(*IN);
     close IN;
     my ($thumb,$x,$y) = Image::GD::Thumbnail::create($srcImage,50);
     open OUT, ">C:/Apache2/htdocs/recordz/upload/thumb_test.jpg" or die 
"Could not save ";
     binmode OUT;
     print OUT $thumb->jpeg;
     close OUT;


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

Date: Mon, 27 Jun 2005 19:11:30 +1000
From: "Sisyphus" <sisyphus1@nomail.afraid.org>
Subject: Re: GD trouble 
Message-Id: <42bfc2bc$0$1797$afc38c87@news.optusnet.com.au>


"Alexandre Jaquet" <""alexjaquet\"@[no spam]msn.com"> wrote in message
news:42bfbc6b$0$1159$5402220f@news.sunrise.ch...
> I could not open the file 00.jpg
> the file exis and it's not in read only mode
>

Find out what $! contains. ie, instead of:

> .... or die "Could not open C:/Documents and
> Settings/alexandre/Mes documents/Mes images/$filename";

try:

or die "Could not open C:/Documents and
 Settings/alexandre/Mes documents/Mes images/$filename: $!";

Hth

Cheers,
Rob




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

Date: Mon, 27 Jun 2005 10:22:30 +0100
From: Brian Wakem <no@email.com>
Subject: Re: GD trouble
Message-Id: <3i9uqlFkisvlU1@individual.net>

Alexandre Jaquet > wrote:
> I could not open the file 00.jpg
> the file exis and it's not in read only mode
> 

>     open IN, 'C:/Documents and Settings/alexandre/Mes documents/Mes 
> images/$filename' 



This tries to open C:/Documents and Settings/alexandre/Mes documents/Mes 
images/$filename

I very much doubt if that is the file you are trying to open.  If you 
want $filename to be interpolated you will need to double quote.


-- 
Brian Wakem




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

Date: Mon, 27 Jun 2005 01:49:03 -0400
From: "Mike" <l6445@comcast.net>
Subject: Proxy and LWP::UserAgent
Message-Id: <ZbSdnX-S87nXDiLfRVn-1A@comcast.com>

I have put together a pretty good working webcrawler using ActivePerl for 
windows. I am trying to get it to access a proxy from a list of PUBLIC 
proxies stored in a text file. I am seem to have trouble in this area. I am 
using a standard agent to access and I am setting up the proxy in the 
standard way using a public proxy from the text file.
the way I am reading the description of a proxy setting in LWP::UserAgent 
is: (bare with me on this logic) I am telling the server I am trying to 
access the web page to send the data to the proxy address I have set up in 
UserAgent . The problem is that I have not notified or accessed the public 
proxy where to tell it where to send the data. In other words, I have not 
before hand notified the proxy server to send the data to my IP address and 
I believe this is where I am having trouble.

I was looking for any information or any help in the use of proxies and 
LWP::UserAgent.

Contact me here or at triad3085@yahoo.com.

Triad 




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

Date: Mon, 27 Jun 2005 03:26:08 -0400
From: "Dave A." <dave@nospam.com>
Subject: Re: RegEx Help, Please?  (match after n)
Message-Id: <PZ-dnTki9bmPNyLfRVn-oQ@rcn.net>

Smarta55 Chris wrote:

>>> Can someone help me find the last n folders in a path,
>>> or the last n OUs in a fully qualified Netware name... for an app object,
>>> etc?
>>> 
>>>Example:
>>>\\server\volume\share\folder\folder\folder
>>>I want to grab just the last 2 folders (including or excluding the
>>>\s), but sometimes there are 3 folders after the share, like in the
>>>example, and sometimes there are more.

<snip dialog in between>

> There's no simple, single-line $ao =~ /some pattern or other/; that'll work?

#!perl -w

my $n = 4; # number of folders to match
my $regexp = qr/((?:\\[^\\]+){$n})$/;

while (<STDIN>) {
chomp;
(my $folders) = m/$regexp/; # matches only if 4 or more folders
print "$folders\n";

# or
# /((?:\\[^\\]+){MIN,MAX})$/
# match *between* MIN and MAX number of folders

# or
# /((?:\\[^\\]+){MIN,})$/
# match *at least* MIN number of folders

# etc...

}
__END__

Dave







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

Date: Mon, 27 Jun 2005 04:07:45 -0400
From: "Dave A." <dave@nospam.com>
Subject: Re: RegEx Help, Please?  (match after n)
Message-Id: <ha6dnXiQ7cpOLiLfRVn-rg@rcn.net>

Dave A. wrote:

> Smarta55 Chris wrote:

>>There's no simple, single-line $ao =~ /some pattern or other/; that'll work?

I want to stress that I would never use a regular expression in a
situation such as this, where a simple *split* is clearly the right tool
for the job.  The code below was intended as an example only.

Why use error-prone regular expressions when one can write, e.g.,
@folders = split( m![\\/]!, $path )

Dave

> #!perl -w
> 
> my $n = 4; # number of folders to match
> my $regexp = qr/((?:\\[^\\]+){$n})$/;
> 
> while (<STDIN>) {
> chomp;
> (my $folders) = m/$regexp/; # matches only if 4 or more folders
> print "$folders\n";
> 
> # or
> # /((?:\\[^\\]+){MIN,MAX})$/
> # match *between* MIN and MAX number of folders
> 
> # or
> # /((?:\\[^\\]+){MIN,})$/
> # match *at least* MIN number of folders
> 
> # etc...
> 
> }
> __END__


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

Date: 27 Jun 2005 01:16:51 -0700
From: neil.shadrach@corryn.com (Neil Shadrach)
Subject: regexp to sql wildcard conversion
Message-Id: <2d184bb4.0506270016.51fa2ad3@posting.google.com>

I have a regular expression to filter results from an sql query.
It would help improve the overall efficiency if the result set could
be reduced by  adding constraints to the query based on the regular
expression.
For example given the expression /^a (fatal|critical) error has
occurred$/
add "like 'a % error has occurred'" to the sql.
Are there any modules [1] or techniques which can derive an sql
wildcarded string from a regular expression? The regular expression
will still be applied to the results so it doesn't matter that the
wildcard string will match more.

The context is searching a historical database of error messages so
fixed strings with a few embedded variables are the norm.

Apologies if this message appears twice - I first posted it via an
internal news server last week but it doesn't appear to have got out
into the wider world.

Thanks

Neil Shadrach

[1] I have looked on CPAN but didn't find anything


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

Date: Mon, 27 Jun 2005 09:12:32 +0200
From: Alexandre Jaquet <""alexjaquet\"@[no spam]msn.com">
Subject: simple upload
Message-Id: <42bfa6f1$0$1146$5402220f@news.sunrise.ch>

Hi,

I could not figure why image in my upload directory was empty
here is my code :

sub uploadImage {
     my $name = shift || '';
     my $file = $query->param('image');

     my $tmpfile=$file;

     open TMP,"C:/Apache2/htdocs/recordz/upload/$tmpfile";
     binmode TMP;
     open OUT,"> C:/Apache2/htdocs/recordz/upload/$name.jpg";
     binmode OUT;
     while (<TMP>)
     {
       print OUT $_;

     }
     close TMP;
     close OUT;

     #system("chmod 777 C:/Apache2/htdocs/recordz/upload/$name.jpg");
     createTumb($name);
}

sub createTumb {

     my $filename = shift || '';
     open IN, 'C:/Apach23/htdocs/recordz/upload/$filename'  or die 
"Could not open.";
     my $srcImage = GD::Image->newFromJpeg(*IN);
     close IN;
     my ($thumb,$x,$y) = Image::GD::Thumbnail::create($srcImage,50);
     open OUT, ">C:/Apache2/htdocs/recordz/thumb_test.jpg" or die "Could 
not save ";
     binmode OUT;
     print OUT $thumb->jpeg;
     close OUT;
}


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

Date: Mon, 27 Jun 2005 09:38:35 +0100
From: Brian Wakem <no@email.com>
Subject: Re: simple upload
Message-Id: <3i9s8bFkh2ucU1@individual.net>

Alexandre Jaquet wrote:

> Hi,
> 
> I could not figure why image in my upload directory was empty
> here is my code :
> 
> sub uploadImage {
>      my $name = shift || '';
>      my $file = $query->param('image');
> 
>      my $tmpfile=$file;
> 
>      open TMP,"C:/Apache2/htdocs/recordz/upload/$tmpfile";



I suspect the file doesn't exist.  Please check the open has succeeded.


>      binmode TMP;
>      open OUT,"> C:/Apache2/htdocs/recordz/upload/$name.jpg";


I suspect this fails too.  Please check this also.



>      binmode OUT;
>      while (<TMP>)
>      {
>        print OUT $_;
> 
>      }


No even if both files are open, I assume $tmpfile is empty, so you write the
contents of an empty file to $name.jpg.


-- 
Brian Wakem



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

Date: Mon, 27 Jun 2005 10:43:05 +0200
From: Alexandre Jaquet <""alexjaquet\"@[no spam]msn.com">
Subject: Re: simple upload
Message-Id: <42bfbc29$0$1159$5402220f@news.sunrise.ch>

Brian Wakem a écrit :
> Alexandre Jaquet wrote:
> 
> 
>>Hi,
>>
>>I could not figure why image in my upload directory was empty
>>here is my code :
>>
>>sub uploadImage {
>>     my $name = shift || '';
>>     my $file = $query->param('image');
>>
>>     my $tmpfile=$file;
>>
>>     open TMP,"C:/Apache2/htdocs/recordz/upload/$tmpfile";
> 
> 
> 
> 
> I suspect the file doesn't exist.  Please check the open has succeeded.
> 
> 
> 
>>     binmode TMP;
>>     open OUT,"> C:/Apache2/htdocs/recordz/upload/$name.jpg";
> 
> 
> 
> I suspect this fails too.  Please check this also.
> 
> 
> 
> 
>>     binmode OUT;
>>     while (<TMP>)
>>     {
>>       print OUT $_;
>>
>>     }
> 
> 
> 
> No even if both files are open, I assume $tmpfile is empty, so you write the
> contents of an empty file to $name.jpg.
> 
> 

I missed multiform on my post action


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

Date: Mon, 27 Jun 2005 11:41:50 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: simple upload
Message-Id: <3i9vv1Fkhn7uU1@individual.net>

Alexandre Jaquet > wrote:
> Brian Wakem a écrit :
>> Alexandre Jaquet wrote:
>>> I could not figure why image in my upload directory was empty

<snip>

> I missed multiform on my post action

That's one of the common mistakes that are catched when using the CPAN 
module CGI::UploadEasy.

http://search.cpan.org/perldoc?CGI%3A%3AUploadEasy

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: 27 Jun 2005 10:56:42 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: UTF-8 to named character entities
Message-Id: <d9om1a$onj$1@mamenchi.zrz.TU-Berlin.DE>

Crap <crappi@hetnet-dot-nl.no-spam.invalid> wrote in comp.lang.perl.misc:
> Hi all,
> 
> I need a conversion from UTF-8 to named character entities (ë ->
> &euml;) and after using the file for publishing purposes I need
> to convert it back to UTF-8. I tried this with HTML:Entities but i
> get very strange results. I know very little about Perl and its
> available modules. I just got perl to work on my Mac. Below is a
> piece of my XML-file and the converted result. Can anybody please
> give me an advise on how to proceed.
> Thanks,
> Chris
> 
> -- XML --
> <a>(…). De andere soort is die welke de contacten en transacties
> tussen patiënten reguleert.’<vn>
> <al>
> <a>EN 1130b31-1131a.</a>
> </al>
> </vn>
> 
> -- after conversion --
> <a>(&acirc;€&brvbar;). De andere soort is
> die welke de contacten en transacties tussen
> pati&Atilde;&laquo;nten
> reguleert.&acirc;€™<vn>
> <al>
> <a>EN 1130b31-1131a.</a>
> </al>
> </vn>

After what conversion?  Please show the call to (presumably)
encode_entities() that produced the result you show.  Also explain in
what way it isn't what you expect.

Cutting and pasting your input into a Perl script

    use HTML::Entities;

    my $str = <<EOS;
    <a>(^E). De andere soort is die welke de contacten en transacties
    tussen patiënten reguleert.^R<vn>
    <al>
    <a>EN 1130b31-1131a.</a>
    </al>
    </vn>
    EOS

    print encode_entities( $str);

gives me different output:

    &lt;a&gt;(^E). De andere soort is die welke de contacten en transacties
    tussen pati&euml;nten reguleert.^R&lt;vn&gt;
    &lt;al&gt;
    &lt;a&gt;EN 1130b31-1131a.&lt;/a&gt;
    &lt;/al&gt;
    &lt;/vn&gt;

Anno


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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