[29915] in Perl-Users-Digest
Perl-Users Digest, Issue: 1158 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jan 3 06:10:50 2008
Date: Thu, 3 Jan 2008 03:09:48 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 3 Jan 2008 Volume: 11 Number: 1158
Today's topics:
"Use of initialized value in scalar assignment" <socyl@987jk.com.invalid>
Re: "Use of initialized value in scalar assignment" <someone@example.com>
Re: "Use of initialized value in scalar assignment" <john@castleamber.com>
anyone have a working captcha perl script for windows ? <jack_posemsky@yahoo.com>
Re: anyone have a working captcha perl script for windo <lihao0129@gmail.com>
calling perl from html page <motic.mail@gmail.com>
Re: calling perl from html page <noreply@gunnar.cc>
Re: calling perl from html page <joost@zeekat.nl>
Re: calling perl from html page <purlgurl@purlgurl.net>
create report from csv file <chris95008@yahoo.com>
Re: create report from csv file davidfilmer@gmail.com
Re: create report from csv file <jurgenex@hotmail.com>
Re: create report from csv file <tadmc@seesig.invalid>
Re: FAQ 6.11 Can I use Perl regular expressions to matc (Marc Espie)
Re: FAQ 6.11 Can I use Perl regular expressions to matc <brian.d.foy@gmail.com>
Re: FAQ 6.16 How do I efficiently match many regular ex <xueweizhong@gmail.com>
Re: FAQ 6.16 How do I efficiently match many regular ex <brian.d.foy@gmail.com>
Re: How Do I Locate a value in a text file and evaluate <karinwalike@comcast.net>
Re: How Do I Locate a value in a text file and evaluate <karinwalike@comcast.net>
Re: How Do I Locate a value in a text file and evaluate <tadmc@seesig.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 2 Jan 2008 20:14:35 +0000 (UTC)
From: kj <socyl@987jk.com.invalid>
Subject: "Use of initialized value in scalar assignment"
Message-Id: <flgrbb$atl$1@reader2.panix.com>
The following innocent-looking one-liner:
% perl -we '$ENV{ FOO } = undef'
produces the warning:
Use of uninitialized value in scalar assignment at -e line 1
Is this a bug, or is there a good reason for this?
FWIW, I've seen this behavior only with %ENV. I got the above
using v5.8.8 on Linux.
TIA!
kj
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
------------------------------
Date: Wed, 02 Jan 2008 20:27:41 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: "Use of initialized value in scalar assignment"
Message-Id: <1tSej.43828$UZ4.18007@edtnps89>
kj wrote:
>
> The following innocent-looking one-liner:
>
> % perl -we '$ENV{ FOO } = undef'
>
> produces the warning:
>
> Use of uninitialized value in scalar assignment at -e line 1
>
> Is this a bug, or is there a good reason for this?
>
> FWIW, I've seen this behavior only with %ENV. I got the above
> using v5.8.8 on Linux.
What makes you think that you could set an environment variable to the
undef value? How does that make sense?
man 3 setenv
Perhaps you meant to use delete() instead:
delete $ENV{ FOO }
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
------------------------------
Date: 2 Jan 2008 20:28:15 GMT
From: John Bokma <john@castleamber.com>
Subject: Re: "Use of initialized value in scalar assignment"
Message-Id: <Xns9A199335D760Acastleamber@130.133.1.4>
kj <socyl@987jk.com.invalid> wrote:
> The following innocent-looking one-liner:
>
> % perl -we '$ENV{ FOO } = undef'
>
> produces the warning:
>
> Use of uninitialized value in scalar assignment at -e line 1
>
> Is this a bug, or is there a good reason for this?
>
> FWIW, I've seen this behavior only with %ENV. I got the above
> using v5.8.8 on Linux.
What do you expect from setting an environment variable to undef?
--
John
Arachnids near Coyolillo - part 1
http://johnbokma.com/mexit/2006/05/04/arachnids-coyolillo-1.html
------------------------------
Date: Wed, 2 Jan 2008 22:12:50 -0800 (PST)
From: Jack <jack_posemsky@yahoo.com>
Subject: anyone have a working captcha perl script for windows ?
Message-Id: <29843fbd-1f7e-4765-87c4-26f55574984e@i12g2000prf.googlegroups.com>
Hi there, I have installed every CPAN Captcha image verification known
and cant get any of them to do a simple task - output to a directory a
set of Captcha images with codes and the code file..you would think
its simple, I tried GD:SecurityImage and this does nothing:
use GD::SecurityImage;
# Create a normal image
my $image = GD::SecurityImage->new(width => 80,
height => 30,
lines => 10,
gd_font => 'giant');
$image->random($your_random_str);
$image->create(normal => 'rect');
my($image_data, $mime_type, $random_number) = $image->out;
It runs but you have no way of knowing "where" the images were
placed. can anyone reply with a true to life working SIMPLE script
that just dumps the images and code file ??????
thank you,
Jack
------------------------------
Date: Wed, 2 Jan 2008 22:42:29 -0800 (PST)
From: "lihao0129@gmail.com" <lihao0129@gmail.com>
Subject: Re: anyone have a working captcha perl script for windows ?
Message-Id: <f796b6f5-b8ec-4bce-ad00-7b1c42793060@w39g2000hsf.googlegroups.com>
On Jan 3, 1:12 am, Jack <jack_posem...@yahoo.com> wrote:
> Hi there, I have installed every CPAN Captcha image verification known
> and cant get any of them to do a simple task - output to a directory a
> set of Captcha images with codes and the code file..you would think
> its simple, I tried GD:SecurityImage and this does nothing:
>
> use GD::SecurityImage;
>
> # Create a normal image
> my $image = GD::SecurityImage->new(width => 80,
> height => 30,
> lines => 10,
> gd_font => 'giant');
> $image->random($your_random_str);
> $image->create(normal => 'rect');
> my($image_data, $mime_type, $random_number) = $image->out;
>
> It runs but you have no way of knowing "where" the images were
> placed. can anyone reply with a true to life working SIMPLE script
> that just dumps the images and code file ??????
I suppose you were in a web-context, so you need to print out the
result to STDOUT. you need also send out content-type header before
sending your image data.. what I did with HTML::Mason:
my($image_data, $mime_type) = $image->out;
binmode STDOUT;
$m->clear_buffer();
$r->content_type("image/$mime_type") ;
$m->print($image_data);
$m->flush_buffer();
$m->abort();
If you were using plain-CGI, and your script filename is captcha.cgi,
then you probably can do things like:[sorry I have no experience with
plain CGI]
{
local $|++;
my($image_data, $mime_type) = $image->out;
binmode STDOUT;
print "Content-type=image/$mime_type";
print $image_data;
close STDOUT;
}
or something like that to print out image data to the web with a
proper content-type(make sure no other data are outputted before
sending content-type header), and then you can fetch it from the other
side with:
<img src="/path/to/captcha.cgi?R=..." alt="" />
For me, the random number is generated from outside captcha.cgi, and
passed in with an encrypted query string(i.e. R=#### as in the above
sample). you can then decrypt it at the beginning of your Perl script
captcha.cgi.. If you like this approach, you need also check out CPAN
for some Crypt:: modules(I am using Crypt::RC4 for this).
BTW. with GD::ImageSecurity, you dont need any temporary file to save
the images....
Good luck,
lihao
------------------------------
Date: Wed, 2 Jan 2008 12:11:20 -0800 (PST)
From: Moti <motic.mail@gmail.com>
Subject: calling perl from html page
Message-Id: <5c1f83a8-c99e-432f-912d-e89083de104d@y5g2000hsf.googlegroups.com>
Hi,
I'm new to perl and have written a script that I want to run on my web
site. My script gets some text lines and parse them.
I've written a html page that conatins a TEXTAREA and a submit button.
I want to paste some text lines inside the TEXTAREA, Then press the
submit button to call my perl script (with the text in the TEXTAREA as
input) .
My questions are:
1) How can I call my perl script from the html page ?
2) Can I do it on my PC or do I need to upload it to the server ?
Thanks in advance, Moti.
------------------------------
Date: Wed, 02 Jan 2008 21:32:18 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: calling perl from html page
Message-Id: <5u2amjF1et3v6U1@mid.individual.net>
Moti wrote:
> I'm new to perl and have written a script that I want to run on my web
> site. My script gets some text lines and parse them.
>
> I've written a html page that conatins a TEXTAREA and a submit button.
> I want to paste some text lines inside the TEXTAREA, Then press the
> submit button to call my perl script (with the text in the TEXTAREA as
> input) .
>
> My questions are:
> 1) How can I call my perl script from the html page ?
By making the script URL the action attribute in the form element. Example:
<form action="http://mysite/cgi-bin/myscript.pl" method="post">
<textarea name="text"></textarea><br>
<input type="submit">
</form>
> 2) Can I do it on my PC or do I need to upload it to the server ?
You can do it on your PC if you have a web server (and, of course, Perl)
installed. Assuming you are on a Windows PC, go to
http://www.indigostar.com/indigoperl.htm for the easiest way to get both.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 02 Jan 2008 21:38:25 +0100
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: calling perl from html page
Message-Id: <87hchw3qv2.fsf@zeekat.nl>
Moti <motic.mail@gmail.com> writes:
> Hi,
> I'm new to perl and have written a script that I want to run on my web
> site. My script gets some text lines and parse them.
>
> I've written a html page that conatins a TEXTAREA and a submit button.
> I want to paste some text lines inside the TEXTAREA, Then press the
> submit button to call my perl script (with the text in the TEXTAREA as
> input) .
>
> My questions are:
> 1) How can I call my perl script from the html page ?
You generally install your script as a CGI script or use mod_perl or
some other more or less server-specific system. CGI is probably the
easiest to learn and certainly the most portable. See the manual page for
the standard CGI module. Type
perldoc CGI
at your command prompt or see http://perldoc.perl.org/CGI.html
See also: http://perlmonks.org/?node_id=519640
I wish I could give you a pointer to a really good perl/cgi tutorial but
it's been ages since I looked at one and I can't seem to find any right
now. Most of what you'll find with google is utter crap. At least you
should know a *bit* about how HTTP (the protocol that powers the web)
works, and then the CGI documentation should make more sense.
This seems OK: http://www.jmarshall.com/easy/http/
Note that you don't need to know all the details of HTTP, but a general
overview is definitely a good thing to have, since then you'll at least
know 1. what the limitations are and 2. how much work CGI.pm is taking
care of for you :-)
> 2) Can I do it on my PC or do I need to upload it to the server ?
You need to put your script at a server that is reachable by your
audience, if you are the only user, you can put it at your own PC,
otherwise, you need to put it somewhere else or make sure your PC is
reachable from the network. In either case, CGI scripts are run from by
a webserver - they're not standalone programs.
> Thanks in advance, Moti.
You're welcome, :-)
Joost.
------------------------------
Date: Wed, 02 Jan 2008 15:56:36 -0800
From: Purl Gurl <purlgurl@purlgurl.net>
Subject: Re: calling perl from html page
Message-Id: <M72dnaiCvPArueHanZ2dnUVZ_qGknZ2d@giganews.com>
Gunnar Hjalmarsson wrote:
> Moti wrote:
(snipped a lot)
>> I'm new to perl and have written a script that I want to run on my web
>> site. My script gets some text lines and parse them.
>> 1) How can I call my perl script from the html page ?
>> 2) Can I do it on my PC or do I need to upload it to the server ?
> You can do it on your PC if you have a web server (and, of course, Perl)
> installed. Assuming you are on a Windows PC, go to
> http://www.indigostar.com/indigoperl.htm for the easiest way to get both.
If I may stick my nose in here where my nose does not belong,
I would strongly urge usage of the August, 2002, release of
Indigo Perl for usage with Windows. If not, my second choice
would be the February, 2005, release of Indigo Perl.
The February, 2003, and the March, 2004, versions of Indigo Perl
have a handful of severe bugs which renders running Apache and
PHP on Windows, almost impossible. These are not bugs introduced
by IndigoStar rather are compatibility problems in early Apache 2.x
versions and bundled PHP programming. These two versions, Apache
has serious compatibility problems with WinXP (NT 5) and PHP shows
equally serious compatibility problems with Apache.
Perl runs fine for all versions. For efficiency, first release
of Perl 5.8 is the fastest running. However, there are compatibility
problems with older Perl scripts and older Perl modules. Perl 5.8
runs much slower than earlier versions but offers more features.
For casual usage, for beginners to moderate skill levels, my
sincere suggestion is to use the older August, 2002, version
of Indigo Perl. This version installs quick and easy, and runs
right off with no issues. This early version is really great
and completely painless to install and run.
--
Purl Gurl
--
So many are stumped by what slips right off the top of my mind
like a man's bad fitting hairpiece.
------------------------------
Date: Mon, 31 Dec 2007 13:30:57 -0800 (PST)
From: Chris <chris95008@yahoo.com>
Subject: create report from csv file
Message-Id: <8b11a8a1-2c01-4e36-b60e-2138df336709@s8g2000prg.googlegroups.com>
Does anybody know of a perl or something similiar that can take a csv
database and create a report. Assumptions the csv file is presorted
and is delimited with | pipes. Only one field will need to match.
R&D
Milpitas
393 Licoln Drive 33,000 sq.ft. 1.20
400 Maple Lane 12,000 sq.ft. 1.25
San Jose
31 First Street 40,000 sq.ft. 1.50
9 Third Street 30,000 sq.ft. 1.40
I've looked at ezscripting.com but they can't group by city.
Thanks,
Chris
------------------------------
Date: Mon, 31 Dec 2007 15:24:40 -0800 (PST)
From: davidfilmer@gmail.com
Subject: Re: create report from csv file
Message-Id: <6a462190-0ece-4231-9229-ecfdba6aa144@i12g2000prf.googlegroups.com>
On Dec 31, 1:30 pm, Chris <chris95...@yahoo.com> wrote:
> Does anybody know of a perl or something similiar that can take a csv
> database and create a report. Assumptions the csv file is presorted
> and is delimited with | pipes.
Then it's not really a CSV file. CSV files are delimited with commas
(that's what the "C" stands for).
This task sounds like it could be handled by a trivial Perl script of
about a half dozen lines.
Even though you have made no apparent effort to locate or familiarize
yourself with the posting guidelines for this newsgroup (posted here
regularly and available at http://www.rehabitation.com/clpmisc/clpmisc_guidelines.html),
you may yet find that some group participants are of good holiday
cheer and may even be willing to toss a quick-and-dirty program at
you. However, since you did not provide any example of your input
data (only a poor description of it), it's hard to help you.
--
The best way to get a good answer is to ask a good question.
David Filmer (http://DavidFilmer.com)
------------------------------
Date: Tue, 01 Jan 2008 00:06:04 GMT
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: create report from csv file
Message-Id: <ho0jn3959outggtbm2bf4gb7ousie0c49k@4ax.com>
On Chris <chris95008@yahoo.com> wrote:
>Does anybody know of a perl or something similiar that can take a csv
>database and create a report.
Calling CSV a database is somewhat a stretch of imagination.
But yes, there are several modules that can parse CSV.
> Assumptions the csv file is presorted
>and is delimited with | pipes.
Then it is not a CSV file.
> Only one field will need to match.
And which one would that be? And what is it supposed to match? And what do
you want to do with the matched data?
>R&D
>
>Milpitas
>393 Licoln Drive 33,000 sq.ft. 1.20
>400 Maple Lane 12,000 sq.ft. 1.25
>
>San Jose
>31 First Street 40,000 sq.ft. 1.50
>9 Third Street 30,000 sq.ft. 1.40
That looks like the data is delimited by tab or hardcoded by position.
jue
------------------------------
Date: Tue, 01 Jan 2008 07:10:33 GMT
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: create report from csv file
Message-Id: <slrnfnj1jr.s64.tadmc@tadmc30.sbcglobal.net>
Chris <chris95008@yahoo.com> wrote:
> Does anybody know of a perl
What does "a perl" mean when you say it?
> or something similiar that can take a csv
> database and create a report.
That should take less than 10 lines of Perl code.
> Assumptions the csv file is presorted
What does sorting have to do with your desired algorithm?
> and is delimited with | pipes. Only one field will need to match.
Need to match *what* ?
> R&D
>
> Milpitas
> 393 Licoln Drive 33,000 sq.ft. 1.20
> 400 Maple Lane 12,000 sq.ft. 1.25
>
> San Jose
> 31 First Street 40,000 sq.ft. 1.50
> 9 Third Street 30,000 sq.ft. 1.40
There are no pipe characters there.
I thought you said that the data was delimited (but you meant separated)
by pipe characters, so what does this data that you are showing have
to do with the problem of splitting pipe-separated fields?
> I've looked at ezscripting.com but they can't group by city.
Look at writing a bit of Perl code instead.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Mon, 31 Dec 2007 14:49:31 +0000 (UTC)
From: espie@lain.home (Marc Espie)
Subject: Re: FAQ 6.11 Can I use Perl regular expressions to match balanced text?
Message-Id: <flavhr$31jp$1@biggoron.nerim.net>
In article <m7vl45-pe7.ln1@blue.stonehenge.com>,
PerlFAQ Server <brian@stonehenge.com> wrote:
>6.11: Can I use Perl regular expressions to match balanced text?
>
>
>
> Historically, Perl regular expressions were not capable of matching
> balanced text. As of more recent versions of perl including 5.6.1
> experimental features have been added that make it possible to do this.
> Look at the documentation for the (??{ }) construct in recent perlre
> manual pages to see an example of matching balanced parentheses. Be sure
> to take special notice of the warnings present in the manual before
> making use of this feature.
I've been using the following trick for many practical applications.
It helps to know why regexps cannot match balanced texts. Specifically,
normal regexps match rational languages, and rational languages cannot
count to an arbitrary number.
Balanced texts are algebraic languages, and they can be generated by
a grammar. The simplest example, with just the parentheses, would be:
D -> (D)D | <empty>
This is just one possible grammar, this one is non-ambiguous, which means
less combinatorial explosion later on.
However, one can use this grammar to build a good approximation of it as
a regular expression.
Specifically, set D0 = 0
then build Dn = (D_{n-1})D_{n-1} | empty
In perl terms:
$e = "";
for (1 .. n) {
$e = "(?:\($e\)$e)|";
}
then Dn is the rational language of all balanced expressions that do not
nest more than n open parentheses.
This can be used to build a regexp that matches all balanced expressions up
to an set level of nesting parentheses automatically. In many cases,
you don't have to go higher than n=15 or 20...
------------------------------
Date: Tue, 01 Jan 2008 09:37:55 -0800
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 6.11 Can I use Perl regular expressions to match balanced text?
Message-Id: <010120080937557778%brian.d.foy@gmail.com>
In article <flavhr$31jp$1@biggoron.nerim.net>, Marc Espie
<espie@lain.home> wrote:
> In article <m7vl45-pe7.ln1@blue.stonehenge.com>,
> PerlFAQ Server <brian@stonehenge.com> wrote:
> >6.11: Can I use Perl regular expressions to match balanced text?
> >
> >
> >
> > Historically, Perl regular expressions were not capable of matching
> > balanced text. As of more recent versions of perl including 5.6.1
> > experimental features have been added that make it possible to do this.
> > Look at the documentation for the (??{ }) construct in recent perlre
> > manual pages to see an example of matching balanced parentheses. Be sure
> > to take special notice of the warnings present in the manual before
> > making use of this feature.
>
> I've been using the following trick for many practical applications.
>
>
> It helps to know why regexps cannot match balanced texts.
That just changed with Perl 5.10, I think, with the recursive patterns,
so I'll need to update this answer. :)
------------------------------
Date: Tue, 1 Jan 2008 00:57:01 -0800 (PST)
From: Todd <xueweizhong@gmail.com>
Subject: Re: FAQ 6.16 How do I efficiently match many regular expressions at once?
Message-Id: <e3a70946-bcbe-4eca-ab38-20d1f154e7fb@h11g2000prf.googlegroups.com>
> @patterns = map { qr/\b$_\b/i } qw( foo bar baz );
>
> LINE: while( <> )
> {
> foreach $pattern ( @patterns )
> {
> print if /$pattern/i;
> next LINE;
> }
> }
>
This codes's execution flow is too tricky to be understandood. Is
there any intention here?
From my understanding, the codes snippet should be changed as
@patterns = map { qr/\b$_\b/i } qw( foo bar baz );
LINE: while( <> )
{
foreach $pattern ( @patterns )
{
if (/$pattern/) {
print;
next LINE;
}
}
}
}
-Todd
------------------------------
Date: Tue, 01 Jan 2008 09:43:14 -0800
From: brian d foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 6.16 How do I efficiently match many regular expressions at once?
Message-Id: <010120080943146893%brian.d.foy@gmail.com>
In article
<e3a70946-bcbe-4eca-ab38-20d1f154e7fb@h11g2000prf.googlegroups.com>,
Todd <xueweizhong@gmail.com> wrote:
> > @patterns = map { qr/\b$_\b/i } qw( foo bar baz );
> >
> > LINE: while( <> )
> > {
> > foreach $pattern ( @patterns )
> > {
> > print if /$pattern/i;
> > next LINE;
> > }
> > }
> >
>
> This codes's execution flow is too tricky to be understandood. Is
> there any intention here?
It looks like that part of the code was supposed to be the same as the
previous code.
Before you start assigning malice, just ask. :)
------------------------------
Date: Wed, 2 Jan 2008 13:48:09 -0800 (PST)
From: kwalike57 <karinwalike@comcast.net>
Subject: Re: How Do I Locate a value in a text file and evaluate it and then write out that line based on the value?
Message-Id: <078c1fd7-495b-4d66-9003-10f8bbc6fa8b@l6g2000prm.googlegroups.com>
On Dec 28 2007, 10:48=A0am, J=FCrgen Exner <jurge...@hotmail.com> wrote:
> On kwalike57 <karinwal...@comcast.net> wrote:
> >I need to use Perl to read through log output from a df -k command on
> >a Unix server, for each line in the log where the value for %Used is
> >greater than 60% I need to write that line of the log out to another
> >text file. =A0The header %Used is located on the line above the actual
> >value, like this:
>
> >%Used
> >60%
>
> Where's the problem? Loop through the file using a standard while(){}.
> When you find a line with a content that is eq()ual to '%Used' then read t=
he
> next line and check if the value is > 60.
>
> >How would I capture and evaluate only the %Used value and no other
> >values in that line?
>
> That depends on what that line actually contains.
> Standard answer: if you know the separator between values, then use split(=
),
> if you know the value then use m/(...)/.
>
> It is impossible to give more detailed suggestions without seeing the actu=
al
> data.
>
> >The 60% occurs first in the value line followed by a percent value for
> >inodes used.
>
> That is nice, but a vague verbal description of the data can only result i=
n
> a vague verbal description of the algorithm.
>
> jue
Hello.
Thanks for the note.
Here is additional information:
Sample file excerpt...
Filesystem 1024-blocks Free %Used Iused %Iused Mounted on
/dev/hd4 131072 38912 71% 4261 32% /
Filesystem 1024-blocks Free %Used Iused %Iused Mounted on
/dev/inputlv 255328256 118925432 54% 564 1% /IPW/input
=46rom this example, I want to evaluate the column labeled %Used for
values greater than 60% and if that value is greater than 60%, I then
want to write that entire line, (/dev/hd4 131072 38912
71% 4261 32% /
) out to a text file that will be emailed out to report on filesystems
that are now at a capacity of 60% or greater.
I already have the script written to create the original df -k output
to a text file and create the email generation. I just need to have
help evaluating the correct values in the original df -k output file
and then creating the new file containing entries of all filesystems
that are at or above 60% capacity.
Does this help clarify my question?
Thanks again,
Karin Walike
------------------------------
Date: Wed, 2 Jan 2008 13:48:55 -0800 (PST)
From: kwalike57 <karinwalike@comcast.net>
Subject: Re: How Do I Locate a value in a text file and evaluate it and then write out that line based on the value?
Message-Id: <c3642e23-ad50-489c-bfc2-16b00127a843@l6g2000prm.googlegroups.com>
On Dec 28 2007, 11:06=A0am, "John W. Krahn" <some...@example.com> wrote:
> kwalike57 wrote:
>
> > I need to use Perl to read through log output from a df -k command on
> > a Unix server, for each line in the log where the value for %Used is
> > greater than 60% I need to write that line of the log out to another
> > text file. =A0The header %Used is located on the line above the actual
> > value, like this:
>
> > %Used
> > 60%
>
> > How would I capture and evaluate only the %Used value and no other
> > values in that line?
>
> > The 60% occurs first in the value line followed by a percent value for
> > inodes used.
>
> open my $ph, '-|', 'df', '-k' or die "Cannot open pipe from 'df' $!";
>
> <$ph> =3D~ /%used?\b|\bused?%/i and my $pos =3D $-[0];
>
> /\A.{$pos}\s*(\d+)/ && $1 > 60 && print while <$ph>;
>
> close $ph or warn $! ? "Error closing 'df' pipe: $!"
> =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 : "Exit status $? from 'df'";
>
> John
> --
> Perl isn't a toolbox, but a small machine shop where you
> can special-order certain sorts of tools at low cost and
> in short order. =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0-- =
Larry Wall- Hide quoted text -
>
> - Show quoted text -
Hello.
Thanks for the note.
Here is additional information:
Sample file excerpt...
Filesystem 1024-blocks Free %Used Iused %Iused Mounted on
/dev/hd4 131072 38912 71% 4261 32% /
Filesystem 1024-blocks Free %Used Iused %Iused Mounted on
/dev/inputlv 255328256 118925432 54% 564 1% /IPW/input
=46rom this example, I want to evaluate the column labeled %Used for
values greater than 60% and if that value is greater than 60%, I then
want to write that entire line, (/dev/hd4 131072 38912
71% 4261 32% /
) out to a text file that will be emailed out to report on filesystems
that are now at a capacity of 60% or greater.
I already have the script written to create the original df -k output
to a text file and create the email generation. I just need to have
help evaluating the correct values in the original df -k output file
and then creating the new file containing entries of all filesystems
that are at or above 60% capacity.
Does this help clarify my question?
Thanks again,
Karin Walike
------------------------------
Date: Thu, 03 Jan 2008 01:02:04 GMT
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: How Do I Locate a value in a text file and evaluate it and then write out that line based on the value?
Message-Id: <slrnfnoc2u.ak9.tadmc@tadmc30.sbcglobal.net>
kwalike57 <karinwalike@comcast.net> wrote:
> I need to use Perl to read through log output from a df -k command on
> a Unix server, for each line in the log where the value for %Used is
> greater than 60% I need to write that line of the log out to another
> text file.
> How would I capture and evaluate only the %Used value and no other
> values in that line?
Match the first run of digits that is followed by a percent sign.
-------------------
#!/usr/bin/perl
use warnings;
use strict;
foreach ( qx/df -k/ ) {
print if /(\d+)%/ and $1 >= 60;
}
-------------------
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 1158
***************************************