Re: If you´re in the mood, help me.

2004-12-10 Thread Philipp Traeder
On Friday 10 December 2004 22:24, [EMAIL PROTECTED] wrote:
> Hi guys,

Hi Diogo,

>
> As you know, i´m having some problems to make this thing work. I have to
> write a script that automatically sends a code and get the some
> information according to that code. I mean, this script has to
> automatically fill in a formfield and get the result. 

Could you describe in more detail what exactly you're trying to do?
If I type the first URL you posted into my browser, I get a page with three 
pairs on input fields and submit buttons - which one do you want to fill out, 
and what should happen after you pressed the submit button?

> But I just can´t get it done. 

Why? What exactly is the problem? Do you get an error message? Do you have a 
specific question?

> If you´re really really in the mood for helping me, I´m posting 
> down here the source code of the page of the form that the script must
> fill in and get the result. The url is:
> http://www.tj.go.gov.br/online/Inicial/Processos/ConsultaProc_1Grau_Capital
>.dml And here is the URL for the page that returns the result:
> http://www.tj.go.gov.br/online/Capital/Processos_SPG/Resp_Processo1.dml
> After this source code, you´ll see the code of my script, please, help me!

[.. snipped approximately 3 GB of HTML source code ;-) ..]
>
>
> PERL Script
> #!/usr/bin/perl

Just a small hint: Always put the following lines at the beginning of a 
script:

use strict;
use warnings;

You've got to get used to it - e.g. you've got to declare all your variables 
before using them, like:
  my $ua = LWP::UserAgent->new();
instead of 
  $ua = ...
But in the long run, it will help you avoid making error)

>   use LWP::UserAgent;
>   $ua = LWP::UserAgent->new;
>   $ua->agent("MyApp/0.1 ");
>   $ua->cookie_jar({});
>
> my $req = HTTP::Request->new(POST =>
> 'http://www.tj.go.gov.br/online/Capital/Processos_SPG/Resp_Processo1.dml');

Judging by the HTML code you posted, you probably do not want to submit a POST 
request, but a GET request instead. The relevant part of the HTML code is:



Note the METHOD="GET" part - this specifies that this form initiates a GET 
request when you press the submit button.I don't know off the top of my head 
how to send a GET request using LWP::UserAgent - the short version might be 
something like this (not tested, take a look at the module documentation for 
the correct syntax):

my $ua = new LWP::UserAgent();
my $url_to_send = 
'http://the_server.com/full/address/to/document?parameter=value';
my $response = $ua -> get($url);
print "response : $response\n";

> #my $req = HTTP::Request->new(POST =>
> 'http://www.tj.go.gov.br/online/Inicial/Processos/ConsultaProc_1Grau_Capita
>l.dml'); $req->content_type('application/x-www-form-urlencoded');
> $req->content('numrproc=009600352534');
> #&mode=dist');
>
>   my $res = $ua->request($req);
>
>   if ($res->is_success) {
>   print $res->content;
>   }
>   else {
>   print $res->status_line, "\n";
>   }

Hope this helps - if you run into problems with this, write to the list what 
you tried and what you got in result. I'm sure somebody can help you.

Philipp

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: subclassing (?) package

2004-12-19 Thread Philipp Traeder
On Sunday 19 December 2004 20:48, JupiterHost.Net wrote:
> Hello group,

Hi,

> I'm trying to subclass a module (at least I think its what is called
> subclassing...)

I'm not sure, but I think subclassing is the appropriate term for this ;-)

> This example below works but I'd like to package GD::Image::Foo in its
> own module, how would I go about doing that? perldoc perlmod and
> perlmodlib didn't seem to address that issue unless of course I'm
> confused which is most likely the case ;p
>

I think what you want to do is to create an own class that inherits from
GD::Image. In Perl (5), a class is basically a package, so you've been on the 
right track when you wrote this sub starting with 

sub GD::Image::Foo {
...

Now just create a new file called Foo which you put into the folder GD/Image, 
so that it can be found by perl.

This class should probably look similar to this (UNTESTED):

##
#!/usr/bin/perl
# file: GD/Image/Foo.pm

# the package name is the class name
package GD::Image::Foo;

use strict;
use warnings;

use GD;

# this declares that you want to inherit from GD::Image
our @ISA = qw(GD::Image);

sub Foo {
my $self = shift;

# work with the image
}

##

Now you should be able to use it instead of the usual image:

[..]
> I'd like that to be:
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
> #use GD;
I think you don't need this line any more because of the next one.

> use GD::Image::Foo; # has sub GD::Image::Foo {} in it ...
>
> # my $image = GD::Image->new(42,21);
You've got to instantiate an object of your new class instead - try:

  my $image = GD::Image::Foo -> new(42,21);

> my $white = $image->colorAllocate(255,255,255);
> $image->transparent($white);
>
> $image->Foo(1,5,9);
>
> Any docs/ideas most appreciated!
>
> TIA

I'm not very experienced with OOP in perl, but I think this should be it - if 
you got the Camel book at hand, take a look into the OOP chapter. It's very 
comprehensible (and funny). If you do not have the camel book, give it to 
yourself as a christmas present ;-)

HTH,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: file and dir time stamps

2005-01-03 Thread Philipp Traeder
On Monday 03 January 2005 21:48, Thomas Browner wrote:
> I have a hard time writing a script that look at file and directories
> time and date stamp then delete any thing that is so many days old. if
> someone would give me a good starting point.

You might want to take a look at File::Find and the stat() method:

#
#!/usr/bin/perl -w

use strict;
use File::Find;

my $dir = shift;

find( 
  sub {  
my @attributes = stat($File::Find::name);
print "found $File::Find::name - ";
print "this file has been modified at " . $attributes[9] . "\n";
  }, 
  $dir
);
#

Inside the method specified as first parameter, you'd only need to check if 
the file modification timestamp (10th value of stat's return value) is bigger 
than the timestamp against which you want to match...if you've got any 
problems with this, post your code and surely someone will be able to help.

>
> Thanks
> Thomas

Hope this helps,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Checking last character of string for punctuation

2005-02-02 Thread Philipp Traeder
On Wednesday 02 February 2005 22:39, Chris Schults wrote:
> Howdy all. I'm a newbie with a newbie question. I assume that I'm in the
> right place.

Yes, thie does sound consistent. ;-)

> I need to update some code a developer programmed for my organization.
>
> The purpose of the code is really basic. It simply prints: $title.
> $subtitle.
>
> However, some of my titles and subtitles end with punctuation ("?", "!",
> ".", "..."). Thus, I end up with: Am I a title that ends with punctuation?.
> Do-oh!.
>
> So, I need to revise the code so that it first checks each string to see if
> it ends with a punctuation character. If it does, don't add the period. If
> not, do add the period. Note: the string should be kept as is.
>
> I believe the key is a regular expression of some sort, but I can't seem to
> figure it out.

You're definitely on the right track using regular expressions - for starters, 
you might want to take a look at

  perldoc perlre
  perldoc perlretut

You probably want a construction like

  if ($variable_that_might_end_in_punctuation !~ //) {
# add the period
  }

This matches your string against the regular expression that you need to put 
between the slashes (without the less-than/greater-than characters) and 
returns true if the string does *not* match the regular expression (the 
opposite operator would be 
  $variable =~ //
which returns true if the regexp matches.

Given the description of your problem, you might be interested in character 
classes - they are described in perlretut (section "Using character 
classes").

HTH,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: TERM::ReadLine and program flow question

2005-02-08 Thread Philipp Traeder
On Tuesday 08 February 2005 18:57, Scott R. Godin wrote:
> This is my first time attempting to use Term::ReadLine to get input from
> the commandline while a script is running. I grok the basics of it, but
> am stumbling over the implementation of it. Let me illustrate:
>
> READLINE:
> {
> # closure, so I don't have to either
> #   -  call Term::ReadLine->new() every time thru the sub, or
> #   -  pass the object to the sub every time thru
> # this way it gets called _once_, period, and I don't have to think
> # about it later
>  my $term = Term::ReadLine->new();
>
>  sub get_input ($;$) {
[..]
>  }
> }
>
[..]
>
> while ( get_input "What is the full path to the directory containing\
> your website .html files", $default->() ) {
>  print && next unless $_; #DEBUG
>  print "nonexistent: $_" && next unless -d ;
>  print "not readable: $_", next unless -r;
>  die  "directory not writable by this process. check permissions on:
> $_" unless -w;
>  $input{htdocs} = $_;
> }
>
[..]
>
> My brain seems frozen today. How do I ensure that the input loop will
> continue if the value is not defined, and test the values if they are ?
> I'm guessing a continue block but I can't seem to wrap my brain around
> the problem today. I should KNOW this, dammit! It's killing me that I
> can't figure it out, and I'm sure it'll be obvious in retrospect.
>
> should I even be using 'while' here?

I would say 'no' to this one ;-)
Why do you need a loop here? The way you've written your get_input() method, 
you'll always get a return value - either the one from the user, or a default 
value. Even if you implement a query without return value, your directory 
checks will catch it because "-d undef" returns 0, so the user would get the 
message "nonexistent: " if he enters no value for a question without default 
value, which is more or less correc.t

Maybe I didn't get the point, but I would probably write it like this:

##
#!/usr/bin/perl -w

use strict;
use Term::ReadLine;

my(%input, $default);

$default = sub { .. };

# declaring the console object globally
my $term;

sub get_input ($;$) {
my($descr, $default) = @_;
print "No description specified for input"
unless $descr;
$default ||= '';
my $result = $term->readline("$descr [$default]: ") || $default;
return $result;
}

### main

$term = Term::ReadLine->new();

$_ = get_input "What is the full path to the directory containing your \ 
website .html files", $default->();
die "nonexistent: $_" unless -d;
die "not readable: $_" unless -r;
die "directory not writable by this process. check permissions on: $_" unless 
-w;
print "ok - got $_\n";
$input{htdocs} = $_;

##

If you want to process a batch query, you can always build a while loop around 
it like this:

my @queries = (
  {'name' => 'htdocs',
   'description' => 'Full path to your htdocs',
   'default' => $default
  },
  {'name' => 'home',
   'description' => 'Your home directory, if you please:',
   'default' => sub { return $ENV{HOME}; }
  }
);

foreach my $query_ref (@queries) {
  $_ = get_input(
  $query_ref -> {'description'},
  $query_ref -> {'default'} -> ()
  );
  die "nonexistent: $_" unless -d;
  die "not readable: $_" unless -r;
  die "directory not writable by this process. check permissions on: $_"  
 unless -w;
  print "ok - got $_ for $query_ref->{'name'}\n";
  $input{$query_ref->{'name'}} = $_;
}

HTH,

Philipp

>
> --
> Scott R. Godin
> Laughing Dragon Services
> www.webdragon.net

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Anonymous array of hashes question

2005-08-04 Thread Philipp Traeder
On Friday 05 August 2005 01:37, Jason Normandin wrote:
[..]
>
> if ($protocol =~ /PING REQUEST/) {
>   push @{$pingRequests{$destination}}, {
>   time => $time,
>   sequenceNumber=>$sequenceNumber
>   };
> }
> elsif ($protocol =~ /PING RESPONSE/) {
>   push @{$pingResponses{$source}}, {
>   time => $time,
>   sequenceNumber=>$sequenceNumber
[..]

> What I want to do however is track the response time between a request and
> response. This would be identified by the same sequence number for a
> request/respone pair. I would like to take the time value for each and
> subtract the response time from the request time to get the response time
> and add that to the response hash.
>
> I cannot figure out how to access the contents of the anonymous hash for
> that one value.
>
> Sudo code would be:
>
> elsif ($protocol =~ /PING RESPONSE/) {
> responseTime=pingRequests{$source}->time -
> pingResponses{$destination)->time if pingRequests{$source}->sequenceNumber
> = pingResponses{$destination}->sequenceNumber;
>
>   push @{$pingResponses{$source}}, {
>   time => $time,
>   sequenceNumber=>$sequenceNumber
> responseTime=>$responseTime
>
>   };
> }
>


Hi Jason,

I think you might want to take a look at the map function - using it, you 
could do something like this:

  my $response = $pingResponse{$destination};
  my $responseTime;
  map { $responseTime = ($response->{'time'} - $_->{'time'})
 if ($_->{'sequenceNumber'} == $response->{'sequenceNumber'})
   } @{$pingRequests{$destination}};

> DOes that make any sense? Can I do what I am trying to accomplish using the
> logic above? If so, what is that syntax?

I'm not sure if I would approach your problem the same way - I don't know what 
exactly you need to have as result, but I would think about storing all 
request/response pairs in a hash with the sequence number as key. This might 
make things easier.

HTH,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Perl CGI and URL rewriting returning source instead of execution

2005-08-29 Thread Philipp Traeder
On Monday 29 August 2005 19:20, Blake Girardot wrote:
> I have a perl cgi application, not mod_perl, but an actual .cgi application
> running under apache on OS X.
>
> As many web apps, it makes use of some long get requests with variable
> labels and values. For example:
>
> http://server.com/cgi-bin/app.cgi?t=new.htm&c=jlpnew.html
>
> I wrote a working url mod_rewrite rule for apache, but instead of the .cgi
> executing, it just returns the source code of the cgi.
>
[..]
>
> Any idea what I am doing wrong, why it just returns the cgi source text? It
> works fine with the actual urls, so I know everything is working normally,
> just not with the rewrite rule.

Hi Blake,

I'm not sure, but I think it might have to do with the order in which you're 
loading the apache modules - I remember seeing something like this when I 
tried to combine RewriteRules and mod_jk (which connects Apache with the 
Tomcat servlet container) on Apache 1.x.

IIRC, all I had to do was to switch the order of the LoadModule lines, e.g. 
something like this (OTTOMH):

  LoadModule modules/mod_rewrite.so
  LoadModule modules/mod_jk.so

HTH,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Array or arrays

2005-10-04 Thread Philipp Traeder
On Tuesday 04 October 2005 07:48, Jabir Ahmed wrote:
[..]
> my @details=split('\t',$line);
> [EMAIL PROTECTED];
> $reccnt+=1;
[..]
>
> How do i read the values of @details trought the
> $record array;
> i want something like this
> print $record[1][1] ==> this would refer to the first
> element in the @details. (this doesnt work)

Hi Jabir,

you can access the contents of an array reference (which is what you got 
inside @record - references to arrays) using the "->" operator, e.g.

  my $first_detail = $record[0] -> [1];

This is actually a shortcut to the somewhat more explicit version of

  # grab the first reference and convert it back into an array
  my @details = @{$record[0]};
  my $first_detail = $details[0];

HTH,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




command line interface handling asynchronicity

2003-11-27 Thread Philipp Traeder
Good morning everybody,

I am writing a small console application, allowing the user to perform
some actions via a shell-like interface. The basics of this were rather
easy, and with the help of some very nice CPAN modules (i.e.
Base::Shell), I have got tab-completion, a help system and much more
already.

The core of the application looks (a bit simplifid and in pseudo-code)
more or less like this:

while ("true") {
$cmd = $term->ReadLine($prompt);
if ($cmd eq "help") {
# process help
}
elsif ($cmd eq "exit"}
last;
}
# ...process other actions
}  

Now I would like to be able to execute a lengthy action that takes
several minutes. I think I can execute this with a fork, allowing the
user to keep on working while the action is being executed. The
appropriate action code would look more or less like this:

# ...
elsif ($cmd eq 'long_action') {
if (!fork) {
 # execute the action in the child process
 sleep 10;
 
 # TODO: notify the user that the action is finished.

 exit;
}
 
}

What I would like to do is perform the action in the forked child
process, and on completion the user should get a message about the
result of the action (which would be true or false, most likely).
The result should look like this for the user:

myshell> normal_action
performing normal action...done.
myshell> long_action
initiating lengthy actiondone.
myshell>
lenghty action completed successfully.
myshell>

Please note that the user should get back the prompt after he started
'long_action', and when the action is finished, he should be informed by
a message in the shell.

With this I have got two problems:
a) I am executing the action in a child process. What would be the best
way for the child process to inform its parent that the execution has
been finished?
b) How can I set up the ReadLine() part in a way that the user is able
to type new actions, but can receive new messages (from finished long
actions) as well? I have played around with Term::ReadKey, and ended up
with something like this:

my ($complete, $key);
my $string = '';
print $prompt;
# ask for input until we have got a complete string
while (not $complete) {
print "so far : $string\n";
# read a single key
while (not defined ($key = ReadKey(-1))) {
# No key yet
# $string seems to be empty here!
print "*" . $string;
sleep 1;
if ($string eq 'test') {
print "youve written nothing serious so far!\n";
print $prompt . $string;
$string = '';
}
}
if ($key eq "\n") {
$complete = 1;
}
else {
$string .= $key;
}
}

This construct should theoretically more or less allow me to check for
individual keystrokes of the user and parallely to print messages if
necessary, but it does not do what I would expect: If I call
ReadKey(-1), it does not seem to "know" the $string variable in the
inner while loop, and if I call ReadKey(0), it looks like all keys are
fetched first, and afterwards the "print" statements are executed.

I hope you see my problem, though I find it hard to describe.

Can anybody give me a clue in which direction I could go with that?

Thank you very much in advance for your attention and your help.

Philipp Traeder
[EMAIL PROTECTED]










-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: command line interface handling asynchronicity

2003-11-27 Thread Philipp Traeder
On Thu, 2003-11-27 at 21:37, drieux wrote:
> 
> On Thursday, Nov 27, 2003, at 09:58 US/Pacific, Douglas Lentz wrote:
> 
> > Re: (A) What's the best way for the child to inform the parent that 
> > it's done?.
> >
> Given that his question (A) is about 'informing'
> the parent that it is finished, he might really
> want to look at
> 
>   perldoc -q signal
> 
> and specifically set up a sig handler for setting up
> a SIGCHLD so that he can set a flag,
> 
>   my $all_my_children = {};
> 
> where the pid that would be returned from the fork,
> which would of course need to be picked up, is recorded.
> 
> cf perldoc perlipc
> 
> and look for 'sub REAPER'
> 
> Then in the main loop check the status of "all_my_children"
> to see if any of them have changed - and if so editorialize.
> This of course means that the long_activity will need to
> exit with say 0 if ok, or some number if not good, and the
> initialization would be say
> 
>   $all_my_children->{$pid} = 'A';
> 
> and as a part of the loop to check the status, one
> gets the return value and then deletes it from the hash.

Thanks for this tip - I will take a look into the topics you have
mentioned, but it sounds very promising. :-)

> This may also help with the 'B' side question -
> as well without getting into the more complex
> set of issues of doing the pipe(), fork()
> manage the multiple selects that would need to
> poll through the long_activities to see if
> new incoming data needs to be collected, or
> is the primate banging on the keyboard.
> 

Though I do not know yet how the first part will work, I honestly do not
understand how a solution to A might help me with the second part of my
question. Could you explain this more detailed?

The danger of primates banging on keyboards is - of course - always
existent and quite high, but in this case I would settle for a first
version that would be usable by more or less normal beings of the
species homo [EMAIL PROTECTED] - v 2.0 would then focus on the keyboard-banging
primates, managers, sales-people etc. ... ,-)

Thank you very much for your help,

Philipp



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: command line interface handling asynchronicity

2003-11-27 Thread Philipp Traeder
> Not related to your question but, have you thought of using a dispatch
> table instead?
> 
> sub help {
> # process help
> }
> 
> sub long_action {
> # process long_action
> }
> 
> my %process = (
> help=> \&help,
> long_action => \&long_action,
> simple_cmd  => sub { print "Anonymous sub for simple command\n" },
> );
> 
> while ( 1 ) {
> my $cmd = $term->ReadLine( $prompt );
> if ( exists $process{ $cmd } ) {
> last if $cmd eq 'exit';
> $process{ $cmd }();
> }
> else {
> print STDERR "Unknown command '$cmd'\n";
> }
> }

Actually, yes - I am currently using something like this, though by far
not as elegant as your code sample.
Then I discovered Base::Shell, and this module comes with more or less
the same approach (for each action you implement a do_xyz method in a
class that inherits from Base::Shell).
I did not use this approach in my code sample because I did not want to
obfuscate it too much...thanks, anyway. :-)

> > Now I would like to be able to execute a lengthy action that takes
> > several minutes. I think I can execute this with a fork, allowing the
> > user to keep on working while the action is being executed. The
> > appropriate action code would look more or less like this:
> > 
> > # ...
> > elsif ($cmd eq 'long_action') {
> > if (!fork) {
> >  # execute the action in the child process
> >  sleep 10;
> > 
> >  # TODO: notify the user that the action is finished.
> > 
> >  exit;
> > }
> > 
> > }
> 
> It is pretty simple, the perlipc man page has some good examples, but it
> is basically like this:
> 
> elsif ( $cmd eq 'long_action' ) {
> defined( my $pid = fork ) or die "Cannot fork: $!";
> unless ( $pid ) {
> # execute the action in the child process
> sleep 10;
> 
> # TODO: notify the user that the action is finished.
> print "'long_action' has finished processing\n";
> exit;
> }
> }
> 

If I am not mistaken, this is more or less exactly what I am doing right
now - the only problem I have got with this is that the user is
interrupted in his work when the 'long_action' finishes - like this:

myshell> long_action
initiating lengthy action...done.

now the user gets the focus back (which was the main reason behind this
exercise), and types a new command

myshell> some other command with some pa

In this very moment the long_action ends and prints

'long_action' has finished processing

As you can see, the user has been interrupted in the middle of typing
his statement, and it looks to him as if he would have lost his prompt.
My initial reaction (as a user) to this behaviour would be to press
enter - in this case the semi-complete command is executed because
$term->readline is still reading keyboard input...

Therefore, I would like to re-write the readline() part so that whenever
the user gets interrupted by a finished long_action, I can present him a
prompt and write his partially completed command so that he can continue
typing it.

> This gets more complicated.  Does the parent really have to know when
> the child has finished?  waitpid() with the WNOHANG option might do what
> you want or you could use signals or you could use some form of IPC like
> System V IPC or sockets, etc., etc.
> 

Thanks - I will take a look into this...this signal thing looks
promising to me (on a first glance)...

> Sorry, I don't know enough about Term::ReadKey to help with that.  :-(
> 
> HTH
> 
> 
> John
> -- 
> use Perl;
> program
> fulfillment

No problem - thank you very much for your support,

Philipp


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Replacing text

2003-12-05 Thread Philipp Traeder
Hi Dan,

have you tried using a regular expression?
I am using something like this for a similar purpose:



open ($fh, $filename);
# go through each line of the file
while ($_ = <$fh>) {
# replace globally in the default variable $_
s/#INSERT#TEXT#HERE/$text_to_insert/g;
}
close ($fh);



Search for "perlre" in perl-doc for more information.

HTH,

Philipp Traeder

On Sat, 2003-12-06 at 00:10, Dan Anderson wrote:
> I have a  script that reads text from a  file and inserts text
> into different  places depending on  what it needs  to do.  But  I use
> split to replace the text, i.e.:
> 
> ($first_part, $second_part) = split "#INSERT#TEXT#HERE#", $document, 2;
> print FILEHANDLE $firstpart, $text_to_insert, $secondpart;
> 
> Is  there a  replace function  in perl  that would  let  me do
> something like  replace "#INSERT#TEXT#HERE", $text_to_insert;?   I was
> going to  write my own  method but was  curious if perl  had something
> faster?
> 
> Thanks in advance,
> 
> -Dan
> 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Recommendations?

2003-12-09 Thread Philipp Traeder
Hi Derek,

On Tue, 2003-12-09 at 21:01, Derek Brinson wrote:
> Where might I find reference (conceptual) stuff about how to launch a
> JAVA app via CGI (or vice versa)? 

Could you specify what kind of Java application you're talking about?
The Java *applications* (as opposed to servlets, EJBs etc.) I know can
be invoked via the command line.

> Still working it out, but it appears that I may need to get some CGI
> variables into a JAVA App.

If it's a normal application, it should be quite easy - something like
this (roughly sketched and not syntax-checked):

use CGI;

my $query = new CGI;

# this is the actual HTML form - could be out-sourced with 
# HTML::Template or something like that in order not to mix 
# HTML and your code too much
my $HTML_FORM = <





END

# get the parameters from the CGI query
my $class_name = $query->param('java_class_name');
my $arg = $query->param('argument1');

# start printing the response
print $query->header();
print $query->start_html();

# have we been called with parameters (i.e. did the user press the
button?)
if ($class_Name) {
# assemble the command line to execute:
# you should be able to find the java executable in 
# $JAVA_HOME/bin
# (this assumes that JAVA_HOME is set, of course, but
#  normally this should be the case)
my $command = $ENV{'JAVA_HOME'} . '/bin/java ';
$command .= $main_class . ' ' . $arg;

# call java to execute your classes "main" method
my $result = system($command) / 256;

# print the result to the browser
print "invoked the java application.\n";
print "the result is " . $result . "\n";
}
else {
# no parameters --> display the form
print $HTML_FORM;
}

print $query->stop_html();

This is more or less it - I'm doing something like this in one of my
scripts, and it's working reasonably well; there are of course some
minor issues you've got to think about, such as:
- do you need libraries to include into your classpath?
(if yes, you can specify them using the -cp argument to java)
- Do you need to get a result from the Java application? 
Does it print stuff into the console? Does it have a return value?
- How long does the application take to execute? In my case, the
application can take more than 1 hour to complete, so I fork and inform
the user per mail about the result.

HTH,

Philipp







-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: SQL annoyance

2004-01-04 Thread Philipp Traeder
Hi Dan,

On Sun, 2004-01-04 at 03:34, dan wrote:
> I have an SQL statement as follows,
> SELECT * FROM memodata WHERE to=1 AND readdate=sent ORDER BY id ASC
> which fails giving an error on the to=1 part.
> I've tried doing that statement without the 'to=1 AND' part, and it works
> fine returning all and more of the data that I want. However when i ask it
> to be more specific, it fails. I've also tried
> SELECT * FROM memodata WHERE to=1
> which also fails on the to=1 part. I've also tried putting in other column
> names, like from=1, but that fails too. And I'm totally clueless as to why,
> as the syntax follows the manual on mysql.com exactly.
> Any pointers as to where I'm going wrong?

just wildly speculating, but I'd guess that "to" and "from" are typical
string values (and not integers) - have you tried something like

SELECT * FROM memodata WHERE to = '1'

BTW: You can find out the column types by typing "describe memodata;" on
your mysql command line.

HTH,

Philipp


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: tracking mail logs

2004-04-08 Thread Philipp Traeder
On Wed, 2004-04-07 at 20:26, WC -Sx- Jones wrote:
> Traeder, Philipp wrote:
> >>-Original Message-
> 
> Should we take this back to the perl list?  After all we
> are talking about writing Perl.

Yes, of course.
If it's getting too module-specific, we can still switch to private
mails.


> > 
> > Therefore, I've got a problem: Using a more general approach, I would not be
> > allowed to apply my "from" filter, but I would have to parse the complete
> > file before
> > filtering. But this would be much less performant than what I'm currently
> > doing.
> > The question is: Is it possible to write a performant module that can be
> > used in
> > different scenarios? Or is this approach too theoretical?
> > If somebody wants to parse a 2GB logfile, he should be prepared to wait some
> > time,
> > shouldn´t he?
> 
> 
> At any rate, if you have a 2GB log file I would seriously
> consider only grep'ing thru it to reduce the initial
> processing impact.

That was my thought as well - though "real" grepping (as in calling
grep) won´t work here because multiple lines make up one record.
Anyway - I'd like to filter the input as soon as possible.

> 
> Also, if you have bounces they prolly look like this:
> 
> Apr  6 21:28:34 chasecreek postfix/smtpd[8394]: [ID 197553 mail.info] 
> 40FA61375E: client=ns.suse.de[195.135.220.2]
> Apr  6 21:28:34 chasecreek postfix/cleanup[8395]: [ID 197553 mail.info] 
> 40FA61375E: message-id=<[EMAIL PROTECTED]>
> Apr  6 21:28:34 chasecreek postfix/qmgr[4787]: [ID 197553 mail.info] 
> 40FA61375E: from=<>, size=3724, nrcpt=1 (queue active)
> Apr  6 21:28:34 chasecreek postfix/local[8396]: [ID 197553 mail.info] 
> 40FA61375E: to=<[EMAIL PROTECTED]>, relay=local, delay=0, status=sent 
> (delivered to mailbox)
> Apr  6 21:28:34 chasecreek postfix/qmgr[4787]: [ID 197553 mail.info] 
> 40FA61375E: removed

My logs look a bit different - something like this:
Jan 31 23:34:11 ns1 sm-mta[10966]: i0VMYAG5010966:
from=<[EMAIL PROTECTED]>, [..]
msgid=<[EMAIL PROTECTED]>,
proto=ESMTP, daemon=MTA, relay=[relay_ip_address]
[..]
Jan 31 23:34:12 ns1 sm-mta[10973]: i0VMYAG5010966:
to=<[EMAIL PROTECTED]>, delay=00:00:02,
xdelay=00:00:01, mailer=esmtp, pri=30388, relay=mx01.somewhere.com.
[relay_ip_address], dsn=2.0.0, stat=Sent (OK id=1An3gr-00043m-00)


> So, unless your logging software is clairevoyent I do not see how
> you will know the "original" from unless you have kept ALL of
> the original bounced messages...

In this scenario, I'm particularly interested in the entries starting
with "to" resp. "from". I'm assuming that the "from" entry comes as the
first "relevant" record for my purposes...therefore I go through the log
line by line and check if it's a "from" record from one of the addresses
I'm interested in. If yes, I write the complete entry into an output
file and keep the (queue) ID in memory.
For all other (not "from") records I just check if the id is one of
those that I'm interested in and write it into the same output file if
necessary.

I hope that this will allow me to parse big log files in a reasonable
amount of time, but I'm afraid this particular approach won't work for a
module. That's no big problem in itself - I could finish my script, and
independently we start writing the general module for parsing sendmail
log files. I'm just wondering if this scenario of big log files that
need to be filtered one way or another isn't a quite common one.

Just my 5 cents,

Philipp


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: combining data from more than one file...

2004-05-21 Thread philipp traeder
On Wednesday 19 May 2004 05:25 pm, Michael Robeson wrote:
> Sorry, I meant to upload this script (see below). However, I have one
> last question. Why can't I use
>
> s/\n//g;# instead of
>
> tr/A-Za-z-//cd;
>
>
>
> in the script below? I thought it would be simpler to remove the
> newline characters from $_ which is all I really want to do. However,
> most of the time all I will see are "-" and letters which is why I set
> the tr function the way I did.

Hi Mike,

I'm not sure if I understand exactly what you want to do here, but if you want 
to remove trailing newlines only, I'd use 
chomp;

>
> I just couldn't figure out why the substitution function wouldn't work
> in this case. How am I setting it up wrong?

Just guessing - could it be that you need to assign the return value of s///?
Something like
  my $var_without_newlines = s/\n//g;
?

HTH,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: NET::FTP

2004-06-05 Thread philipp traeder
On Saturday 05 June 2004 HH:28:05, Edward Ludlow wrote:
> I'm a newbie to Perl - I'm having to dip in and try and do some coding 
> as I need a script that will move a file from one server to another.  I 
> believe this can be done with the Net::FTP object.

> I've played around whit this a fair bit, and I think this script should
> work..

Hi Edward,

the script looks good to me - some small annotations below:

>
> #!/usr/bin/perl

Normally I use a standard header like this:

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

The "-w" switch enables some quite helpful warnings, while
"use strict" forces you to write "clean" code, i.e. you've got to
declare variables etc. You've got to get used to this, but in the
long run, it makes your life much easier.

> print "Content-type: text/plain","\n\n";
>
> use Net::FTP;
> $ftp = Net::FTP->new("www.slbsu.org.uk", Debug => 0)
> or die "Cannot connect to some.host.name: $@";

If you enable "use strict", you've got to declare the $ftp variable
like this:

  my $ftp = Net::FTP -> new()

>
> $ftp->login("username",'password')
> or die "Cannot login ", $ftp->message;
>
> $ftp->quit;
>
>
>
> But it doesn't!  If I upload that script as it is, it just returns a
> blank page with no errors, when I know that the username and password
> are wrong - so why does it not tell me?

The problem that you've got here is that error messages (e.g. everything 
produced by "die") are generally written to the web server's error log, but 
not to the screen.
If you execute your script on the command line, you'll see the error message.

You can change this behaviour by putting something like

  use CGI::Carp 'fatalsToBrowser';

at the beginning of your script. This will print all fatal messages to the 
browser.

While you're at it, you might want to take a look at the module CGI - it helps 
you to deal with many common CGI problems (type "perldoc CGI" on your command 
line to read more about it).

> PS If anyone fancies outlining how I'd code a script to transfer one
> file to another location, that would be much appreciated...:)

"perldoc Net::FTP" is your friend - there you'll find documentation for the 
put() method, which should be what you want.
Basically, you just need to extend your script a bit - something like: 

my $ftp = Net::FTP->new(...);
$ftp->login("username", "password");

# change the working directory on the server
$ftp->cwd("dir/where/you/want/to/put/your/file");

$ftp->put("name/of/your/local/file");

$ftp->quit();

If you are behind a firewall/proxy/something like this, you might also want to 
set the passive property in the constructor - this did the trick for me once 
after searching for some hours:

my $ftp = Net::FTP->new($ftp_address, Debug => 0, Passive => 1)
  or die "cannot connect to $ftp_address : $@";

HTH,

Philipp



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: NET::FTP

2004-06-05 Thread Philipp Traeder
On Saturday 05 June 2004 HH:58:11, Edward Ludlow wrote:
> philipp traeder wrote:
> > "perldoc Net::FTP" is your friend - there you'll find documentation for
> > the put() method, which should be what you want.
> > Basically, you just need to extend your script a bit - something like:
> >
> > my $ftp = Net::FTP->new(...);
> > $ftp->login("username", "password");
> >
> > # change the working directory on the server
> > $ftp->cwd("dir/where/you/want/to/put/your/file");
> >
> > $ftp->put("name/of/your/local/file");
> >
> > $ftp->quit();
>
> The script now successfully launches two FTP sessions, but how exactly
> do I use put() to move a file from one of the sessions to the other?

Hi Ed,

excuse me - my last post might have been a bit confusing.
The script I sketched was meant to be a complete script, not an extension to 
the script you already wrote.

You need only one FTP session, of course - this session connects to the remote 
FTP server, uploads the file, and disconnects again.

Just take your original script and put something like the following lines 
between the "$ftp->login" and the "$ftp->quit()" lines:

  my $remote_directory = "name/of/the/remote/directory";
  $ftp->cwd($remote_directory)
   or die "Cannot change working directory ", $ftp->message;

  my $filename = "name/of/your/local/file";
  $ftp->put($filename)
   or die "cannot upload file $filename ", $ftp->message;

HTH,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: different versions of same Perl module in different Apache vhosts

2004-06-05 Thread Philipp Traeder
On Saturday 05 June 2004 HH:18:16, Andrew Gaffney wrote:
> I didn't really know where to post this since it isn't specifically Apache
> or Perl, so I'm posting herejust because :)
>
> I run 2 vhosts under Apache 1.3.29 (needed for mod_perl-1.x which is needed
> by HTML::Mason) on my Gentoo server. One vhost is the current production
> site and the other vhost is the development version of the site. I use a
> custom Perl module for authentication and other common functions for all my
> Perl CGI/mod_perl scripts.
>
> I want to be able to make changes to the module, but I only want it to
> affect the second vhost. Basically, I need to have 2 copies of my custom
> module, one for each vhost. Is there an easy way to do this?

Hi Andrew,

that's a very interesting question ;-)

I don't know anything about mod_perl, but I'd think that it depends on how you
load your module and where it is located. IIRC, you can set environment 
variables per vhost. Maybe there's a way of modifying the @INC variable for 
your development vhost?
Or - a less elegant option: Set an environment variable (or rewrite the URL) 
for the development vhost, and replace your authentication module with a 
module that checks this environment variable (or: a URL parameter) and loads 
the right module.

Let's say your module is called authentication.pm - rename it to 
authentication_real.pm and duplicate it as authentication_dev.pm
Create a new file authentication.pm that does something like:

if ($ENV{'development_special_purpose'}) {
  require 'authentication_dev.pm';
}
else {
  require 'authentication_real.pm';
}

I'm not speaking from experience here and I've not tested or re-checked if 
this works, just thinking in loud voice ;-)

HTH,

Philipp


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Sending email via SMTP

2004-06-25 Thread Philipp Traeder
On Thursday 24 June 2004 22:43, Mike Blezien wrote:
> Hello,
>
> I'm looking at using the Net::SMTP module to send email as opposed to the
> standard method of "sendmail".
>
> Been reading through the docs on the module, but not real clear on how to
> setup the "To:", "From:", "Reply-to:", "Subject:". and other headers, and
> actual body of the email to be sent, with this module.. was hoping someone
> maybe kind enough to maybe post a sample of code, using this module.

Hi Mike,

is there a specific reason for using Net::SMTP?
I haven't worked with Net::SMTP so far, but from what you're writing, it seems 
to me as if Mail::Sender would be a more simple alternative ;-)

#!/usr/bin/perl -w

use strict;
use Mail::Sender;

my $mail_sender = new Mail::Sender {
smtp => 'name.of.your.mail.server',
from => '[EMAIL PROTECTED]'
};

$mail_sender->MailMsg(
{to => '[EMAIL PROTECTED]',
  subject => 'Test',
 msg => 'This is from Mail::Sender'
}
)
  or die "cant send message - error code : $Mail::Sender::Error. Stopped";

$mail_sender -> Close();

__END__

see perldoc Mail::Sender for details.

HTH,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Assigning a variable to hash keys and values

2004-06-29 Thread Philipp Traeder
On Tuesday 29 June 2004 08:49, Daniel Falkenberg wrote:
> Hello All,

Hi Dan,

> I currently have a hash of a hash...
>
> > %HoH = (
> > Key1=> {
> > Apple => "Green",
> > Banna => "Yellow",
> > },
> > Key2=> {
> > Carrot=> "Orange",
> > Tomoatoe  => "Red",
> > },
> >  );
>
> How can I assign Key2 to a variable?

# If you want to assign Key2's value, you could so something like:
my $key2_ref = $HoH{Key2};
print "key2_ref : $key2_ref\n";

# Note that $key2_ref contains a hash-ref now, so if you want to use it as a 
# hash, you should tell perl that you want to use it as an hash:
my %key2_hash = %{$key2_ref};
print "key2->carrot : " . $key2_hash{Carrot} . "\n";

# You can use the same technique to access the inner hashes:
my $carrot_color = ${$HoH{Key2}}{Carrot};
print "carrot color : $carrot_color\n";
  
# Theres another version of accessing a value of a hash ref
# that more pleasant to the eye:
my $carrot_color2 = $HoH{Key2}->{Carrot};
print "carrot color 2 : $carrot_color2\n";

Take a look at
  perldoc perlreftut

It's a very good (and short) tutorial about references that explains all this 
much better than I can. 

HTH,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Extracting fields from a data file

2004-06-29 Thread Philipp Traeder
On Tuesday 29 June 2004 17:04, mohammed chafik wrote:
> header, 06-12-2004, path,
> /usr/bin/sh,attribute,100555,tom,other,315,56,11,54,77,10,88,
> subject,bscs,sgrp,9936,6785,0 0,return,success,0 (line3)
> ---
>
> I need to generate an output file like this (deleting fields between
> attribute and subject, please note that number of those fields is
> variable):
> ---
> header, 06-12-2004, path, /usr/bin/sh,
> subject,bscs,sgrp,9936,6785,0 0,return,success,0 (line1)

I'd use a regular expression to pull out the parts before "attribute" and 
after "subject" (maybe including it, depends on what you want) and just 
concatenate them together.

Take a look at
perldoc perlre

If you need help with the regex, let us know.

HTH,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Extracting fields from a data file

2004-06-29 Thread Philipp Traeder
On Tuesday 29 June 2004 18:44, mohammed chafik wrote:
> That's what i've tried (may be it is not the best approch);

If you ask me, the general approach is quite ok...

> Any way, My script doesn't work, it returns an error message (Use of
> uninitialized value at formater.pl line 22,  chunk 4.)
>
> -
> #!/usr/local/bin/perl -w

I'd always include 
  use strict;
as first statement in your script. This saves you a lot of time.

>
> $i=1;
> $k=1;
>
> open (INDATA, "
> open (OUTDATA, ">out_file.txt") || die("Can't open out file");
>
>
>
> while( $line =  ) {

You're reading each line into a variable called $line...

>
> chomp;
>
> @fields = split(",", $_);

but here you're working on $_.
You should either do

while ( $_ =  ) {
  chomp;
  my @fields = split(",");
  ..
}

or 

while ( my $line =  ) {
chomp $line;
my @fields = split(",", $line);
}

This in one source for the "uninitialized value" messages.

>
> for ($i = 0; $i < 400; $i++) {

The other source for the messages is that you're trying to access values in 
the array @fields that do not exist.
In your data file, @fields holds something like 15 records, certainly not 400.
I'd do something like

  for (my $i = 0; $i <= $#fields, $i++) {

which loops until $i has reached the last field of @fields ($# 
holds the last index of an array).

> if( $fields[$i]=~ /subject/ ) { $k=$i}
> }
>
> $line = join(":", $fields[0], $fields[2],$fields[$k], $fields[$k+1]);
>
> print OUTDATA "$line\n";
>
>
> }
>
> close INDATA;
> close OUDATA;

Another warning message tells you that you've got a typo here ;-)

HTH,

Philipp

PS.: Please bottom-post.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Extracting fields from a data file

2004-06-29 Thread Philipp Traeder
On Tuesday 29 June 2004 19:26, Wiggins d Anconia wrote:
> > On Tuesday 29 June 2004 18:44, mohammed chafik wrote:
> > > That's what i've tried (may be it is not the best approch);
> >
> > If you ask me, the general approach is quite ok...
>
> Good suggestions, if we are going to stick with the loop, and we only
> care that we advance as long as we haven't found the subject then
> throwing a 'last' in after the assignment, would provide at least some
> speed up. If there are a significant # of lines to parse and the subject
> may appear early enough on the line then this could be a noticeable
> improvement. 

You're right, of course...

> It would also make sense to adjust $i initial point forward 
> if we can be guaranteed that subject occurs after a minimum number of
> fields on a line, which does seem indicated since we are using 0,2
> indexes later not relative to the subject, so $i could be set at 3
> initially.  Turn my nitpicking back off now ;-)...

...but I was just trying to keep my own perfectionism at a tolerable 
level. ;-)
I'm quite sure that some people on this list would re-write this script in a 
maximum of two lines, but since Chafik's scripts is working after all, I 
thought it might be fair to give him a chance of improving his own script...

Generally, I'd (still) think that regular expressions might be a good idea 
here...e.g. see Gunnar´s post  ;-)

Philipp 

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Fill a string with zeros.

2004-07-02 Thread Philipp Traeder
On Friday 02 July 2004 15:55, Rod Za wrote:
> Hi all,
>
> Someone knows an way to do this more easy?
>
> _BEGIN_
> #!/usr/bin/perl
> use warnings;
> use strict;
> my $job = 15;
> my $job_name = 'd0';
> print "JOBNAME $job_name LENGTH: ".length($job_name)."\n";
> print "JOB...: $job  LENGTH: ".length($job)."\n";
> print substr($job_name,-length($job_name),-length($job)).$job."-001\n";
> _END_
>

Hi Rod,

take a look at the sprintf function ("perldoc -f sprintf") - something like:

#!/usr/bin/perl -w

use strict;

my $shortnumber = '10';
my $longnumber = '1000';

print sprintf("shortnumber : %06d\n", $shortnumber);
print sprintf("longnumber  : %06d\n", $longnumber);

might do the trick.

BTW: It's easier to help if you specify what you want to do - in this case it 
didn't matter much, but it can take some time to understand what a piece of 
code should be doing... ;-)

HTH,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Timeout problem

2004-07-06 Thread Philipp Traeder
On Tuesday 06 July 2004 10:58, Werner Otto wrote:
> Hi All,
>
> I have the following script:

Hi Otto,

IIRC, you've posted nearly exactly the same question last thursday...

>
> #!/usr/bin/perl
> use IO::Socket;
>
> my $host=shift @ARGV or die 'need hostname';
> my $port=shift @ARGV or die 'need port number';
> my [EMAIL PROTECTED] or die 'need timeout';;

I think you want
  my $timeout = shift @ARGV or die 'need timeout';
here...otherwise you set $timeout to the number of arguments left in @ARGV, 
which is "1" at this point...

> my $socket=IO::Socket::INET->new(PeerAddr=> $host,
> PeerPort => $port,
> Proto => 'tcp',
> Type => SOCK_STREAM

Bob Showalter told you last thursday that you're missing a comma between the 
"Type" and "Timeout" hash keys in your call to IO::Socket::INET->new(), but 
it's still missing in the source you posted now.
Did you try if it changes anything if you put this comma there? 

Replace
Type => SOCK_STREAM
by
Type => SOCK_STREAM,# <-- HERE


> Timeout => defined($timeout)?$timeout:1) or die "Can't talk to
> $host at $port";
>
[..]
> When doing this test on a connection that reponds it timesout after 1
> second. When I do this on a connection that is live but the port is
> incorrect it timesout after 1 second. My problem is when the pc is
> switched off it does not timeout after 1 second.
>
[..]

This sounds strange indeed - if I try to connect to a server that's not there, 
I get the error message after a quite short time (might be 1 second, but I'm 
not sure...), regardless of what I set "timeout" to...but maybe I'm not 
testing correctly.

Your problem might be the missing 'shift' above - for me it looks ok now...if 
it still does not work, I would take another look at the IO::Socket 
documentation - are you sure that the timeout you specify in the constructor 
is doing what you want (e.g. handling the timeout on connect vs. handling the 
timeout after connect)?

And please indicate next time that you already asked this question so that we 
don't have to search through the archives to find the problem's history...

HTH,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Running Perl CGI MS XP System

2004-07-07 Thread Philipp Traeder
On Wednesday 07 July 2004 12:15, Jerry Preston wrote:
> I am looking for a way to run Active Perl CGI on my PC that is setup on
> Windows XP.  I have installed Apache and I am trying to figure out how
> to
> set it up the Virtual Host mode to run Perl script with CGI like I do on
> my
> work SUN station.  Any ideas on how do this or is there a better way?

Hi Jerry,

what exactly do you mean by saying "set it upt the Virtual Host mode"?
I'm running CGI scripts written in Perl on a W2K machine - the steps for 
setting this up are (more or less):

- install ActivePerl out of the box
- (optional:) add ".pl" to the PATHEXT environment variable (this lets you 
execute "*.pl" scripts without having to type the ".pl".
- install Apache
- add/modify the following lines in your httpd.conf:

  # call Perl to execute .pl scripts
  AddHandler cgi-script .cgi .pl
  # use the Perl interpreter you find in the registry (as opposed to the on
  # specified on the first line of your perl script); setting this option may
  # help if you want to be able to run your scripts on Unix and Windows.
  ScriptInterpreterSource Registry

Now you've got multiple choices:
a) put your perl scripts into apache's cgi-bin directory
b) create a directory entry for the path where your CGI scripts are:

  
# This line is necessary for CGI scripts
Options FollowSymLinks ExecCGI
# Tailor as you need
Order allow, deny
Allow from all
  

c) create a virtual host, set the document root and add the Options shown 
above in the directory entry.

For me, this is working nicely.

I've read about successful installations of mod_perl on Windows as well (which 
should be better in terms of performance), but I couldn't get it working.

HTH,

Philipp


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Could anyone please answer a simple PERL question.

2004-07-08 Thread Philipp Traeder
On Thursday 08 July 2004 HH:18:19, JupiterHost.Net wrote:
> Marco wrote:

Hi Marco,

> > and on DOS prompt when I say, perl simple.pl
> > it says:
> > 'perl' is not recognized as an internal or external
> > command,
> >
> > what am I missing? an execution path or something?
>
> Not sure, you may need to ask ann Active Staelist if noone else knows.
>
> I'm not really a Windows guy so my knowlefge is limited :)
>

I'm not sure if I got the full thread of your question, but the error message 
you posted above normally indicates that "perl" is not part of your "path" 
environment variable. you can try this by calling perl using it's full path:


C:\Path\to\your\perl\scripts> C:\Z_Perl_584\Perl\bin\perl simple.pl

If this works, you might want to include the path to perl into your path 
variable - you can do this for one process with a command like

  SET PATH=%PATH%;C:\Z_PERL_584\Perl\bin

or generally in the Settings (I believe it's in Settings | Control Panel | 
Advanced | Environment Variables, but I'm not sure). If you change it 
permanently, reboot Windows, because otherwise the changed environment 
variable won't be available to all processes.

HTH,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




[Solved] Could anyone please answer a simple PERL question.

2004-07-08 Thread Philipp Traeder
On Thursday 08 July 2004 HH:31:20, [EMAIL PROTECTED] wrote:
> A sure kill is to search for "perl*" and take note of the path.  Then you
> can do one of the following:
>

Just to let you know: The "path" variable has been the problem (as Marco wrote 
me off-list).

Another happy customer ;-)

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: delete vs undef

2004-07-09 Thread Philipp Traeder
On Friday 09 July 2004 17:14, Christopher J. Bottaro wrote:
> i want to remove items from a hash then later see if they exist using
[..]
> which should i use?  delete() or undef()?  obviously i could write a small
> script to test this (which i'm going to know), but i'd also like to hear
> from an expert about the subtle (if any) difference between the two if they
> both work.

I don't know what an expert would say, but for testing if a hash contains an 
element, I normally use "exists":

  if (exists ($hash{'mykey'})) {
print 'mykey exists.';
  }

>
> also, are these functionally equivalent?
> $myvar = undef();
> undef($myvar);

I'd think so, but I'm not sure.

HTH,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: delete vs undef

2004-07-09 Thread Philipp Traeder
On Friday 09 July 2004 19:25, Gunnar Hjalmarsson wrote:
> Philipp Traeder wrote:
> > I don't know what an expert would say,
>
> Neither do I. :)

I think this is a good base for talking about hashes. ;-)

> > but for testing if a hash contains an element, I normally use
> > "exists":
>
> Your wording "if a hash contains an element" is ambigous IMO. A hash
> or associative array consists of key/value pairs, where the keys are
> indexes and the values are considered to be the elements (I think).

Ok - that's a possible terminology, and yes, I wasn't completely precise ;-)

>
> >   if (exists ($hash{'mykey'})) {
> > print 'mykey exists.';
> >   }
>
> That's fine, as long as you are aware that $hash{mykey} may well be
> undefined even if it "exists".

I think *this* is the interesting point here - it's quite possible that a 
certain key exists in a hash, but has an undefined value:

  my %hash = (42 => undef);

  print "42 exists\n" if (exists $hash{42});
  print "42 is defined\n" if (defined $hash{42});

If you ask me, you can't put up a general rule about using "exists" or 
"defined" - it's a questions of how/on which conditions the hash has been 
filled...

Just my 5 cent,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Serving up a pdf file

2004-07-21 Thread Philipp Traeder
On Wednesday 21 July 2004 HH:53:19, David Arnold wrote:
> All,

Hi David,
>
> I have a page with a link "Quiz1".
>
> When the user clicks on the the link, a perl script will be summoned that
> will populate forms of a pdf document.
>
> Now, I could create a new page at this point with a link to the newly
> created pdf, but could someone suggest a technique where I simply send the
> pdf to the user after the pdf forms have been populated?
>
> Does that sound like a redirect or does someone have a better suggestion?
>

if I understand your problem correctly, you want to generate a pdf file when 
the user clicks a link, and when the pdf is generated completely, you want to 
send it back to him?

If yes, just create the pdf file on the fly and send it back - I don't know 
how to generate pdf files in perl, therefore I'll just give you an example 
that creates a text file (untested, for demonstration only):

#!/usr/bin/perl -w

use strict;
use CGI;

my $query = new CGI();

# print the header (you need to modify this to the correct content-type for 
pdfs)
print $query -> header(-type => 'text/plain');

for (my $loop = 1; $loop <= 10; $loop++) {
  print "line $loop\n";
}

If you execute this as CGI script, the user will receive a text file that he 
can save. I think you should be able to do the same for PDFs.

HTH,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Serving up a pdf file

2004-07-21 Thread Philipp Traeder
On Wednesday 21 July 2004 HH:44:20, David Arnold wrote:
> Phillip,

Hi David,

please bottom post.
>
> Thanks, but this is not quite what I was looking for.
>
> When the user clicks on "Quiz1" a perl script will be called to generate
> and compile a tex file using pdflatex. Once that is complete, I will have a
> file Quiz1.pdf which I want to send back to the user.

maybe I don't get it, but I think the base principle stays the same - as long 
as you specify the correct http content-type, you can to what you want before 
sending it back to the user, and the user will receive your script's output 
as a file (i.e. the browser should ask the user if it wants to open or save 
the file etc.). It should be transparent to the user whether a file is 
returned by the web server directly or if you create it on the fly.

Let me re-write the example (untested, again):

#!/usr/bin/perl -w

use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use FileHandle;

my $query = new CGI();

print $query -> header(-type => 'text/plain');

# call an external program to generate a file
system('netstat > netstat.file')
or die "could not call netstat : $!";

# open the file and sent it back to the user
my $fh = new FileHandle();
open($fh, 'netstat.file')
or die "could not open netstat file : $!";
while (<$fh>) {
print;
}
close($fh)
or die "could not close handle to netstat file : $!";

If I'm on the wrong track, let me know - otherwise this should do the trick.

HTH,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Perl and XML::Simple

2004-07-22 Thread Philipp Traeder
On Monday 19 July 2004 HH:04:06, David Arnold wrote:
> All

Good morning,

>
> I tried to run this:
>
[..]
> my $resp_xml=XMLin('./Responses.xml',forcearray=>1);
>
> print Dumper $resp_xml;
>
> On this file:
>
> [EMAIL PROTECTED] perlxml]# cat -A Responses.xml
>  
> And I got this error message:
>
> [EMAIL PROTECTED] perlxml]# ./Responses.pl
> Not a quote character [Ln: 1, Col: 38]
>
> Can anyone help?

maybe. ;-)

As far as I know, you must quote all attribute values in XML, i..e. the first 
line of your file should be
  
instead of
  

Otherwise it's not valid XML and can probably not be parsed correctly.

Taking a look at your file, it looks like you'll have the problem elsewhere as 
well - it might be a good idea to take a look at the code that is producing 
this XML file.

HTH,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: find out who was online at a given time

2004-07-22 Thread Philipp Traeder
On Tuesday 20 July 2004 18:34, [EMAIL PROTECTED] wrote:
> Ok, this may or may not be a tricky one I will try and be succinct in my
> statement.
>
> I have a database (mysql 4.0) with radius log entries for each day, we
> receive emails about Acceptable Use Abuses and must figure out exactly
> who was online with a certain IP address when the abuse occurred. As you
> will see below there are multiple starts and stops for any given IP
> address so here is the scenario:
>
> Problem: Spam Abuse
> IP of offender: 66.50.xxX.245
> Date of offense: 2004-07-05
> Time of offense: 16:15
>
[..]
>  now of course I changed the usernames and modified the IP for  this
> mailing but that doesn't matter, now, the time field in the Database IS
> a time data type. What I need to be able to do is find the start before
> the offense time, and the stop after the offense time so I know that the
> person with the start and the stop is the one that committed the abuse.
>
> I haven't actually put code to bits yet, because I am not exactly sure
> how to go about creating this logic code. I don't think I can just say
> if $timefield < time of offense and $timefield > time of offense; return
> some stuff.
>

Wouldn't it be enough if you would get the first entry before the "time of 
offense"? You could do something like:

select *
from your_table_name
where ip = 'xxx.xxx.xxx.xxx'
  and timefield < time_of_offense
order by timefield desc

I'm not sure about the "order by" part (either it must be "asc" or "desc"), 
but if you select everything before the time of offense and take the first 
entry, you should get the guy who logged in last.

HTH,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




executing code that's inside a variable [Re: Code in Variable ausführen?]

2004-07-23 Thread Philipp Traeder
On Friday 23 July 2004 11:53, Bastian Angerstein wrote:
> Hello,

Hi Bastian,

>
> is it possible to execute code that is within a var?
>
> like:
>
> $var = 'print "Hallo Welt\n"';
>
> I had seen something like that in compination with eval...

something like this?

my $var = 'print "Hallo Welt\n";';
eval($var) or die "could not execute : $@";

HTH,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Regular expression generator/creator

2004-08-28 Thread Philipp Traeder
On Friday 27 August 2004 HH:21:13, Chris Devers wrote:
> On Fri, 27 Aug 2004, Mark Maunder wrote:
> > I've google'd and CPAN'd and no luck. Is there a tool out there that
> > will generate a regular expression based on a series of string inputs
> > that are similar but have parts that differ[?]
>
[..]
>
> My hunch is that flinging a bunch of text at some kind of regex maker
> and telling it to figure out on its own how to match or not match
> different examples is going to be a variant of the halting problem.
>
>  
>  
>
> And I'd be stunned if you could solve that by the end of the day :-)

Hi Chris,

thanks for those links - that's quite interesting.
I'm not sure if I understood the Halting Problem completely, but could you 
give a hint what brings you to the assumption that "automatically generating 
regular expressions from a bunch of text" is a variant of the Halting 
Problem?

I'm facing a roughly similar problem at the moment, and I was planning on 
using String::Compare or something like it for comparing strings char by 
char. Taking a first glance at the code, it doesn't look too hard to modify 
it in a way that it returns not only the similarity between two strings, but 
also a string with special characters at those places that are different - 
something that I could call like:

  my $a = 'abcdXef';
  my $b = 'abcdYef';
  my ($similarity, $regexp) = compare_strings($a, $b);

and would return the similarity as percentile of matching chars (6/7 in this 
case) and a regex that looks like 
  abcd.ef

Is this problem different to the one you were talking about? If not, why 
shouldn't it be solvable?

Philipp


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Regular expression generator/creator

2004-08-28 Thread Philipp Traeder
On Saturday 28 August 2004 HH:27:20, Chris Devers wrote:
> On Sat, 28 Aug 2004, Philipp Traeder wrote:
> > I'm not sure if I understood the Halting Problem completely, but could
> > you give a hint what brings you to the assumption that "automatically
> > generating regular expressions from a bunch of text" is a variant of
> > the Halting Problem?
>
> I'm not a computer science theorist or anything, and could easily be
> wrong about my guess there, but it just seems like the same sort of
> broadly unbounded scenario that the halting problem deals with.
>
> The halting problem, for those that haven't heard of it, basically
> states that it is impossible to determine whether any random program
> will ever finish properly, because most will succeed or fail quickly but
> some will legitimately need infinite time to complete. It was conceived
> by Alan Turing before the first electronic computers were yet built, and
> is itself a variant on Kurt Godel's incompleteness theorem:
>
[..]
>
> Anyway, all of this & more isdescribed at extreme length in the great
> book _Godel, Escher, Bach_, if you want to learn more from an author who
> can actually explain this stuff without mangling it, as I've probably
> done :-)

Thanks for the explanation and the book title - I'll definitely take a look at 
it. This stuff sounds fascinating.

> >  my $a = 'abcdXef';
> >  my $b = 'abcdYef';
> >  my ($similarity, $regexp) = compare_strings($a, $b);
> >
> > and would return the similarity as percentile of matching chars (6/7
> > in this case) and a regex that looks like
> >
> >  abcd.ef
> >
> > Is this problem different to the one you were talking about? If not, why
> > shouldn't it be solvable?
>
> As I say before, I'm not a theorist or anything, it's all just hunches
> here :-).
>
> That said, the example you give is pretty well restricted, which would
> seem to lend to the problem being solvable. On the other hand, the
> example you give is so well restricted that it didn't take you any
> trouble at all to come up with the regex yourself.
>
> My suspicion is that as the problem gets more and more nuanced,
> automatic tools will have an increasingly hard time keeping up.
>
> This also gets into the sorts of topics that artificial intelligence
> researchers spend time pondering about -- how do you get a program to
> automatically recognize that a random image is a person (rather than,
> say, a statue), etc. It sounds simple, but it's really tricy stuff...

You're right - the problem I'm trying to solve is quite restricted - and I'm 
very thankful for this ;-)
Basically, I'm trying to write an application that "recognizes" log file 
formats, so that the following lines are identified as several manifestations 
of the same log message:

  could not delete user 3248234
  could not delete user 2348723

or even

  failed to connect to primary server
  failed to connect to secondary server

What I would like to see is a count of how many "manifestations" of each log 
message are being thrown, independently of the actual data they might 
contain. Since I do not want to hardcode the log messages into my 
application, I would like to generate regexes on the fly as they are needed.

So far, I'm quite confident that this should be solvable, but I agree that 
it'll become increasingly difficult if the connections between messages get 
more complex.

Thanks again for this interesting perspective,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: Regular expression generator/creator

2004-08-30 Thread Philipp Traeder
On Sunday 29 August 2004 HH:58:18, Jenda Krynicky wrote:
> From: Philipp Traeder <[EMAIL PROTECTED]>
>
> > You're right - the problem I'm trying to solve is quite restricted -
> > and I'm very thankful for this ;-) Basically, I'm trying to write an
> > application that "recognizes" log file formats, so that the following
> > lines are identified as several manifestations of the same log
> > message:
> >
> >   could not delete user 3248234
> >   could not delete user 2348723
> >
> > or even
> >
> >   failed to connect to primary server
> >   failed to connect to secondary server
> >
> > What I would like to see is a count of how many "manifestations" of
> > each log message are being thrown, independently of the actual data
> > they might contain. Since I do not want to hardcode the log messages
> > into my application, I would like to generate regexes on the fly as
> > they are needed.
>
> Well and how are you going to tell the program which messages to take
> as the same?
> Do you plan to teach the app as it reads the lines? Do you want it to
> ask which group is a line that doesn't match any of the regexps so
> far and have the regexp modified on the fly to match that line as
> well?
>
> Or what do you want to do?
>
> IMHO it might be best to use handmade regexps, just don't have them
> built into the application, but read from a config file. That is for
> each type of logs you'd have a file with something like this:
>
>   delete_user=^could not delete user \d+
>   connect=^failed to connect to (?:primary|secondary) server
>   ...
>
> read the file, compile the regexps with qr// and have the application
> try to match them and have the messages counted in the first group
> whose regexp matches.
>
>
> Do I make sense or am I babbling nonsense?

You're making perfect sense - the problem is not as trivial as I thought 
originally, but I think it's not that bad as long as you don't require a 
precision of 100%.

In a perl script I wrote some time ago, I'm grouping log messages by comparing 
them word by word, using the String::Compare module like this:

compare($message1, $message2, word_by_word => 5);

If I read the module's code correctly, the strings are split up by whitespace 
and then compared char by char. Using this approach, I get a high similarity 
even if the differing parts of the strings do not have the same length, like 
in
failed to connect to primary server
failed to connect to secondary server

What I did now was to extend String::Compare in a way that it records the 
differing parts of the strings in a string array for each string (actually, I 
did not extend String::Compare, but ported it to Java, because I'm writing 
the application in Java, but the idea should be the same) and returns a 
"wildcarded" version of the string, i.e. a version that replaces each 
character that is not identical in both strings with a wildcard string.

Currently, I'm not using the regexp that is generated in this way for matching 
new messages, because I ran in some kind of deadlock: What should I do when I 
get a message for which I do not have a matching regexp yet? Since I do have 
only one occurence of this message so far, I can not detect a pattern, thus I 
can not generate a regexp. Therefore, I've got to compare all messages that 
follow in the method described above against the real messages, not against a 
wildcarded version.
Anyway - if you choose the wildcard-character wisely, I think you should be 
able to generate a regexp that is surely not as good as one written by a 
human, but probably good enough (e.g. you could take 
  (.*?)
as wildcard character for each differing "word").

At the moment, this should be enough to solve my problem - I'm already using 
the word-by-word string comparison successfully, and it looks as if the 
ported/extended java version of String::Compare would do what I need. 
Nevertheless I could imagine that you could build better regexps by comparing 
the data that you extracted from the message (since I need to extract the 
data anyway to use them later, this is a very likely option). Let's say I've 
got the following log messages taken from a web application:

  30/08/2004 23:25:01 processed request for a.html - took 35 ms
  30/08/2004 23:25:05 processed request for ab.html - took 42 ms
  30/08/2004 23:25:05 processed request for a.html - took 37 ms

My application compares the messages, detects that they are very similar, and 
creates the following pattern (assuming that the wildcard char is an asterisk 
and that a multi-character difference is replaced by one wildcard char):

  30/08/2004 23:25:* processed re

Re: counting gaps in sequence data

2004-10-14 Thread Philipp Traeder
On Thursday 14 October 2004 21:44, Michael Robeson wrote:
> Here is as far as I can get with some real code and pseudo code. This
> is just to show you that I am actually trying. :-)

Hi Michael,

this looks quite promising - I'll try to sketch a solution without giving 
everything away ;-)

>
> Pseudo - code

This is really important: Always start your scripts with

use warnings;
use strict;

This will help you avoiding errors.

>
> 
> # open DNA sequence file
> 
>
> print "Enter in the name of the DNA sequence file:\n";
> chomp (my $dna_seq = );
> open(DNA_SEQ, $dna_seq)
>   or die "Can't open sequence file for input: $!";
>
> 
> # read sequence data into a hash - not sure if this is how I should do
> it?
> 
>
> my %sequences;
>
> $/ = '>'; # set to read in paragraph mode
>
> print "\n***Discovered the following DNA sequences:***\n";
>
> while (  ) {
>   chomp;
>   next unless s/^\s*(.+)//;
>  my $name = $1;
>  s/\s//g;
>  $sequences{$name} = $_;
>  print "$name found!\n";
> }
> close DNA_SEQ;

This part is not working completely for me - I get the first sequence only.
I've never got used to working with the $/ operator, therefore I'd rewrite 
this part like this (without wanting to say that this would be easier than 
your approach):

print "\n***Discovered the following DNA sequences:***\n";

# each line holds either a caption or a sequence
my $is_sequence_line = 0; # first line holds a caption
my $name;
while (  ) {
 chomp;
 
 if ($is_sequence_line) {   
# this line holds a sequence 
$sequences{$name} = $_;
print "sequence for $name found!\n";
 }
 else {
# this line holds a name - remember it
print "new name : $_\n";
$name = $_; 
 }
 
 $is_sequence_line = ! $is_sequence_line;
}
close DNA_SEQ;

print "\n";

>
>
> ###
> # search for and characterize gaps
> ###
>
> <>
>
> %gaptype;
>
> <>
> foreach /\D(-+)\D/ found in each sequece # searches for gaps flanked by
> sequence
>   $position = pos($1);
>   $gaplength = $1;
>   $gaplength =~ tr/-//g;  # count the number of '-' for that particular
>   # gap being processed
>   $gaptype{gaplength}++;  # count the number of times each gap type
> appears
>
> <>
>

# first, we need to iterate over the sequences
while (my ($name, $sequence) = each(%sequences)) {
# now we can work on each sequence
print "working on sequence $name\n";
print "sequence : $sequence\n";
# find all gaps in the sequence
# (the g modifier means to search for all occurences)
while ($sequence =~ /(-+)/g) {
print "\n";
# the special variables $`, $& and $' give you the
# text left of the match, the match itself, and the
# text right of the match.
# Using those variables and the length() function,
# you can print something like this:
print "found the following gap : '" . $& . "'\n";
print "the text before the gap : '" . $` . "'\n";
print "the text after the gap : '" . $' . "'\n";
print "the text before the gap is " . length ($`) . " chars long.\n";
}
print "\n";

}

I hope this might give you an approach for handling this - with the variables 
I printed, you should be able to fill your %gaptype hash like you sketched 
above (you find the length of the gap in length($&), and the gap's position 
is the same as the "length of the text left of the gap" + 1).

> OUTPUT_
>
> Human
> number of 3 base pair gaps:   2
>   at positions:   6, 16
> number of 5 base pair gaps:   1
>   at positions:   25
> .
> .. and so on...

You could either (easy variant) print this information while running through 
the while loop or (a bit harder, but might be easier in the long run if you 
need to process the data further) store the amount and position of the gaps 
inside a two-dimensional hash of arrays - something like:

  my %gaps = 
( human => 
  { 3 => [6, 16],
5 => [25]
  },
  chimp =>
  ...
)

It's a bit tricky to deal with structures like this, but once you got used to 
them, you must love them ;-)

Hope this helps.

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: parse xml

2004-10-25 Thread Philipp Traeder
On Monday 25 October 2004 16:49, Jenda Krynicky wrote:
> From: "Traeder, Philipp" <[EMAIL PROTECTED]>
>
> > print $ref->{'ResultItem'}->[0]{'MenuName'};
>
> I think it's better to either skip all the -> between subscriptions
> or include them all:
>
>   print $ref->{'ResultItem'}[0]{'MenuName'};
> or
>   print $ref->{'ResultItem'}->[0]->{'MenuName'};
>

You're right - I should have taken another look at this before posting.
My main focus was on pointing out XML::Simple combined with Data::Dumper -  
though this is *not* an excuse ;-).

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: parse xml

2004-10-28 Thread Philipp Traeder
Hi Franklin,

please bottom post (write your answer below the quoted text) - it's much 
easier to follow a thread this way.

On Thursday 28 October 2004 02:11, Franklin wrote:
> >> > print $ref->{'ResultItem'}->[0]{'MenuName'};

> I tried this one , but it seems not working:(
> Not an ARRAY reference at test.pl line 8

Taking a look at the other thread you opened on this list, my first guess is 
that your input files differ (your new file seems to have "ResultItemOne" as 
top level element while your original post's top level element was called 
"ResultItem").

I'd suggest to read the XML file via XML::Simple and to dump it via 
Data::Dumper - then you can see what the data structure looks like. After 
that you just need to play around a bit with array and hash references. If 
you run into problems with this, post the output of Data::Dumper to the list 
and somebody will be able to help.

HTH,

Philipp


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: xml parsing

2004-10-29 Thread Philipp Traeder
On Thursday 28 October 2004 10:56, E.Horn wrote:

Good morning,

> this gives me a DTD as output.

DTD?
As in the kind of document that describes XML files?
If yes, an XML Parser might be the wrong tool for parsing this kind of file.
Could you give us an example?

> My problem is I want to parse this output!
> But how can ich give it to the second code that this parses the result
> of (sub_daten_einlesen)
> I hope someone understands my question ;-)

[..snipped some code...]
>
>
> $url1 =daten_einlesen();
> $doc = get $url1;
> print $doc;

>
> #!/xprog/bin/perl
>
> # use module
> use XML::Simple;
> use Data::Dumper;
>
> # create object
> $xml = new XML::Simple;
>
> # read XML file
> $data = $xml->XMLin("which path???");

If the output you want to parse is stored in $doc, you should be able to pass 
it directly to XML::Simple:

  my $data = $xml->XMLin($doc);

HTH,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Need help with creating a web forwarding site.

2004-11-13 Thread Philipp Traeder
On Saturday 13 November 2004 13:51, Zeus Odin wrote:
> I would like to create a site that does nothing but forward requests to a
> destination site, say mydest.com. This is for nothing illicit, I am simply
> trying to circumvent a firewall's list of banned sites.
>
> :-)
>
> For instance, if I were to go to http://www.mysite.com, it would send a
> request to GET http://www.mydest.com, download to mysite.com all text and
> images to display a copy of mydest.com, then return to the client an image
> of the mydest.com page from mysite.com. Everything must appear to come from
> mysite.com.

Hi Zeus,

> I imagine I might use LWP::UserAgent for GETting, POSTing, and mirroring;
> and HTML::Parser, HTML::SimpleLinkExtor, or HTML::LinkExtor for processing
> links. I know nothing about CGI, mod_perl, or Apache but am willing to
> learn. I am probably forgetting to mention security, encryption, caching,
> and cookies. I usually use Window$ XP but also have RedHat 9 installed.

I guess LWP::UserAgent might be interesting in this context, but I wouldn't 
try to parse the responses you get. Why don't you pass the resulting code 
through only?
Something like (not tested, pseudo code only):

#!/usr/bin/perl -w

use strict;
use CGI;
use LWP::UserAgent;

# let's say your script is called like this:
# http://mysite.com/relay.pl?url=http://www.disney.com
my $query = new CGI();
my $url_to_visit = $query->param('url');

my $ua = new LWP::UserAgent();
# you should use something more general than "GET" here...don't know the
# syntax OTTOMH
my $response = $ua -> get($url_to_visit);
print $response;

> First, are there any modules that already do this? Why reinvent the box?
> ("Reinvent the wheel" is so trite.) Second, any pointers would be helpful.
> Of course, I have espoused that perl.beginners is a self-help group;
> therefore, I am not expecting any lines of code whatsoever. Just looking
> for advice, pointers, suggestions, caveats, watch-out-fors and general
> information. Should be a fun exercise!

I'm not sure, but this sounds more or less like something I read in the 
documentation of mod_proxy - maybe you want to take a look at

  http://httpd.apache.org/docs/mod/mod_proxy.html

Without having thought about it too much, there might be some security-related 
concerns you might want to think about - if you implement something like this 
accessible to the public, you allow everybody to visit web pages in a way 
that it looks like you/your server did it. What if somebody uses your "relay" 
server to download MP3s illegally? 

Just my 5 cent,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Need help with creating a web forwarding site.

2004-11-14 Thread Philipp Traeder
On Sunday 14 November 2004 12:25, Zeus Odin wrote:
> "Philipp Traeder" <[EMAIL PROTECTED]> wrote in message...
>
> > I guess LWP::UserAgent might be interesting in this context, but I
>
> wouldn't
>
> > try to parse the responses you get. Why don't you pass the resulting code
> > through only?
>
> I imagine the resulting code you're referring to is more than a server
> response of 200, 400, etc. Right?

Yep, I was thinking about the full HTTP response (including headers, HTML code 
etc.)

>
> > Something like (not tested, pseudo code only):
> >
> > #!/usr/bin/perl -w
> >
> > use strict;
> > use CGI;
> > use LWP::UserAgent;
> >
> > # let's say your script is called like this:
> > # http://mysite.com/relay.pl?url=http://www.disney.com
> > my $query = new CGI();
> > my $url_to_visit = $query->param('url');
>
> Is $query used only to get the url parameter?

In this script, yes - but thinking about it again, I guess you would need to 
do some things more.

What you're writing is more or less a proxy:

-- ----
| client   |   --> | proxy   |  --> | server  |
-- ----

The base idea behind this (as I see it - I've never worked with something like 
this, so be advised that I might talk complete nonsense here ;-) ) is that 
the client "thinks" he's talking with the proxy, but the proxy acts as 
intermediate, forwards all requests and executes them against the real 
server.

Therefore, the code I sketched in the last posting is not enough by far - 
you've got to duplicate the whole request.
Let's take a look at how a google query looks like:

Request1)
GET http://www.google.com
The response is a simple HTML page with a button and an input field for the 
search string.

Let's say the second request looks like this (just speculating - I'm too lazy 
to check how it looks like in details):
Request2)
GET http://www.google.com?query=the_input_from_the_text_field&action=search

Let's ignore for a moment the problem that you need to tell your script 
against which site you want to connect - if we assume that it'll be 
google.com always, you could write a script like:

# get all the request parameters that have been sent to us:
my $query = new CGI();
my @names = $query->param();
# now we would need to convert them into a format that LWP::UserAgent can use
foreach my $param_name (@names) {
  [...]
}

>
> > my $ua = new LWP::UserAgent();
> > # you should use something more general than "GET" here...don't know the
> > # syntax OTTOMH
> > my $response = $ua -> get($url_to_visit);
> > print $response;
>
> I would imagine I would have to interpret each web page click to determine
> if a GET, POST, or running code is necessary.

Yes, and each "web page click" is a request that is sent to your script - 
therefore you could decide whether to use GET or POST by taking a look at the 
method of the request your script has received - if the client sent you a 
GET, you need to send a GET etc.

A first version shouldn't be too hard, but the details might become 
interesting - what about cookies, HTTP authentication, http headers, 
forwards/redirects etc?

>
> > I'm not sure, but this sounds more or less like something I read in the
> > documentation of mod_proxy - maybe you want to take a look at
> >
> >   http://httpd.apache.org/docs/mod/mod_proxy.html
>
> Thanks. I will take a look.

This might be a good idea if you want to avoid headaches ;-)

>
> > Without having thought about it too much, there might be some
>
> security-related
>
> > concerns you might want to think about - if you implement something like
>
> this
>
> > accessible to the public, you allow everybody to visit web pages in a way
> > that it looks like you/your server did it. What if somebody uses your
>
> "relay"
>
> > server to download MP3s illegally?
>
> This is not a web site I will advertise. I will allow only certain ip
> addresses, so at most 5 people will use it. If they absuse it in any way, I
> can just strangle them because I know them all.
>
> >:-)

Then everything you need are good relations to the local cops - make them 
offers they can't refuse. ;-)

HTH,

Philipp

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>