Re: math module and array manipulation

2006-08-15 Thread David Greenberg

I'm sure there's an easier/better way of doing this, but in the interest of
simplicity, let's look at this approach:

First, a red flag goes up when you say that you have an array of 12
numbers.  Will it always be twelve?

The second red flag is that you are splitting the array into quarters based
on the fact that you need the calculations done for every three numbers.
Again, will this always be three?  Why?  More importantly, why are they not
already in separate lists/arrays?

Enough of that.  Here is a simple solution for splitting the arrays up:

use strict;
use Statistics::Lite
# Takes a reference to an array and returns a list of references to arrays.
sub arr_split {
 my @arr = @{shift(@_)};
 my @new_arr = ();


On 8/15/06, JupiterHost.Net [EMAIL PROTECTED] wrote:



I have an array contains 12 numbers. I want to
calculate the mean and standard deviation for very
three numbers. I just wonder which math module is
available to do the job.

Wonder no longer :) Find out for sure:

 http://search.cpane.org/



 I think you meant http://search.cpan.org.  :)

Indeed :)

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response





Re: Problem com var on a require...

2004-11-09 Thread David Greenberg
I don't want to begin to understand why you're doing this, but if you
make a.pl read:
#!/usr/bin/perl
$test = 'World!';
require 'b.def';
print $abacus;

it should work.  If you mean for b.def to define some standard
functionality, try defining subs in it instead.

-David


On Tue, 9 Nov 2004 17:48:36 -0200, Jair V. B. Junior [EMAIL PROTECTED] wrote:
 Hi all, here comes a little confusing question :-)
 
 a.pl:
 #!/usr/bin/perl
 
 require 'b.def';
 $test = 'World!';
 print $abacus;
 
 b.def:
 $abacus = Hello $test;
 
 When I run it:
 $ perl a.pl
 Hello
 
 Why is this going wrong?
 
 Thanks!
 
 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Passing shell variables to PERL

2004-10-05 Thread David Greenberg
$ENV{ABC}

This works for me, but I don't have a good understanding of what is
going on to make it work.

HTH,
David

On Tue, 5 Oct 2004 14:32:27 -0400, Willy Perez [EMAIL PROTECTED] wrote:
 
 Hi,
 
 Is there a method to pass a shell assigned variable to perl?
 
 For ex:
 
 ABC=xyc
 
 perl -ne 'print $ABC'
 
 In awk you could use ENVIRON[varname], is there something
 compatible in perl.
 
 
 Willy Perez
 Liz Claiborne IT
 (201) 295-7011
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: String to Numeric of an Array

2004-09-14 Thread David Greenberg
In a few circumstances, such as binding parameters to a database, you
may need to do this, but on the whole, as everyone else has pointed
out, Perl will do this for you.

If you are using this for one of those few cases, you can change them
explicitly like this:
@array = ('1','2','3');
@arrayNum = map { $_ + 0 } (@array);

This maps every value in @array to its numeric equivalent because it
is used in an addition operation.  The values are pushed into
@arrayNum for later use.

This is a hack, so only use it if you need to.  In most cases, just
let Perl do it for you.

-David


On Tue, 14 Sep 2004 11:02:13 -0300, Shaw, Matthew [EMAIL PROTECTED] wrote:
 Edward:
 
 What you have there is an array with only one scalar element (an array
 reference containing 3 values). Note that $array[1]  $array[2] would be
 undefined in your example. I think what you intended was to do:
 
 @array = ('1','2','3'); # An array containing three elements, '1', '2',
 '3'
 (Or more simply: @array = (1..3); )
 
 With regards to switching between string  numeric values, perl will do
 this automagically for you. You can just perform whatever math you want
 as per normal. Consider the following:
 
 @array = ( '1', '2', '3');
 print $array[0] + 1;
 
 Output: 2
 
 Hope this helps.
 
 Matt Shaw
 http://www.thinktechnology.ca/
 
  -Original Message-
  From: Edward WIJAYA [mailto:[EMAIL PROTECTED]
  Sent: Tuesday, September 14, 2004 10:12 PM
  To: [EMAIL PROTECTED]
  Subject: String to Numeric of an Array
 
  Hi,
 
  How can I change the value of this array:
 
  @array = ['1','2','3']; #which contain string numeric
 
  to
 
  @arrayNum = [1,2,3];  #as pure numeric
  
  Regards,
  Edward WIJAY
 
  --
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  http://learn.perl.org/ http://learn.perl.org/first-response
 
 
 
 
 
 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: How to dynamically taking the multiple input arguments?

2004-09-10 Thread David Greenberg
foreach( @ARGV ) {
   open IN, $_ or die Couldn't open $_: $!\n;
   chomp( my @data = IN );
   close IN;
   foreach( @data ) { s/\s+//g; }
   foreach( 0..$#data ) { $results[$_] .= $data[$_]; }
}
This is a little shorter and saves on iterations:
for my $file (@ARGV) {
 open IN, $file or die Couldn't open $file: $!\n;
 @results = map { my $line = $_; chomp $line; $line =~ s/\s+//g;
$line } (IN);
 close IN;
}

-David

On Fri, 10 Sep 2004 11:35:09 -0500, Errin Larsen [EMAIL PROTECTED] wrote:
 Here ya go ... this works for me.  I tested it with up to 5 input
 files and it was still workin'.  It does have a bug, though.  It
 doesn't check whether all the input files are the same length.  Nor
 did I test what happens when they AREN'T the same length.  Let me know
 what ya think:
 
 #!/usr/bin/perl
 
 use warnings;
 use strict;
 
 unless( @ARGV = 2 ) { die Usage: $0 file1 file2 [file3...]\n; }
 
 my @results;
 
 foreach( @ARGV ) {
 open IN, $_ or die Couldn't open $_: $!\n;
 chomp( my @data = IN );
 close IN;
 foreach( @data ) { s/\s+//g; }
 foreach( 0..$#data ) { $results[$_] .= $data[$_]; }
 }
 
 foreach( @results ) { print $_\n; }
 
 
 
 --Errin
 
 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: How to dynamically taking the multiple input arguments?

2004-09-10 Thread David Greenberg
I'm no expert, but chomp won't give you what you think it will:
my @arr = ('a', b\n, c\n);
print join (,,chomp (@arr));

This will print:
2

while this:
my @arr = ('a', b\n, c\n);
chomp (@arr);
print join (,,@arr);

will print:
a,b,c

Map will run whatever is in the code block (between the {}'s) on every
value in the list passed to it (between the ()'s).  The last statement
in the code block is like a return value.  Map builds the results list
out of all of the return values.  With a foreach loop, it would be:
my @results = ();
foreach (IN) {
 my $line = $_;
 chomp $line;
 $line =~ s/\s+//g;
 push (@results, $line); #appends $line to the @results list
}

Hope this helps.

-David

On Fri, 10 Sep 2004 11:58:30 -0500, Errin Larsen [EMAIL PROTECTED] wrote:
 On Fri, 10 Sep 2004 12:44:51 -0400, David Greenberg
 [EMAIL PROTECTED] wrote:
  foreach( @ARGV ) {
 open IN, $_ or die Couldn't open $_: $!\n;
 chomp( my @data = IN );
 close IN;
 foreach( @data ) { s/\s+//g; }
 foreach( 0..$#data ) { $results[$_] .= $data[$_]; }
  }
  This is a little shorter and saves on iterations:
  for my $file (@ARGV) {
   open IN, $file or die Couldn't open $file: $!\n;
   @results = map { my $line = $_; chomp $line; $line =~ s/\s+//g;
  $line } (IN);
   close IN;
  }
 
  -David
 
 
 Can you throw the 'chomp' in the assignment in that 'map' statement?
 Then, can you also throw in the substitution in the mix?  like this:
   @results = map{ my $line = chomp(  s/\s+//g ); } ( IN );
 
 And if so, why not this:
 
   @results = map{ chomp( s/\s+//g ) } ( IN );
 
 As long as we're playing Perl-Golf!!
 
 I truly don't understand what 'map' is doing.  Can you explain it to
 me?  I have tried to read perldoc -f map but it's a little weird and
 hard to follow!
 
 --Errin


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: How to dynamically taking the multiple input arguments?

2004-09-10 Thread David Greenberg
Opps, I missed that.  Instead of:
@results = map { my $line = $_; chomp $line; $line =~ s/\s+//g; $line } (@data);
try:
my @newresults = map { my $line = $_; chomp $line; $line =~ s/\s+//g;
shift (@results) . $line } (@data);
@results = @newresults;

-David

On Fri, 10 Sep 2004 13:40:04 -0500, Errin Larsen [EMAIL PROTECTED] wrote:
 On Sat, 11 Sep 2004 02:20:32 +0800, Bee [EMAIL PROTECTED] wrote:
 
 
   foreach( @ARGV ) {
  open IN, $_ or die Couldn't open $_: $!\n;
  chomp( my @data = IN );
  close IN;
  foreach( @data ) { s/\s+//g; }
  foreach( 0..$#data ) { $results[$_] .= $data[$_]; }
   }
   This is a little shorter and saves on iterations:
   for my $file (@ARGV) {
open IN, $file or die Couldn't open $file: $!\n;
@results = map { my $line = $_; chomp $line; $line =~ s/\s+//g;
 
  @results seems would be re-assigned when the next file comes...
 
  Besides, I guess chomp is not nesessary here.. \s+ means [\t\r\n\f]+,
  so \r, \n or \r\n would seem to be cleared by the s expression.
 
   $line } (IN);
close IN;
   }
  
 
  I would suggest to write in this way :
  my @res = ();
  foreach( @ARGV ) {
 open IN, $_ or die Couldn't open $_: $!\n;
 my @data = IN;
 close IN;
 
  s/\s+//g  for @data;
  @res = ( @res, @data );
  }
 
  Code not been tested, but the concept is something like this.
  HTH
 
 
 
 Ok ... Thanks for helpin' out, HTH!  I tried out your suggestions and
 now the code looks like this:
 
 #!/usr/bin/perl
 use warnings;
 use strict;
 
 unless( @ARGV = 2 ) { die Usage: $0 file1 file2 [file3...]\n; }
 
 my @results = ();
 foreach my $file ( @ARGV ) {
 open IN, $file or die Couldn't open $file: $!\n;
 my @data = IN;
 close IN;
 s/\s+//g  foreach( @data );
 @results = ( @results, @data );
 }
 
 foreach( @results ) { print $_\n; }
 
 But now the output is as follows.  We want the output to look like this:
   OneFirst
   TwoSecond
   ThreeThird
 But instead, it's coming out like this:
One
Two
Three
First
Second
Third
 Given the two test input files:
 file1:   file2:
 OneFirst
 TwoSecond
 Three  Third
 
 --Errin


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: How to dynamically taking the multiple input arguments?

2004-09-10 Thread David Greenberg
I'm not sure if shift (@results) . $line; and shift @results . $line
would work differently.  It depends on whether the order of operations
gives precedence to . or to handing an argument to a function.  My
guess is that . gets precedence, in which case shift @results . $line;
will give you something weird that you don't want.

I suggest you look up the perldocs on shift, but basically if you have
any array, like:
my @arr = ('a', 'b', 'c');

the result of:
print shift (@arr);

will be:
a

and @arr will now only be:
('b', 'c')

In other words, it takes the first element off of the array.  It is
often used to get arguments to a function:
sub foo {
 my $arg1 = shift;
 my $arg2 = shift;
 print $arg1 .   . $arg2;
}
foo (hello, world);

would print:
hello world

So, shift (@results) . $line; is taking the next value from @results
and appending $line to it.
That value will then be the next value in @newresults.

It takes a bit of getting used to.  I suggest reading a little about
functional programming to fully grasp the list manipulation functions
like map, grep, split, join, etc.

-David


On Fri, 10 Sep 2004 14:37:28 -0500, Errin Larsen [EMAIL PROTECTED] wrote:
 On Fri, 10 Sep 2004 15:01:34 -0400, David Greenberg
 [EMAIL PROTECTED] wrote:
  Opps, I missed that.  Instead of:
  @results = map { my $line = $_; chomp $line; $line =~ s/\s+//g; $line } (@data);
  try:
  my @newresults = map { my $line = $_; chomp $line; $line =~ s/\s+//g;
  shift (@results) . $line } (@data);
  @results = @newresults;
 
  -David
 
 
 Ok ... please forgive my n00b-ness, but can you help me understand a
 couple of things here.  This part:
 
shift (@results) . $line
 
 Is it the same as:
 
shift @results . $line
 
 I'm thinking no.  But I don't know what the difference is.  I also
 don't understand what exactly that shift is doing, but if I understand
 the difference with the parens maybe It'll start to make more sense to
 me.
 
 --Errin


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Loading an array

2004-09-01 Thread David Greenberg
I'm no expert, but if I were to do what it looks like you are trying
to do, I would use the following code:

my @ArrayofInputHex = map { hex($_) }  @ArrayofInput;
my @ArrayofCompareHex = map { hex($_) } @ArrayofCompare;

One of the main benefits of this code is that when you use strict;
like you should, you don't have to worry about local variables inside
the loop.

Hope this helps,
David

On Wed, 1 Sep 2004 12:46:57 -0700, Shawn Sharp [EMAIL PROTECTED] wrote:
 I need some help, I am running this code to load values into the
 $ArrayofCompareHex [$g] array.  Currently it is not working.  The
 $comparevalue gets the correct value but the value is not past into the
 array.  Here is a portion of my code.  Any ideas
 
 230 my $g =0;
 
 231 for ($g = 0; $g  $mps; ++$g)
 
 {
 
 239 $value = hex($ArrayofInput [$g]);
 
 240 $ArrayofInputHex [$g] = $value;
 
 241 $comparevalue = hex($ArrayofCompare [$g]);
 
 242 $ArrayofCompareHex [$g] =$comparevalue;
 
 }
 
 thanks in advance
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Is my DB code bad?

2004-09-01 Thread David Greenberg
On Wed, 1 Sep 2004 15:42:16 -0500, Dave Kettmann [EMAIL PROTECTED] wrote:
 First off, Thanks to Jenda and Wiggins for their quick response. I have found the 
 answer to my question in Jenda's help (the missing ''s)
 

I strongly suggest you take Jenda's advice about using placeholders
instead.  Say the value for $user is:
' OR user_name LIKE '%'--

My SQL may be a little off, but in general, this or something like it
could then change your delete statement to delete everything from your
table.  Even if only a few people are accessing it, there is always
the possibility that one of them will enter a single quote into the
text box and cause unexpected behavior.

I'll stop my rant here.  Use this information as you wish.

-David

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Sed-type-function

2004-08-23 Thread David Greenberg
$str =~ s/Auth.notice: //;
$str =~ s/\[[\]]*\]//;

print $str;

I'm not sure if there's a way to put it all in one line, but this
should do it nonetheless.

-David

On Mon, 23 Aug 2004 14:31:01 -0500, Dave Kettmann
[EMAIL PROTECTED] wrote:
 Ok ... I'm going to try to confuse everyone again because either a) I'm dense or b) 
 I'm asking the wrong question. Everyone can agree with option a, and I will not get 
 mad :). Ok .. here goes again...
 
 I looked at s2p and it spit out 2 pages of perl code of which the sed command was a 
 small bit of code. It is nothing major that I want to do an example is below:
 
 I want this ...:
 
 Aug 23 14:28:32 Auth.notice: (Access-Request 10.10.116.4 166 000611-011c0c): Login 
 OK [000611-011c0c]
 
 To be this ...:
 Aug 23 14:25:32 (Access-Request 10.10.116.4 166 000611-011c0c): Login OK
 
 Or to make it easier, I want to take out the 'Auth.notice: ' and anything encased in 
 []'s.
 
 I dont know if im confusing things more, or if I was pointed in the right direction 
 and I just dont understand. Someone please help this poor confused person figure out 
 WTH he is doing wrong :-D
 
 Dave Ketmmann
 NetLogic
 636-561-0680
 
 
 
 -Original Message-
 From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
 Sent: Monday, August 23, 2004 11:04 AM
 To: Dave Kettmann
 Cc: Perl List (E-mail)
 Subject: RE: Sed-type-function
 
  Hmm .. wonder why I didnt see that in any of the books i looked at. Ok
 off I go then, Thanks for the help! Sorry to  confuse you guys :)
 
  Dave
 
 start here -
 perldoc perlop (or
 http://www.perldoc.com/perl5.8.4/pod/perlop.html#Regexp-Quote-Like-Operators)
 and
 perldoc perlretut ( or http://www.perldoc.com/perl5.8.4/pod/perlretut.html)
 
 Jeff
 
  I guess and easy syntax for search and replace similar to:
 
  s/this/that/g ...
 
 Perl has that, you can use exactly the same syntax -- s/search/replace/g
 
 hth
 Jeff
 
  Guess I will look at the s2p you mentioned as well.
  Dave
 
 -Original Message-
 From: Randy W. Sims [mailto:[EMAIL PROTECTED]
 Sent: Monday, August 23, 2004 10:39 AM
 To: Dave Kettmann
 Cc: Perl List (E-mail)
 Subject: Re: Sed-type-function
 
 Dave Kettmann wrote:
  List,
 
  Does perl have any built-in sed-like function? I found ASED.pm, but would
 rather go with something built in. I looked around a bit, but didnt find
 anything. I guess I could go with using the Shell module but would rather
 using as few modules as possible.
 
 I'm not sure what you mean by sed-like function. Perl can do anything
 sed can do. There is also a script that converts sed to perl, see
 `perldoc s2p`
 
 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response
 
 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response
 
 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: date calculations

2004-08-17 Thread David Greenberg
Date::Manip from CPAN

-David

On Tue, 17 Aug 2004 12:50:16 -0400, [EMAIL PROTECTED]
[EMAIL PROTECTED] wrote:
 All,
 
 If I wanted to subtract 1 from a date on the 1st of any month what module
 will reflect the correct date?  For example, system time is 09.01.04 and I
 want data from 08.31.04, I would have to subtract 1 day.  Which module do
 I need to install?
 
 thanks,
 derek


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: globals

2004-08-17 Thread David Greenberg
If you really want to use a BAD method, which you should NOT use:
while (...) {
 $total = $row[0];
 ...
}
print $total . \n;

What you SHOULD do is:
use strict;
...
my $total = ;
while (...) {
 $total = $row[0];
 ...
}
print $total . \n;


-David

On Tue, 17 Aug 2004 10:55:25 -0600, Wiggins d Anconia
[EMAIL PROTECTED] wrote:
  After searching through the Perl Bookshelf CD, I have found that you can
  declare a global and then use local() to change that value for a block
  of code. I haven't found how to use a value from within a block of code
  outside that block of code though. Is this possible? I'm sure I just
  don't know what to search for in the bookshelf.
 
  EXAMPLE:
  
  while (my(@row) = $sth1-fetchrow_array)
  {
  my ($total) = $row[0];
  print Total Scanned:\t $total\n;
  }
 
  print Total:\t $total\n;
 
 
 Essentially you need to declare the variable at the proper scope level.
 So in this example, you need to declare $total outside of the loop,
 
 my $total = 0;
 
 For instance. For much more and a very good coverage of scoping, check out:
 
 http://perl.plover.com/FAQs/Namespaces.html
 
 http://danconia.org
 
 
 
 
 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Sending Email

2004-08-16 Thread David Greenberg
Mail::Send and Mail::Mailer are a couple, though I'm sure there are others.

-David

On Mon, 16 Aug 2004 09:00:33 -0700, Fontenot, Paul
[EMAIL PROTECTED] wrote:
 I'm in need of a way to send the output of a script from a windows
 server via email and I'm drawing a blank. What is the module called?
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Translate sed / Perl

2004-08-13 Thread David Greenberg
Hi Errin,

Try something like this:

#!/usr/bin/perl
use strict;
my $file = 'filename';
open FH $fh;
my $text = ;
while (my $line = FH and $line !~ /System Temperatures/) {}
while (my $line = FH and $line !~ /==*/) { $text .= $line; }
print $text;

__END__

It may not be elegant, but it should work.
-David


On Fri, 13 Aug 2004 08:19:43 -0500, Errin Larsen [EMAIL PROTECTED] wrote:
 Hey guys (and gals, I imagine!),
 
 I'm really new to perl. I've been working through some beginners
 tutorials and now I need (want!) to use perl to overhaul something I
 wrote in the past.  I've got a script (in bash) that I use that has a
 particular sed command in it.  The command is as follows:
 
  sed -n '/System Temperatures/,/==*/p' FILENAME
 
 The file in question has text that looks like this:
 
 BEGIN FILE SAMPLE
 No failures found in System
 ===
 
 = Environmental Status =
 
 System Temperatures (Celsius):
 ---
 Device  Temperature Status
 ---
 CPU0 65 OK
 CPU1 63 OK
 CPU2 64 OK
 CPU3 63 OK
 MB   35 OK
 IOB  30 OK
 DBP0 32 OK
 
 =
 
 Front Status Panel:
 ---
 Keyswitch position: NORMAL
 
 END FILE SAMPLE
 
 (obviously, this is output from the Sun Solaris' prtdiag -v command!)
 
 I want to collect just the temperature data from this file, so I use
 the above sed command to pull out only the lines:
 
 BEGIN SAMPLE
 System Temperatures (Celsius):
 ---
 Device  Temperature Status
 ---
 CPU0 65 OK
 CPU1 63 OK
 CPU2 64 OK
 CPU3 63 OK
 MB   35 OK
 IOB  30 OK
 DBP0 32 OK
 
 =
 END SAMPLE
 
 What I'm looking for is a graceful way to do this in a perl script.
 I'm kinda at a loss for where to begin.  Can you help me out?
 
 Thanks,
 
 --Errin Larsen
 
 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Here is the URL for Beginning Perl

2004-08-13 Thread David Greenberg
 
 I am sure the server is running, but typing in the ip address keeps
 getting me a connection refused message. Hence, I think somewhere I need
 to make myself an acceptable client.
 
Can you ping 127.0.0.1 or access ftp through that IP.  If so, it
probably is an http configuration.  If not, it has something to do
with the network settings of the machine.  What is the output of
`ifconfig` (UNIX/LINUX) or `ipconfig` (Windows)?
-David

On Fri, 13 Aug 2004 09:18:08 -0400, hcohen2 [EMAIL PROTECTED] wrote:
 Chris Devers wrote:
 
  OK, my problem is that the attempt to connect using 127.0.0.1 gets a
  message something like connection refused by the server.
 
  Is there some location in the httpd.conf file to list an acceptable
  client?
 
 
  Is the web server running on your desktop? Yes or no?
 
 Yes, it's on this machine I am writing from.
 
 
 
  If it's on a different computer, than the address 127.0.0.1 will never
  work, because all communication to 127.0.0.1/localhost stays on the
  computer that the communication originated from.
 
  If it's on a different computer, you need to figure out what the
  server's real address is. It is not  never will be 127.0.0.1.
 
 When I finish rebuilding one of my machines that I intend to use as a
 server (perhaps for an intranet) this might become an issue. But not
 right now.
 
 
 
  If it's on the computer you're using, that's a different matter, and
  we can go over that, but it sounds to me like you're using a bad address.
 
 
 I am sure the server is running, but typing in the ip address keeps
 getting me a connection refused message. Hence, I think somewhere I need
 to make myself an acceptable client.
 
 
 
 
 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: awk like question

2004-08-13 Thread David Greenberg
#!/usr/bin/perl
use strict;
open FH filename.txt;
my %myhash = ();
while (my $line = FH) {
  if ($line =~ /(\S+)\s+(\S+)\s+\S+.*/) {
$myhash{$1} = $2;
  }
}
...
__END__

-David

On Fri, 13 Aug 2004 12:05:16 -0500, Errin Larsen [EMAIL PROTECTED] wrote:
 ok.  I'm not getting my question across clearly.  Let me try again.
 
 I have a collection of data in a text file.  Here is an example:
 
 ## foobar.txt ##
 one  two  three
 A B C
 yes  nomaybe
 
 In a script (not on the command line) I want to be able to parse this
 data so that the first two elements in each line of the file end up in
 a hash as a key/value pair.  If I was to declare this hash I'm
 refering to in a perl script in a literal context, I imagine it would
 look like this, given the above text file:
 
 my %myhash = ( one=two, A=B, yes=no );
 
 Perhaps I'm wrong (I am rather new to this Perl stuff!).  However, I
 do not want to declare it literally, I want to parse the file to
 create that hash.  The code to parse the file, extract the first two
 elements of each line of that file and create a hash of key/value
 pairs using those first two elements is what I would like to know how
 to do!
 
 Thx!
 
 --Errin
 
 
 
 
 On 13 Aug 2004 16:57:00 +0100, Jose Alves de Castro [EMAIL PROTECTED] wrote:
  On Fri, 2004-08-13 at 16:51, Errin Larsen wrote:
   um, can anyone explain the 'print' function below to me?
  
   specifically ... this:
  
 'print @F[0,5]'
 
  The -a signal splits the input lines and stores the resulting elements
  in @F
 
  Example:
 
  perl -nae 'print $F[1]\n' file.txt
 
  where file.txt contains
 
  one two three
  four five six
 
  prints:
 
  two
  five
 
  Also, although this splitting on spaces, you can also use the -F signal
  to define what you're splitting in.
 
  See `perldoc perlrun`
 
  HTH,
 
  jac
 
  PS:
 
  Oh, print @F[0,5], of course, prints the first six elements of @F, and
  since they're between double quotes, they're joined with whatever is in
  $ (usually a space)
 
 
 
   How do I use this idea in a script instead of a command line?  also,
   how is the input getting into this function?  I mean, I understand $_
   and all, but on a command line, are we piping to that command?  what's
   with the '@F'?
  
   Thanks for the help!
  
   --Errin
  
  
   On Fri, 13 Aug 2004 09:52:04 -0400, [EMAIL PROTECTED]
   [EMAIL PROTECTED] wrote:
Thanks too all who passed some knowledge on, but I ended up using :
   
 while (D) {
   
## look for 9840S and ebexpire
## declare OFS = tab
## tell split to split on IRS 0,15. very similar to awk
print $
   
if (($_ =~ /9840S/)  ($_ =~ /ebexpire, ebexpire/ )) {
 local $, = \t;
print FOO +(split)[0,1,5], $/;
#print +(split)[0,1,5], $/;
   
Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams
614-566-4145
   
John W. Krahn [EMAIL PROTECTED]
08/13/2004 08:51 AM
   
To: Perl Beginners [EMAIL PROTECTED]
cc:
Subject:Re: awk like question
   
[EMAIL PROTECTED] wrote:
 All,
   
Hello,
   
 wasn't sure if this was received b/c I got a reurne to sender error..


 How can I print certain fields delimited by ' '?
 In awk I would write awk '{print $1, $6}' filename
   
The Perl equivalent of that is:
   
perl -lane 'print @F[0,5]'
   
 Here is an out file that I want to grab data from :

 04/29/04 11:00:28 [  6687:ebexpire, [EMAIL PROTECTED] E00796   9840S  537
   
 2B0234233543E6A4
 04/29/04 11:00:28 [  6687:ebexpire, [EMAIL PROTECTED] E00830   9840S  571
   
 D402325A8345ABDE
 04/29/04 11:00:28 [  6687:ebexpire, [EMAIL PROTECTED] E00066   9840S  127
   
 5202333193B75CBB
 04/29/04 11:00:28 [  6687:ebexpire, [EMAIL PROTECTED] E00501   9840S  168
   
 4B0233BABA5813F6

 I want fields one two and six or the date, time and E string.
 Does it matter whether I use a foreach or a while (filehandle)  ?
   
You could write that in Perl as:
   
perl -lane 'print @F[0,1,5]'
   
John
--
use Perl;
program
fulfillment
   
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response
   
   
  --
  José Alves de Castro [EMAIL PROTECTED]
http://natura.di.uminho.pt/~jac
 
 
 
 
 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response
 


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response