comp.lang.perl.misc
  Home FAQ Contact Sign in
comp.lang.perl.misc only
 
Advanced search
January 2008
motuwethfrsasuw
 123456 1
78910111213 2
14151617181920 3
21222324252627 4
28293031    5
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
  Restrict IP access to a Perl application         


Author: barramundi9
Date: Jan 29, 2008 23:04

Dear all:

I am a newbie to Perl and have an application written in Perl. I put
IPs that are "allowed" to access the application into a file called
"ip.allow".

I then tried to compare the $ENV{REMOTE_ADDRESS} to the IPs in
"ip.allow" to determine the access right which looks like the
following:

10.0.0.1
10.0.0.2
10.0.0.3

And the code is:

$address=$ENV{'REMOTE_ADDR'};
Show full article (0.81Kb)
5 Comments
  Re: List of directories within a directory         


Author: Jürgen Exner
Date: Jan 29, 2008 20:36

Al Moodie nospam.com> wrote:
>I have a directory with 200 sub directories in it. How do I create a
>list of the sub directory names?

Didn't I just read exactly the same question from a name sake of yours in a
different NG? You may want to read up on the difference between
cross-posting (which is rarely appropriate) and multi-posting (which is
never justified).

Same answer as there: I would use File::Find and prune at a depth of 2.

jue
no comments
  Re: List of directories within a directory         


Author: John W. Krahn
Date: Jan 29, 2008 18:30

Al Moodie wrote:
> I have a directory with 200 sub directories in it. How do I create a
> list of the sub directory names?
>
> I know how create a list of all the files in a directory:
>
> opendir(DIR, $dirname) or die "can't open $dirname: $!";
> while (defined($file = readdir(DIR))) {
> next if($file =~ m/^\./);
> next if($file eq "");

"" is not a valid file name so this test will *always* fail.

$ mkdir ''
mkdir: cannot create directory `': No such file or directory
$ touch ''
touch: cannot touch `': No such file or directory
> push (@filenames, $file);

Since you didn't test the file type your @filenames array contains all
types including subdirectories.
Show full article (1.01Kb)
2 Comments
  Re: List of directories within a directory         


Author: Ben Morrow
Date: Jan 29, 2008 18:26

Quoth Al Moodie nospam.com>:
> I have a directory with 200 sub directories in it. How do I create a
> list of the sub directory names?

Recursively, or just the immediate subdirectories?
> I know how create a list of all the files in a directory:
>
> opendir(DIR, $dirname) or die "can't open $dirname: $!";
> while (defined($file = readdir(DIR))) {
> next if($file =~ m/^\./);
> next if($file eq "");

For just the immediate subdirs you need

next if !-d "$dirname/$file";

or possibly

next if -l "$dirname/$file" or !-d _;

depending on your definition of 'directory', or the equivalent with
File::Spec if you want to be more portable (your exclusion of .*
suggests you are on Unix). For finding files (directories are just
files) recursively, use File::Find or one of the more modern
alternatives like File::Find::Rule.
Show full article (0.87Kb)
no comments
  FAQ 8.40 How do I avoid zombies on a Unix system?         


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

This is an excerpt from the latest version perlfaq8.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 .

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

8.40: How do I avoid zombies on a Unix system?

Use the reaper code from "Signals" in perlipc to call wait() when a
SIGCHLD is received, or else use the double-fork technique described in
"How do I start a process in the background?" in perlfaq8.

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

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.23Kb)
no comments
  ssh into remote nodes, do mulitple commands         


Author: Nene
Date: Jan 29, 2008 17:32

Hello,

I'm trying to use Net::SSH to ssh into 3 nodes and move/copy files
with File::Copy. For now, I scripted it to find files of a certain
age and move them.
The $cmd variable is working, but when I try to move the files, it
errors with copy failed. Please critique or suggest a better way.
Thanks in advance!!!!
######################################################

#!/usr/bin/perl -w
use Net::SSH::Perl qw(sshopen2);
use strict;

my %%LIST = (

1 => "node1",
2 => "node1",
3 => "node1"

);

foreach my $ESP (sort values %%LIST) {
Show full article (0.91Kb)
1 Comment
  "negative" regexp         


Author: Petr Vileta
Date: Jan 29, 2008 17:10

I have problem to construct regexp, this is out of my brain ;-) please help.

I have string

$string="
href='abc.htm'>click";

and I need to remove all html tags except . The result should be

$string="click";

Now I do it this way

# replace < with Ctrl-B and > with Ctrl-E for all tags
$string=~s//\cb$1\ce/g;
# remove all html tags
$string=~s/<.+?>//g;
# replace back all Ctrl-B with <
$string=~s/\cb/
# replace back all Ctrl-E with >
$string=~s/\ce/>/g;
Show full article (0.80Kb)
19 Comments
  domains, top level, collecting a list of         


Author: wardbayern
Date: Jan 29, 2008 12:37

Is there a perl way, verses finding a published list, to collect
current top level domain names?

Thanks.
2 Comments
  FAQ 9.15 How do I parse a mail header?         


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

This is an excerpt from the latest version perlfaq9.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 .

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

9.15: How do I parse a mail header?

For a quick-and-dirty solution, try this solution derived from "split"
in perlfunc:

$/ = '';
$header = ;
$header =~ s/\n\s+/ /g; # merge continuation lines
%%head = ( UNIX_FROM_LINE, split /^([-\w]+):\s*/m, $header );

That solution doesn't do well if, for example, you're trying to maintain
all the Received lines. A more complete approach is to use the
Mail::Header module from CPAN (part of the MailTools package).

--------------------------------------------------------------------
Show full article (1.49Kb)
no comments
  Odd (undocumented?) behavior of RAM file within a loop         


Author: David Filmer
Date: Jan 29, 2008 10:53

Greetings. I am writing a program which processes some files within a
loop, and I am using the ability (as of Perl 5.8) to open a filehandle
on a scalar reference (which I recycle in the loop). Kindly consider
this stripped-down trivial code example which illustrates my question:

#!/usr/bin/perl
use strict; use warnings;

foreach (1..3) {
warn "Pass #$_\n";
my $file_in_memory;
open(my $fh, '>', \$file_in_memory) or die "Oops - $!\n";
close $fh;
}

__END__

It works fine for the first pass. However, subsequent passes emit warnings:

Pass #1
Pass #2
Use of uninitialized value in open at /perl/blah line 7.
Pass #3
Use of uninitialized value in open at /perl/blah line 7.
Show full article (1.25Kb)
5 Comments
1 2