Re: PERL VS MOD_PERL

2007-07-05 Thread Jeff Pang

There are some difference details between them.If you really want to
know it,you may first need to see what's mod_perl and how it
works.Take a look at:

mod_perl official documents:
http://perl.apache.org/docs/index.html

Why mod_perl by Stas Bekman:
http://www.perl.com/pub/a/2002/02/26/whatismodperl.html


2007/7/5, Dinesh kumar [EMAIL PROTECTED]:

Hi all,

  can any one tell me what is the difference between perl and
mod_perl in detail ??


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





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




Re: PERL VS MOD_PERL

2007-07-05 Thread Chas Owens

On 7/5/07, Dinesh kumar [EMAIL PROTECTED] wrote:

Hi all,

  can any one tell me what is the difference between perl and
mod_perl in detail ??


Four letters (mod_).  Seriously, mod_perl is a Perl interpreter built
into Apache to enable some efficiency hacks.

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




Memory leaks with threads

2007-07-05 Thread Michael Scondo
Hi,
I'm still trying to get familiar with threads and sockets.

However, I got in some troubles with memory leaks, could anyone perhaps give 
me a hint in which way I should write a multithreaded socket server ?


I wrote a small server, which accepts connections on a tcp socket and spawns a 
new thread for each connection, which terminates when the socket has been 
closed.

The server runs fine, however, while stresstesting, I experienced a runaway of 
the memory consumption.
After a few hundred connects and disconnects I'll get an Out of memory. :-(

In order to test threads in perl, I wrote a new script which just spawns and 
terminates threads. ( Attached it below )

I already figured out that global variables seem to lead to memory leaks, 
however, although the memory size raises slower now, it still raises. ( which 
I didn't expect ).

I stumbled over http://search.cpan.org/~rybskej/forks-0.23/lib/forks.pm, which 
seems to be a replacement for ithreads and also has the advantage of not 
needing a thread enabled perl.
However, there are still memory leaks with this module.



My conclusion is to write a preforked server, using the forks module mentioned 
above and create a pool of  say 50 preforked threads at startup time.

But, are there perhaps any better possiblities or recommendations ?

Thanks,
Michael

--

#!/usr/bin/perl -w

use threads;
use threads::shared;

#use forks;
#use forks::shared;

share $threadscount;
$threadscount = 0;

share $createthreads;
$createthreads = 1;

share $maxthreads;
$maxthreads = 0;


sub thread{
my $count;
{ 
lock $threadscount;
$threadscount ++;
$count = $threadscount;

lock $maxthreads;
if ( $count$maxthreads ){
$maxthreads = $count;
}
}
#print $count\n;
sleep 4;

lock $threadscount;
$threadscount --;
}


sub threadcreator{
my $tc;
do {
my $t = threads-create(thread);
$t-detach();
lock $createthreads;
$tc = $createthreads;
} while ( $tc );
}


while ( 1 ){
{
lock $createthreads;
$createthreads = 1;
}

my $thread = threads-create(threadcreator);
$thread-detach();
sleep 4;

{
lock $createthreads;
$createthreads = 0;
}

my $count;
do {
#sleep 3;
lock $threadscount;
$count = $threadscount;
} while ( $count  0 );
{ 
lock $maxthreads;
print maxthreads: $maxthreads\n;
}
}


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




SWF::Builder ActionScript classpath

2007-07-05 Thread Shannon Scott

Hello,
I have been using SWF::Builder to create swf files from actionscript ( 
.as files ).  It works great until I try to use some actionscript with 
an import statement, then I get this error:

Syntax error. ';' is expected. in 1

I don't think there are any issues with the code because it is part of a 
sample provided.  I think my probelm is that I don't have the classpath 
set right.  I found this line in the sample instructions:
If you want to use the accompanying ActionScript libraries, you will 
want to add the |/lib/| directory to your Classpath in the Flash 
authoring environment.
How do I add to the Flash Authoring Environment Classpath when I am 
using SWF::Builder to generate the swf files?

I tried using:
$ENV{'CLASSPATH'} = '/path/to/lib';
in the perl script, but it did not help.
Any help is appreciated.
Thank you.
Shannon



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




Re: foreach broken in my script

2007-07-05 Thread oryann9

--- Randal L. Schwartz [EMAIL PROTECTED]
wrote:

  Jeff == Jeff Pang [EMAIL PROTECTED]
 writes:
 
 Jeff May you need eval?Like,
 
 No.  Wrong direction for a solution.  Don't suggest
 things like this.  Plenty
 of proper answers elsewhere in the thread, so I
 won't repeat them.
 
 DO NOT USE STRING EVAL.  EVER.
 
 Until you understand why I said that. :)

Will you kindly explain the logic/reasoning behind
this EVER rule?

thank you...



   

Got a little couch potato? 
Check out fun summer activities for kids.
http://search.yahoo.com/search?fr=oni_on_mailp=summer+activities+for+kidscs=bz
 

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




Re: foreach broken in my script

2007-07-05 Thread Chas Owens

On 7/5/07, oryann9 [EMAIL PROTECTED] wrote:

--- Randal L. Schwartz [EMAIL PROTECTED]
wrote:

snip

 DO NOT USE STRING EVAL.  EVER.

 Until you understand why I said that. :)

Will you kindly explain the logic/reasoning behind
this EVER rule?

snip

Almost anything you want to do with the string version of eval can be
done more safely and maintainable in some other way.  If you want to
use string eval, first look for any possible way to avoid it.  If you
can't find a solution that doesn't use string eval, then ask the list.
There are very few legitimate cases where string eval can be used,
and even those are dangerous and full of traps for the unwary.

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




RE: syntax error of some sort?

2007-07-05 Thread Joseph L. Casale
Chas/Prabu,
The script is moving along nicely now:)
Incredible how I missed the obvious, although I have been staring at it for so 
long...

Thanks!
jlc

-Original Message-
From: Prabu Ayyappan [mailto:[EMAIL PROTECTED]
Sent: Wednesday, July 04, 2007 11:16 PM
To: Joseph L. Casale; beginners@perl.org
Subject: RE: syntax error of some sort?

@list = (Exchange,Filter,DNS,Domain);
sub stop_it {
$vm = $_[0];
print $vm\n;
}
stop_it(@list)

  A semi-colon is missing in the list assignment.

  if you want to get the first value of the list then you have to use

  $_[0]

  Second Value means

  $_[1] and so on...

  To get all the values from the list..

  sub stop_it {
(@vm) = @_;
print @vm\n;
}

  get it from @_ and assign it to an array @vm .Then you can navigate through 
the array with foreach or some for loops

  @_ will have the arguments passed to the sub-routine.


  Hope this help you.

  Thanks,
  Prabu

Joseph L. Casale [EMAIL PROTECTED] wrote:
  Heh,

Clearly I need to sleep!
This doesn't even work either?


#!/usr/bin/perl -w
@list = (Exchange,Filter,DNS,Domain)

sub stop_it {
$vm = $_[0];
print $vm\n;
}

stop_it(@list)



What is wrong here?
jlc







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





-
Food fight? Enjoy some healthy debate
in the Yahoo! Answers Food  Drink QA.




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




Re: SWF::Builder ActionScript classpath

2007-07-05 Thread Tom Phoenix

On 7/5/07, Shannon Scott [EMAIL PROTECTED] wrote:


I have been using SWF::Builder to create swf files from actionscript (
.as files ).  It works great until I try to use some actionscript with
an import statement, then I get this error:
Syntax error. ';' is expected. in 1


That's not one of perl's error messages, so I'm guessing it's coming
from either SWF::Builder or some other software you've got that I
don't.


I don't think there are any issues with the code because it is part of a
sample provided.


If you say so. But have you ever been able to get the sample
provided to work properly? I've seen plenty of sample software that
didn't work as advertised. It used to work that way, you see, with an
earlier version of the frobnicator, but we don't keep the sample code
up to date any longer

In any case, have you considered that maybe, somewhere around line 1
of something, you need to add a semicolon or otherwise adjust some
piece of non-Perl syntax?


How do I add to the Flash Authoring Environment Classpath when I am
using SWF::Builder to generate the swf files?


SWF::Builder looks complex enough that it probably needs a FAQ and a
mailing list, if it doesn't have those already. But this is a Perl
Beginners' forum; although it's possible that somebody here knows how
to help you, it's much more likely that you'll get the best help most
quickly by tracking down the experts on SWF::Builder, wherever they
hang out. You may even need to ask the module's author for
clarification.

But maybe you access the Flash Authoring Environment Classpath the
same way whether you use SWF::Builder or not. In that case, your help
would come from the analogous set of experts, FAQ, and mailing lists
for that programming environment. But as they are likely to be more
numerous than the crew for SWF::Builder, they are similarly likely to
have a well-established presence on the net, so finding them will be
all the easier.

Good luck with it!

--Tom Phoenix
Stonehenge Perl Training

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




RE: a question write to file!

2007-07-05 Thread Thomas Bätzler
herostar1981 [EMAIL PROTECTED] asked:
 I have a big question.
 why are the contents different between what I write to file 
 and what print in screen?

Obviously you are doing something wrong ;-)

If you want us to help you, please send a minimal code sample
that demonstrates your problem.

TIA,
Thomas


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




Extract year from date field and display the records

2007-07-05 Thread Alma
Hi All,

I have to build a search module which takes the parameter as year (ex
2007,2008 etc) ,title  subjects.

Here is the module

sub search {

  my($year,$author,$conference,$subject) = @_;
my $sth1=$dbh-prepare(select date_upload from docs);
my $res=$sth1-execute();
if ($res==0){
$result=0;
}
#   my @records=$sth1-fetchrow_array();
#   my @date;
#   foreach my $row(@records){
#   if((index($row,$date))==0){
#   push @date,$row;
#   }

  my $sth=$databasehandle-prepare(select
title,author,s.name,file from docs d join subject s on
s.id=d.subject_id and d.author_name=$author and s.id=$subject);
my $res = $sth-execute();

my @results;

while (my $array_ref1 =$sth-fetchrow_arrayref){
 push @results,[EMAIL PROTECTED];
}

return @results;
}

My Database is storing the date_uploaded field as date type.

I am lost , guidence in this regard is appreciated.

my subroutine should be able to search year value in date_upload field
in the docs  show me the result.
I am using  postgresql and new user of it.


my above attemp may be wrong please suggest me the any good approach
to retrieve the data.


Thanks in advance


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




Snippet explanation please

2007-07-05 Thread Monty
I'm reading Network Programming with Perl by Lincoln Stein, and I've
come across a snippet of code I'mnot quite following:

open (WHOFH, who |) or die Can't open who: $!;

While (WHOFH) {
next unless /^(\S+)/;
$who{$1}++;
}

It's the 'next' line I'm unclear on.  I know that results: parse the
first field from each output line of the 'who' command, but I'm
wondering why this might have been done in this way.  It seems to me
that the 'next' line states get the next record unless the current
one startes with a non-whitespace character.

The UNIX 'who' command output lines always start with non-whitespace
characters, as far as I can see.  It seems just as sensible to leave
this line out.  Does anyone know additional value to doing this?

Also, the '$who{$1}++' lines has the same effect here as awk '{ print
$1 }', and leads me to believe that $2, $3, etc. also exist, but that
doesn't seem to be the case as I've tried printing those variables.
How does the '$1' work in this case?

Thanks


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




Re: SOS: a question write to file!

2007-07-05 Thread Tom Phoenix

On 7/5/07, herostar1981 [EMAIL PROTECTED] wrote:


why are the contents different between what I write to file and what
print in screen?


Because of something in your source code.

Cheers!

--Tom Phoenix
Stonehenge Perl Training

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




Re: Snippet explanation please

2007-07-05 Thread John W. Krahn

Monty wrote:

I'm reading Network Programming with Perl by Lincoln Stein, and I've
come across a snippet of code I'mnot quite following:

open (WHOFH, who |) or die Can't open who: $!;

While (WHOFH) {


'While' is an error.  What the code probably said was 'while' (Perl is case 
sensitive.)


This reads each line from the file/pipe where line is defined by the Input 
Record Separator $/ and the current line is stored in the $_ variable.



next unless /^(\S+)/;


The current line is matched against the regular expression /^(\S+)/ which says 
that the beginning of the line must start with one or more non-whitespace 
characters and those non-whitespace characters are captured by the parentheses 
into the $1 variable.  If the current line does not match the pattern the next 
loops back to the start and another line is obtained.




$who{$1}++;


If the pattern matched we get to this point where the captured string is used 
as the key of the %who hash and the value of that key is incremented.




}

It's the 'next' line I'm unclear on.  I know that results: parse the
first field from each output line of the 'who' command, but I'm
wondering why this might have been done in this way.  It seems to me
that the 'next' line states get the next record unless the current
one startes with a non-whitespace character.

The UNIX 'who' command output lines always start with non-whitespace
characters, as far as I can see.  It seems just as sensible to leave
this line out.  Does anyone know additional value to doing this?


You should never use the numeric variables like $1 unless you are sure that 
the pattern matched otherwise the value in $1 will be left over from a 
previous successful match so this ensures that $1 always has a valid value.




Also, the '$who{$1}++' lines has the same effect here as awk '{ print
$1 }',


In perl awk '{ print $1 }' would be written as perl -lane'print $F[0]'



and leads me to believe that $2, $3, etc. also exist, but that
doesn't seem to be the case as I've tried printing those variables.
How does the '$1' work in this case?


perldoc perlre

You have to have sets of parentheses for each numeric variable.



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.-- Larry Wall

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




Re: interpolation of function reference in a here doc

2007-07-05 Thread Brad Baxter
On Jul 2, 9:27 am, [EMAIL PROTECTED] (Rob Dixon) wrote:
 Gabriel Striewe wrote:
  What do I do wrong?

 First of all, the ampersand subroutine designation is outdated and dangerous
 and it is far better to use the indirect notation for a subroutine call:

 $hello-()

 Perl will interpolate only simple variables or array or hash elements
 or slices. However we can cheat by putting the result of the call into
 an anonymous array and then dereferencing it:

 print END;
 hello @{[$hello-()]}
 END

And don't worry too much about simply using a string:

my $msg = $hello-();
print END;
hello $msg
END

--
Brad


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




Re: Snippet explanation please

2007-07-05 Thread Paul Lalli
On Jul 5, 10:49 am, [EMAIL PROTECTED] (Monty) wrote:
 I'm reading Network Programming with Perl by Lincoln Stein, and I've
 come across a snippet of code I'mnot quite following:

 open (WHOFH, who |) or die Can't open who: $!;

 While (WHOFH) {

Please configure your mail/newsreader not to randomly capitalize
words.  There is no While keyword in Perl.

 next unless /^(\S+)/;
 $who{$1}++;
 }

 It's the 'next' line I'm unclear on.  I know that results: parse the
 first field from each output line of the 'who' command, but I'm
 wondering why this might have been done in this way.  It seems to me
 that the 'next' line states get the next record unless the current
 one startes with a non-whitespace character.

 The UNIX 'who' command output lines always start with non-whitespace
 characters, as far as I can see.  It seems just as sensible to leave
 this line out.  Does anyone know additional value to doing this?

Well, the next command is actually doing three things at once.  First,
it's determining whether or not the current line starts with non-
whitespace characters.  Then, if it doesn't start with whitespace
characters, it skips the remainder of this iteration of the while
loop.  Finally, if it does start with whitespace characters, it's
saving those characters in $1.

The third part is obviously important.  As for the first two, I have
no idea - maybe there are some rare circumstances in which `who`
returns blanks at the start of the line?

 Also, the '$who{$1}++' lines has the same effect here as awk '{ print
 $1 }',

No it doesn't.  $who{$1}++ increments the value in the %who hash that
has the key $1.  `awk '{ print $1 }'` prints the first element of the
string that awk has parsed.  Perl's $1 and awk's $1 are wholly
unrelated.

 and leads me to believe that $2, $3, etc. also exist

They exist, yes.  But they're not what you think they are, any more
than Perl's $1 is what you think it is.

 but that
 doesn't seem to be the case as I've tried printing those variables.
 How does the '$1' work in this case?

$1, $2, $3, etc store the contents of the sequentially numbered
parentheses-enclosed submatches of the most recent successful pattern
match.  For example:

hello world =~ /(\w+) (\w+)/;
print $1-$2\n;  #prints hello-world
fo bar baz =~ /(o{2})(o)(o+)/;
print $1 $2 $3\n;  #prints oo o oo

Any successful pattern match will set ALL $number variables.  If
there are only two capturing parentheses, $1 and $2 are set to
whatever those captured submatches are, and $3 and up are set to
undef.  If there are no captured parentheses, all of $1 on up are set
to undef.

In your example, only one set of captured parentheses existed in the
pattern match, and so only $1 was set to a defined value.

Read more about regular expressions in:
perldoc perlretut
perldoc perlre
perldoc perlreref

Paul Lalli


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




Re: a question write to file!

2007-07-05 Thread herostar1981
On 7 5 ,   11 42 , [EMAIL PROTECTED] (T Baetzler) wrote:
Thanks...

The following loop is used to format the contents:
for my $key (keys %station)
{ $sta[$k].=Placemark\n visibility0/visibilityname$key/
namedescription![CDATA[hrcenterh3a href=http://
globec.whoi.eduU.S.GLOBEC/a /h3img src=\http://mapservice-
xu.whoi.edu/globec.gif\brP
a href=http://mapservice-xu.whoi.edu/maps-bin/globec-xu/map4GEORGES
BANK MAPSERVER/a/center
phra href=http://globec.whoi.edu/jg/serv/globec/gb/
inventory.html1?project%20eq%20$cruise[$k]$cruise[$k]/a
p.$key.centertable border=1trthinstrument/ththcast/
ththdate_time/ththse_flag/ththlat/ththlon/
ththdepth_w/ththdepth/ththcomments/th/tr;
  my @[EMAIL PROTECTED];
  for (my $p=0;$p=$#tmp_lev0;$p++)
{ my @[EMAIL PROTECTED];
 $sta[$k].=trtd.join(/tdtd,@sta_tmp)./td/tr;
}
  $sta[$k].=/table/centerphrcenter$date/center]]/
description\n.Point\ncoordinates.$tmp_lev0[0][5].','.
$tmp_lev0[0][4].,0/coordinates\n /Point/Placemark\n;
}

}


And, this  is used to finish the whole file content:
for (my $i=0;$i=$#data;$i++)
  {  $kml.=Folderopen0/opennamestation/name.
$sta[$i]./Folder;}

At this point, if I use following script, I can work as I wish:
print Content-type: text/html\n\n;
print $kml;

if I use print FID $kml;, the trouble is coming...

What happened?

BR,
xu
 herostar1981 [EMAIL PROTECTED] asked:

  I have a big question.
  why are the contents different between what I write to file
  and what print in screen?

 Obviously you are doing something wrong ;-)

 If you want us to help you, please send a minimal code sample
 that demonstrates your problem.

 TIA,
 Thomas



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




Re: SOS: a question write to file!

2007-07-05 Thread herostar1981
Thanks.

But I can not understand you.
Can you tell me the correct methods?

I am not sure what's wrong.
And I have spent the whole morning to find the mistake.

Please help me...

BR,
xu
On 7 5 ,   11 35 , [EMAIL PROTECTED] (Tom Phoenix) wrote:
 On 7/5/07, herostar1981 [EMAIL PROTECTED] wrote:

  why are the contents different between what I write to file and what
  print in screen?

 Because of something in your source code.

 Cheers!

 --Tom Phoenix
 Stonehenge Perl Training



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




Re: Snippet explanation please

2007-07-05 Thread Tom Phoenix

On 7/5/07, Monty [EMAIL PROTECTED] wrote:


I'm reading Network Programming with Perl by Lincoln Stein, and I've
come across a snippet of code I'mnot quite following:

open (WHOFH, who |) or die Can't open who: $!;

While (WHOFH) {
next unless /^(\S+)/;
$who{$1}++;
}


That should be while, not While; you probably know that perl is
case-sensitive. But the rest of it looks like something Dr. Stein
might write.


It's the 'next' line I'm unclear on.  I know that results: parse the
first field from each output line of the 'who' command, but I'm
wondering why this might have been done in this way.  It seems to me
that the 'next' line states get the next record unless the current
one startes with a non-whitespace character.

The UNIX 'who' command output lines always start with non-whitespace
characters, as far as I can see.  It seems just as sensible to leave
this line out.  Does anyone know additional value to doing this?


I believe Dr. Stein was using that line primarily to capture the
username at the beginning of the line, ensuring that the pattern match
succeeds. Another programmer might do that like this:

   unless (/^(\S+)/) {
 warn unexpected data from 'who' command: '$_', continuing;
 next;
   }

This program makes noise where the other was silent, but only when it
encounters somebody's unusual (buggy?) who command. If it didn't have
the warning, it would be close to what's in the book.


Also, the '$who{$1}++' lines has the same effect here as awk '{ print
$1 }',


Well, ye, that's true except that it's not. But I think you're
just talking about $1 here.


and leads me to believe that $2, $3, etc. also exist, but that
doesn't seem to be the case as I've tried printing those variables.
How does the '$1' work in this case?


There's one memory variable for each pair of memory parentheses in the
last successful pattern match. This one has only one pair, so it has
only $1. The others, $2 and so on, are all undef. You can have $42 if
you have 42 pairs of memory parentheses in your pattern, but in that
case please don't ask me to help maintain your code. In any case, the
perlre manpage has the details.

In general, it's poor form to use $1 and friends except shortly after
a successful pattern match, so likewise it's poor form not to check
the result of the pattern match, even if you're sure it will succeed.

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

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




Re: Snippet explanation please

2007-07-05 Thread Jenda Krynicky
From: Monty [EMAIL PROTECTED]
 I'm reading Network Programming with Perl by Lincoln Stein, and I've
 come across a snippet of code I'mnot quite following:
 
 open (WHOFH, who |) or die Can't open who: $!;
 
 While (WHOFH) {
 next unless /^(\S+)/;
 $who{$1}++;
 }
 
 It's the 'next' line I'm unclear on.  I know that results: parse the
 first field from each output line of the 'who' command, but I'm
 wondering why this might have been done in this way.  It seems to me
 that the 'next' line states get the next record unless the current
 one startes with a non-whitespace character.
 
 The UNIX 'who' command output lines always start with non-whitespace
 characters, as far as I can see.  It seems just as sensible to leave
 this line out.  Does anyone know additional value to doing this?
 
 Also, the '$who{$1}++' lines has the same effect here as awk '{ print
 $1 }', and leads me to believe that $2, $3, etc. also exist, but that
 doesn't seem to be the case as I've tried printing those variables.
 How does the '$1' work in this case?

The
  next unless /^(\S+)/;
serves two purposes. First it makes sure you do not try to process 
lines that are empty or start with whitespace (whether that's likely 
to happen or not I have no idea) and it captures the first word 
from the line so that you can access it via $1.

The magic is in the regular expression

  /^(\S+)/

The \S means any character except whitespace, the + means one or 
more such characters, the () mean that you are interested in those 
characters and the ^ means that you are searching for thise non-
whitespace characters in the beginning of the string only.

So that line could be read as

  go read the next line if the current one doesn't start with non-
whitespace characters. If it does, remember them in $1.

HTH, Jenda

= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


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




Re: SOS: a question write to file!

2007-07-05 Thread herostar1981
I am sorry.
Can you explain clearly?

I don't know what's wrong.

Your mean is the script code or the content I want to write to the
file?

Thanks a lot.
Best Regards,
xu
On 7 5 ,   11 35 , [EMAIL PROTECTED] (Tom Phoenix) wrote:
 On 7/5/07, herostar1981 [EMAIL PROTECTED] wrote:

  why are the contents different between what I write to file and what
  print in screen?

 Because of something in your source code.

 Cheers!

 --Tom Phoenix
 Stonehenge Perl Training



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




Re: a question write to file!

2007-07-05 Thread Tom Phoenix

On 7/5/07, herostar1981 [EMAIL PROTECTED] wrote:


for (my $i=0;$i=$#data;$i++)
  {  $kml.=Folderopen0/opennamestation/name.
$sta[$i]./Folder;}


That _might_ be correct. But why does the loop count through the last
element of the @data array, when you're processing the @sta array? And
did you ever initialize $kml?

Most uses of the computed for loop, like that one, are simpler as a
foreach loop in Perl:

 foreach my $i (0..$#data) { ... }

Or even this:

 foreach my $element (@data) { ... }


At this point, if I use following script, I can work as I wish:
print Content-type: text/html\n\n;
print $kml;

if I use print FID $kml;, the trouble is coming...


What trouble? Are you saying that $kml printed to a file is different
than $kml rendered in a web browser, or what?

Good luck with it!

--Tom Phoenix
Stonehenge Perl Training

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




Re: help with syntax using an if statement

2007-07-05 Thread Daluk
On 5 Jul, 00:24, [EMAIL PROTECTED] (Ken Foskey) wrote:
 On Wed, 2007-07-04 at 19:00 +0200, Martin Barth wrote:
  Hi

   if (($DeviceType eq Switch) || ($DeviceType eq Router) ||
   ($DeviceType eq Hub) || ($DeviceType eq Access point))

   what i would like to do is check each device type with where the first
   letter is uppercase or lowercase

  this should help:

  if( $DeviceType =~ m/^([Ss]witch|[Rr]outer|[Hh]ub|[Aa]ccess point)$/) { ...

 Knowing systems:

 if( $DeviceType =~ m/^(switch|router|hub|access point)$/i ) {

 The i modifier is ignore case.

 I think there is a word boundary \ and \ that might be useful rather
 than ^$ as well.

 --
 Ken Foskey
 FOSS developer




guys,

thank you very much for your responses..   Martin i used your line and
it worked :-)

Ken, sorry, i got slightly lost on your last comment about the word
boundary?  would you mind explaining for me

thanks
Dal


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




require question

2007-07-05 Thread Robert Hicks

When I see code that starts with:

require 5.6.0;

Does that mean that the version of Perl can be 5.6.0 and above or that 
it *has to be* 5.6.0?


Robert

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




Re: require question

2007-07-05 Thread Chas Owens

On 7/5/07, Robert Hicks [EMAIL PROTECTED] wrote:

When I see code that starts with:

require 5.6.0;

Does that mean that the version of Perl can be 5.6.0 and above or that
it *has to be* 5.6.0?

Robert


from perldoc -f require
  VERSION may be either a numeric argument such as 5.006, which
  will be compared to $], or a literal of the form v5.6.1, which
  will be compared to $^V (aka $PERL_VERSION).  A fatal error is
  produced at run time if VERSION is greater than the version of
  the current Perl interpreter.  Compare with use, which can do
  a similar check at compile time.

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




Re: require question

2007-07-05 Thread oryann9
 When I see code that starts with:
 
 require 5.6.0;
 
 Does that mean that the version of Perl can be 5.6.0
 and above or that 
 it *has to be* 5.6.0?

...that version and above 
see the output from;
perldoc -f require



 

It's here! Your new message!  
Get new email alerts with the free Yahoo! Toolbar.
http://tools.search.yahoo.com/toolbar/features/mail/

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




DBD::Oracle for perl testing issues

2007-07-05 Thread Dan King
I am attempting to install DBD::Oracle for Perl. I am having some
difficulties though. During the make test procedure a number of my
tests fail. One of them is the 10general.t test.

It fails on lines 31 and 32 which has

is system(exit 1;), 18, 'system exit 1 should return 256';
is system(exit 0;), 0, 'system exit 0 should return 0';

The errors states that both lines return a value of -1 instead of 256
and 0 respectively.

I don't understand why it would return such a thing because as far as
I can tell it should be returning the correct value. I am using a Unix
system with Solaris 9 and Oracle 10 installed.

Thanks for any help offerened


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




Re: a question write to file!

2007-07-05 Thread herostar1981

 At this point, if I use following script, I can work as I wish:
 print Content-type: text/html\n\n;
 print $kml;

Placemark
 visibility1/visibilitynamestation38/namedescription!
[CDATA[hrcenterh3a href=http://globec.whoi.eduU.S.GLOBEC/a
/
h3img src=http://mapservice-xu.whoi.edu/globec.gif;brP
a href=http://mapservice-xu.whoi.edu/maps-bin/globec-xu/map4GEORGES
BANK MAPSERVER/a/center
phra href=http://globec.whoi.edu/jg/serv/globec/gb/
inventory.html1?project%20eq%20AL9404AL9404/a
p38centertable border=1trthstation_id/ththinstrument/
ththcast/ththdate_time/ththse_flag/ththlat/
ththlon/
ththdepth_w/ththdepth/ththcomments/th/
trtrtdMkVCTD/
tdtd38/tdtd1994-6-8 04:55/tdtdnd/tdtd41.8008/
tdtd-68.2667/tdtd124.0/tdtd110.0/tdtdnd/td/
trtrtdMkVCTD/tdtd38/tdtd1994-6-8 05:02/tdtdnd/
tdtd41.8017/tdtd-68.2667/tdtdnd/tdtdnd/tdtdnd/
td/
trtrtdMOC1/tdtd38/tdtd1994-6-8 05:08/tdtdnd/
tdtd41.8083/tdtd-68.2633/tdtd119.0/tdtd100.0/
tdtdMOC1198/td/trtrtdMOC1/tdtd38/tdtd1994-6-8
05:53/tdtdnd/tdtd41.8017/tdtd-68.2967/tdtd146.0/
tdtdnd/tdtdnd/td/tr/table/centerphrcenter/
center]]/description
Point
coordinates-68.2667,41.8008,0/coordinates
 /Point/Placemark


As you see, this is the html source.

 if I use print FID $kml;, the trouble is coming...

Placemark
 visibility1/visibilitynamestation/namedescription!
[CDATA[hrcenterh3a href=http://globec.whoi.eduU.S.GLOBEC/a
/
h3img src=http://mapservice-xu.whoi.edu/globec.gif;brP
a href=http://mapservice-xu.whoi.edu/maps-bin/globec-xu/map4GEORGES
BANK MAPSERVER/a/center
phra href=http://globec.whoi.edu/jg/serv/globec/gb/
inventory.html1?project%20eq%20/a
pcentertable border=1trthstation_id/ththinstrument/
ththcast/ththdate_time/ththse_flag/ththlat/
ththlon/
ththdepth_w/ththdepth/ththcomments/th/trtrtd/
tdtd/tdtd-- :/tdtd/tdtd/tdtd/tdtd/tdtd/
tdtd/td/trtrtd/tdtd/tdtd-- :/tdtd/tdtd/
tdtd/tdtd/tdtd/tdtd/td/trtrtd/tdtd/
tdtd-- :/tdtd/tdtd/tdtd/tdtd/tdtd/tdtd/
td/trtrtd/tdtd/tdtd-- :/tdtd/tdtd/tdtd/
tdtd/tdtd/tdtd/td/tr/table/
centerphrcenterThu
Jul 5 10:36:08 EDT 2007/center]]/description
Point
coordinates,,0/coordinates
 /Point/Placemark


This is the file contents..




 What trouble? Are you saying that $kml printed to a file is different
 than $kml rendered in a web browser, or what?

yes, they are different. I don't know how to describe it..



 Good luck with it!

 --Tom Phoenix
 Stonehenge Perl Training



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




Re: Snippet explanation please

2007-07-05 Thread Jenda Krynicky
From: Monty [EMAIL PROTECTED]
 Thanks for all the replies, both in this group and in separate e-
 mails.
 
 Things have been cleared up.  My major misunderstanding was in the
 fact that $1, $2, etc. can exist outside the RegEx.  I previously
 thought they had to be confined to the expression itself.  Through
 some experimenting I find they no longer exist once the block defined
 by the 'while' statement is complete.  I presume they'll get redefined
 with another RegEx, but I've yet to experiment on that.

The assignment to $1 and friends is local()ized to the current block:

abc =~ /.(.)./;
print top level \$1=$1\n;
{
 123 =~ /.(.)./;
 print in block \$1=$1\n;
}
print top level again \$1=$1\n;

once you leave the block in which the match occurred, the $1, $2, ... 
gets reassigned to whatever value it had before the block.

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


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




Re: a question write to file!

2007-07-05 Thread herostar1981
please...

this forum refresh so slowly

On 7 5 ,   1 06 , [EMAIL PROTECTED] (Tom Phoenix) wrote:
 On 7/5/07, herostar1981 [EMAIL PROTECTED] wrote:

  for (my $i=0;$i=$#data;$i++)
{  $kml.=Folderopen0/opennamestation/name.
  $sta[$i]./Folder;}

 That _might_ be correct. But why does the loop count through the last
 element of the @data array, when you're processing the @sta array? And
 did you ever initialize $kml?

 Most uses of the computed for loop, like that one, are simpler as a
 foreach loop in Perl:

   foreach my $i (0..$#data) { ... }

 Or even this:

   foreach my $element (@data) { ... }

  At this point, if I use following script, I can work as I wish:
  print Content-type: text/html\n\n;
  print $kml;

  if I use print FID $kml;, the trouble is coming...

 What trouble? Are you saying that $kml printed to a file is different
 than $kml rendered in a web browser, or what?

 Good luck with it!

 --Tom Phoenix
 Stonehenge Perl Training



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




Re: su and password in a Perl script

2007-07-05 Thread Tom Phoenix

On 7/5/07, Lakshmi Sailaja [EMAIL PROTECTED] wrote:


I want to automate the following through Perl:
su - user
and provide password
check if the login is successful or not.


You'll probably have an easier time using sudo, instead of su; it's
made for this sort of thing. See whether yours has the -S command line
option, to get the password from its standard input instead of the
terminal. You could try using IPC::Open3, maybe something like this:

 my($wr, $rd, $er);
 my $pid = open3($wr, $rd, $er, 'sudo -S some command');
 sleep 1; # let it start and ask for password
 print $wr seCret\n;  # the password

Good luck with it!

--Tom Phoenix
Stonehenge Perl Training

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




Re: DBD::Oracle for perl testing issues

2007-07-05 Thread Tom Phoenix

On 7/5/07, Dan King [EMAIL PROTECTED] wrote:


I am attempting to install DBD::Oracle for Perl. I am having some
difficulties though. During the make test procedure a number of my
tests fail. One of them is the 10general.t test.

It fails on lines 31 and 32 which has

is system(exit 1;), 18, 'system exit 1 should return 256';
is system(exit 0;), 0, 'system exit 0 should return 0';

The errors states that both lines return a value of -1 instead of 256
and 0 respectively.


This doesn't look like a problem with Oracle, but instead a problem
with perl or your OS.

Could there be a program on your system with the unfortunate name of 'exit'?

Could your perl binary be misconfigured? Did it pass all tests before
installation?

Good luck with it!

--Tom Phoenix
Stonehenge Perl Training

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




GetOptions with dynamic set of options

2007-07-05 Thread Ray
Hi,
I'm trying to build a generic Parsing Arguments functions that would
be driven by an array of possible options that is defined by a
specific program. I'm trying to use this feature of GetOptions:

my %h = ();
GetOptions (\%h, 'length=i');   # will store in $h{length}

But what I would like to do is to not have to hard code the 'length=i'
option directly in the argument for GetOptions, but rather this be
based on some list. Here is what I would like to do (but the options
part is not working). Anyone have any suggestions or recommendations
(maybe I'm going at this all wrong)?


use Getopt::Long;
use Data::Dumper qw(Dumper);
our %MyArgs = ();
our %OptList = ();
sub ParseArgs {
GetOptions(%OptList) or Getopt::Long::HelpMessage(2);
}


@GlobalSwitches = (test,showlog);   # These will be available
to any program
@LocalSwitches = (noadd, noemail); # These will be placed in
an ini file
@OptionList = (strategy,country);  # These will be placed
in an ini file
# strategy option could contain: LT or MT or ST or ALL
# country option could contain a ISO country code, I would like to
support multiple values

@SwitchList = (@GlobalSwitches, @LocalSwitches);

foreach my $switch (@SwitchList) {$OptList{$switch} = \
$MyArgs{$switch}}
print Available command line args \n . Dumper(%MyArgs) ;

foreach my $option (@OptionList) {$OptList{$option} = \
$MyArgs{$option}}
print Available command line args is now \n . Dumper(%MyArgs) ;

ParseArgs;

# Switch Results
print loading into DB is turned OFF\n if $MyArgs{noadd};
print E-mailing results is turned OFF\n if $MyArgs{noemail};
print Running in TEST Mode\n if $MyArgs{test};
print Running in SHOWLOG Mode\n if $MyArgs{showlog};

#Option Results
print Strategy is: $MyArgs{strategy} \n if $MyArgs{strategy};
print Country is: $MyArgs{country} \n if $MyArgs{country};

exit;


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




Proper way to halt a script

2007-07-05 Thread Joseph L. Casale
I am reading perldoc.perl.org and am not understanding exit and die clearly.

If I have a conditional in a sub that I want to validate with, what is the 
correct way to do the following:


1.   End the sub and return back to the script without continuing that sub.

2.   End the entire script without *any* further execution.

How do I write this?

Thanks!
jlc




Re: Proper way to halt a script

2007-07-05 Thread rcook
 I am reading perldoc.perl.org and am not understanding exit and die
 clearly.

 If I have a conditional in a sub that I want to validate with, what is the
 correct way to do the following:


 1.   End the sub and return back to the script without continuing that
 sub.


 if (condition){last}   gets you out of that loop


 2.   End the entire script without *any* further execution.

 if (condition){exit()}   although you might want to look at 'die' as
well, depends on what you are doing


Owen




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




Re: Proper way to halt a script

2007-07-05 Thread rcook
 I am reading perldoc.perl.org and am not understanding exit and die
 clearly.

 If I have a conditional in a sub that I want to validate with, what is
 the
 correct way to do the following:


 1.   End the sub and return back to the script without continuing
 that
 sub.


  if (condition){last}   gets you out of that loop


Ooops, meant to say

   if (condition){return}




Owen


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




Re: GetOptions with dynamic set of options

2007-07-05 Thread Ray
On Jul 5, 5:41 pm, [EMAIL PROTECTED] (Tom Phoenix) wrote:

 If that's the feature you're trying to use, why are you trying to use
 it like that? It seems to want a reference to a hash and a string, but
 you give it a hash? Try giving it a reference to a hash and a string,
 maybe something like this:

 GetOptions($target_hash_ref, $item_name=$letter) or ...

 Hope this helps!

I think I should have explained my code. I want to try to construct
the arguments for GetOptions, but in a dynamic way. So, instead of
hard-coding my switches, like this:
GetOptions (
   showlog   = \$MyArgs{showlog},
   'strategy=s'  = \$MyArgs{strategy}
)

like is shown in the GetOptions documentation page, I would like to
feed the list based upon some arrays (@GlobalSwitches, @LocalSwitches,
and @OptionList). I like using the %MyArgs{option} approach because
then I wouldn't have to declare a variable for each option I may have.
Having said that.. I'm not sure how I could do as you suggest.. How
would I set $target_hash_ref to support say the showlog switch, and
the strategy option? Would I be able to refer to each option such as
$target_hash_ref{showlog}, or $target_hash_ref{strategy} ?
Thanks alot for your help
Ray


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