I'm trying to edit a text file that looks like this:
TYPE=Ethernet
HWADDR=00:....
IPV6INIT=no
MTU=1500
IPADDR=192.168.2.247
...
(Its actually the /etc/sysconfig/network-scripts/ifcfg- file on red hat Linux)
Instead of reading and rewriting the file each time I want to modify it, I figured I could use grep, sed, awk or the native text ...
In Perl, one can do the following
for (@foo) {
# do something
next if $seen{$_}++;
}
I would like to be able to do the equivalent in Python, that is to skip a block if it has been executed once.
...
I am using Active Perl and am looking for ways to set up a local repository to install various modules. Main reason behind is the production server has no internet access.
Can anyone point me any quick start or step-by-step tutorials on this?
...
I wrote a Perl program which forks and calls a background program in the child process and has a endless while loop which does some stuff in the parent process. Now the while loop should be left when the background program in the child process terminates:
$pid = fork();
if ( !$pid ) {
exec( "program args" );
} else {
while ( 1 )...
The spreadsheet is Excel 97-2003 compatible and permissions 777
use strict;
use Spreadsheet::ParseExcel;
print "Content-type: text/html\n\n";
my $parser = Spreadsheet::ParseExcel->new();
print "<br>gets here:".__LINE__;
my $workbook = $parser->parse('test.xls');
print "<br>never gets here:".__LINE__;
...
I need to check whether a Unicode directory exists in Perl. I am using Windows XP and Perl Camelbox 5.10.0.
If I try to create a directory (like Sinan suggested here stackoverflow.com/questions/2184726) that already exists the program dies.
Unfortunately if ( !-d $dir_name ) { # create directory $dir_name } doesn't seem to recognize Un...
I have a web application that uses a parser created with Parse::RecDescent. A parser object is needed in several parts of the application and since the parser takes quite a bit of memory I have up to now treated the parser object as a singleton. This works well in a pure CGI environment since only one expression is parsed by the same obj...
I have a Perl DBIx::Class search the looks like this:
my $rs = shift->search( {
-and => [
{ 'for_revocation' => 1 },
[
{
status => {
'not_in' => [ 'revoked', 'revoking']
},
},
{
...
I need to create a "obscuring" function which replaces clear-text password in line, before writing it to log.
It looks like this:
function pass_obscure {
my $logline = shift;
my $pass = "wer32pass$"; # this password is an example, the real one is received as parameter, or already stored as global value
$logline =~ ...
I am looping through a big data file and like to detect the type of variable in each column,
eg if it is an Intenger or a Float etc.
It works perfectly fine, however, at the moment it is still very basic and I like to add another idea.
So far the declaration of the variable is based on the second row of the data set.
(The first one is us...
I want to scan the passwd file and change the order of words in the comment field from firstname lastname to lastname firstname, and force the surname to capitals.
So, change every line from:
jbloggs:x:9999:99:Joe Bloggs:/home/jbloggs:/bin/ksh
to:
jbloggs:x:9999:99:BLOGGS Joe:/home/jbloggs:/bin/ksh
I'm new to Perl and I'm having p...
How do you either:
have a sub return a sub
or
execute text as code
in Perl?
Also, how do I have an anonymous function store state?
...
Using Apache 2.2 and mod_perl on Ubuntu 8.04 I have several applications on a server. Using Apache in pre-forking mode. Usually things are working well but once in a while I see one of Apache processes using 100% of the CPU.
There are several web sites on the server with their own VirtualHosts and there are
is and SVN server running vi...
I am reading a postfix mail log file into an array and then looping through it to extract messages. On the first pass, I'm checking for a match on the "to=" line and grabbing the message ID. After building an array of MSGIDs, I'm looping back through the array to extract information on the to=, from=, and client= lines.
What I'd like to...
This question has 2 sections one for "single line match" and one for "multi line region matching" Also, I have a semi working solution, I want to find more robustness and elegance in my solution.
Single Line Match:
I would like to duplicate each line of an input file such that the second line was a regex modification of the first:
E.G...
So I have a bit of problem figuring what Perl does in the following case:
while(1){
$inputLine=<STDIN>
#parse $inputLine below
#BUT FIRST, I need to check if $inputLine = EOF
}
before I get the obvious answer of using while(<>){}, let me say that there is a very strong reason that I have to do the above (basically setting up an alar...
This sample script:
#!/usr/bin/perl -w
while (1)
{
sleep(1);
}
takes about 264 kB
grep -A1 heap /proc/9216/smaps
0817b000-081bd000 rw-p 0817b000 00:00 0 [heap]
Size: 264 kB
but when I only add my module:
#!/usr/bin/perl -w
use my_module;
while (1)
{
sleep(1);
}
it takes 18092 kB !
grep -A1 heap ...
I'm trying to find an alternative to the Cache::Memcached Perl module that works with Windows XP. Or, to somehow get Cache::Memcached working on Windows XP.
A bit of background: the production environtment (web server) is Solaris 10, which I've already installed memcached and Cache::Memcached, and all works fine. However, the developme...
Is POSIX pselect available in Perl? A CPAN module is fine also.
...
I use the following code to generate a spam report using SpamAssassin:
use Mail::SpamAssassin;
my $sa = Mail::SpamAssassin->new();
open FILE, "<", "mail.txt";
my @lines = <FILE>;
my $mail = $sa->parse(@lines);
my $status = $sa->check($mail);
my $report = $status->get_report();
$report =~ s/\n/\n<br>/g;
print "<h1>Spam Report</h1>";...