[22614] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4835 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 11 21:05:35 2003

Date: Fri, 11 Apr 2003 18:05:05 -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           Fri, 11 Apr 2003     Volume: 10 Number: 4835

Today's topics:
    Re: avoid using extra variable <jurgenex@hotmail.com>
    Re: Capture URL Title & Regex <mbudash@sonic.net>
        DBI and binding [attempt 2] <bigus NO @ SPAM creationfactor .net>
    Re: DBI and binding [attempt 2] <bigus NO @ SPAM creationfactor .net>
    Re: DBI and binding <rereidy@indra.com>
    Re: DBI and binding <bigus NO @ SPAM creationfactor .net>
    Re: DBI and binding <mbudash@sonic.net>
    Re: From Perl 5.6 migration to 5.8 problem <kalinabears@hdc.com.au>
    Re: hashes as lists (Kevin Shay)
    Re: Perl/Shell Script with logs <bob@aol.com>
    Re: Ugly code; what does it do? <acm2@ukc.ac.uk>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 12 Apr 2003 00:40:31 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: avoid using extra variable
Message-Id: <3gJla.262$ok3.105@nwrddc03.gnilink.net>

Eric Osman wrote:
> The following attempt to avoid the variable doesn't produce the
> desired result:
>
>       my $index = 7;
>       print "The previous index which is $index-1 is an even
> number\n";

Does

    print "The previous index which is " . $index-1 . " is an even
number\n";

work for you?

jue




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

Date: Fri, 11 Apr 2003 23:03:44 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Capture URL Title & Regex
Message-Id: <mbudash-5B84B5.16034411042003@typhoon.sonic.net>

In article <3e9714fa$0$89190$a0465688@nnrp.fuse.net>,
 "Paanwa" <paanwa@hotmail.com> wrote:

> I am wondering if there is a better way of capturing the title of a URL.  I
> am using it in conjunction with a 'send this page to a friend' script.  Is
> there a more efficient way of capturing the title?
> 
> code example:
> --------------------------------
> my $Url;
> my $UrlTitle;
>  $Url = $ENV{HTTP_REFERER};  # The URL of the referring page.
>  use LWP::Simple;
>  $UrlTitle = get $Url;                         #Read the content of the URL
> into a string variable.
> s/.*(<title>)//s for $UrlTitle;              #Dump all text prior to <title>
> tag.
> s/(<\/title>).*//s for $UrlTitle;            #Dump all text after </title>
> tag.
> 
> PAW
> 
> 

use LWP::Simple;
use HTML::TokeParser;
my $c = get $Url;
my $p = HTML::TokeParser->new(\$c);                        
my $tag = $p->get_tag("title");
print $p->get_text, "\n";

hth-

-- 
Michael Budash


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

Date: Fri, 11 Apr 2003 23:19:22 +0100
From: "Bigus" <bigus NO @ SPAM creationfactor .net>
Subject: DBI and binding [attempt 2]
Message-Id: <zbHla.214$FA6.4254@newsfep4-glfd.server.ntli.net>

Hi

I've not used DBI before and am having problems getting the hang of binding.

I have a routine like this:

============================
# --- prepare query --- #

if($by eq "thread"){
  $sth = $db->prepare("SELECT * FROM thetable WHERE refs LIKE '%$display%'
OR messageid = '$display' ORDER BY article DESC");}

elsif($by eq "poster"){
  $sth = $db->prepare("SELECT * FROM thetable WHERE poster = '$display'
ORDER BY thedate DESC");}

elsif($by eq "date"){
  $sth = $db->prepare("SELECT * FROM thetable
WHERE thedate LIKE '$display%' ORDER BY thedate DESC");}

# --- execute the query --- #

if(!$sth->execute){
  print "Failed to get data from thetable";}

else{
  while(@row = $sth->fetchrow_array){
    # code to process records
  }
}
============================

What that does is checks to see what format the data in $display is going to
by looking at the $by variable. It then prepares the appropriate SELECT
query.

$display will either be the reference of posting that started a thread in a
newsgroup, or the poster's name, or the date. The query needs to match the
contents of the appropriate column in different ways (ie: some of them use
LIKE and wildcards.. this is Jet SQL to an Access database, btw).

The problem is that $display can contain any characters, so after a previous
enquiry Benjamin kindly pointed me in the direction of "binding".

So, I've tried substituting $display for a ? and then doing
"$sth->execute($display)" but it didn't pick up any records (plus when
retrieving records by thread, it wants 2 bind parameters). I guess I must be
using the bind thingies incorrectly, but I've failed to crack it so far, so
wondering if anyone can give me a further pointer?

Many thanks

Bigus




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

Date: Fri, 11 Apr 2003 23:25:57 +0100
From: "Bigus" <bigus NO @ SPAM creationfactor .net>
Subject: Re: DBI and binding [attempt 2]
Message-Id: <KhHla.219$FA6.4077@newsfep4-glfd.server.ntli.net>


"Bigus" <bigus NO @ SPAM creationfactor .net> wrote in message
news:zbHla.214$FA6.4254@newsfep4-glfd.server.ntli.net...
> Hi
>
> I've not used DBI before and am having problems getting the hang of
binding.
>
> I have a routine like this:
>
> ============================
> # --- prepare query --- #
>
> if($by eq "thread"){
>   $sth = $db->prepare("SELECT * FROM thetable WHERE refs LIKE '%$display%'
> OR messageid = '$display' ORDER BY article DESC");}
>
> elsif($by eq "poster"){
>   $sth = $db->prepare("SELECT * FROM thetable WHERE poster = '$display'
> ORDER BY thedate DESC");}
>
> elsif($by eq "date"){
>   $sth = $db->prepare("SELECT * FROM thetable
> WHERE thedate LIKE '$display%' ORDER BY thedate DESC");}
>
> # --- execute the query --- #
>
> if(!$sth->execute){
>   print "Failed to get data from thetable";}
>
> else{
>   while(@row = $sth->fetchrow_array){
>     # code to process records
>   }
> }
> ============================
>
> What that does is checks to see what format the data in $display is going
to
> by looking at the $by variable. It then prepares the appropriate SELECT
> query.
>
> $display will either be the reference of posting that started a thread in
a
> newsgroup, or the poster's name, or the date. The query needs to match the
> contents of the appropriate column in different ways (ie: some of them use
> LIKE and wildcards.. this is Jet SQL to an Access database, btw).
>
> The problem is that $display can contain any characters,

It might help if I gave a couple of examples that have given me trouble..
that is, if the posters name contained in $display is say:

Fred[123]

or

John 'Johnny' Hill

then both fail whereas a poster with the name:

John

will work fine. So, apostrophes and square brackets probably need some sort
of escaping.. which is why binding was recommended.

Bigus




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

Date: Fri, 11 Apr 2003 16:13:42 -0600
From: Ron Reidy <rereidy@indra.com>
Subject: Re: DBI and binding
Message-Id: <3E973E16.4040206@indra.com>

So, what's the problem?  What are you expecting to see?

--
Ron Reidy
Oracle DNA

Bigus wrote:
> Hi
> 
> I've not used DBI before and am having problems getting the hang of binding.
> 
> I have a routine like this:
> 
> ============================
> if($by eq "vt"){
>   $sth = $db->prepare("SELECT * FROM thetable WHERE refs LIKE '%$display%'
> OR messageid = '$display' ORDER BY article DESC");}
> 
> elsif($by eq "vn"){
>   $sth = $db->prepare("SELECT * FROM thetable WHERE poster = '$display'
> ORDER BY thedate DESC");}
> 
> elsif($by eq "vd"){
>   $display =~ s/^(.*) .*/$1/; $sth = $db->prepare("SELECT * FROM thetable
> WHERE thedate LIKE '$display%' ORDER BY thedate DESC");}
> 
> 
> if(!$sth->execute){
>   print "Failed to get data from thetable";}
> 
> else{
>   while(@row = $sth->fetchrow_array){
>     # code to process records
>   }
> }
> ============================
> 
> 



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

Date: Fri, 11 Apr 2003 23:18:31 +0100
From: "Bigus" <bigus NO @ SPAM creationfactor .net>
Subject: Re: DBI and binding
Message-Id: <MaHla.212$FA6.4254@newsfep4-glfd.server.ntli.net>

"Ron Reidy" <rereidy@indra.com> wrote in message
news:3E973E16.4040206@indra.com...
> So, what's the problem?  What are you expecting to see?

Sorry.. I posted that prematurely and cancelled the message (but evidently
not quick enough for everybody ;).. please see the full version.

Regards

Bigus




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

Date: Fri, 11 Apr 2003 23:09:48 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: DBI and binding
Message-Id: <mbudash-018449.16094711042003@typhoon.sonic.net>

In article <k9Hla.210$FA6.4057@newsfep4-glfd.server.ntli.net>,
 "Bigus" <bigus NO @ SPAM creationfactor .net> wrote:

> Hi
> 
> I've not used DBI before and am having problems getting the hang of binding.
> 
> I have a routine like this:
> 
> ============================
> # --- prepare query --- #
> 
> if($by eq "thread"){
>   $sth = $db->prepare("SELECT * FROM thetable WHERE refs LIKE '%$display%'
> OR messageid = '$display' ORDER BY article DESC");}
> 
> elsif($by eq "poster"){
>   $sth = $db->prepare("SELECT * FROM thetable WHERE poster = '$display'
> ORDER BY thedate DESC");}
> 
> elsif($by eq "date"){
>   $sth = $db->prepare("SELECT * FROM thetable
> WHERE thedate LIKE '$display%' ORDER BY thedate DESC");}
> 
> # --- execute the query --- #
> 
> if(!$sth->execute){
>   print "Failed to get data from thetable";}
> 
> else{
>   while(@row = $sth->fetchrow_array){
>     # code to process records
>   }
> }
> ============================
> 
> What that does is checks to see what format the data in $display is going to
> by looking at the $by variable. It then prepares the appropriate SELECT
> query.
> 
> $display will either be the reference of posting that started a thread in a
> newsgroup, or the poster's name, or the date. The query needs to match the
> contents of the appropriate column in different ways (ie: some of them use
> LIKE and wildcards.. this is Jet SQL to an Access database, btw).
> 
> The problem is that $display can contain any characters, so after a previous
> enquiry Benjamin kindly pointed me in the direction of "binding".
> 
> So, I've tried substituting $display for a ? and then doing
> "$sth->execute($display)" but it didn't pick up any records (plus when
> retrieving records by thread, it wants 2 bind parameters). I guess I must be
> using the bind thingies incorrectly, but I've failed to crack it so far, so
> wondering if anyone can give me a further pointer?
> 
> Many thanks
> 
> Bigus
> 
> 

let's see your actual code that doesn't work...

btw, binding (in this case, placeholders) is one way to handle this. 
here's another:

$quoted_display = $db->quote($display);

now use $quoted_display in place of $display in your above sql 
statements.

hth-

-- 
Michael Budash


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

Date: Sat, 12 Apr 2003 09:15:38 +1000
From: "Sisyphus" <kalinabears@hdc.com.au>
Subject: Re: From Perl 5.6 migration to 5.8 problem
Message-Id: <3e974d8e$0$31384@echo-01.iinet.net.au>


"Kasp" <kasp@epatra.com> wrote in message
news:b75ofe$vtp$1@newsreader.mailgate.org...
> Hi,
>
> I am facing a peculiar problem. Wonder if anyone out here has faced
> something similar and has a solution.
>
> I can compile and run a piece of code (on Windows 2000) written in C++
that
> uses Perl libraries (Perl56.lib + PerlEz.lib). Now that I want it to run
> with Perl 5.8, I simply tried to replace these files with those from
version
> Perl5.8. But now it does not link. The error I get is:
>
> "PerlInterp.obj : error LNK2001: unresolved external symbol _Perl_sv_2pv
> ../bin/debug/Scrubber.exe : fatal error LNK1120: 1 unresolved externals"
>

It might need to find 'perl58.lib' (located in perl\lib\core\) to "resolve"
that "external symbol".

Are you sure that all references to 'perl56*' have been amended to 'perl58*'
?

Cheers,
Rob




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

Date: 11 Apr 2003 17:12:34 -0700
From: kevin_shay@yahoo.com (Kevin Shay)
Subject: Re: hashes as lists
Message-Id: <5550ef1e.0304111612.626d295a@posting.google.com>

genericax@hotmail.com (Sara) wrote in message
news:<776e0325.0304110624.9c187bf@posting.google.com>
> Now I have a request. Eric and I talked about (2) useful ways to deal
> with hashes with a succinct and effective syntax. I suspect the Guru's
> know about 1000 more that we hadn't thought of- so even though it may
> see obvious to you, please post more here?

Here's one: when you have an array and/or a list of values, and you
want to succinctly create a hash whose keys are those values (so you
can do "does this value exist?" checks):

my %h = map { $_ => 1 } (@a, $foo, $bar);

Kevin
--
perl -MLWP::UserAgent -e '$u=new LWP::UserAgent;$u->agent("japh");
print join(" ",(split(/\s+/,(split/\n/,$u->request(HTTP::Request->
new(GET=>join("",split(/\n/,"http://groups.google.com/groups?selm=
4365%40omepd.UUCP&output=gplain"))))->content)[60]))[0..3]),",\n"'


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

Date: Fri, 11 Apr 2003 22:19:10 GMT
From: Optional <bob@aol.com>
Subject: Re: Perl/Shell Script with logs
Message-Id: <0dfe9v42efdo066vht7q5n2u6ejj7pevjk@4ax.com>

I've heard a rumor that on Thu, 10 Apr 2003 10:03:21 +0800,
"nntpquest" <nntpquest@yahoo.com> wrote the following:

>Hi
>
>I am not very good at Perl or Shell Script but I am trying to use either one
>to get useful information from my firewall logs easily.
>
>I have a sample of my firewall logs here and what I would like to do is to
>create a perl or shell script that will
>
>1. list all denied IP addresses only (source)(excluding ports)
>2. count how many times it was denied
>3. count how many times access to an IP address is denied (destination) and
>the IP address itself
>
>Is there anyone out there who is willing to help me? Thank you.
>
>Apr 10 09:21:00 firewall %PIX-6-106015: Deny TCP (no connection) from
>10.7.1.34/80 to 203.82.66.1/1433 flags SYN ACK  on interface others
>Apr 10 09:21:00 firewall %PIX-6-106015: Deny TCP (no connection) from
>219.95.50.173/64515 to 123.123.123.123/80 flags FIN ACK  on interface
>outside
>Apr 10 09:21:01 firewall %PIX-6-106015: Deny TCP (no connection) from
>202.71.98.114/2837 to 123.123.123.123/80 flags FIN PSH ACK  on interface
>outside
>Apr 10 09:21:01 firewall %PIX-6-106015: Deny TCP (no connection) from
>203.82.66.1/1274 to 234.234.234.234/80 flags RST  on interface outside
>Apr 10 09:21:02 firewall %PIX-4-106023: Deny tcp src outside:64.4.9.59/4708
>dst others:234.234.234.234/25 by access-group "out2in"
>Apr 10 09:21:02 firewall %PIX-6-106015: Deny TCP (no connection) from
>203.82.66.1/1425 to 234.234.234.234/80 flags RST  on interface outside
>Apr 10 09:21:03 firewall %PIX-6-106015: Deny TCP (no connection) from
>219.95.50.173/64515 to 123.123.123.123/80 flags FIN ACK  on interface
>outside
>Apr 10 09:21:09 firewall %PIX-6-106015: Deny TCP (no connection) from
>202.185.19.11/4101 to 123.123.123.123/80 flags RST  on interface outside
>Apr 10 09:21:09 firewall %PIX-6-106015: Deny TCP (no connection) from
>210.195.240.58/3197 to 345.345.345.345/80 flags ACK  on interface outside
>Apr 10 09:21:09 firewall %PIX-6-106015: Deny TCP (no connection) from
>210.195.240.58/3198 to 345.345.345.345/80 flags ACK  on interface outside
>Apr 10 09:21:09 firewall %PIX-6-106015: Deny TCP (no connection) from
>219.95.50.173/64515 to 123.123.123.123/80 flags FIN ACK  on interface
>outside
>Apr 10 09:21:13 firewall %PIX-6-106015: Deny TCP (no connection) from
>210.195.150.71/1069 to 123.123.123.123/80 flags RST  on interface outside
>Apr 10 09:21:13 firewall %PIX-4-106023: Deny tcp src
>outside:202.188.127.61/38345 dst others:345.345.345.345/21 by access-group
>"out2in"
>Apr 10 09:21:13 firewall %PIX-6-106015: Deny TCP (no connection) from
>210.195.150.71/1069 to 123.123.123.123/80 flags RST  on interface outside
>Apr 10 09:21:14 firewall %PIX-6-106015: Deny TCP (no connection) from
>219.93.8.5/63418 to 234.234.234.234/80 flags FIN ACK  on interface outside
>Apr 10 09:21:14 firewall %PIX-6-106015: Deny TCP (no connection) from
>219.93.8.5/63418 to 234.234.234.234/80 flags FIN ACK  on interface outside
>Apr 10 09:21:15 firewall %PIX-6-106015: Deny TCP (no connection) from
>210.195.240.58/3202 to 345.345.345.345/80 flags ACK  on interface outside
>Apr 10 09:21:16 firewall %PIX-6-106015: Deny TCP (no connection) from
>210.195.240.58/3202 to 345.345.345.345/80 flags ACK  on interface outside
>Apr 10 09:21:16 firewall %PIX-4-106023: Deny tcp src
>outside:202.188.127.61/38345 dst others:345.345.345.345/21 by access-group
>"out2in"
>Apr 10 09:21:19 firewall %PIX-6-106015: Deny TCP (no connection) from
>161.142.234.67/1504 to 123.123.123.123/80 flags RST  on interface outside
>Apr 10 09:21:21 firewall %PIX-6-106015: Deny TCP (no connection) from
>219.95.50.173/64515 to 123.123.123.123/80 flags FIN ACK  on interface
>outside
>Apr 10 09:21:22 firewall %PIX-6-106015: Deny TCP (no connection) from
>202.75.183.217/11205 to 123.123.123.123/80 flags FIN ACK  on interface
>outside
>Apr 10 09:21:22 firewall %PIX-4-106023: Deny tcp src
>outside:209.202.131.231/59508 dst others:234.234.234.234/25 by access-group
>"out2in"
>Apr 10 09:21:24 firewall %PIX-6-106015: Deny TCP (no connection) from
>202.75.183.217/11205 to 123.123.123.123/80 flags FIN ACK  on interface
>outside
>
>

OK, not having a ton of time to put into this, I came up with this to
parse out the info you need.  All you have to do is create a hash and
stuff the IP (as key) in and incriment counter for each.  You may want
a hash for source and 1 for destination...

#!/usr/bin/perl -w
use strict;
my (
    $foo1,     $foo2, $type1,  $bar1, $bar2, $from1,
    $fromport, $to1,  $toport, $int1, $line
  )
  = undef;

open( INPUTFH, "fwlog.txt" ) or die "\n\n\tCan't open input file\n\n";

while ( $line = <INPUTFH> ) {    #Start processing loop
    chomp($line);
    $line =~ s/^\s+//g;          #Strip leading white space

    ( $foo2, $foo1 ) = split ( ": ", $line );

    if ( $line =~ /from/i ) {
        ( $type1, $bar1 )     = split ( "from ",   $foo1 );
        ( $from1, $bar1 )     = split ( " to ",    $bar1 );
        ( $from1, $fromport ) = split ( "/",       $from1 );
        ( $to1,   $int1 )     = split ( " flags ", $bar1 );
        ( $to1,   $toport )   = split ( "/",       $to1 );
    }
    else {
        ( $type1,    $bar1 )     = split ( "side:", $foo1 );
        ( $from1,    $bar2 )     = split ( ":",     $bar1 );
        ( $from1,    $fromport ) = split ( "/",     $from1 );
        ( $fromport, $foo2 )     = split ( " ",     $fromport );
        ( $to1,      $int1 )     = split ( " by ",  $bar2 );
        ( $to1,      $toport )   = split ( "/",     $to1 );
    }

    print
"Type is: $type1\nFrom IP is: $from1\nFrom port is: $fromport\nTo IP
is: $to1\nTo port is: $toport\nOther info is: $int1\n\n";
    (
        $foo1,     $foo2, $type1,  $bar1, $bar2, $from1,
        $fromport, $to1,  $toport, $int1, $line
      )
      = undef;
}

If you want date/time also, that (and other stuff) is held in $foo2
and you can do whatever you want with it from there.

HTH!


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

Date: Fri, 11 Apr 2003 23:28:42 +0100
From: Tony McNulty <acm2@ukc.ac.uk>
Subject: Re: Ugly code; what does it do?
Message-Id: <oprnhkp4mj2czp9w@news.ukc.ac.uk>

On Fri, 11 Apr 2003 21:14:00 GMT, Michael P. Broida 
<michael.p.broida@boeing.com> wrote:

[snip]

> 	At the very end, I don't understand the use of:
> 			if( $$[-1] );

$$[-1] refers to the last element of the array. Useful tool that I've not 
seen in any other language.

i.e., @a = qw/a b c/;print $a[-1]; would print out the letter c.

> 		Thanks again!
> 			Mike

np.

-- 
--------------------------------------
web:   http://mercutio.digitalrice.com
email: acm2 at ukc dot ac dot uk
--------------------------------------


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

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


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