These 3 lines of code:
if (fork()) {sleep 10; exit(0);}
$SIG{'CHLD'} = 'IGNORE';
exit(system("/usr/lib/nagios/plugins/check_ping -H google.com -w
500,20% -c 1000,40% 1> /tmp/stdout.txt 2> /tmp/stderr.txt; echo $? >
/tmp/res.txt"));
return "PING WARNING - Packet loss = 0%, RTA = 62.08
ms|rta=62.07
I did this in tcsh:
> perl -le 'exit(2); sub END {system("date");}' ; echo $status
Mon May 17 11:09:43 MDT 2010
0
In other words, the return value of the date command in an END subroutine
overrides my desired exit value.
How do I fix this? I want to tell Perl: if I explicitly do exit($foo), I
wa
This code:
perl -le 'use Date::Parse; for $tz ("MST", "MDT", "MST7MDT") {print
str2time("04 Jul 2009 14:42:00 $tz");}'
returns:
1246743720
1246740120
1246743720
In other words, str2time returns the same Unix time for
MST and MST7MDT on July 4th.
That's incorrect: on July 4th, MST7MDT should eq
How do I easily model first-in-first-out (FIFO) financial transactions
in Perl? Example:
% I buy 100 shares of XYZ for $8/share on Day 1, another 100 shares
for $9/share on Day 2, and another 100 shares for $10/share on Day 3.
% On Day 4, I sell 150 shares for $11/share. I calculate my profit
According to "man perlrun", the "-0777" option sets $/ to 0777 and
slurps files whole. This works fine.
However, when I did 'local $/="0777"' in a script, it usually worked,
but sometimes failed and only slurped part of the file.
Changing this to "local $/ = undef" worked fine.
Why?
--
We're j
perl -le 'printf("%f %f %f\n", 4294967295, 2147483647*2**32,
2147483647*2**32+4294967295)'
4294967295.00 9223372032559808512.00 9223372036854775808.00
Why? The answer is really 9223372036854775807 (one number lower), and
it's obvious that adding 2 and 5 in the units column should yiel
If I do a for loop in a subroutine, do I have to declare it private
with my()? I always though for() did that for me, but I ran into a bug
where code like this:
sub foo {for $i (1..2) {print $i;}}
affected my global $i (I think). Or was I imagining it?
--
We're just a Bunch Of Regular Guys, a c
I want to do "function completion". If I have functions called where()
and which(), I want whe() to call where(), whi() to call which(), and
wh() to return something like "Ambigious: where() and which() both
match wh()".
What's the best/easiest way to do this?
--
We're just a Bunch Of Regular Gu
I want foo() and bar() to do the same thing. One way to do this:
sub foo {return bar(@_);}
Is there a more clever way using \&bar and things like that?
--
We're just a Bunch Of Regular Guys, a collective group that's trying
to understand and assimilate technology. We feel that resistance to
new
I "cpan Text::Unidecode" on 2 machines and then ran this code:
use utf8;
use Text::Unidecode;
print unidecode("\x{5317}\x{4EB0}")."\n";
print unidecode("\xd0\x90\xd0\xbb")."\n";
print unidecode("\xe3\x82\xa2")."\n";
On both machines, the first line correctly prints "Bei Jing", the
author's test c
I'm trying to convert UTF-8 to ASCII in Perl. Is there an easy way to
do this?
I tried Unicode::UTF8simple, but ended up w/ many ctrl-a's, which
can't be right.
I'm going for an extremely complete transliteration, so I want ETH
(for example) to be converted to both "d" and "dh". In other words, m
-Original Message-
>> From: Kelly Jones [mailto:kelly.terry.jo...@gmail.com]
>> Sent: Friday, April 10, 2009 13:33
>> To: beginners@perl.org
>> Subject: Replace string with list of strings via character changes
>>
>> I want to replace all the o's in a
I want to replace all the o's in a string with x's or y's and all the
a's in a string with u's or v's.
Example: given string "foobar", the output would be this list of strings
fxxbur (change both o's to x, and the a to u)
fxxbvr (both o's to x, a to y)
fxybur (first o to x, second to y, and the a
>> Original Message
>> Subject: Calling subroutine every second using alarm fails
>> From: Kelly Jones
>> Date: Wed, April 01, 2009 5:48 am
>> To: beginners@perl.org
>>
>>
>> I want a script that constantly accepts user input, b
I want a script that constantly accepts user input, but runs a
subroutine every second to do other work. My attempt:
$|=1; $SIG{'ALRM'}= "\&alarm_sub"; &alarm_sub;
while (<>) {print "You typed: $_\n";}
sub alarm_sub {print "ALARM!\n"; alarm 1; return;}
fails miserably. What's the right way to do
> perl -le '$x=; print $x'
hello <- I TYPED THIS IN AND HIT RETURN
hello
> perl -le 'my($x)=; print $x'
hello <- I TYPED THIS IN AND HIT RETURN
[no answer, hangs forever]
Why?
--
We're just a Bunch Of Regular Guys, a collective group that's trying
to understand and assimilate technology. We fee
I'm trying to write a Perl DNS server that answers queries (A, NS,
TXT, CNAME, LOC, MX, etc-- pretty much anything in
http://en.wikipedia.org/wiki/List_of_DNS_record_types) based on the
time of day, current weather in Paris, number of users on my server,
the IP address of the requestor, a hash of t
Consider:
perl -le '$hash{"foo-bar"} = 1; print $hash{foo-bar}'
[no result]
perl -le '$hash{"foobar"} = 1; print $hash{foobar}'
1
I sort of understand this: in the first script, Perl treats foo-bar as
a subtraction, and sets $hash{0} to 1. In the second one it assumes
you just left off some quot
How can I see all the local, global, etc Perl variables defined at a
given point in my program?
--
We're just a Bunch Of Regular Guys, a collective group that's trying
to understand and assimilate technology. We feel that resistance to
new ideas and technology is unwise and ultimately futile.
--
I saw something like this in a mimedefang tutorial:
sub foo () {return 1;}
By trial and error, I discovered this means: foo takes EXACTLY four
arguments, no less, no more.
Where can I learn more about this syntax/feature?
--
We're just a Bunch Of Regular Guys, a collective group that's try
I want an efficient subroutine that inserts $elt into @x and returns
the percentile of $elt in @x.
For example, if @x is (2,2,3,3,3,4,5,6,7,8) and $elt is 3, the
subroutine returns .363636... and @x is now
(2,2,3,3,3,3,4,5,6,7,8). Why .363636...?:
% After insertion, @x has 11 elements. $elt (3)
I begrudgingly use a Windows SharePoint server at a customer's request.
I'd like to automate (command-line) updating and creating documents,
lists, etc.
Is there a Unix tool that does this?
I know SharePoint has an "API", which basically spoofs the GET/POST
calls that your browser would make(?).
I have a file with this in it:
a.b = 10
c.d.e = 11
f.g.h.i.j.k = 12
Based on that, I want to set:
$HASH{a}{b} = 10;
$HASH{c}{d}{e} = 11;
$HASH{f}{g}{h}{i}{j}{k} = 12;
This is easy using eval(), but is there a better way?
I realize that entries like "a.b = 10" and "a.b.c = 13" would
conflict, s
Many programming languages (including Perl, Ruby, and PHP) support hashes:
$color['apple'] = 'red';
$color['ruby'] = 'red';
$type['apple'] = 'fruit';
$type['ruby'] = 'gem';
This quickly lets me find the color or type of a given item.
In this sense, color() and type() are like mathematical funct
I've scraped an HTML page and gotten back a string that looks like this:
[... bunch of stuff I don't care about ...]
bar
some text here
boing
[... bunch of stuff I don't care about ...]
Is there a Perl module that will take this string and return a hash
representing the current (default) for
I want to use system() (or `command`) to run an external command from
my Perl script. However, if the external command takes more than 30
seconds (for example) to run, I want to kill it, and move on with the
rest of my Perl script. How do I do this?
--
We're just a Bunch Of Regular Guys, a collec
perl -w dings me if I use a variable just once:
Name "main::foo" used only once: possible typo...
even if I'm magically defining/using $foo somewhere else.
Is there any way to tag a variable to tell the -w option that I'm
intentionally using that variable just once, and not to warn me about it?
Inside a subroutine, I want to use this hash:
%hash = ("apple" => "red", "pear" => "green", "[EMAIL PROTECTED]" => "yellow");
to set my($apple)="red", my($pear)="green", my($lemon)="yellow"
[getting rid of the junk '@' and '!' chars in the key]
This is approximately what PHP's extract() does. T
I've used xinetd to set up a test nameserver on port 1024. Here's the
Net::DNS Perl I'm using to say (falsely) that news.yahoo.com resolves
to 10.1.2.3 with a TTL of 1 day:
$res = Net::DNS::Packet->new();
$rr = Net::DNS::RR->new("news.yahoo.com. 86400 A 10.1.2.3");
$res->push(answer => $rr);
prin
29 matches
Mail list logo