Re: bizarre math

2005-12-03 Thread Bryan Harris


>> I just ran into this today, and have no clue what's going on:
>> 
>> % perl -e 'print 10-5.5, "\n"'
>> 4.5
>> % perl -e 'print 10-05.5, "\n"'
>> 55
>> 
>> How does 10 minus 5.5 equal 55?  Obviously it's the leading zero, but I
>> can't think of any reason why it should do that...
> 
> It seems that 05 is taken as octal (leading zero literals are octal),
> and there not being an 'octal' point supported, '.' is takee as a concat. so :
> 
> decimal 10 - octal 5( which is decimal 5 also ) = 5 conat 5 => 55
> 
> Aloha => Beau;
> [EMAIL PROTECTED]
> 2005-12-03


Wow, thanks, Beau.

That's scary, I never considered that as something that could happen.  I
wonder if I've ever mis-processed data with a leading zero and gotten the
wrong answer...  Yikes.

- Bryan




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




Re: config files

2005-12-03 Thread M. Lewis



Randal L. Schwartz wrote:

"M" == M Lewis <[EMAIL PROTECTED]> writes:



M> do '/absolute/path/to/mcr.conf';

M> Which defeats my purpose of getting the configuration items out of the
M> scripts themselves. I don't want the users to have to edit the three
M> scripts, only the mcr.conf file.

If your configs are relative to the file itself, consider that
__FILE__ is the name of the current file, *when* compiled.  So,
if you have to pull in an additional file that's in the same directory
as your module or script, just add:

BEGIN {
use File::Spec;
my @place = File::Spec->splitpath(__FILE__);
$place[-1] = "config.pl";
require File::Spec->catpath(@place);
}

This guarantees to bring in a file named config.pl in the same directory
as your script (if used from the main program) or the .pm file if used
from the module.

A simpler version is like this:

BEGIN {
  require __FILE__ . "-config.pl";
}

which makes the config file "fred-config.pl" for a program named fred,
or "fred.pm-config.pl" for the fred.pm module.  If your OS can handle
funky names like that, you're golden.



Interesting. Thanks much Randal. I will experiment with this also.

Thanks,
Mike


--

 Don't compare floating point numbers solely for equality.
  00:50:01 up 6 days, 19:40,  5 users,  load average: 0.03, 0.26, 0.31

 Linux Registered User #241685  http://counter.li.org

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




Re: bizarre math

2005-12-03 Thread Beau E. Cox
Hi Bryan Harris -
  
At 2005-12-03, 19:19:02 you wrote:
>
>
>I just ran into this today, and have no clue what's going on:
>
>% perl -e 'print 10-5.5, "\n"'
>4.5
>% perl -e 'print 10-05.5, "\n"'
>55
>
>How does 10 minus 5.5 equal 55?  Obviously it's the leading zero, but I
>can't think of any reason why it should do that...
>
>- B
>

It seems that 05 is taken as octal (leading zero literals are octal),
and there not being an 'octal' point supported, '.' is takee as a concat. so :

decimal 10 - octal 5( which is decimal 5 also ) = 5 conat 5 => 55

Aloha => Beau;
[EMAIL PROTECTED]
2005-12-03



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




bizarre math

2005-12-03 Thread Bryan Harris


I just ran into this today, and have no clue what's going on:

% perl -e 'print 10-5.5, "\n"'
4.5
% perl -e 'print 10-05.5, "\n"'
55

How does 10 minus 5.5 equal 55?  Obviously it's the leading zero, but I
can't think of any reason why it should do that...

- B



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




file::find

2005-12-03 Thread robert
Greetings folks!

how`s doing? ;) ,, i`ve one question for you. I`m trying to count files on 
drive using file::find module with latest activestate perl build. I want to 
achieve same result like running command "dir /S" from the root, e.g f:\dir 
/S. Problem is that my script returns less files like dir command. Could 
somebody help me out from this? In case that i want also to count links as 
files, script returns 0 :( ..
xxx
use File::Find;
my $count = 0;
find sub {
  $count++ if -f and -s and -B and not -l;
}, "f:\\";
print "$count\n";


Thank you in advance for yours creative inputs.
Cheers,
Robert 



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




Re: Moving Folder Access denied

2005-12-03 Thread Mulander
> Just a brief of what is hapening
> i have a file with text like this
>
> aaa.bbb e:\cme\abc.vws
>
> i am splitting this data based on space and want to move the data in 
> e:\cme\abc.vws to e:\cme1\.
>
How many spaces do you have between the filenames ?
If more then one adjust your regex in split:

split /\s+/,$your_line;

Hope it helps,
Mulander

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




installing DBD::mysql

2005-12-03 Thread Octavian Rasnita
Hi,

I have tried to install DBD::mysql under Linux manually and also using cpan,
but the "make test" command gives the error saying that it can't connect to
the server using the socket /var/lib/mysql/mysql.sock.

I know that MySQL is not using that socket but /tmp/mysql.sock, but I don't
know how to let DBD::mysql know that.

I have set the --testuser, --testpassword, --testdb, and even the port and
the host, but it still tries to use /var/lib/mysql/mysql.sock socket.

Now I have changed the socket in my.cnf and I was able to install
DBD::mysql, but isn't possible to specify another socket than that default
one chosen by DBD::mysql?

Thank you.

Teddy


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




Re: Why not to use env (was Re: Perl executable pathname needs to be hardwired?)

2005-12-03 Thread Chris Devers
On Sat, 3 Dec 2005, Randal L. Schwartz wrote:

> > "Chris" == Chris Devers <[EMAIL PROTECTED]> writes:
> 
> Chris> My understanding is that the Python idiom is to avoid putting the full 
> Chris> path, in favor of something like
> 
> Chris> #!/usr/bin/env python
> 
> This won't work if env is not in /usr/bin (like say, /bin/env).

Right. My assumption is that the Python idiom must have arisen from a 
time when the language was new enough that you couldn't depend on it 
being somewhere like /usr/bin, but (apparently) /usr/bin/env was more 
likely to exist and to do the right thing. I guess.
 
> Chris> #!env python
> 
> This won't work if env is not in your current directory!  (odds on
> that, 0% unless you're cd'ed to /usr/bin or /bin, see above.)

Right again. 

I didn't mean to pass this off as "here's what you should do", so much 
as "here's what I'm cargo-culting from what I've seen in Python 
examples". :-)




-- 
Chris Devers

¼5£‡øÜޚÄ
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 


Re: Flushing Buffers (WAS: recursive search)

2005-12-03 Thread John Doe
John W. Krahn am Samstag, 3. Dezember 2005 15.27:
> John Doe wrote:
> > The Ghost am Freitag, 2. Dezember 2005 19.30:
> >> print "$_: ";
> >>my @lines=;
> >
> > and close opened files:
> >
> > close FILE or die "couldn't close $File::Find::name: $!";
> >
> >>print "$#lines\n";
> >>$totalLines+=$#lines; #wanted's value is ignored so we have to
> >>do this here.
> >>return;}
> >>print "$totalLines\n";
>
> You bring up an interesting point about closing the filehandle because
> normally you don't have to worry about that as perl will do the right
> thing. 

Not sure if I understand you correctly: 
Do you suggest *not* to close filehandles, because it's done by perl "doing 
the right thing"?
Or should one decide in every case, if closing should be explicitly done or 
not?

My thought was: When I always close filehandles, I don't have to think about 
closing or not closing them (comparable to give always signs when driving, 
even if nobody else is on the road).

For exemple perldoc -f open states:

   "[...] You don't have to close FILEHANDLE if you are immediately 
going to do another "open" on it [...]"

In a normal case, there is one point at which any filehandle is not reopened: 
After the last reopening. So this case would have to be checked in a loop 
(pseudocode: close FH if finished reopening)?

> However in the example I posted using the $. variable: 
>
> sub wanted {
> ...
> () = ;
> print "$.\n";
> $totalLines += $.;
> }
> print "$totalLines\n";
>
> Produces an incorrect value for $totalLines unless you close the filehandle

I did not see this point.

> but if you don't close the filehandle then you can do this:
>
> sub wanted {
> ...
> () = ;
> }
> print "$.\n";

Sorry if it's just a misunderstanding by me wasting your time!

joe


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




Re: Open source IDE for Perl

2005-12-03 Thread Randal L. Schwartz
> "Andrej" == Andrej Kastrin <[EMAIL PROTECTED]> writes:

Andrej> Dear all,
Andrej> which is yours "best" open source IDE for Perl. I use SciTE under
Andrej> Linux, but I'm a little confused on Windows. Which do you prefer?

GNU Emacs.  Runs fine on Unix, Windows, Darwin, etc.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
 http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

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




Re: config files

2005-12-03 Thread Randal L. Schwartz
> "M" == M Lewis <[EMAIL PROTECTED]> writes:

M> do '/absolute/path/to/mcr.conf';

M> Which defeats my purpose of getting the configuration items out of the
M> scripts themselves. I don't want the users to have to edit the three
M> scripts, only the mcr.conf file.

If your configs are relative to the file itself, consider that
__FILE__ is the name of the current file, *when* compiled.  So,
if you have to pull in an additional file that's in the same directory
as your module or script, just add:

BEGIN {
use File::Spec;
my @place = File::Spec->splitpath(__FILE__);
$place[-1] = "config.pl";
require File::Spec->catpath(@place);
}

This guarantees to bring in a file named config.pl in the same directory
as your script (if used from the main program) or the .pm file if used
from the module.

A simpler version is like this:

BEGIN {
  require __FILE__ . "-config.pl";
}

which makes the config file "fred-config.pl" for a program named fred,
or "fred.pm-config.pl" for the fred.pm module.  If your OS can handle
funky names like that, you're golden.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
 http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

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




Re: Help with syntax "local (*in);

2005-12-03 Thread Randal L. Schwartz
> "Timothy" == Timothy Johnson <[EMAIL PROTECTED]> writes:

Timothy> You're creating a typeglob *in and declaring it to be local.  I'm not
Timothy> sure why you would want to do this, but this makes $in, @in, and %in 
all
Timothy> local.

and &in, and the filehandle/directoryhandle "in", also local.  And
the format called "in".

Globs are used for a lot of things!

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
 http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

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




Re: Perl executable pathname needs to be hardwired?

2005-12-03 Thread Randal L. Schwartz
> "Adriano" == Adriano Ferreira <[EMAIL PROTECTED]> writes:

Adriano> Ok. I will try to be less lazy. What I was trying to workaround is to
Adriano> place perl binaries at a place available to my user, using a
Adriano> distribution which was supposed to be installed by 'root' (which I am
Adriano> not). The machine I was working at had no 'gcc' and I thought it would
Adriano> be a good idea to get a shortcut rather than building/installing gcc
Adriano> and then perl.

See my other message.  Make a Makefile.PL to install your script.  It
will install the user-suggested place with the right #! line
automatically.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
 http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

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




Why not to use env (was Re: Perl executable pathname needs to be hardwired?)

2005-12-03 Thread Randal L. Schwartz
> "Chris" == Chris Devers <[EMAIL PROTECTED]> writes:

Chris> My understanding is that the Python idiom is to avoid putting the full 
Chris> path, in favor of something like

Chris> #!/usr/bin/env python

This won't work if env is not in /usr/bin (like say, /bin/env).

Chris> #!env python

This won't work if env is not in your current directory!  (odds on
that, 0% unless you're cd'ed to /usr/bin or /bin, see above.)

The problem is that #! is a low-level action.

I actually dislike the way "env" is bandied about as the solution.

One problem is that while Perl may be in *my* PATH for an unusual
location, it's not neccessarily in *your* PATH.  And it may not even
be the same Perl!  I have four versions of Perl installed on my laptop
here, and depending on how my PATH is shuffled, I'll get an entirely
different version of Perl.  (This is the same problem with depending
on the PERL5LIB env variable.  You should put "use lib" *in* the
program instead.)

Another problem is that it's a double fork... the kernel launches env,
and env launches Perl... *every* time.  For a command launched once
per day, no biggy, but imagine a CGI script launched 10 times a
second.

If you use Makefile.PL to install your script, you can simply put
#!perl on the first line, and that'll be *rewritten* at install
time to be the "right thing" to launch the same Perl that launched
your Makefile.PL.  Very cool.  More people should use this.

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
 http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

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




Re: Flushing Buffers (WAS: recursive search)

2005-12-03 Thread John W. Krahn
John Doe wrote:
> The Ghost am Freitag, 2. Dezember 2005 19.30:
> 
>>   print "$_: ";
>>  my @lines=;
> 
> and close opened files:
> 
>   close FILE or die "couldn't close $File::Find::name: $!";
> 
>>  print "$#lines\n";
>>  $totalLines+=$#lines; #wanted's value is ignored so we have to
>>do this here.
>>  return;}
>>  print "$totalLines\n";

You bring up an interesting point about closing the filehandle because
normally you don't have to worry about that as perl will do the right thing.
However in the example I posted using the $. variable:

sub wanted {

...

() = ;
print "$.\n";
$totalLines += $.;
}
print "$totalLines\n";

Produces an incorrect value for $totalLines unless you close the filehandle
but if you don't close the filehandle then you can do this:

sub wanted {

...

() = ;
}
print "$.\n";



John
-- 
use Perl;
program
fulfillment

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




Re: Flushing Buffers (WAS: recursive search)

2005-12-03 Thread John W. Krahn
John Doe wrote:
> The Ghost am Freitag, 2. Dezember 2005 19.30:
> 
>>   open FILE, "<$File::Find::name";
> 
> Always check if operations succeeded:
> 
>open (FILE, '<', $File::Find::name) 
>   or die "couldn't open $File::Find::name: $!";

Thanks, don't know how I missed that.  :-)


John
-- 
use Perl;
program
fulfillment

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




Intercommunication between Perl and C

2005-12-03 Thread He Nan
What should I do if I need an intercommunication between a perl and c
program ? Are there any examples I could follow , or what books I should
read ? I'm confused...


Re: Flushing Buffers (WAS: recursive search)

2005-12-03 Thread John Doe
The Ghost am Freitag, 2. Dezember 2005 19.30:

Hi,

In addition to John W. Krahn's good advices:

> So far I did this:
>
> #!/usr/bin/perl
>
> use File::Find;
> my $totalLines;
>  find(\&wanted, '@directories');
>  sub wanted {
>unless ($_=~m/.html|.mas|.pl|.txt$/i) {return 0;} #filter the kinds
> of files you want
>open FILE, "<$File::Find::name";

Always check if operations succeeded:

   open (FILE, '<', $File::Find::name) 
  or die "couldn't open $File::Find::name: $!";

>print "$_: ";
>   my @lines=;

and close opened files:

close FILE or die "couldn't close $File::Find::name: $!";

>   print "$#lines\n";
>   $totalLines+=$#lines; #wanted's value is ignored so we have to
> do this here.
>   return;}
>   print "$totalLines\n";
>
> This only limits me by the size of the file, or no?
>
> Thanks!

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




Re: Sockets questions

2005-12-03 Thread Octavian Rasnita
From: "Scott" <[EMAIL PROTECTED]>

> I recently started messing with perl sockets and I was wondering if it is
> possible to do any of the following:
>
> - Pre-shared key, to act as some sort of authentication. Currently I have
> it checking the peer address, but I figure that could be spoofed.
>

Where can I find more about IP spoofing in general and how I can protect
against it?

Thanks.



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