comp.lang.perl.misc
  Home FAQ Contact Sign in
comp.lang.perl.misc only
 
Advanced search
February 2008
motuwethfrsasuw
    123 5
45678910 6
11121314151617 7
18192021222324 8
2526272829   9
2008
 Jan   Feb   Mar   Apr 
 May   Jun   Jul   Aug 
 Sep   Oct   Nov   Dec 
2008 2007 2006  
total
comp.lang.perl.misc Profile…
RELATED GROUPS

POPULAR GROUPS

more...

 Up
  FAQ 4.54 Why does defined() return true on empty arrays and hashes?         


Author: PerlFAQ Server
Date: Feb 29, 2008 18:03

This is an excerpt from the latest version perlfaq4.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

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

4.54: Why does defined() return true on empty arrays and hashes?

The short story is that you should probably only use defined on scalars
or functions, not on aggregates (arrays and hashes). See "defined" in
perlfunc in the 5.004 release or later of Perl for more detail.

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

The perlfaq-workers, a group of volunteers, maintain the perlfaq. They
are not necessarily experts in every domain where Perl might show up,
so please include as much information as possible and relevant in any
corrections. The perlfaq-workers also don't have access to every
operating system or platform, so please include relevant details for
corrections to examples that do not work on particular platforms.
Working code is greatly appreciated.
Show full article (1.25Kb)
no comments
  Recommendation for a SNMP module to collect asset data from Cisco devices         


Author: Tom Brown
Date: Feb 29, 2008 13:04

Hello,

There are plenty SNMP modules out there and I would like to ask for
some recommendations. The goal is to gather asset data from Cisco
devices by SNMP and to aggregate it in an Excel sheet using
Spreadsheet::WriteExcel.

In order to be most flexible I would define the OID's (the return
values will contain the values like device model, hostname, chassis,
serial-number and so on) as plain ascii file and pass it to the script
as option.

My approach for the processing itself is to store the returned values
for each polled OID into a hash (per device) and when completed to
append one row per device using Spreadsheet::WriteExcel.

So far the demand and my ideas.

Which SNMP module could provide the best functions for my demand?

Regards,

Tom
2 Comments
  FAQ 4.53 How do I manipulate arrays of bits?         


Author: PerlFAQ Server
Date: Feb 29, 2008 12:03

This is an excerpt from the latest version perlfaq4.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

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

4.53: How do I manipulate arrays of bits?

Use "pack()" and "unpack()", or else "vec()" and the bitwise operations.

For example, this sets $vec to have bit N set if $ints[N] was set:

$vec = '';
foreach(@ints) { vec($vec,$_,1) = 1 }

Here's how, given a vector in $vec, you can get those bits into your
@ints array:
Show full article (4.99Kb)
11 Comments
  Finding number of file from gzip'ed format         


Author: sopan.shewale
Date: Feb 29, 2008 11:58

Hi,

I am not sure if this is the right group to ask this question - i am
sorry if this is not the right place.

Problem: Let us say we have file called "myfile.txt". The size of the
file is huge. The file is gziped - the gziped filename is
"myfile.txt.gz". I am interested to find the number of lines of
myfile.txt from myfile.txt.gz without gunziping it.

I know if it is allowed to gunzip then just use "gunzip -c
myfile.txt.gz | wc -l" this can give the number of lines.

My problem is time taken to gunzip is huge file is very large.

Is there any way to count the number of lines using Perl script/Any
other method - just to figure out number of "\n" chars hidden inside
the file-use something from the algorithm of gzip?

Appreciate your time efforts to read the problem and thank you so much
for investing time to read this problem.

Please help me with solution or pointers to read (already reading
http://www.gzip.org/algorithm.txt).

--sopan
2 Comments
  every(seconds => 4)         


Author: Ted Zlatanov
Date: Feb 29, 2008 10:30

I've extended the every() function I discussed before to handle the
'seconds' syntax, so you can say

while (<>)
{
...
if (every(seconds=>60))
{
# do this every minute when input arrives
}
elsif (every(5000) || every(943, "second one")) # distinguish the second call's hash entry
{
}
}

Here's my implementation, which preserves the semantics of the original
every(N) function as well. I'm curious if anyone has ideas for more
things I can add. I am debating if it's worth putting on CPAN (I don't
know of anything like it already on CPAN). It seems like a really
simple piece of code that doesn't necessarily merit its own module, but
it's really useful to me...
Show full article (1.16Kb)
no comments
  Hell of a time extracting bits from a vector         


Author: Idgarad
Date: Feb 29, 2008 09:09

I am generating a SHA1 digest that I want to use for some values.

I want to take the digest that is generated at extact a given number
of bits, in sequence.

SHA1 generates 160 bits.

I would like to partition that 160 bits into an array storing the
value of those bits

for instance (in short form using only 10 bits grabbing 2 at a time)
lets say I have:

1010010101

and I am grabbing pairs I need (from least to most):

@somearray

$somearray[0] = 1 (01)
$somearray[1] = 1 (01)
$somearray[2] = 1 (01)
$somearray[3] = 2 (10)
$somearray[4] = 2 (10)

I I tried using vec (going back to the full 160 bits) but it fails
miserably. Here a sample

Using vec($digest,$loop*8,8) (Grabbing 8 bits)
Show full article (1.17Kb)
5 Comments
  Newbie needs help with IO::Socket (maybe IO::Select)         


Author: Boerni
Date: Feb 29, 2008 06:41

Hi all

I'm playing around with IO::Socket and try to build a small Client/Server
App.

The Serverpart is working as it's supposed to, but I have some problems with
the Clientpart.

So I have a couple of Questions:
1. How can a Client react to a Servermessage (Server prints to Socket), when
it's not expecting a Servermessage (For example another client connects to
the server and kicks the first one or the server is beeing shutdown). If I
use the IO::Select approach like in the Serverpart, the Client is blocked
and the User can't interact with it anymore.

2. Why does $socket->connected still return the peer-address, eventhough the
server is shutdown?

I'm sure there is a solution for this (probably by using IO::Select), but I
can't find any examples of Clientcode using this.

Here's what I have (simplified... the "real" Client is using Tk):
Show full article (5.08Kb)
2 Comments
  How to set a HARD memory limit for apache         


Author: Ignoramus12509
Date: Feb 29, 2008 06:30

I have a Linux server that I am configuring for Apache to me used with
mod_perl.

I want to make sure that no apache child can, ever, under any
circumstances, exceed some memory size limit such as 300 MB.

I looked at perl modules such as Apache2::Resource and
Apache2::SizeLimit and they would not work for me. The former just
does not do its job, and the second a) just checks memory size and b)
does not work with threaded MPM.

What I want is a very simple thing: I want an apache daemon to
INSTANTLY DIE if it ever reaches size of X such as X = 300 MB. I do
not want to "give them a chance". I also do not want to "check the
size at some times (like in CleanupHandler)". I want behaviour such as
that specified by bash ulimit function. Instant death immediately upon
reaching the limit.

The reason for this is that I do not want a memory consuming bug in my
mod_perl code to damage my server.

At the same time, I would like to set a lower limit that would exit
apache gracefully and that would be checked from, say, a
CleanupHandler.
Show full article (1.12Kb)
4 Comments
  FAQ 4.52 How do I sort an array by (anything)?         


Author: PerlFAQ Server
Date: Feb 29, 2008 06:03

This is an excerpt from the latest version perlfaq4.pod, which
comes with the standard Perl distribution. These postings aim to
reduce the number of repeated questions as well as allow the community
to review and update the answers. The latest version of the complete
perlfaq is at http://faq.perl.org .

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

4.52: How do I sort an array by (anything)?

Supply a comparison function to sort() (described in "sort" in
perlfunc):

@list = sort { $a <=> $b } @list;

The default sort function is cmp, string comparison, which would sort
"(1, 2, 10)" into "(1, 10, 2)". "<=>", used above, is the numerical
comparison operator.

If you have a complicated function needed to pull out the part you want
to sort on, then don't do it inside the sort function. Pull it out
first, because the sort BLOCK can be called many times for the same
element. Here's an example of how to pull out the first word after the
first number on each item, and then sort those words case-insensitively.
Show full article (2.80Kb)
no comments
  Secure FTP         


Author: john_paul_byrne
Date: Feb 29, 2008 03:14

Hi,

I am setting up a cron job which calls a perl script, at the end of
which, I want to upload a file to a secure ftp server.

Can somebody point me in the best way to approach this? A sample would
be fantastic ;o)

John
4 Comments
1 2