Re: doubt with hash

2005-01-13 Thread Tor Hildrum
On Fri, 14 Jan 2005 12:09:03 +0530, Anish Kumar K.
<[EMAIL PROTECTED]> wrote:
> Hi All
> 
> I have a hash say. %browserType in which assume there are values...
> 
> %browserType=(
> "IE"=>2,
> "NETSCAPE"=>3,
> "FIREFOX"=>5
> );
> 
> I need to calculate one morething say percentage utilisation for each 
> browser..
> 
> ie..If IE is 2 = the percentage is calculated as (2/(2+3+5))*100
>NETSCAPE=(3/(2+3+5))*100
>FIREFOX=(5/(2+3+5))*100
> 
> and pass this in this single hash...I am new to this hash...I thought there 
> are two values possible, KEY and VALUE in hash
> is there a way I can add one more
> 
> "IE"=>2=>10
> "NETSCAPE=>3=>20
> 
> Please help
> 
> Anish

## calculate total
my $total = 0;

foreach keys (%hash) {
$total += $hash{$_};
}

## create a new hash to an anonymous array
foreach keys (%hash) {
 $percentage = ($hash{$_}/$total) * 100;
$browsertype{$_} = [$hash{$_}, $percentage];
}

## access
foreach keys (%browsertype) {
   print "Value: $_: $browsertype{$_}[0]\n";
   print "Percentage: $_: $browsertype{$_}[1]\n";
}

Untested though :)

Tor
Tor

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




Re: use warnings

2005-01-13 Thread Owen Cook

On Fri, 14 Jan 2005, Mark Cohen wrote:

> 
> While the use strict is quite clear to me "Perl pragma to restrict unsafe
> contructs" ,
> the use warnings "Perl pragma to control optional warnings" is not.
> What programming risks could I get without the use warnings ?

perldoc -q warnings

Found in FAQ 7
How do I temporarily block warnings?

If you are running Perl 5.6.0 or better, the "use warnings" pragma
allows fine control of what warning are produced.  See perllexwarn for
more details.

   {
   no warnings;  # temporarily turn off warnings
   $a = $b + $c; # I know these might be undef
   }

so as an example, run this program
-
#!/usr/bin/perl -w

use strict;
use warnings;
my ($a,$b,$c);
&addit;
sub addit
 {
   #no warnings;  # temporarily turn off warnings
   $a = $b + $c; # I know these might be undef
   }


print "$a\n"
---

Firstly as is, then secondly with the # removed from  #no warnings




Perhaps you will see the difference, and value of warnings



Owen


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




use warnings

2005-01-13 Thread Mark Cohen

Hello,
While the use strict is quite clear to me "Perl pragma to restrict unsafe
contructs" ,
the use warnings "Perl pragma to control optional warnings" is not.
What programming risks could I get without the use warnings ?

Thanks Mark



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




xml and perl help

2005-01-13 Thread johnny yu
hello.
i am new with perl and working on a program to sort and manage my dvds 
instead of using windows program.  i export the windows data using built in 
function to make it xml, how can i read this with perl so i can put in 
mysql?  i try xml::simple but it doesn't work.  can someone show me example 
program?  i know how to do the mysql part.

this is what xml output looks like:


  
   http://a9.com/Star%20Wars:%20Episode%20IV%20-%20A%20New%20Hope?imdbid=tt0076759";>
Star Wars: Episode IV - A New Hope
Science Fiction
121
   
   http://a9.com/Star%20Wars:%20Episode%20V%20-%20The%20Empire%20Strikes%20Back%20(1980)?imdbid=tt0080684">
Star Wars: Episode V - The Empire Strikes Back
Science Fiction
128
   
   http://a9.com/Star%20Wars:%20Episode%20VI%20-%20Return%20of%20the%20Jedi?imdbid=tt0086190";>
Star Wars: Episode VI - Return of the Jedi
Science Fiction
134
   
 


thx.
johnny
_
Take advantage of powerful junk e-mail filters built on patented Microsoft® 
SmartScreen Technology. 
http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines 
 Start enjoying all the benefits of MSN® Premium right now and get the 
first two months FREE*.

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



doubt with hash

2005-01-13 Thread Anish Kumar K.
Hi All

I have a hash say. %browserType in which assume there are values...

%browserType=(
"IE"=>2,
"NETSCAPE"=>3,
"FIREFOX"=>5
);

I need to calculate one morething say percentage utilisation for each browser..

ie..If IE is 2 = the percentage is calculated as (2/(2+3+5))*100
   NETSCAPE=(3/(2+3+5))*100
   FIREFOX=(5/(2+3+5))*100

and pass this in this single hash...I am new to this hash...I thought there are 
two values possible, KEY and VALUE in hash
is there a way I can add one more 

"IE"=>2=>10
"NETSCAPE=>3=>20

Please help

Anish


Re: Perl Socket

2005-01-13 Thread Mark Goland

- Original Message - 
From: "Groleo Marius" <[EMAIL PROTECTED]>
To: 
Sent: Thursday, January 13, 2005 4:46 AM
Subject: Perl Socket


> Hi list!
Hello Marius,
>
> im try-ing this code, to get a multi line server response:
>
> use Socket;
> socket(sock, AF_INET, SOCK_STREAM, getprotobyname('tcp')) || die "error:
$!\n";
> $dest = sockaddr_in($_[0], inet_aton($_[1]));
> connect(sock, $dest) || die "error: $!\n";
> select(sock);
>
> while ($response=) {
>   print;
> }
> close (sock) || die "close: $!\n";
>
> The thing is that after it gets the whole response, the script hangs,

That is because you are looping on a read and once you client sends all of
it's data on soket, the server block's on next read. You should build
sometype of a controll scheme into your script.


> and i have to quit using Ctrl+c.
>
> Question:
> How can i get the whole server response, that is a multi-lined
> response, and to get the script not to hang??
>
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
>
>
>



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




Re: strict and warnings

2005-01-13 Thread Chris Devers
On Thu, 13 Jan 2005, Randy W. Sims wrote:

> But, I don't really worry about it. I've never used anything like that 
> in my code. If there are speed problems, there are usually better 
> candidates for optimization. I have never had to remove, or even think 
> about removing, either pragma for speed considerations.
 
There's a reason that optimization is called the root of all evil.

If your code is running so slowly that you're seriously considering 
removing strictures & warnings for the negligible speed boost that doing 
so may bring, you *really* need to reconsider your approach to whatever 
the problem at hand may be.

There is *always* a better and safer place to go optimizing.

Yes, warnings can be annoying for backwards-compatible modules, but I 
think that counts as an esoteric justification for what is otherwise a 
bad habit. For the bulk of code that has no constraints on 5 or 10 year 
old versions of Perl, that shouldn't be a problem.

 

-- 
Chris Devers

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




Re: strict and warnings

2005-01-13 Thread Randy W. Sims
JupiterHost.Net wrote:

Chris Devers wrote:
On Thu, 13 Jan 2005, Dave Kettmann wrote:

[...] Some of the time I see them say that the [strict / warnings] 
pragmas are good for developing programs/scripts. The way it is 
worded some times it seems as if after the program is written and in 
'production' to take these lines out of the code. Do they slow down 
how perl processes the programs? Does it hurt to leave them in?

No, leave them in, always. 

Yep!
There should be little if any noticable speed difference.

Also 100% correct:
I did a  benchmark of
 use strict;
 use warnings;
 print 1;
vs.
 print 1;
Benchmark: timing 1000 iterations of no pragma, w/ pragma...
 no pragma: 4.9282 wallclock secs ( 4.79 usr +  0.01 sys =  4.80 CPU) @ 
208.33/s (n=1000)
 w/ pragma: 4.97848 wallclock secs ( 4.95 usr + -0.01 sys =  4.94 CPU) @ 
2024291.50/s (n=1000)
   Rate w/ pragma no pragma
w/ pragma 2024291/s--   -3%
no pragma 208/s3%--

So it costs 3% more every ten million times it runs, the benefits of 
leaving it in are much more valuabel than 3%/1000 :)
Actually, what happens is that importing those pragma cause flags to be 
set (eg $^H, see `perldoc perlvar`). Perl checks these flags during 
certain operations. If the flags are set then perl will do extra 
checking in the case of strict.pm and also emit warnings in the case of 
warnings.pm, so your benchmark doesn't really measure the cost. You'd 
have to benchmark on a project by project basis.

Not that I'm trying persuade anyone against using them. As I said, I 
pretty much always use them. Any needed optimizations can usually be 
found elsewhere.

Randy.

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



Re: encoding script

2005-01-13 Thread Chris Devers
On Thu, 13 Jan 2005, JupiterHost.Net wrote:

> > > perl -mstrict -we 'for(`ls`) { chomp;print `grep foo $_`; }'
> >   By which you're basically saying the following non-Perl statement::
> 
> 
> Right we already covered that a day or so ago, the shell is not the 
> way to go:

Oh?

I love Perl, but it isn't the right tool for every problem.

In this case, I think the OP just wanted, in a convoluted way, this:

$ some_program *

I see no way in which Perl can make this simpler. :-)
 
 

-- 
Chris Devers

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




Re: strict and warnings

2005-01-13 Thread JupiterHost.Net

Chris Devers wrote:
On Thu, 13 Jan 2005, Dave Kettmann wrote:

[...] Some of the time I see them say that the [strict / warnings] 
pragmas are good for developing programs/scripts. The way it is worded 
some times it seems as if after the program is written and in 
'production' to take these lines out of the code. Do they slow down 
how perl processes the programs? Does it hurt to leave them in?

No, leave them in, always. 
Yep!
There should be little if any noticable speed difference.
Also 100% correct:
I did a  benchmark of
 use strict;
 use warnings;
 print 1;
vs.
 print 1;
Benchmark: timing 1000 iterations of no pragma, w/ pragma...
 no pragma: 4.9282 wallclock secs ( 4.79 usr +  0.01 sys =  4.80 CPU) @ 
208.33/s (n=1000)
 w/ pragma: 4.97848 wallclock secs ( 4.95 usr + -0.01 sys =  4.94 CPU) 
@ 2024291.50/s (n=1000)
   Rate w/ pragma no pragma
w/ pragma 2024291/s--   -3%
no pragma 208/s3%--

So it costs 3% more every ten million times it runs, the benefits of 
leaving it in are much more valuabel than 3%/1000 :)

It may be differnt on your perl/OS/etc but that should give everyone a 
general idea, and if not then feel free to benchmark it on your OS/Perl...

They're a safety net for developing new code, and they're a safety net 
for protecting against future breakage. The latter becomes especially 
important as time goes on, where if you're the one mainting the program 
you no longer remember how it works, or (more typically) someone else is 
maintaining it and they have to figure out what your intentions were. 
Agreed!
If I'm given code to work with I feel much better if it already ahs 
strict and warnings, at least I know they put some effort into writing 
it and it makes my mind rest assured ;p

Having the discipline that strict & warnings enforces ensures that the 
code should be that much more maintainable in the long term.

So, leave them in. Always.
Couldn't have said it better myself Chris!
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: strict and warnings

2005-01-13 Thread Chris Devers
On Thu, 13 Jan 2005, Dave Kettmann wrote:

> [...] Some of the time I see them say that the [strict / warnings] 
> pragmas are good for developing programs/scripts. The way it is worded 
> some times it seems as if after the program is written and in 
> 'production' to take these lines out of the code. Do they slow down 
> how perl processes the programs? Does it hurt to leave them in?

No, leave them in, always. 

There should be little if any noticable speed difference.

They're a safety net for developing new code, and they're a safety net 
for protecting against future breakage. The latter becomes especially 
important as time goes on, where if you're the one mainting the program 
you no longer remember how it works, or (more typically) someone else is 
maintaining it and they have to figure out what your intentions were. 

Having the discipline that strict & warnings enforces ensures that the 
code should be that much more maintainable in the long term.

So, leave them in. Always.
 

-- 
Chris Devers

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




Re: checking for errors

2005-01-13 Thread John W. Krahn
John W. Krahn wrote:
Tim Wolak wrote:
I have a script that is checking a service to see if its running and 
that its log file does not contain two error message to confirm that 
it has not died. However the subrutine is just saying its up when I 
have put the error message in the last line of the log to make sure it 
sees that its down.  Please have a look at the code snipit and any 
help would be great.

sub grepstring {
  open LOG, "tail gw_20050105.log |", or die "Log file not found $!";
Since you are using a piped open you should also close() the filehandle 
and verify that it closed correctly.

perldoc -f close
perldoc perlopentut
You should probably also use a lexically scoped filehandle.
  while () {
$newlog = ;
You putting the first line into $_ and the second line into $newlog so 
you are only examining the contents of every second line.

if ($newlog =~ /^Read failed on socket/ || /^EFIXException::/) {
Correction, you are examining every odd numbered line for /^EFIXException::/ 
and every even numbered line for /^Read failed on socket/.


exit $exit_codes{'CRITICAL'};
print "Log entry can not be found GW down!\n";
} else {
print "GW is UP!\n";
exit $exit_codes{'OK'};
}
} }

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: strict and warnings

2005-01-13 Thread Randy W. Sims
Dave Kettmann wrote:
Hello all,
I have seen in quite a few posts to the list from the non-beginners, who I think all of us beginners appreciate them taking their time to help us true beginners, make some references to the strict and warnings pragmas. So I have a question about them. Some of the time I see them say that the pragmas are good for developing programs/scripts. The way it is worded some times it seems as if after the program is written and in 'production' to take these lines out of the code. Do they slow down how perl processes the programs? Does it hurt to leave them in? 

Just a question from a beginner who is trying to progress along the wonderful road of Perl :)
In just about all the code I write, I use strict & warnings (in every 
package). The exeception is in Module::Build and some of its ancillary 
modules where we don't use warnings because we try to remain backwards 
compatable to at least 5.005 and warnings only appeared in 5.006.

However, there is some baggage in using warnings, and some people do 
remove it from production code. If you're really concerned, I'd suggest 
benchmarking. If after benchmarking you notice a significant change, you 
can try something like:

use if $ENV{UNDER_CONSTRUCTION}, strict;
use if $ENV{UNDER_CONSTRUCTION}, warnings;
or even:
BEGIN {
if ( $ENV{UNDER_CONSTRUCTION} ) {
for my $m ( qw( strict warnings ) ) {
require "$m.pm"; $m->import;
}
}
}
But, I don't really worry about it. I've never used anything like that 
in my code. If there are speed problems, there are usually better 
candidates for optimization. I have never had to remove, or even think 
about removing, either pragma for speed considerations.

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



Re: checking for errors

2005-01-13 Thread John W. Krahn
Tim Wolak wrote:
Hello all,
Hello,
I have a script that is checking a service to see if its running and 
that its log file does not contain two error message to confirm that it 
has not died. However the subrutine is just saying its up when I have 
put the error message in the last line of the log to make sure it sees 
that its down.  Please have a look at the code snipit and any help would 
be great.

sub grepstring {
  open LOG, "tail gw_20050105.log |", or die "Log file not found $!";
Since you are using a piped open you should also close() the filehandle and 
verify that it closed correctly.

perldoc -f close
perldoc perlopentut
You should probably also use a lexically scoped filehandle.

  while () {
$newlog = ;
You putting the first line into $_ and the second line into $newlog so you are 
only examining the contents of every second line.


if ($newlog =~ /^Read failed on socket/ || /^EFIXException::/) {
exit $exit_codes{'CRITICAL'};
print "Log entry can not be found GW down!\n";
} else {
print "GW is UP!\n";
exit $exit_codes{'OK'};
}
} }

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: strict and warnings

2005-01-13 Thread John W. Krahn
Dave Kettmann wrote:
Hello all,
Hello,
I have seen in quite a few posts to the list from the non-beginners,
who I think all of us beginners appreciate them taking their time to
help us true beginners, make some references to the strict and
warnings pragmas. So I have a question about them. Some of the time
I see them say that the pragmas are good for developing
programs/scripts. The way it is worded some times it seems as if
after the program is written and in 'production' to take these lines
out of the code. Do they slow down how perl processes the programs?
Does it hurt to leave them in? 
In general, pragmas only affect the compilation of your program with the 
exception of some warnings that happen during execution so there should be no 
slowdown.  With that in mind, you could use the Benchmark module to verify the 
effects one way or the other.  :-)

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: strict and warnings

2005-01-13 Thread JupiterHost.Net

Dave Kettmann wrote:
Hello all,
hello,
I have seen in quite a few posts to the list from the non-beginners, who I think all of us beginners appreciate them taking their time to help us true beginners, make some references to the strict and warnings pragmas. So I have a question about them. Some of the time I see them say that the pragmas are good for developing programs/scripts. The way it is worded some times it seems as if after the program is written and in 'production' to take these lines out of the code. Do they slow down how perl processes the programs? Does it hurt to leave them in? 
During development 100% for sure, after it's done 99% (because when is 
soemthing ever really done ?)

I'd say, leave them in, because what if you want to modify it in a year 
and do something wrong. Then you (or your successor)  might forget 
strict and warnings and beat the brains out trying to find the problem 
when strict/warnings woudl've prevented that. Or what if they add a 
variabel that's wacky out of scope? It could kill your entire script, 
delete your databse etc. unless perl tels you about it first :)

As for speed/over head, thats a good question, maybe I'll benchmark it 
if I get time :)

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



Re: Image Creation: labels

2005-01-13 Thread Daniel Kasak
Randy W. Sims wrote:

Too mailing-specific
or use some of the PostScript::* modules to roll your own.
Now *THAT* is what I was after.
Postscript::Simple seems to do everything I want, and *very* easily.
Thanks :)
--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: [EMAIL PROTECTED]
website: http://www.nusconsulting.com.au
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 


Re: Image Creation: labels

2005-01-13 Thread Daniel Kasak
zentara wrote:
On Thu, 13 Jan 2005 14:20:34 +1100, [EMAIL PROTECTED] (Daniel
Kasak) wrote:
 

I'm hunting for a method of creating labels under Linux.
I've already looked at everything on freshmeat.net that came up when I 
searched for 'labels'. None of them cut it.

Requirements:
- Coloured, rotated ( 90 degrees ) text rendering
- Coloured rectangle rendering
That's it. You'd think one of the existing labelling packages would 
accomodate me so far, right? Nope.

Background:
We have a filing system where each file has a label, which is made up of 
( mainly ) coloured numbers ( ie each number gets a different colour 
*background* ). This last bit ... the coloured background ... is what's 
stopping me from using any of the existing labelling packages.

So now that I've decided that there isn't anything out there that does 
what I want, I'm going to have to write something. What should I use?

I've had a brief look at PDF::API2, but I can't even figure out if it 
does what I want - the documentation is a little nonexistant.
So should I use GD?
   

I can see a way with Tk and the Tk::Canvas, but it would probably take
some work aligning the pages for printout.
My idea would be to create a canvas of the proper page size, and create
properly aligned rectangles on it for each label. 

In those rectangles you can create other smaller rectangles and give
them fill colors as needed by your number system, then lay numbers on
top, with another color for the numbered text.  You can also choose your
fonts, and you can be clever in positioning your letters to give the
effect of rotated text.
The canvas can then be exported to postscript, or a jpg with
the WinPhoto module.
For a super simple example:
#!/usr/bin/perl
use Tk;
use strict;
my $w=20;
my $x=0;
my $y=0;
my %nums = (
  0 => ['black','yellow'],
  1 => ['yellow','black'],
  2 => ['white','green'],
  3 => ['green','white'],
  4 => ['grey','red'],
  5 => ['red','grey'],
  6 => ['blue','white'],
  7 => ['white','blue'],
  8 => ['orange','grey45'],
  9 => ['grey45','orange'],
);
my $mw=tkinit;
my $c = $mw->Canvas->pack;
for (0..9) {
my $item=$c->createRectangle($x,$y,$x+20,$y+20,
-fill=> ${$nums{$_}}[0],
 );
my $text = $c->createText($x+10,$y+10,
  -anchor=>'center',
  -fill => ${$nums{$_}}[1],
  -text => $_
 );
 $x+=20;
}
$mw->Button(
   -text=> "Save",
   -command => [sub {
$c->update;
my @capture=();
my ($x0,$y0,$x1,$y1)=$c->bbox('all');
@capture=('-x'=>$x0,'-y'=>$y0,-height=>$y1-$y0,-width=>$x1-$x0);
$c -> postscript(-colormode=>'color',
  -file=>$0.'.ps',
  -rotate=>0,
  -width=>800,
  -height=>500,
  @capture);
 }
 ]  )->pack;
MainLoop;
 

Interesting. I haven't used Tk before ( I'm using Gtk2 ), but that 
doesn't look too hard. I'll look more into it when I get some time.
Thanks :)

--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: [EMAIL PROTECTED]
website: http://www.nusconsulting.com.au
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 


strict and warnings

2005-01-13 Thread Dave Kettmann
Hello all,

I have seen in quite a few posts to the list from the non-beginners, who I 
think all of us beginners appreciate them taking their time to help us true 
beginners, make some references to the strict and warnings pragmas. So I have a 
question about them. Some of the time I see them say that the pragmas are good 
for developing programs/scripts. The way it is worded some times it seems as if 
after the program is written and in 'production' to take these lines out of the 
code. Do they slow down how perl processes the programs? Does it hurt to leave 
them in? 

Just a question from a beginner who is trying to progress along the wonderful 
road of Perl :)

Thanks,

Dave Kettmann
NetLogic
636-561-0680

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




Re: Transforming a space-separated string to an array for words.

2005-01-13 Thread Bryan R Harris

> Robin <[EMAIL PROTECTED]> suggested:
>> This will split up the string based on the pattern (in this
>> case, a single space. You may want to change that to gain
>> robustness, e.g. /[ \t]+/ will split on any number of spaces and tabs)
> 
> I suggest /\s+/ instead. This splits on any whitespace,
> and it'll also remove trailing whitespace like those
> pesky trailing \n:


And further, use split(' ',$numbers), which is a special case that splits on
all whitespace, ignoring initial whitespace.  Just a bare "split" does that
by default.

Try this:

perl -e '$_ = "1 2 3 4 5  "; print "method 1:  ", join(",",split /\s+/),
"\n", "method 2: ", join(",",split), "\n";'

- B


RE: Crypt SSLeay

2005-01-13 Thread Tham, Philip
I found the problem. Just as you explained I just ran perl at the
command line and it invoked the perl that was bundled with Solaris. On
repeating the same with /usr/local/bin/perl which I built, it worked.

Thanks for your help.

Philip
-Original Message-
From: Wiggins d Anconia [mailto:[EMAIL PROTECTED] 
Sent: Thursday, January 13, 2005 6:37 AM
To: Tham, Philip; beginners@perl.org
Subject: RE: Crypt SSLeay


Please bottom post

> I faced two problems:
> 
> 1. The build assumes that cc is the default compiler in the system. I 
> have gcc 2. I created a link from gcc to cc to fixed the above. This 
> time it is rejecting some of the compile options like -KPIC and -x03 
> and -xdepend. It seems these options are supported by gcc. How can I 
> get a makefile which is gcc compatible.
> 
> Philip

To my knowledge you must use the same C compiler to build module source
files as the actual Perl itself. I don't believe creating a link is
sufficient, as you are seeing the compile time options are different for
various C compilers, and I believe the objects will not be compatible
with the perl interpreter. I would suggest installing the same C
compiler or rebuilding a gcc version of Perl.

http://danconia.org

> 
> -Original Message-
> From: Wiggins d Anconia [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, January 12, 2005 1:00 PM
> To: Tham, Philip; beginners@perl.org
> Subject: Re: Crypt SSLeay
> 
> 
> 
> 
> > I did a build on the latest version of perl. However the library
> > Crypt::SSLeay is not present. Any idea how do I build this library?
It
> 
> > is required for https requests.
> > 
> > Philip
> > 
> 
> The documentation for the module includes installation tips,
> 
> http://search.cpan.org/~chamas/Crypt-SSLeay-0.51/SSLeay.pm
> 
> Easiest way would be to use CPAN for me.
> 
> perl -MCPAN -e shell
> cpan> install Crypt::SSLeay
> 
> http://danconia.org
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
> 
> 
> 



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



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




upload files using MySQL database

2005-01-13 Thread Maxipoint Rep Office
how upload files with Perl using MySQL database?
i wish that file be uploaded to the one folder on the server and the path og
image must be added into MySQL database column..


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




Re: checking for errors

2005-01-13 Thread Ing. Branislav Gerzo
Tim Wolak [TW], on Thursday, January 13, 2005 at 09:15 (-0600) wrote
about:

TW>  if ($newlog =~ /^Read failed on socket/ || /^EFIXException::/) {

for me it seems, this line is bad, when you rewrite it to:

if ($newlog =~ /^(Read failed on socket|EFIXException::)/) {

it works ?

-- 

 ...m8s, cu l8r, Brano.

["The sun is in the east even though the day is done" -Pink Floyd]



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




Re: checking for errors

2005-01-13 Thread JupiterHost.Net

Tim Wolak wrote:
Hello all,
I have a script that is checking a service to see if its running and 
that its log file does not contain two error message to confirm that it 
has not died. However the subrutine is just saying its up when I have 
put the error message in the last line of the log to make sure it sees 
that its down.  Please have a look at the code snipit and any help would 
be great.
use strict;
use warnings;
always always always!
Thanks,
Tim
sub grepstring {
  open LOG, "tail gw_20050105.log |", or die "Log file not found $!";
It wasn't found? are you sure, what if it found but the permisions won't 
allow it to be read, what if it was locked? Let $! tell you the exact 
reason :)

Why are you piping tail's output to LOG?
Why not
 open LOG, 'gw_20050105.log' or die "open qw_200050105 failed: $!";
  while () {
$newlog = ;
my $newlog would be better so its in scope, just using $_ would be even 
better :)

if ($newlog =~ /^Read failed on socket/ || /^EFIXException::/) {
exit $exit_codes{'CRITICAL'};
print "Log entry can not be found GW down!\n";
This will never get printed because its already exited

} else {
print "GW is UP!\n";
exit $exit_codes{'OK'};
}
} }
   
How about this:
 open LOG, 'gw_20050105.log' or die "open qw_200050105 failed: $!";
 while() {
 if(/^Read failed on socket/ || /^EFIXException::/) {
 print "Log entry can not be found GW down!\n";
 exit $exit_codes{CRITICAL};
 } else {
 print "GW is UP!\n";
 exit $exit_codes{OK};
 }
 }
 close LOG;
HTH :)
Lee.M - JupiterHost.Net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



checking for errors

2005-01-13 Thread Tim Wolak
Hello all,
I have a script that is checking a service to see if its running and 
that its log file does not contain two error message to confirm that it 
has not died. However the subrutine is just saying its up when I have 
put the error message in the last line of the log to make sure it sees 
that its down.  Please have a look at the code snipit and any help would 
be great.

Thanks,
Tim
sub grepstring {
  open LOG, "tail gw_20050105.log |", or die "Log file not found $!";
  while () {
$newlog = ;
if ($newlog =~ /^Read failed on socket/ || /^EFIXException::/) {
exit $exit_codes{'CRITICAL'};
print "Log entry can not be found GW down!\n";
} else {
print "GW is UP!\n";
exit $exit_codes{'OK'};
}
  
  } 
}


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



Re: Any call-response subscription packages available ?

2005-01-13 Thread Wiggins d Anconia
> WebDragon wrote:
> > I'm curious to know if there are any generic call-response subscribe 
> > packages out there written in Perl (preferably object oriented in
design)
> > 
> > i.e. what I am looking for is,
> > {
> > o  user subscribes via form on website, gives e-mail address and 
> > creates a password
> > 
> > o  user is sent a 'call' e-mail saying "you've just been
subscribed. 
> > did you want this? if so, click this URL"
> > 
> > o  clicking the URL 'response' finishes the subscription process, 
> > and users data is then sent onward. user recieves a confirmation
message 
> > as a result of their webclick both in the webpage itself and via
e-mail, 
> > thanking them for joining.
> > 
> > o  eventually something is done to clean up the data for which
there 
> > was no further 'response'.
> > }
> > 
> > I would like to have such a feature as part of a package I'm writing
for 
> > this client, rather than just blindly accept the data and their choice 
> > of e-mail. That and I really hate to have to re-invent the wheel if 
> > something suitable is already available for use that has worked around 
> > some of the obvious problems involved with this issue.
> > 
> > There are several open source packages out there that implement such 
> > things but it is rarely something semi-separate from the package itself 
> > that can be easily extracted, genericised, and put to use elsewhere. I 
> > would prefer something that is 'the thing itself' and easily integrated 
> > further into whatever needs it. (rather than spending a few weeks 
> > stripping it out of whatever package I find that does it well enough to 
> > suit my needs, and refactoring it. ack! :)
> > 
> > If anyone has any information leading to such a thing, I would be most 
> > grateful. Surely someone has done this by now?
> 
> never saw a response to this, so I'm reposting once in the hopes that 
> perhaps someone else will see it that has any recommendations.
> 
> -- 
> Scott R. Godin
> Laughing Dragon Services
> www.webdragon.net
> 

I somewhat suspect not. The problem is that having this generic would be
rather difficult to design, for several reasons. How do you store the
data?  Database, flat text, sendmail alias file, xml, or process it some
other way.  How are the pages being generated?  CGI, mod_perl.  Are the
pages templated, what template language to use if so, if not are they
static, do they come in only one language, how many languages does the
site use? Depending on how the pages are generated (see above)
determines a lot about what URLs have to look like.  Then there is the
whole range of session management, how do you link up a subscription
e-mail with the data store? What e-mail server is installed, are the
required mail modules installed?  Then there are the hundreds of other
options available, aka are there separate subscription models, are the
passwords clear or encrypted, is there a tool to retrieve/reset
passwords, etc. All of this contributes to creating a framework that is
daunting, and likely slow and bulky to accomodate so many different
options.  At that point you are better off heading in one of two
directions, using a prebuilt framework for the site itself, or
reinventing the wheel (and I do *NOT* say this lightly).

But I could be wrong...

http://danconia.org

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




Re: Break a loop in Netware's PERL

2005-01-13 Thread Jenda Krynicky
From: "GMane Python" <[EMAIL PROTECTED]>
> 
> do
> {
>my $MySocket=new IO::Socket::INET->new(Proto=>"udp",
>PeerPort=>43278,
>PeerAddr=>'10.151.24.174'
>  ) or die "Can't make UDP socket: $@";
>$msg="PyHB";
> 
>print "Sending Heartbeat.";
>$MySocket->send($msg);
>sleep (5);
> }
> while (1==1);
> 

Sorry, can't help with the problem, just commenting on the syntax ...

I believe most people would find your code easier to read if it was 
written like this:

while (1) {
   my $MySocket=new IO::Socket::INET->new(Proto=>"udp",
   PeerPort=>43278,
   PeerAddr=>'10.151.24.174'
 ) or die "Can't make UDP socket: $@";
   $msg="PyHB";

   print "Sending Heartbeat.";
   $MySocket->send($msg);
   sleep (5);
}


the 
do
{
...
} while (something);
looks a bit scary to me. (Looks like the do...loop statement in 
Basic.) It's good if you do need to execute the loop contents before 
evaluating the condition for the first time, but in this case the 
condition is always true so there's no point.

I actually had to consult perldoc perlsyn, I did not remember "while" 
as a statement modifier works differently if the statement it 
modifies is do{} and if it's not so I thought the do{}while() would 
not work as expected.

Compare
$x = 5;
do {print "ahoj $x\n"} while ($x--);
and
$x = 5;
print "ahoj $x\n" while ($x--);

I find this a bit confusing.

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]
 




Re: Any call-response subscription packages available ?

2005-01-13 Thread Jenda Krynicky
From: "Scott R. Godin" <[EMAIL PROTECTED]>
> WebDragon wrote:
> > I'm curious to know if there are any generic call-response subscribe
> > packages out there written in Perl (preferably object oriented in
> > design)
> > 
> > i.e. what I am looking for is,
> > {
> > o  user subscribes via form on website, gives e-mail address and
> > 
> > creates a password
> > 
> > o  user is sent a 'call' e-mail saying "you've just been
> > subscribed. 
> > did you want this? if so, click this URL"
> > 
> > o  clicking the URL 'response' finishes the subscription
> > process, 
> > and users data is then sent onward. user recieves a confirmation
> > message as a result of their webclick both in the webpage itself and
> > via e-mail, thanking them for joining.
> > 
> > o  eventually something is done to clean up the data for which
> > there 
> > was no further 'response'.

I don't think you'll find something. Even though this is a common 
enough task I don't think it warants a module. It's not hard to do 
and it needs to be tightly integrated with the rest of your website.

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]
 




Re: Precedence confusion

2005-01-13 Thread Jan Eden
Hi John,

John W. Krahn wrote on 13.01.2005:

>Jan Eden wrote:

>>It also does not show up if I enclose the ternary operator in
>>brackets:
>>
>>my $server = shift || ($string =~ /(foo|bar)/ ? $1 : 'default');
>>
>>While this solves my problem, I still do not get the reason for it.
>>Could someone shed a light on this precedence confusion?
>
>If we remove some parentheses:
>
>my $server = ( shift || ( $string =~ /(foo|bar)/ ) ) ? $1 :
>'default';
>
Aha! Now I get it.
>
>Or you could just read perlop:
>
I did. But I was confused, that's why I posted here.

Thanks for clearing things up,

Jan
-- 
There are two major products that come out of Berkeley: LSD and UNIX. We don't 
believe this to be a coincidence. - Jeremy S. Anderson

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




RE: Crypt SSLeay

2005-01-13 Thread Wiggins d Anconia
Please bottom post

> I faced two problems:
> 
> 1. The build assumes that cc is the default compiler in the system. I
> have gcc
> 2. I created a link from gcc to cc to fixed the above. This time it is
> rejecting some of the compile options like -KPIC and -x03 and -xdepend.
> It seems these options are supported by gcc. How can I get a makefile
> which is gcc compatible.
> 
> Philip

To my knowledge you must use the same C compiler to build module source
files as the actual Perl itself. I don't believe creating a link is
sufficient, as you are seeing the compile time options are different for
various C compilers, and I believe the objects will not be compatible
with the perl interpreter. I would suggest installing the same C
compiler or rebuilding a gcc version of Perl.

http://danconia.org

> 
> -Original Message-
> From: Wiggins d Anconia [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, January 12, 2005 1:00 PM
> To: Tham, Philip; beginners@perl.org
> Subject: Re: Crypt SSLeay
> 
> 
> 
> 
> > I did a build on the latest version of perl. However the library 
> > Crypt::SSLeay is not present. Any idea how do I build this library? It
> 
> > is required for https requests.
> > 
> > Philip
> > 
> 
> The documentation for the module includes installation tips, 
> 
> http://search.cpan.org/~chamas/Crypt-SSLeay-0.51/SSLeay.pm
> 
> Easiest way would be to use CPAN for me.
> 
> perl -MCPAN -e shell
> cpan> install Crypt::SSLeay
> 
> http://danconia.org
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
> 
> 
> 



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




Re: Any call-response subscription packages available ?

2005-01-13 Thread Scott R. Godin
WebDragon wrote:
I'm curious to know if there are any generic call-response subscribe 
packages out there written in Perl (preferably object oriented in design)

i.e. what I am looking for is,
{
o  user subscribes via form on website, gives e-mail address and 
creates a password

o  user is sent a 'call' e-mail saying "you've just been subscribed. 
did you want this? if so, click this URL"

o  clicking the URL 'response' finishes the subscription process, 
and users data is then sent onward. user recieves a confirmation message 
as a result of their webclick both in the webpage itself and via e-mail, 
thanking them for joining.

o  eventually something is done to clean up the data for which there 
was no further 'response'.
}

I would like to have such a feature as part of a package I'm writing for 
this client, rather than just blindly accept the data and their choice 
of e-mail. That and I really hate to have to re-invent the wheel if 
something suitable is already available for use that has worked around 
some of the obvious problems involved with this issue.

There are several open source packages out there that implement such 
things but it is rarely something semi-separate from the package itself 
that can be easily extracted, genericised, and put to use elsewhere. I 
would prefer something that is 'the thing itself' and easily integrated 
further into whatever needs it. (rather than spending a few weeks 
stripping it out of whatever package I find that does it well enough to 
suit my needs, and refactoring it. ack! :)

If anyone has any information leading to such a thing, I would be most 
grateful. Surely someone has done this by now?
never saw a response to this, so I'm reposting once in the hopes that 
perhaps someone else will see it that has any recommendations.

--
Scott R. Godin
Laughing Dragon Services
www.webdragon.net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: A Beginner's problem

2005-01-13 Thread John W. Krahn
Doug Essinger-Hileman wrote:
I am just learning Perl, and am having a problem with something which 
seems like it should be so easy. Still . . . . I have read through a 
couple of books, including _Beginning Perl_ and _Picking Up Perl_, to 
no avail.

I am trying to read a file, then assign some information within a 
script. The problem comes in assigning. My file has three lines. The 
first line contains a list of names seperated by spaces; the next two 
lines contain numbers:

Doug Sandy Lois
0
1
In order to isolate the problem, I have created a simplified script:
You should really use the warnings and strict pragmas while developing your 
program to let perl help you find mistakes.

use warnings;
use strict;

#read from file
open (CONTROL1, "You should *ALWAYS* verify that the file opened correctly.
open CONTROL1, '<', 'test.cont' or die "Cannot open 'test.cont' $!";

@constants = ;
close (CONTROL1);
#parse
$names = @constants[0];
If you had had warnings enabled then perl would have complained about that.

@group = qw($names);
perldoc perlop
[snip]
   qw/STRING/
   Evaluates to a list of the words extracted out of STRING, using
   embedded whitespace as the word delimiters.  It can be
   understood as being roughly equivalent to:
   split(' ', q/STRING/);
   the differences being that it generates a real list at compile
   time, and in scalar context it returns the last element in the
   list.  So this expression:
   qw(foo bar baz)
   is semantically equivalent to the list:
   'foo', 'bar', 'baz'

#print
open (CONTROL2, ">test2.cont");
You should *ALWAYS* verify that the file opened correctly.
open CONTROL2, '>', 'test2.cont' or die "Cannot open 'test2.cont' $!";

print CONTROL2 "Names: $names";
print CONTROL2 "Group: @group";
close (CONTROL2);
The test2.cont file shows that $names is being set as I expected: to 
a string (Doug Sandy Lois). I assumed that @group = qw($names) would 
fill the array with the string of names. However, test2.cont shows 
that the value of @group is "$names". Obviously, my assumption was 
wrong.

So is there a way to directly fill the @group array with the string 
now stored in $names? Or do I have to split the string and fill the 
array in that manner?
You will have to split the string like:
my @group = split ' ', $names;

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: encoding script

2005-01-13 Thread JupiterHost.Net
perl -mstrict -we 'for(`ls`) { chomp;print `grep foo $_`; }'
  
By which you're basically saying the following non-Perl statement::

Right we already covered that a day or so ago, the shell is not the way 
to go:

 perl -mstrict -MFile::Slurp -we 'for(read_dir(".")) { print "Process 
$_ here\n"; }

All perl, answers the OP's question :)
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: A Beginner's problem

2005-01-13 Thread JupiterHost.Net

Doug Essinger-Hileman wrote:
I am just learning Perl, and am having a problem with something which 
seems like it should be so easy. Still . . . . I have read through a 
couple of books, including _Beginning Perl_ and _Picking Up Perl_, to 
no avail.

I am trying to read a file, then assign some information within a 
script. The problem comes in assigning. My file has three lines. The 
first line contains a list of names seperated by spaces; the next two 
lines contain numbers:

Doug Sandy Lois
0
1
In order to isolate the problem, I have created a simplified script:
# always always always do these, they will tell you about errors for you :)
use strict;
use warnings;

#read from file
open (CONTROL1, "always always test to see if it opened or not: (and don't use double 
quotes when nothgin is beinf interpolated so Perl doesn't have to check 
it to see if somethign needs interpolated)

 open CONTROL1, '
@constants = ;
my @constants = ;
close (CONTROL1);
You don;t need parens necessarily here:
close CONTROL1;
easier to read IMHO
#parse
$names = @constants[0];
my $names = $constants[0];
IE $ instead of @, strict and warnings would've told you about that I 
imagine

@group = qw($names);
you;'re adding the literl string $names to @group
my @group = ($names);
or do you mean:
 my @group = split /\s+/, $names;
#print
open (CONTROL2, ">test2.cont");
open CONTROL2, '>test2.cont' or die "Could not open test2.cont: $!";
print CONTROL2 "Names: $names";
print CONTROL2 "Group: @group";
print CONTROL2 "Group: $_\n" for @group;
close (CONTROL2);
close CONTROL2;
HTH :)
Lee.M - JupiterHost.Net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Break a loop in Netware's PERL

2005-01-13 Thread GMane Python
But I;ve already got a sleep 5 in there.  See?

use IO::Socket::INET;
#use Time::HiRes qw( time alarm sleep );

do
{
   my $MySocket=new IO::Socket::INET->new(Proto=>"udp",
   PeerPort=>43278,
   PeerAddr=>'10.151.24.174'
 ) or die "Can't make UDP socket: $@";
   $msg="PyHB";

   print "Sending Heartbeat.";
   $MySocket->send($msg);
   sleep (5);
}
while (1==1);

-Dave
"Chris Devers" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> On Wed, 12 Jan 2005, John W. Krahn wrote:
>
> > GMane Python wrote:
> >
> > > I'm absolutely new to PERL -- actually, I'm using it for exactly 1
> > > project I'm mostly through.  On Netware's v5.8 of PERL, I have
> > > basically a loop, a while 1==1 {  }.  On Netware, I can't
> > > break out of this with CTRL-C. CTRL-D, etc.  I'd like to put a check
> > > inside the loop to see if 'break' key was pressed.  Can someone
> > > please tell me how to do this?
> >
> > Novell has a news group at:
> > news://developer-forums.novell.com/novell.devsup.perl that may be able
> > to answer your question.  (I haven't used Netware in a looong time.)
>
> Maybe it's looping too fast for the ctrl+C to get through. Does it work
> better if you change it to something like this?
>
>while (1 == 1) { stuff(); sleep 1 }
>
> That should at least give you a window of opportunity...
>
>
>
> -- 
> Chris Devers
>
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
>
>
>




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




RE: A Beginner's problem

2005-01-13 Thread Bob Showalter
Doug Essinger-Hileman wrote:
> I am just learning Perl, and am having a problem with something which
> seems like it should be so easy. Still . . . . I have read through a
> couple of books, including _Beginning Perl_ and _Picking Up Perl_, to
> no avail.

Welcome!

> 
> I am trying to read a file, then assign some information within a
> script. The problem comes in assigning. My file has three lines. The
> first line contains a list of names seperated by spaces; the next two
> lines contain numbers:
> 
> Doug Sandy Lois
> 0
> 1
> 
> In order to isolate the problem, I have created a simplified script:
> 
> #read from file
> 
> open (CONTROL1, " @constants = ;
> close (CONTROL1);
> 
> #parse
> 
> $names = @constants[0];
> @group = qw($names);
> 
> #print
> 
> open (CONTROL2, ">test2.cont");
> print CONTROL2 "Names: $names";
> print CONTROL2 "Group: @group";
> close (CONTROL2);
> 
> The test2.cont file shows that $names is being set as I expected: to
> a string (Doug Sandy Lois). I assumed that @group = qw($names) would
> fill the array with the string of names. However, test2.cont shows
> that the value of @group is "$names". Obviously, my assumption was
> wrong.
> 
> So is there a way to directly fill the @group array with the string
> now stored in $names? Or do I have to split the string and fill the
> array in that manner?

qw() means "quote words". It's a shortcut for specifying a list of
LITERAL strings without having to use quotes and commas.

What you want is:

   @group = split ' ', $names;

qw() is documented in perldoc perlop. For the documentation on split(),
see perldoc -f split

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




Re: Precedence confusion

2005-01-13 Thread John W. Krahn
Jan Eden wrote:
Hi,
Hello,
I wrote the following:
#!/usr/bin/perl -wT
use strict;
my ($server) = sitemode("test");
print $server;
sub sitemode {
my $string = "foonky";
my $server = shift || $string =~ /(foo|bar)/ ? $1 : 'default';
return $server;
}
Now this throws an error. The error does not occur when I call the
subroutine without an argument:
It is actually a warning, not an error.  An error would exit the program 
without running it.


sitemode();
It also does not show up if I enclose the ternary operator in brackets:
my $server = shift || ($string =~ /(foo|bar)/ ? $1 : 'default');
While this solves my problem, I still do not get the reason for it.
Could someone shed a light on this precedence confusion?
You can ask perl to do it for you:
$ perl -MO=Deparse,-p -e'sub sitemode { my $server = shift || $string =~ 
/(foo|bar)/ ? $1 : "default"; }'
sub sitemode {
(my $server = ((shift(@_) || ($string =~ /(foo|bar)/)) ? $1 : 'default'));
}
-e syntax OK

If we remove some parentheses:
my $server = ( shift || ( $string =~ /(foo|bar)/ ) ) ? $1 : 'default';
Or you could just read perlop:
perldoc perlop
[snip]
   left=~ !~
   left* / % x
   left+ - .
   left<< >>
   nonassocnamed unary operators
   nonassoc< > <= >= lt gt le ge
   nonassoc== != <=> eq ne cmp
   left&
   left| ^
   left&&
   left||
   nonassoc..  ...
   right   ?:
   right   = += -= *= etc.
Where you can see that =~ has higher precedence than || which has higher 
precedence than ?: which has higher precedence than =.


John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



A Beginner's problem

2005-01-13 Thread Doug Essinger-Hileman
I am just learning Perl, and am having a problem with something which 
seems like it should be so easy. Still . . . . I have read through a 
couple of books, including _Beginning Perl_ and _Picking Up Perl_, to 
no avail.

I am trying to read a file, then assign some information within a 
script. The problem comes in assigning. My file has three lines. The 
first line contains a list of names seperated by spaces; the next two 
lines contain numbers:

Doug Sandy Lois
0
1

In order to isolate the problem, I have created a simplified script:

#read from file

open (CONTROL1, ";
close (CONTROL1);

#parse

$names = @constants[0];
@group = qw($names);

#print

open (CONTROL2, ">test2.cont");
print CONTROL2 "Names: $names";
print CONTROL2 "Group: @group";
close (CONTROL2);

The test2.cont file shows that $names is being set as I expected: to 
a string (Doug Sandy Lois). I assumed that @group = qw($names) would 
fill the array with the string of names. However, test2.cont shows 
that the value of @group is "$names". Obviously, my assumption was 
wrong.

So is there a way to directly fill the @group array with the string 
now stored in $names? Or do I have to split the string and fill the 
array in that manner?

Doug

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




Re: Pattern matching variables

2005-01-13 Thread Tor Hildrum
On Wed, 12 Jan 2005 17:27:46 -0700, Dan Fish <[EMAIL PROTECTED]> wrote:
> Are ALL pattern matching variables set back to undef once another m// or
> s/// expression is encountered, even if it contains no parenthized
> expressions?
> 
> For example, I would have expected $1 & $2 to be valid in BOTH print
> statements below...

   The numbered match variables ($1, $2, $3, etc.) and the related punctu-
   ation set ($+, $&, $`, $', and $^N) are all dynamically scoped until
   the end of the enclosing block or _until the next successful match_,
   whichever comes first. 

Thus:
__Successfull second pattern match__
perl -e '$foo = "hello"; $foo =~ /(l+)/; print "$1\n"; print "ok\n" if
$foo =~ /hello/; print " $1\n"'
ll
ok 

__Unsuccessfull second pattern match__
perl -e '$foo = "hello"; $foo =~ /(l+)/; print "$1\n"; print "nope\n"
unless $foo =~ /helo/; print " $1\n"'
ll
nope 
ll


Tor

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




Re: Pattern matching variables

2005-01-13 Thread John W. Krahn
Dan Fish wrote:
Are ALL pattern matching variables set back to undef once another m// or
s/// expression is encountered, even if it contains no parenthized
expressions?  
perldoc perlre
[snip]
   The numbered match variables ($1, $2, $3, etc.) and the related
   punctuation set ($+, $&, $`, $', and $^N) are all dynamically scoped
   until the end of the enclosing block or until the next successful
   match, whichever comes first.  (See "Compound Statements" in perlsyn.)
   NOTE: failed matches in Perl do not reset the match variables, which
   makes easier to write code that tests for a series of more specific
   cases and remembers the best match.
So in other words, a successful match of any kind will reset the match 
variables.

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Precedence confusion

2005-01-13 Thread Jan Eden
Hi,

I wrote the following:

#!/usr/bin/perl -wT

use strict;

my ($server) = sitemode("test");
print $server;

sub sitemode {
my $string = "foonky";
my $server = shift || $string =~ /(foo|bar)/ ? $1 : 'default';
return $server;
}

Now this throws an error. The error does not occur when I call the subroutine 
without an argument:

sitemode();

It also does not show up if I enclose the ternary operator in brackets:

my $server = shift || ($string =~ /(foo|bar)/ ? $1 : 'default');

While this solves my problem, I still do not get the reason for it. Could 
someone shed a light on this precedence confusion?

Thanks,

Jan
-- 
There are two major products that come out of Berkeley: LSD and UNIX. We don't 
believe this to be a coincidence. - Jeremy S. Anderson

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




RE: Transforming a space-separated string to an array for words.

2005-01-13 Thread Thomas Bätzler
Robin <[EMAIL PROTECTED]> suggested:
> This will split up the string based on the pattern (in this 
> case, a single space. You may want to change that to gain 
> robustness, e.g. /[ \t]+/ will split on any number of spaces and tabs)

I suggest /\s+/ instead. This splits on any whitespace,
and it'll also remove trailing whitespace like those
pesky trailing \n:


#!/usr/bin/perl -w

use strict;

my $string = "foo baz bar\n";

foreach my $word (split/[ \t]+/, $string) {
  print "'$word'\n";
}

foreach my $word ( split/\s+/, $string ) {
  print "'$word'\n";
}


HTH,
Thomas

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




Pattern matching variables

2005-01-13 Thread Dan Fish
Are ALL pattern matching variables set back to undef once another m// or
s/// expression is encountered, even if it contains no parenthized
expressions?  

For example, I would have expected $1 & $2 to be valid in BOTH print
statements below...
 
#!/usr/bin/perl -w
#
$string="ABC DEF GHI JKL MNO PQR STU";

if ($string =~ /(.{7})\s+(.{7})\s+/)
{
   $p1 = $1; 
   $p2 = $2;
   print ("1 = $1, 2 = $2, p1 = $p1, p2 = $p2\n");
   
   $p1 =~ s/\s+//g;
   print ("1 = $1, 2 = $2, p1 = $p1, p2 = $p2\n");
}

Thanks,
-Dan

---
Dan Fish - [EMAIL PROTECTED] 
"A -good- dive buddy will be there if you run out of air, a -great- one will
be there before you run out!"


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




Perl Socket

2005-01-13 Thread Groleo Marius
Hi list!

im try-ing this code, to get a multi line server response:

use Socket;
socket(sock, AF_INET, SOCK_STREAM, getprotobyname('tcp')) || die "error: $!\n";
$dest = sockaddr_in($_[0], inet_aton($_[1]));
connect(sock, $dest) || die "error: $!\n";
select(sock);

while ($response=) {
  print;
}
close (sock) || die "close: $!\n";

The thing is that after it gets the whole response, the script hangs,
and i have to quit using Ctrl+c.

Question:
How can i get the whole server response, that is a multi-lined
response, and to get the script not to hang??

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




Output ordering for hash

2005-01-13 Thread Rohit RS
After parsing an XMl file i get the Data:Dumper output
as

$VAR1 = {
 'xmlns:xsi' =>
http://www.w3.org/2001/XMLSchema-instance',
  'EmployeeTemplate' => {
'Details' => {
 'Age' => [
  ' 26',
  ' 28'
 ],
 'Company' => [
  ' IBM',
  ' Oracle'
 ]
  },
 'Employee' => {
'EMP_NO' => [
' 001',
' 002'
   ],
'EMP_NAME' => [
   ' A',
   ' B'
 ]
   },
 'Workprofile' => {
 'Designation' => [
   ' Systems Analyst',
   ' Software
Engineer'
 ],
 'Experience' => [
' 2',
' 4'
  ]
 }
   }
};


I need to print the output as
001,A,26,IBM,Systems Analyst,2
002,B,28,Oracle,Software Enginner,4

I could access the array values for keys(Experience
etc...) using the code below
=
#!usr/local/bin/perl

# use module
use XML::Simple;
use Data::Dumper;

# create object
$xml = new XML::Simple;

# read XML file
my $data = $xml ->XMLin("myxml.xml");

# print output
print Dumper($data);

foreach $key(keys % {$data}) #This is for Emplyee
etc..
{
#This is at level 'Details ' etc ...
foreach $subkey(keys % {${$data}{$key}}) 
{

foreach $subsubkey(keys %{$
{$data}{$key}{$subkey} })
{
   
@[EMAIL PROTECTED];
# Get length of the array
$len = @array;
if ($len == 0)
{
 print
"${$data}{$key}{$subkey}{$subsubkey}\n";
}
else {

for($i=0;$i<$len;$i++)
{
   print "$array[$i]\n";
}
 }
  
}

}
}
==
This code gives me
 26
 28
 IBM
 Oracle
 001
 002
 A
 B
 Systems Analyst
 Software Engineer
 2
 4



Yahoo! India Matrimony: Find your partner online. 
http://yahoo.shaadi.com/india-matrimony/

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




Re: problem with extracting line

2005-01-13 Thread Randy W. Sims
Anish Kumar K. wrote:
Hi I have text file in which I have the below mentioned lines
This is a test
start-first
First Line testing
end-first
How are you
Finally
start-second
Tested
end-second
I have a perl file which reads the above file and stores in the variable say 
$message
#!/usr/bin/perl
use strict;
open INPUT,"fp.txt" || die "File does not exist";
my $message="";
while()
{
$message=$message.$_;
}
if ($message =~ (/start_first/../end_first/))
{
   print "The line is $1";
}
What I expect is that from the variable, $message I wanted to print out this "First Line testing" as in the text file i have specified the pointers.. In Short I wanted to print the lines in between two words in a file/variable.
Below is an example of how the .. operator works. You can find a good 
description in `perldoc perlop` section "Range Operators"

#!/usr/bin/perl
use strict;
use warnings;
while (defined( my $line =  )) {
if ( $line =~ /start-/ .. $line =~ /end-/ ) {
print "The line is $line";
}
}
__DATA__
This is a test
start-first
First Line testing
end-first
How are you
Finally
start-second
Tested
end-second
# Note that the loop above can and often is abbreviated:
while ( ) {
if ( /start-/ .. /end-/ ) {
print "The line is $_";
}
}
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]