[23007] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5227 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Jul 16 03:05:48 2003

Date: Wed, 16 Jul 2003 00: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           Wed, 16 Jul 2003     Volume: 10 Number: 5227

Today's topics:
    Re: Devel::Coverage <jacqui.caren@ntlworld.com>
    Re: filehandle to variable problem (Jay Tilton)
        Help understanding MAP <Jodyman@hotmail.com>
    Re: Help understanding MAP <nanae@perusion.com>
    Re: Help understanding MAP <uri@stemsystems.com>
    Re: Help understanding MAP <thepoet@nexgo.de>
    Re: Need Perl teacher/school: Network programming <jacqui.caren@ntlworld.com>
    Re: Need Perl teacher/school: Network programming <flavell@mail.cern.ch>
        Perl Script creates html doc - want to jump to anchor (TWW)
    Re: Perl Script creates html doc - want to jump to anch <asu1@c-o-r-n-e-l-l.edu>
    Re: Perl Script creates html doc - want to jump to anch <nanae@perusion.com>
        Running CGI through browser from local hard disk (Dr. John P. Costella)
    Re: Running CGI through browser from local hard disk <bwalton@rochester.rr.com>
    Re: Running CGI through browser from local hard disk <asu1@c-o-r-n-e-l-l.edu>
    Re: Running CGI through browser from local hard disk <noreply@gunnar.cc>
    Re: Running CGI through browser from local hard disk <fluhmann@vvm.com>
    Re: sprintf help (Jay Tilton)
    Re: text parse (david)
    Re: Use module (maybe) w/o dying SOLVED <jaspax@u.washington.edu>
    Re: Use module (maybe) w/o dying <REMOVEsdnCAPS@comcast.net>
    Re: Use module (maybe) w/o dying (gnarred)
    Re: Win32::GUI <fluhmann@vvm.com>
    Re: Win32::GUI jnk@kenobiz.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 15 Jul 2003 23:14:26 +0100
From: Jacqui Caren <jacqui.caren@ntlworld.com>
Subject: Re: Devel::Coverage
Message-Id: <Xns93B9EC6E879EFjacquicntlworldcom@195.8.68.222>

jkeen@concentric.net (James E Keenan) wrote in
news:b955da04.0307021258.5b01e5a3@posting.google.com: 

> himal5@hotmail.com (Himal) wrote in message
> news:<365e1935.0307020447.57c48e88@posting.google.com>... 
>> Well it was my error in using Devel::Coverage that was giving me
>> problems.
>> 
>> I have downloaded Devel-Coverage-0.2.gz from CPAN and the README in
>> it explains it rather simply how to go about it.
>> 
>> There do seem to be an issue using it with perl 5.8.0.
>> 
> 
> I took a look at this myself.  Note that version 0.2 has not been
> updated since July 2000 (predating Perl 5.8 by 23 months) and did not
> include *any* tests in its distribution.  Having no tests, it never
> passed any installation tests conducted by CPAN testers.  If you have
> further problems with it, you will have no choice but to contact the
> module's author directly -- and hope he is still maintaining it!
> 
> Jim Keenan
> 

Or take over ownership of the module if the owner is no longer 
contactable.

Another option is to contact the perl "qwalitee" folks who appear to take
a very light hearted approach to quality are actualy wokring on some 
neat tools. At least they were the last time I had eought tuits spare to
read p5p :-)

Jacqui
 


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

Date: Tue, 15 Jul 2003 22:57:49 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: filehandle to variable problem
Message-Id: <3f1486d5.27017246@news.erols.com>

mathias <mathias@gms.lu> wrote:

: Greg Bacon wrote:
: 
: > : like *main::FH or main::STDOUT or GLOB(0x80f60ac)
: > 
: > It's a filehandle.  Why do you care what it looks like when you print
: > its internal representation?  What did you expect to happen?
: > 
: > Greg

: well i was waiting for bla instead of any of the strings i had.
: can you give me a way then to get "bla" from this filehandle ?

Your code is short enough that including it in the article is
preferable to making readers go out to the web to see it.

[grabbed from http://www.tiasarea.org/perl.html]
    #!/usr/bin/perl -w
    use strict;

    sub runme {
    my $fh=shift;
    print $fh "bla\n"; }

    my $var;
    open FH, '>', \$var;
    runme(\*FH);
    $var = *FH;
    close FH;

    print "var: \n";
    print ">".$var."<\n";

    the output from this script is: 
    var: 
    >*main::FH< 

In Perl 5.8.0, "open FH, '>', \$var" will cause stuff printed to FH to
go into $var.  Cut out the "$var = *FH;" line and look in $var for
your 'bla'.

In an older Perl, that form of open() does not have the same behavior.
It just ends up stringifying the scalar reference, creating a file
named like "SCALAR(0x1a653b4)".



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

Date: Wed, 16 Jul 2003 04:43:41 GMT
From: "Jodyman" <Jodyman@hotmail.com>
Subject: Help understanding MAP
Message-Id: <1K4Ra.103347$Io.8885149@newsread2.prod.itd.earthlink.net>

After reading llama, camel, perldoc and searching web for explainations, I
just don't get how map works.

I'm sure it is something simple.  I'm sure it's what I need to solve my
problem.

I've tried the following and received no results (printed blanks):

my $n = 0;
my %b = map { $_ => $n++ } @na;

and:

my %b36 = map { $b36{$_} } @na;

@na contains a list of numbers from ( 48 .. 57 and 65 .. 90 ) [0-9 and A-Z]

I'm trying to create a base 36 counter so as I count 0 - 35 I grab the
corresponding:

0   1    2   3   4   5   6   7   8   9  10 11 12 ... 34 35
48 49 50 51 52 53 54 55 56 57 65 66 67 ... 89 90
0   1    2   3   4   5   6   7   8   9   A  B  C       Y  Z

I just don't understand the construction of map.  How it works with lists
and hashes.

Any help would be appreciated.

Jodyman




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

Date: Wed, 16 Jul 2003 05:07:06 +0000 (UTC)
From: Perusion hostmaster <nanae@perusion.com>
Subject: Re: Help understanding MAP
Message-Id: <slrnbh9nbq.eu6.nanae@ns.valuemedia.com>

On Wed, 16 Jul 2003 04:43:41 GMT, Jodyman <Jodyman@hotmail.com> wrote:
> After reading llama, camel, perldoc and searching web for explainations, I
> just don't get how map works.
> 
> I'm sure it is something simple.  I'm sure it's what I need to solve my
> problem.
> 
> I've tried the following and received no results (printed blanks):
> 
> my $n = 0;
> my %b = map { $_ => $n++ } @na;
> 
> and:
> 
> my %b36 = map { $b36{$_} } @na;
> 
> @na contains a list of numbers from ( 48 .. 57 and 65 .. 90 ) [0-9 and A-Z]

Just a little list context problem. Without surrounding parens, the
second value is output as the result of the map (remember => is nothing
but a comma in practice).

	my @na = ( 48 .. 57, 65 .. 90 );
	my $n = 0;
	my %b = map { ($_ => $n++) } @na;

	use Data::Dumper; 
	$Data::Dumper::Terse = 1;

	print Dumper(\%b);


-- 
Perusion Hostmaster

"Being against torture ought to be sort of a bipartisan thing."
-- Karl Lehenbauer


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

Date: Wed, 16 Jul 2003 05:19:49 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Help understanding MAP
Message-Id: <x7isq33v62.fsf@mail.sysarch.com>

>>>>> "Ph" == Perusion hostmaster <nanae@perusion.com> writes:

  >> I've tried the following and received no results (printed blanks):
  >> 
  >> my $n = 0;
  >> my %b = map { $_ => $n++ } @na;
  >> 
  >> and:
  >> 
  >> my %b36 = map { $b36{$_} } @na;
  >> 
  >> @na contains a list of numbers from ( 48 .. 57 and 65 .. 90 ) [0-9 and A-Z]

  Ph> Just a little list context problem. Without surrounding parens, the
  Ph> second value is output as the result of the map (remember => is nothing
  Ph> but a comma in practice).

  Ph> 	my %b = map { ($_ => $n++) } @na;

those parens are not needed. from perldoc -f map:

	Evaluates BLOCK or EXPR in list context,

the real bug is this line:

	my %b36 = map { $b36{$_} } @na;
                        ^^^^

i don't see where %b36 is initialized. i think he meant to use $b{$_} in
the map block.

and even with that fix it makes no sense. that map makes a list of @na's
elements converted to their index. so it has 1 for 1 conversion. but it
is being assigned to a hash which wants pairs of key/values (such as
with the first assignment to %b). so i don't know what the OP really
wants and how to fix it since he hasn't stated what %b36 should
have. maybe it was supposed to be @b36 which makes more sense as he is
just converting numbers to their indices (doing base 36 math it seems).

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Wed, 16 Jul 2003 08:46:08 +0200
From: "Christian Winter" <thepoet@nexgo.de>
Subject: Re: Help understanding MAP
Message-Id: <3f14f4b1$0$6766$9b4e6d93@newsread2.arcor-online.net>

"Jodyman" <Jodyman@hotmail.com> wrote:
> After reading llama, camel, perldoc and searching web for explainations,
I
> just don't get how map works.
>
> I'm sure it is something simple.  I'm sure it's what I need to solve my
> problem.

Should be so.
IMHO the first map statement should read like
my %b = map { $n++ => chr($_) } (48..57,65..90);
which is equvalent to
my %b = map { $n++, chr($_) } (48..57,65..90);
(Just the "=>").

If i got it right, you then simply want to construct
a reverse hash in %b36.
$n = 0;
my %b36 = map { chr($_) => $n++ } (48..57,65..90);
or using the previously generated %b hash:
my %b36 = map { $b{$_} => $_ } keys %b;

HTH
-Christian



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

Date: Tue, 15 Jul 2003 23:11:08 +0100
From: Jacqui Caren <jacqui.caren@ntlworld.com>
Subject: Re: Need Perl teacher/school: Network programming
Message-Id: <Xns93B9EBDEDEB99jacquicntlworldcom@195.8.68.222>

Irving Kimura <irving_kimura@lycos.com> wrote in news:bdv3bi$r7m$1
@reader1.panix.com:

> I appreciate the pointer, but I'm familiar with that script, and
> I can tell you that 1) it can't handle anything other than the
> simplest HTTP; most importantly, it doesn't listen to the HTTPS
> port; and 2) some of the classes it uses have changed since 1997,
> and as a result the script is broken.

Have you considered taking the apache proxy code (under apache2)
and putting the logging code into this.

The perl proxy module can and does allow you to do some wondefull
things - not just content lagging.

I and a work colleague did a web proxy that converted certain
occurrences of Microsoft specific terminology to Borgism's
such as drone, collective, assimilation :-)

We then pointed it at a number of web sites - the results were
VERY scary...

The object of the excercise was to get across the idea of contextual 
parsing of content. Our exercise was funny bu did get the very
important point across.

Note sure if anyone has gotten any of the proxy modules
working with SSL. Be very interested if they have though
although it does seem rather silly to app-relay what should
be a single SSL encypted connection and then store the contents
in plain text ;_)

Jacqui


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

Date: Wed, 16 Jul 2003 00:53:01 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Need Perl teacher/school: Network programming
Message-Id: <Pine.LNX.4.53.0307160041290.23806@lxplus084.cern.ch>

On Tue, Jul 15, Jacqui Caren inscribed on the eternal scroll:

> The perl proxy module can and does allow you to do some wondefull
> things - not just content lagging.

It's a bit warm for that just now  ;-)  SCNR

> Note sure if anyone has gotten any of the proxy modules
> working with SSL. Be very interested if they have though
> although it does seem rather silly to app-relay what should
> be a single SSL encypted connection and then store the contents
> in plain text ;_)

I'm a bit confused as to what you have in mind here.

If that's possible at all, I mean other than deliberate co-operation
between the server and the proxy, then it represents a complete
security failure. The client and server are supposed to negotiate an
end to end encrypted path precisely in order to prevent any
intermediate from overhearing what goes on.  If the proxy succeeds in
masquerading as the target server, then that whole purpose is
defeated, and the crypto folk would surely be working on overtime to
solve the problem, no?  But you know this already, so you must have
had something else in mind, I trow.

Sure, if you had the "proxy" (in the informal sense, rather than in
the strict HTTP sense) acting as an "httpd accelerator" (as the squid
folks used to call it, anyway), then from the point of view of the
client the "proxy" _is_ the end server, and what goes on behind the
scenes is something else.  OK, so I guess that might have been what
you had in mind...?

cheers

-- 
     "The operator has a long-standing problem with short formations" -
     news report about a train service - translation: the operator
     provides a short train, and the travellers get a long stand.


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

Date: 15 Jul 2003 21:13:42 -0700
From: tww@execpc.com (TWW)
Subject: Perl Script creates html doc - want to jump to anchor
Message-Id: <1abd8043.0307152013.45074ef6@posting.google.com>

Greetings,
I am writing a Perl script that generates html documents on the fly. 
In some instances the document is rather long, and the desire exists
to have the script result in the browser jumping to an anchor within
the document.

A file for the generated HTML document is not created.  Is this a
problem with my issue above?  Are there issues with not creating a
file that may come and haunt me in the future.

One suggestion was to append some Javascript code that gets executed
when the document is loaded (the Javascript references the anchor).

Perhaps this is in the wrong group, but I figured a Perl guru could
address this.

Thanks for any help you can offer,
Tom


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

Date: 16 Jul 2003 04:26:20 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Perl Script creates html doc - want to jump to anchor
Message-Id: <Xns93BA4780A653asu1cornelledu@132.236.56.8>

tww@execpc.com (TWW) wrote in news:1abd8043.0307152013.45074ef6
@posting.google.com:

> Greetings,
> I am writing a Perl script that generates html documents on the fly. 
> In some instances the document is rather long, and the desire exists
> to have the script result in the browser jumping to an anchor within
> the document.
> 
> A file for the generated HTML document is not created.  Is this a
> problem with my issue above?  Are there issues with not creating a
> file that may come and haunt me in the future.

If a file were generated, you could then redirect the browser to the 
specified anchor in the generated document.
 
> One suggestion was to append some Javascript code that gets executed
> when the document is loaded (the Javascript references the anchor).

You use the onload event handler for the document for this I guess.

> Perhaps this is in the wrong group, but I figured a Perl guru could
> address this.

You are probably better off asking this question in a CGI group (e.g 
comp.infosystems.www.authoring.cgi) as the solution does not depend on 
Perl.

-- 
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov


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

Date: Wed, 16 Jul 2003 04:51:47 +0000 (UTC)
From: Perusion hostmaster <nanae@perusion.com>
Subject: Re: Perl Script creates html doc - want to jump to anchor
Message-Id: <slrnbh9mf3.ei0.nanae@ns.valuemedia.com>

On 15 Jul 2003 21:13:42 -0700, TWW <tww@execpc.com> wrote:
> Greetings,
> I am writing a Perl script that generates html documents on the fly. 
> In some instances the document is rather long, and the desire exists
> to have the script result in the browser jumping to an anchor within
> the document.
> 
> A file for the generated HTML document is not created.  Is this a
> problem with my issue above?  Are there issues with not creating a
> file that may come and haunt me in the future.
> 
> One suggestion was to append some Javascript code that gets executed
> when the document is loaded (the Javascript references the anchor).
> 
> Perhaps this is in the wrong group, but I figured a Perl guru could
> address this.

No, nothing really to do with Perl per se.

I am surprised you didn't just try accessing the document with

	http://yourdocs.com/cgi-bin/perlprog#anchor

because it would work just fine providing you had

	<a name=anchor>something</a>

in your generated document.


-- 
Perusion Hostmaster

"Being against torture ought to be sort of a bipartisan thing."
-- Karl Lehenbauer


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

Date: 15 Jul 2003 19:11:06 -0700
From: jpcostella@hotmail.com (Dr. John P. Costella)
Subject: Running CGI through browser from local hard disk
Message-Id: <e5141246.0307151811.77bd99fe@posting.google.com>

Hi folks, this probably has a simple answer ... I'm new to Perl so
please be gentle. :)

I am trying to test what a browser would show when accessing a CGI
script, but without going through an actual server. I have Perl
running fine on the local machine (Win XP) and am working through some
tutorials etc. But if I try to access the file through MSIE it runs
the script from a command prompt rather than piping the result back to
the browser.

Is this possible to do without the actual server? (I intend to put the
final working script onto a real server down the track, but for
various reasons that's not possible at this time.)

Thanks greatly for any help. 

John Costella


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

Date: Wed, 16 Jul 2003 02:16:23 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Running CGI through browser from local hard disk
Message-Id: <3F14B56A.7020100@rochester.rr.com>

Dr. John P. Costella wrote:

 ...
> I am trying to test what a browser would show when accessing a CGI
> script, but without going through an actual server. I have Perl
> running fine on the local machine (Win XP) and am working through some
> tutorials etc. But if I try to access the file through MSIE it runs
> the script from a command prompt rather than piping the result back to
> the browser.
> 
> Is this possible to do without the actual server? (I intend to put the
> final working script onto a real server down the track, but for
> various reasons that's not possible at this time.)
 ...
> John Costella
> 

What do you have against running a local server?  Here is one in Perl if 
you don't have one:

use HTTP::Daemon;
use IPC::Open2;
$|=1;
my $server=HTTP::Daemon->new(LocalPort=>80,LocalAddr=>'localhost');
print "Please contact me at <URL:", $server->url, ">\n";
while($client=$server->accept){
	while(my $answer=$client->get_request){
		$ans=$answer->as_string;
		@ans=split /\n/,$ans;
		$client->autoflush;
		if($answer->method eq 'GET'){
			$path=$answer->url->path;
			(error,last) unless $path=~s#^/##;
			if($path=~/html$/i){
				$client->send_file_response($path);
				last;
			}
			if($path=~/cgi$/i){
				$ENV{REQUEST_METHOD}=$answer->method;
				$query=$answer->url->query;
				$ENV{CONTENT_LENGTH}=length($query);
				$ENV{QUERY_STRING}=$query;
				$out=`perl $path`;
				$out=~s/.*?\n\n//s; #remove HTTP header
				print $client $out;
				last;
			}
		}
		if($answer->method eq 'POST'){
			$path=$answer->url->path;
			(error,last) unless $path=~s#^/##;
			if($path=~/cgi$/i){
				$query=$answer->url->query;
				$ENV{REQUEST_METHOD}=$answer->method;
				for(@ans){
					$ENV{CONTENT_LENGTH}=$1 if /Content-Length: (\d+)/;
					$ENV{HTTP_REFERRER}=$1 if /Referer: (.*)/;
				}
				$query=$ans[-1];
				undef $CGI;undef $OUT;
				$pid=open2($CGI,$OUT,"perl","$path") or error;
				print $OUT $query;
				close $OUT;
				@out=<$CGI>;
				waitpid $pid,0;
				$out=join "\n",@out;
				$out=~s/.*?\n\n//s; #remove HTTP header
				print $client $out;
				last;
			}
		}
		last;
	}
	print "CLOSE: ", $client->reason, "\n" if $client->reason;
	undef $client;
}

sub error{
	$client->error(RC_FORBIDDEN);
	print "An error occurred in $ans\n";
}

-- 
Bob Walton



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

Date: 16 Jul 2003 02:30:07 GMT
From: "A. Sinan Unur" <asu1@c-o-r-n-e-l-l.edu>
Subject: Re: Running CGI through browser from local hard disk
Message-Id: <Xns93B9E4E8863ECasu1cornelledu@132.236.56.8>

jpcostella@hotmail.com (Dr. John P. Costella) wrote in 
news:e5141246.0307151811.77bd99fe@posting.google.com:

> Is this possible to do without the actual server? (I intend to put the
> final working script onto a real server down the track, but for
> various reasons that's not possible at this time.)

Install a web server on your computer. There are many available. Of course, 
you can always use Apache. In fact IndigoPerl packages the whole thing 
together (though I have never used it).

Sinan.

-- 
A. Sinan Unur
asu1@c-o-r-n-e-l-l.edu
Remove dashes for address
Spam bait: mailto:uce@ftc.gov


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

Date: Wed, 16 Jul 2003 04:31:22 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Running CGI through browser from local hard disk
Message-Id: <bf2dcn$abi9o$1@ID-184292.news.uni-berlin.de>

Dr. John P. Costella wrote:
> I am trying to test what a browser would show when accessing a CGI
> script, but without going through an actual server.

Well, you do need a server. It does not need to be a remote server, 
though, but you can well install a web server for development and test 
purposes on your local machine.

Personally I have good experiences from using the bundle available at 
http://www.indigostar.com/indigoperl.htm
I haven't heard of any solution that is easier to install than 
IndigoPerl, and it gives you Perl, Apache, CGI, PHP...

But since you already have Perl running, another option is to download 
and install a web server, such as Apache (http://www.apache.org/), 
separately.

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



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

Date: Tue, 15 Jul 2003 22:00:50 -0500
From: Jeremy Fluhmann <fluhmann@vvm.com>
Subject: Re: Running CGI through browser from local hard disk
Message-Id: <IwidnfmjW7w2IImiRTvUqw@vvm.com>


> I am trying to test what a browser would show when accessing a CGI
> script, but without going through an actual server. I have Perl
> running fine on the local machine (Win XP) and am working through some
> tutorials etc. But if I try to access the file through MSIE it runs
> the script from a command prompt rather than piping the result back to
> the browser.
> 
> Is this possible to do without the actual server? (I intend to put the
> final working script onto a real server down the track, but for
> various reasons that's not possible at this time.)

Try here: http://www.xarka.com/optiperl/index.html  it has a trial 
download and I think it's $29 to buy.  You may also do a search on 
http://download.com.com  I know I used to use one that had a separate 
window to show you what the CGI would look like in a Browser.  (I think 
it was the OptiPerl above.

Jeremy Fluhmann
McLane Information Systems



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

Date: Tue, 15 Jul 2003 22:20:02 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: sprintf help
Message-Id: <3f147a1c.23759541@news.erols.com>

Matt Oliverius <moliverius@w-link.net> wrote:

: Does anyone know of an alternate way of doing the following in Perl?
: 
: @caps{@buckets} = ('Half','Full')
: [sprintf('%0*b', scalar @buckets, $_) =~ /[01]/g];

Trying to get around 5.004's lack of a sprintf %b conversion?
It used to be done with pack/unpack.

    my $bcount = scalar @buckets;
    @caps{@buckets} =
      ('Half', 'Full')
      [ 
        (unpack('B32', pack 'N', $_) =~ m/[01]/g)
        [-@buckets .. -1] 
      ]

unpack('B*', pack 'N', $_) converts $_ to a string of 0/1 bits.

m/[01]/g bursts the first (the only) scalar value created by unpack()
into a list of 0/1 characters.

[-@buckets .. -1] slices the appropriate number of elements from the
end of the list created by m/[01]/g .



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

Date: 15 Jul 2003 20:22:43 -0700
From: dwlepage@yahoo.com (david)
Subject: Re: text parse
Message-Id: <b09a22ae.0307151922.35375f2f@posting.google.com>

dwlepage@yahoo.com (david) wrote in message news:<b09a22ae.0307151028.3c9e869d@posting.google.com>...
> dwlepage@yahoo.com (david) wrote in message news:<b09a22ae.0307141743.2450c9a4@posting.google.com>...
> > Im trying to parse a file with data such as this:
> > (ip's changed for obvious reasons)
> > 
> > acl add table=ipaddr name=127.0.0.1 burb=Firewall \
> >     comments='Firewall network object for DNS proxy ACL redirection' \
> >     lastchangedby='root on 08/12/02 13:36:23'
> > acl add table=ipaddr name=127.1.1.1 burb=external \
> >     lastchangedby='dlepage on 06/24/03 10:25:30'
> > 
> > I want the end output to look like:
> > 
> > acl add name=127.0.0.1 ipaddr=127.0.0.1 comments='Firewall network
> > object for DNS proxy ACL redirection'
> > acl add name=127.1.1.1 ipaddr=127.1.1.1 comments=
> > 
> > so basically I only want to capture the IP after the 'name=' value,
> > and anything in the 'comments' field, if at all. Here is what I have
> > so far, which works, but im so new to programming that I know my
> > coding stinks. Any suggestions to make this more efficient
> > appreciated.
> > 
> > #!/usr/bin/perl -w
> > use strict;
> > 
> > my ($ip,$comment);
> > 
> > open(IN, "<$ARGV[0]") || die "Cant open $!";
> > flock (IN, 1);
> > 
> > while( <IN> ) {
> > s/\\//g; # get rid of newlines
> > 
> >         # match on acl's with comments
> >         if (/^acl add table=ipaddr name=(\d+\.\d+\.\d+\.\d+) burb=(.+)
> > comments=
> > (.+)/) {
> >                 print "acl add name=$1 ipaddr=$1 comments=$3\n";
> >         }
> > 
> >         # else match without comments
> >         elsif (/^acl add table=ipaddr name=(\d+\.\d+\.\d+\.\d+)
> > burb=(.+)$/) {
> >                 print "acl add name=$1 ipaddr=$1 comments=\n";
> >         }
> > }
> > close(IN);
> > 
> > -d
> 
> 
> I did find a bug with this. There are continuation lines for each
> entry. Each line that I want to analyze should start with the 'add acl
> table' - this current version will not properly grab data after the
> continuation (\) line. Im trying to remove these now.

Ok, call me stupid. Since noone has anything to add, I thought id post
the solution I came up with.. It seems to work just fine..

use strict;

# check argvs
if (@ARGV != 1) {
print "Usage: perl acl.pl <filename>\n";
exit 666
}

# open and lock file
open(IN, "<$ARGV[0]") || die "Cant open \"$ARGV[0]\" : $!";
flock (IN, 1);
open(OUT, ">import.txt") || die "$!";
flock (IN, 2);

my ($line,$ip,$comment);

while (defined ($line = <IN> ))  {      # rejoin continuation lines
        chomp $line;
        if ($line =~ s/\\$//) {
            $line .= <IN>;
            redo unless eof(IN);
        }

        # match on lines with comments
        if ($line =~ /^acl add table=ipaddr name=(\d+\.\d+\.\d+\.\d+)
bu
rb=(.+) comments=(.+) lastchangedby=(.*)$/)  {
                print "acl add name=$1 ipaddr=$1 comments=$3\n";
        }

        # else match lines without comments
        elsif ($line =~ /^acl add table=ipaddr
name=(\d+\.\d+\.\d+\.\d+)
 burb=(.+) lastchangedby=(.*)$/) {
                print "acl add name=$1 ipaddr=$1 comments=\n";
        }
}
close(IN);
close(OUT);

__DATA__
acl add table=ipaddr name=127.0.0.1 burb=Firewall \
           comments='Firewall network object for DNS proxy ACL
redirection' \
           lastchangedby='root on 08/12/02 13:36:23'
acl add table=ipaddr name=127.1.1.1 burb=external \
          lastchangedby='dlepage on 06/24/03 10:25:30'

output:

acl add name=127.0.0.1 ipaddr=127.0.0.1 comments='Firewall network
object for DNS proxy ACL redirection'
acl add name=127.1.1.1 ipaddr=127.1.1.1 comments=

Thanks for all the help.


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

Date: Tue, 15 Jul 2003 23:17:34 -0700
From: JS Bangs <jaspax@u.washington.edu>
Subject: Re: Use module (maybe) w/o dying SOLVED
Message-Id: <Pine.A41.4.55.0307152312210.74042@dante18.u.washington.edu>

JS Bangs sikyal:

> nobull@mail.com sikyal:
>
> > sholden@flexal.cs.usyd.edu.au (Sam Holden) wrote in message news:<slrnbh7fkd.75q.sholden@flexal.cs.usyd.edu.au>...
> > > On Tue, 15 Jul 2003 00:07:46 -0700, JS Bangs <jaspax@u.washington.edu> wrote:
> > > > I'm stumped. I wanted to use a module if it was available, but not to die
> > > > if the module was unavailable. I originally wrote:
> > > >
> > > > our $WHATIF = 0;
> > > > eval {
> > > > 	use Whatif;
> > > > 	$WHATIF = 1;
> > > > };
> >
> > > eval "use Whatif;";
> > > $WHATIF = 1 unless $@;
> >
> > I prefer the idiom:
> >
> > our $WHATIF = eval "use Whatif; 1";
>
> I had tried the string approach, but with no luck. Looking at the debugger
> more carefully, it appears that Whatif is successfully used, but the
> whatif block later in the codes doesn't work correctly.
>
> I suspect the problem has to do with the whatif block itself, now. Thanks
> for helping me eliminate this as a potential source of the problem.

This proved to be the case. Because Whatif isn't used at compile time, its
prototypes aren't loaded, so the whatif block later in the code doesn't
compile correctly. I was able to fix the problem by moving the string eval
into a BEGIN block. I also decided to define a dummy whatif() to be used
when the real thing isn't available, so that compilation of the whatif
block always proceeds the same and to obviate the need for the $WHATIF
variable. The final result looks like this:

BEGIN {
    eval 'sub whatif (&;$) {}' if not eval 'use Whatif; 1';
}

Short and sweet and does the trick. Something like this should be useful
to other people in a similar situation.


Jesse S. Bangs jaspax@u.washington.edu
http://students.washington.edu/jaspax/
http://students.washington.edu/jaspax/blog


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

Date: Tue, 15 Jul 2003 22:06:15 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Use module (maybe) w/o dying
Message-Id: <Xns93B9EB0FFC63Asdn.comcast@206.127.4.25>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

JS Bangs <jaspax@u.washington.edu> wrote in
news:Pine.A41.4.55.0307150002510.66634@dante18.u.washington.edu: 

> I'm stumped. I wanted to use a module if it was available, but not to
> die if the module was unavailable. I originally wrote:
> 
> our $WHATIF = 0;
> eval {
>      use Whatif;
>      $WHATIF = 1;
> };

"use" happens at compile-time, and the eval block is compiled when the 
program is compiled.  *Not* when the eval gets executed, at run-time.

There are two solutions.  One is to delay the compilation until run-time 
by enclosing the "use" in a string:

    eval 'use Whatif';
    $whatif_available = $@? 0 : 1;

I don't like that approach, because it involves the overhead of invoking 
the compiler again at run-time.  The second approach is:

    eval {require Whatif};
    $whatif_available = $@? 0 : 1;

"require" happens at runtime, not when the eval block is compiled.

If you need the determination to be made at compile-time; for example if 
subroutines or other things depend on whether the module is available, 
you should enclose the whole thing in a BEGIN block:

    BEGIN {
        eval { require Whatif };
        $whatif_available = $@? 0 : 1;
    }

- -- 
Eric
$_ =  reverse sort qw p ekca lre Js reh ts
p, $/.r, map $_.$", qw e p h tona e; print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBPxTBL2PeouIeTNHoEQL28QCeI9SrFCotoNUCmD1hXLnpcbGX8ewAnA6L
ov7KK4/ufUFzF7vBOBAbDDm1
=a3xo
-----END PGP SIGNATURE-----


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

Date: 15 Jul 2003 20:37:59 -0700
From: gnarred@yahoo.com (gnarred)
Subject: Re: Use module (maybe) w/o dying
Message-Id: <2edd058c.0307151937.1d4a2720@posting.google.com>

JS Bangs <jaspax@u.washington.edu> wrote in message news:<Pine.A41.4.55.0307151352120.91260@dante60.u.washington.edu>...
> nobull@mail.com sikyal:
> 
> > sholden@flexal.cs.usyd.edu.au (Sam Holden) wrote in message news:<slrnbh7fkd.75q.sholden@flexal.cs.usyd.edu.au>...
> > > On Tue, 15 Jul 2003 00:07:46 -0700, JS Bangs <jaspax@u.washington.edu> wrote:
> > > > I'm stumped. I wanted to use a module if it was available, but not to die
> > > > if the module was unavailable. I originally wrote:
> > > >
> > > > our $WHATIF = 0;
> > > > eval {
> > > > 	use Whatif;
> > > > 	$WHATIF = 1;
> > > > };
>  
> > > eval "use Whatif;";
> > > $WHATIF = 1 unless $@;
> >
> > I prefer the idiom:
> >
> > our $WHATIF = eval "use Whatif; 1";
> 
> I had tried the string approach, but with no luck. Looking at the debugger
> more carefully, it appears that Whatif is successfully used, but the
> whatif block later in the codes doesn't work correctly.
> 
> I suspect the problem has to do with the whatif block itself, now. Thanks
> for helping me eliminate this as a potential source of the problem.
> 

Modules are just Perl files that exist in the paths defined in @INC.
So you can step through @INC, and test if the modules exist:

BEGIN {
 our $module = 'Carp';
 for my $i (@INC) {
   if (-e "$i/$module.pm") {  # does module file exist?
      require "$i/$module.pm";
      $module->import();
   }
 }
}

That should take care of it!

gnarred


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

Date: Tue, 15 Jul 2003 22:04:06 -0500
From: Jeremy Fluhmann <fluhmann@vvm.com>
Subject: Re: Win32::GUI
Message-Id: <IwidnfijW7zyI4miRTvUqw@vvm.com>

jnk@kenobiz.com wrote:
> In the documentation that I have read about this module it tells only
> about manipulating the windows that you have created with it.  What
> about windows that are already in existence....how can i manipulate
> them.  Press buttons, close them and what not.
> 
> Should I seek a different module?
> 
> Thanks for your time and attention.

Try here: http://www.bahnhof.se/~johanl/perl/Loft/
It's called GUI Loft.  It lets you drag/drop buttons, labels, images, 
and whatnot.  You'll have to tinker with it some.  I had to do this to 
get the properties window to show up (you'll need the properties window) 
http://www.bahnhof.se/~johanl/perl/Loft/faq.html#the%20properties%20window%20is%20missing!

Jeremy Fluhmann
McLane Company



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

Date: Wed, 16 Jul 2003 03:55:18 GMT
From: jnk@kenobiz.com
Subject: Re: Win32::GUI
Message-Id: <2ui9hv8uq1oeo7o3m53t0a4g57b8gb1rj5@4ax.com>

I dont think I explained myself correctly.  I dont want to actually
create any windows.  I just want my perl program to "press" an "ok"
button on an open dialog box so that i dont have to do it. I am just
trying to automate a process so that i dont have to be present at the
computer when this dialog box appears and needs clicking.

On Tue, 15 Jul 2003 22:04:06 -0500, Jeremy Fluhmann <fluhmann@vvm.com>
wrote:

>jnk@kenobiz.com wrote:
>> In the documentation that I have read about this module it tells only
>> about manipulating the windows that you have created with it.  What
>> about windows that are already in existence....how can i manipulate
>> them.  Press buttons, close them and what not.
>> 
>> Should I seek a different module?
>> 
>> Thanks for your time and attention.
>
>Try here: http://www.bahnhof.se/~johanl/perl/Loft/
>It's called GUI Loft.  It lets you drag/drop buttons, labels, images, 
>and whatnot.  You'll have to tinker with it some.  I had to do this to 
>get the properties window to show up (you'll need the properties window) 
>http://www.bahnhof.se/~johanl/perl/Loft/faq.html#the%20properties%20window%20is%20missing!
>
>Jeremy Fluhmann
>McLane Company



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

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


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