Re: Reading a directory and Renaming the file

2003-10-30 Thread Sudarshan Raghavan
James Parsons wrote:

Hi all 

I've this Perl script to read all  files in a directory and if it finds a
file with a certain then rename  the file to header, but is doesn't search
the right directory and doesn't even look for the HPAY header.
Ops  forgot to include the script.

#!/usr/bin/perl -w

use strict;

my $dir = "/interfaces/tdbank/test/";

opendir DIR, $dir;

You must always check opendir's return value.

my @files = readdir DIR;

Here is your problem, readdir returns only the filenames not the entire 
path. i.e. You must prepend $dir to these returned filenames or chdir to 
$dir to be able to access these files. One other option is to use the 
glob operator, this will give you the full pathnames.

my @files = <$dir/*>;

my %hash = ('HPAY' => 'file1' ,

   'HRET' => 'file2');



for (my $i=0; $i

You are used to C style coding, you can just write the loop construct as
for my $file (@files) {
#$file contains the filename
 open FILE,"$files[$i]" || die "Unable to open file $files[$i] because
$!\n"; 
 my $header = ;

 print "header -->" , $header, "\n";

When you read in a line from a file, the newline comes along with it 
(actually $/ comes along with it, this variable is set to newline by 
default. perldoc perlvar). You must chomp of $/ (newline) before using 
it in this case as your hash keys don't have newlines in them.
chomp ($header);

 close FILE;

Maybe you should add a check here to see if the header is actually a 
valid key in the hash
if (exists ($hash{$header})) {

#Perform your mv operation if this condition is true

 my $command = "mv $files[$i] $hash{$header}";

 print "command -->", $command, "\n";

 system $command;

Make sure to check $? for the exit status of $command.
perldoc -f system
}

And I get the following Errors:



   
Use of uninitialized value in concatenation (.) or string at ./process_f
iles.sh line 14.

command -->mv ..

Usage: mv [-i | -f]  [--] src target

  or: mv [-i | -f]  [--] src1 ... srcN directory

readline() on closed filehandle FILE at ./process_files.sh line 11. 
Use of uninitialized value in print at ./process_files.sh line 12.  
header -->

Use of uninitialized value in hash element at ./process_files.sh line 14
.
Use of uninitialized value in concatenation (.) or string at
./process_files.sh line 14.
command -->mv file1

Usage: mv [-i | -f]  [--] src target

  or: mv [-i | -f]  [--] src1 ... srcN directory

readline() on closed filehandle FILE at ./process_files.sh line 11. 
Use of uninitialized value in print at ./process_files.sh line 12.  
header -->

Use of uninitialized value in hash element at ./process_files.sh line 14
.
Use of uninitialized value in concatenation (.) or string at
./process_files.sh line 14.
command -->mv file2

Usage: mv [-i | -f]  [--] src target

  or: mv [-i | -f]  [--] src1 ... srcN directory

etrprodftp /usr/local/sbin



Any help would be great..

James Parsons.



 



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Splitting OR Regex

2003-10-30 Thread Scott, Joshua
Hello,

How can I split the data in a line by a single whitespace but also keep
portions between quotes together?  Here is an example of a line of data I'm
trying to parse:

id=firewall time="2003-10-30 04:15:01" fw=66.74.67.229 pri=5 c=256 m=38
msg="ICMP packet dropped" n=63211 src=1.1.1.1 dst=2.2.2.2

What I would like to do is keep the data between the quotes together despite
the spaces.  This is what I'm expecting to get:

Id=firewall
Time="2003-10-30 04:15:01"
Fw=66.74.67.229
Msg="ICMP packet dropped"
...etc

How should I go about doing this?  What I have currently is a regex that
splits out the entire line, but certain fields have changed so my original
code doesn't work as well.

Thank you very much!

Joshua Scott

==
NOTICE - This communication may contain confidential and privileged 
information that is for the sole use of the intended recipient. Any viewing,
copying or distribution of, or reliance on this message by unintended
recipients is strictly prohibited. If you have received this message in
error, please notify us immediately by replying to the message and deleting
it from your computer.

==


watch out for virus masquerading as Microsoft

2003-10-30 Thread Art Mahanna
Since I subscribed to this forum this afternoon I've received four separate
emails containing the [EMAIL PROTECTED] virus.  This email arrives masquerading
as a Microsoft public service, supposedly containing patches for Outlook.
As Microsoft has stated, they DO NOT send patches through email.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Image conversion modules?

2003-10-30 Thread Daniel Staal
Could someone recommend a good image file conversion/manipulation 
module?  I'm having trouble finding one that actually works...

Here are my requirements:
*Must run under Mac OS X (10.3, but if it tested to earlier it should 
be fine.)
*Must handle the following image formats: TIFF, PNG.
*Must be able to handle alpha channels.

Would be nice to haves are:
*Handle PDF, JPEG, GIF, PICT, BMP.
*Can do affine transformations.
I've tried Imager (Mac does not compile to needed formats) 
Image::Imlib2 (Does not compile on Mac) and Image::Magick (Won't 
install on Mac.)

I'm currently using ImageMagick directly, but it won't handle TIFF 
files on Mac.  If I can get something to convert them into something 
ImageMagick *can* handle then I can use it to do the rest.  Something 
that can handle alpha channels in PDF files would be good too. 
(ImageMagick won't.)

Any ideas?  I'm willing to do Mac-specific, if someone has a good way 
to access the QuickTime/Quartz API's through Perl.

(Oh, and Panther's 'sips' command-line program doesn't handle alpha 
channels.)

Any ideas?

Daniel T. Staal

---
This email copyright the author.  Unless otherwise noted, you
are expressly allowed to retransmit, quote, or otherwise use
the contents for non-commercial purposes.  This copyright will
expire 5 years after the author's death, or in 30 years,
whichever is longer, unless such a period is in excess of
local copyright law.
---
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: complex condition

2003-10-30 Thread LoBue, Mark
> -Original Message-
> From: Steve Gilbert [mailto:[EMAIL PROTECTED]
> Sent: Thursday, October 30, 2003 9:08 AM
> To: [EMAIL PROTECTED]
> Subject: complex condition
> 
> 
> I know there must be a way to do the following:
> 
> if (($foobar > 3) || ($foo="t" && $bar = "b")) {print
> "yup"}
> 
> Of course this is wrong, but what I want is to print
> yup if $foobar >3 or $foo=t and $bar=b.
> 
> so:
> $foobar=4 $foo=a $bar=b is true
> $foobar=1 $foo=f $bar=b is true

Barring your problem of using = instead of eq, how is this one true?  
$foo has to be "t" and $bar has to be "b"
   OR
$foobar has to be greater than 3 (it is 1).

Both sides of that OR are false.

-Mark

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Data::Dumper->dump()ing a hash?

2003-10-30 Thread Kevin Old
On Thu, 2003-10-30 at 18:09, Kevin Pfeiffer wrote:
> In article <[EMAIL PROTECTED]>, Kevin Old
> wrote:
> [...]
> > my %entry;
> > 
> > $entry{"genre"} = "Rock";
> > $entry{"artist"} = "3 Doors Down";
> > $entry{"album"} = "Away from the Sun";
> > $entry{"disc"} = "Away from the Sun";
> > $entry{"file"} = "3dd.mp3";
> > $entry{"fullpath"} = "/mp3s/3dd";
> >  $Data::Dumper::Purity = 1;
> > print Data::Dumper->Dump( [\%entry], [ '*entry' ] );
> > #my $dumpedvalues = $dumper->Dump();
> > #print $dumpedvalues . "\n";
> > 
> > 
> > ***OUTPUT***
> > 
> > %entry = (
> >'album' => 'Away from the Sun',
> >'artist' => '3 Doors Down',
> >'fullpath' => '/mp3s/3dd',
> >'file' => '3dd.mp3',
> >'disc' => 'Away from the Sun',
> >'genre' => 'Rock'
> >  );
> > 
> 
> Hi Kevin,
> 
> This was interesting! I see what the difference is between your example and
> "Dumper(\%entry)", but I wish I also understood what the man page says
> about this:
> 
> 
>  In the extended usage form, the references to be dumped can be given
> user-specified names.  If a name begins with a "*", the output will
> describe the dereferenced type of the supplied reference for hashes and
> arrays, and coderefs.
> 
> 
> The 1st sentence I understand, but not "the dereferenced type of the
> supplied reference."
> 
> I just tried this without the asterisk and get "$entry" instead of "%entry"
> (or "$VAR1" using the plain procedure).
> 
> So in plain(er) English that means: if the name begins with an "*", the
> output type will match that of the referenced variable"?
> 
> -K
> -- 
> Kevin Pfeiffer

Kevin,

Yeah, I guess that's it.  I'm not really sure how it works (yet), but I
got it from Programming Perl.  Here's that whole subsection:


9.7 Saving Data Structures
If you want to save your data structures for use by another program
later, there are many ways to do it. The easiest way is to use Perl's
Data::Dumper module, which turns a (possibly self-referential) data
structure into a string that can be saved externally and later
reconstituted with eval or do.


use Data::Dumper;
$Data::Dumper::Purity = 1;   # since %TV is self-referential
open (FILE, "> tvinfo.perldata") or die "can't open tvinfo: $!";
print FILE Data::Dumper->Dump([\%TV], ['*TV']);
close FILE   or die "can't close tvinfo: $!";

A separate program (or the same program) can then read in the file
later:


open (FILE, "< tvinfo.perldata") or die "can't open tvinfo: $!";
undef $/;# read in file all at once
eval ; # recreate %TV
die "can't recreate tv data from tvinfo.perldata: $@" if $@;
close FILE   or die "can't close tvinfo: $!";
print $TV{simpsons}{members}[2]{age};

or simply:


do "tvinfo.perldata"or die "can't recreate tvinfo: $! $@";
print $TV{simpsons}{members}[2]{age};

Many other solutions are available, with storage formats ranging from
packed binary (very fast) to XML (very interoperable). Check out a CPAN
mirror near you today!


Maybe one of the Perl Gods can explain ithope this helps, though.

Kevin

-- 
Kevin Old <[EMAIL PROTECTED]>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Face lift survey

2003-10-30 Thread Dan Muey
Here's a thought I'd like to get opinions on...

A recent post that talked about a php calendar script got me thinking.
One thing that draws people who don't know better to PHP over Perl is
that the php scripts they can get look really really nice, phpbb, for instance.
Those developers have spent much time in making it look very nice which is good.

The thing is that most people don't take the time to realize that it's not PHP 
that makes it look so nice it's the html/css/styles/images that make it so cool 
looking. But since it looks so cool it must be the best right? That's how Windows 
got it's place, by looking cool when everything else was ugly cli. (it sure 
wasn't it's personality ;p )

--So what am I saying, what is the point man, out with it already! 

The point is, does anyone think that with systems developed in Perl 
(especially web based ones) we should consciously place more emphasis on the 
skin as well as the guts?

For example:
The calendar script mentioned above was pretty slick looking and had nice features.
Every one of those features and more could be and have been done with Perl versions 
of the same type of thing. The problem is the free Perl scripts that do the same 
things are pretty ugly html wise.

---Who cares you say, it's not Perl's job to make it look nice?
Right but it's not PHP's job either and some of them look very nice.

--OK again, who cares what does it matter?
It matters because people will begin look at PHP as a "pretty" language and Perl as an 
"Ugly"
Language suitable only for scary nerd in the dark work while they use PHP for what the 
public 
sees. And then shy away from Perl.

--But the world will not end if I make ugly html as long as it works like a tank! 
--And what evil will this lead up to besides?
For one, people recommending PHP scripts on a Perl list, the last place 
you'd think such a thing would happen.

-- Ok I'm with you but what to do?

I say we each put more personal emphasis on the look of the output 
of things we develop and stress that to people the same way we stress 
using strict, using modules instead of reinventing stuff, and making 
things platform independent.

Thoughts, feelings, pros, cons, pummeling?

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Data::Dumper->dump()ing a hash?

2003-10-30 Thread Kevin Pfeiffer
In article <[EMAIL PROTECTED]>, Kevin Old
wrote:
[...]
> my %entry;
> 
> $entry{"genre"} = "Rock";
> $entry{"artist"} = "3 Doors Down";
> $entry{"album"} = "Away from the Sun";
> $entry{"disc"} = "Away from the Sun";
> $entry{"file"} = "3dd.mp3";
> $entry{"fullpath"} = "/mp3s/3dd";
>  $Data::Dumper::Purity = 1;
> print Data::Dumper->Dump( [\%entry], [ '*entry' ] );
> #my $dumpedvalues = $dumper->Dump();
> #print $dumpedvalues . "\n";
> 
> 
> ***OUTPUT***
> 
> %entry = (
>'album' => 'Away from the Sun',
>'artist' => '3 Doors Down',
>'fullpath' => '/mp3s/3dd',
>'file' => '3dd.mp3',
>'disc' => 'Away from the Sun',
>'genre' => 'Rock'
>  );
> 

Hi Kevin,

This was interesting! I see what the difference is between your example and
"Dumper(\%entry)", but I wish I also understood what the man page says
about this:


 In the extended usage form, the references to be dumped can be given
user-specified names.  If a name begins with a "*", the output will
describe the dereferenced type of the supplied reference for hashes and
arrays, and coderefs.


The 1st sentence I understand, but not "the dereferenced type of the
supplied reference."

I just tried this without the asterisk and get "$entry" instead of "%entry"
(or "$VAR1" using the plain procedure).

So in plain(er) English that means: if the name begins with an "*", the
output type will match that of the referenced variable"?

-K
-- 
Kevin Pfeiffer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Web-based calendar script

2003-10-30 Thread Dan Muey
It's PHP eee :)

> -Original Message-
> From: Jeffrey Pearson [mailto:[EMAIL PROTECTED] 
> Sent: Thursday, October 30, 2003 4:19 PM
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: RE: Web-based calendar script
> 
> 
> I just discovered 
>  
> http://www.sweetphp.com/projects/TotalCalendar/ 
>  r/>  
>  
> Im 
> REALLY REALLY liking it.
>  
> Jeff
>  
> PS: If you 
> contact the author (he is really a cool guy), let him know I 
> referred you to him.
> 
>   -Original Message- 
>   From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
>   Sent: Thu 10/30/2003 2:18 PM 
>   To: [EMAIL PROTECTED] 
>   Cc: 
>   Subject: Web-based calendar script
>   
>   
>
> 
> 


Re: Data::Dumper->dump()ing a hash?

2003-10-30 Thread Kevin Old
On Thu, 2003-10-30 at 16:53, Dan Anderson wrote:
> When I use the following code to dump a hash:
> 
> $entry{"genre"} = $genre;
> $entry{"artist"} = $artist;
> $entry{"album"} = $album;
> $entry{"disc"} = $disc;
> $entry{"file"} = $file;
> $entry{"fullpath"} = $fullpath;
> 
> my $dumper = Data::Dumper->new( [%entry], [ qw () ] );
> my $dumpedvalues = $dumper->Dump();
> print $dumpedvalues . "\n";
> 
> I get the following output:
> 
> $VAR1 = "album";
> $VAR2 = "Prose Combat";
> $VAR3 = "disc";
> $VAR4 = 1;
> $VAR5 = "artist";
> $VAR6 = "MC Solaar";
> $VAR7 = "file";
> $VAR8 = "04_a_la_claire_fontaine.ogg";
> $VAR9 = "genre";
> $VAR10 = "French Rap";
> $VAR11 = "fullpath";
> $VAR12 = "/ogg/French Rap/MC Solaar/Prose
> Combat/04_a_la_claire_fontaine.ogg";
> 
> I've figured out that I can use qw() to change the variable names, but
> is there any way to either get an output like the code that created the
> hash, or in the form:
> 
> $hash = {
>album => "Prose Combat",
># etc...
> }

Dan,

You're s close.

>From the Camel book Chapter 9 Saving Data Structures shows how to save
hashes to another file.

Here's what you're example will look like:

#!/usr/bin/perl

use warnings;
use strict;
use Data::Dumper;

my %entry;

$entry{"genre"} = "Rock";
$entry{"artist"} = "3 Doors Down";
$entry{"album"} = "Away from the Sun";
$entry{"disc"} = "Away from the Sun";
$entry{"file"} = "3dd.mp3";
$entry{"fullpath"} = "/mp3s/3dd";
 $Data::Dumper::Purity = 1;
print Data::Dumper->Dump( [\%entry], [ '*entry' ] );
#my $dumpedvalues = $dumper->Dump();
#print $dumpedvalues . "\n";


***OUTPUT***

%entry = (
   'album' => 'Away from the Sun',
   'artist' => '3 Doors Down',
   'fullpath' => '/mp3s/3dd',
   'file' => '3dd.mp3',
   'disc' => 'Away from the Sun',
   'genre' => 'Rock'
 );

Hope this helps,
Kevin

-- 
Kevin Old <[EMAIL PROTECTED]>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Data::Dumper->dump()ing a hash?

2003-10-30 Thread Kevin Pfeiffer
In article <[EMAIL PROTECTED]>, Dan Anderson wrote:

> When I use the following code to dump a hash:
[...]
> I've figured out that I can use qw() to change the variable names, but
> is there any way to either get an output like the code that created the
> hash, or in the form:
> 
> $hash = {
>album => "Prose Combat",
># etc...
> }

Try...

use Data::Dumper

print Dumper(\$hash_ref);

(If I understood what you mean)

-Kevin


-- 
Kevin Pfeiffer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: What is my name

2003-10-30 Thread Kevin Pfeiffer
In article <[EMAIL PROTECTED]>, Brian Gerard wrote:
[...]
> I ran into exactly this issue, but I wanted to just get the actual script
> name.  $0 returns the entire path the script was invoked as.  ie - $0
> could be "../../foo/bar/blarch/scriptname.pl", but I just wanted
> "scriptname.pl".
> 
> Here's a line that will give you exactly that.
> ($PROGNAME = $0) =~ s|(\.?\.?(/[^/]+)*/)?([^/]+)|$3|;

I have two questions...

I came up with this earlier today:
my ($program) = $0 =~ /([^\/]+)$/;

Doesn't it do the same? (Question 1)

If I don't escape the slash in the char class -- i.e. /([^\/]+)$/ -- I get
this error:
Unmatched [ in regex; marked by <-- HERE in m/([ <-- HERE ^/ at ./test-0
line 7.

This makes no sense to me (since this is Perl and not sed or something)...
(implied Question 2)

-Kevin


--
Kevin Pfeiffer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Web-based calendar script

2003-10-30 Thread Jeffrey Pearson
I just discovered 
 
http://www.sweetphp.com/projects/TotalCalendar/ 
  
 
Im REALLY REALLY liking it.
 
Jeff
 
PS: If you contact the author (he is really a cool guy), let him know I referred you 
to him.

-Original Message- 
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Thu 10/30/2003 2:18 PM 
To: [EMAIL PROTECTED] 
Cc: 
Subject: Web-based calendar script


 



Web-based calendar script

2003-10-30 Thread William.Ampeh




Hello,

I am looking for a Web-based calendar manager, preferably one that uses
postgres or mysql, Perl DBI, or plain text.  Can anyone recommend one?  I
mean one that is easy to use and manage.

__

William Ampeh (x3939)
Federal Reserve Board


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Range of dates help needed

2003-10-30 Thread Rob Dixon
Kevin Old wrote:
>
> On Thu, 2003-10-30 at 07:06, Rob Dixon wrote:
> > Kevin Old" wrote:
> > > Basically I'd like a hash (or whatever) that looks like this:
> > >
> > > %datepairs = (
> > > # Saturday to  Following Friday
> > > '10/11/2003' => '10/17/2003',
> > > '10/18/2003' => '10/24/2003',
> > > '10/25/2003' => '10/31/2003',
> > > '11/01/2003' => '11/07/2003',
> > > '11/08/2003' => '11/14/2003',
> > > '11/15/2003' => '11/21/2003',
> > > '11/22/2003' => '11/28/2003',
> > > );
> > >
> >
> > This seemed like a fun exercise so I wrote the program below. It builds
> > an array of eight elements, each of which is a reference to a two-element
> > array containing the start and end dates of that week. I thought that was
> > more appropriate than the tied hash you were using.
> >
> > Your specification wasn't exact so it may need some tweaking.
>
> Rob,
>
> Thanks for your help, although honestly I'm more confused.  Your output
> shows the same dates for all references in the array of dates you
> build.  I'm looking for (based on the day it's run) the past 3 week and
> next 4 week ranges from Saturday to Friday.  In my hash above, the keys
> are Saturdays and the values are their following Fridays.
>
> Thanks for your help though, I've learned about two new modules.

Sorry Kevin.

That's what comes of 'tidying up' my code after I got it working!

Change the loop to this:

  for (1 .. 8) {

my $week;

for my $ymd ($first, $first + 6) {
  my $mmdd = sprintf "%02d/%02d/%04d", (split '-', $ymd)[1, 2, 0];
  push @$week, $mmdd;
}

push @dates, $week;

$first += 7;
  }

And you get this output, which is a little better!

Cheers,

Rob


@dates = (
   [
 '10/04/2003',
 '10/10/2003'
   ],
   [
 '10/11/2003',
 '10/17/2003'
   ],
   [
 '10/18/2003',
 '10/24/2003'
   ],
   [
 '10/25/2003',
 '10/31/2003'
   ],
   [
 '11/01/2003',
 '11/07/2003'
   ],
   [
 '11/08/2003',
 '11/14/2003'
   ],
   [
 '11/15/2003',
 '11/21/2003'
   ],
   [
 '11/22/2003',
 '11/28/2003'
   ]
 );



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Data::Dumper->dump()ing a hash?

2003-10-30 Thread Dan Anderson
When I use the following code to dump a hash:

$entry{"genre"} = $genre;
$entry{"artist"} = $artist;
$entry{"album"} = $album;
$entry{"disc"} = $disc;
$entry{"file"} = $file;
$entry{"fullpath"} = $fullpath;

my $dumper = Data::Dumper->new( [%entry], [ qw () ] );
my $dumpedvalues = $dumper->Dump();
print $dumpedvalues . "\n";

I get the following output:

$VAR1 = "album";
$VAR2 = "Prose Combat";
$VAR3 = "disc";
$VAR4 = 1;
$VAR5 = "artist";
$VAR6 = "MC Solaar";
$VAR7 = "file";
$VAR8 = "04_a_la_claire_fontaine.ogg";
$VAR9 = "genre";
$VAR10 = "French Rap";
$VAR11 = "fullpath";
$VAR12 = "/ogg/French Rap/MC Solaar/Prose
Combat/04_a_la_claire_fontaine.ogg";

I've figured out that I can use qw() to change the variable names, but
is there any way to either get an output like the code that created the
hash, or in the form:

$hash = {
   album => "Prose Combat",
   # etc...
}

Thanks in advance,

Dan

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Password Authentication

2003-10-30 Thread Dan Muey
> Hello:

Howdy

> 
> I'm attempting to create a CGI script for password requests 

> Software error:
> Can't locate Authen/SASL.pm in @INC (@INC contains: 
> D:/Perl/lib D:/Perl/site/lib .) at D:/Perl/lib/Net/SMTP.pm 

You can do two things:

1) install Authen::SASL
2) Try to use a different type of authentication.
I do this with Mail::Sender
auth => 'LOGIN',
Or auth => 'SASL'
Etc

See the Mail::Sender page for more info.

>
> use strict;
> use CGI qw(:standard);
 ^ If all you are using is the param function just do
use CGI qw(param);

> use CGI::Carp qw(fatalsToBrowser);
> my $smtp = Net::SMTP->new('smtp.sbcglobal.yahoo.com');
> 
> $smtp->auth('[EMAIL PROTECTED]','mypasswordhere');
 ^^ This probably has to be the same as 
one of either $ENV{USER} or $email like yo uuse below (IE mail() or to() ), 
if not you will probably have problems. I'd change $ENV{USER} below to 
$smtp->mail('[EMAIL PROTECTED]');
 
> $smtp->mail($ENV{USER});
> $smtp->to($email);

[snip]

> $smtp->quit;
> 
> my $name;
> my $value;
  ^^ Whatare these doing?

> 
> print "Location: $redirect\n\n";
> 
> exit;
  ^ is unnecessary.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



tip with expect+sending '~.'

2003-10-30 Thread mgoland

Hello Perl'ers

I am trying to automate some stuff that I normaly do using tip command. I am 
wondering if anyone can give me a hint how I can go about sending special signal such 
as '~.' or '~#' '

Thanks in Advance,
Mark G


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Corrupted Data

2003-10-30 Thread Jimstone77
In a message dated 10/30/03 12:04:07 PM Eastern Standard Time, 
[EMAIL PROTECTED] writes:


> Yes there is. (Apart from the typo on the open(NEW,...) line.)
> 
> The problem is that things could happened between you close the old 
> file and rename the new one. And even more likely there can be a 
> process that already has the old file open. So even if you rename the 
> files, the process still has the old one. And as soon as you unlock 
> it, the other process starts reading ... the old data.
> 
> You HAVE to use a separate log file!
> 
> Eg. like this (I'm sure someone will be happy to correct me if I 
> screw up)
> 
>   sysopen(FH, "file.lock", O_WRONLY|O_EXCL|O_CREAT)
> or die "can't open  file.lock: $!";
>   open(OLD,$old) or die "Can't Open File: $!";
>   open(NEW,">$new") or die "Can't Open File: $!";
>   while () {
> if ($_ =~ /NO_EMAIL/) { 
>  $count++;
> } else {
>  print NEW $_;
> }
>   }
>   close(NEW) or die "Can't Close File: $!";
>   close(OLD) or die "Can't Close Old: $!";
>   unlink $old or die "cannot unlink the old file\n";
>   rename($new => $old) or die "cannot rename\n";
>   close FH;
>   unlink "file.lock";
> 
> or
> 
>   open(LCK, ">file.lock")
> or die "can't open  file.lock: $!";
> # so someone else has it opened as well, who cares
>   flock(LCK, LOCK_EX)
> or die "can't lock the lock: $!";
># I am the only one who can have it locked though
>   open(OLD,$old) or die "Can't Open File: $!";
>   open(NEW,">$new") or die "Can't Open File: $!";
>   while () {
> if ($_ =~ /NO_EMAIL/) { 
>  $count++;
> } else {
>  print NEW $_;
> }
>   }
>   close(NEW) or die "Can't Close File: $!";
>   close(OLD) or die "Can't Close Old: $!";
>   unlink $old or die "cannot unlink the old file\n";
>   rename($new => $old) or die "cannot rename\n";
>   close LCK;
> 
> The second seems a little safer to me (the system will remove the 
> LOCK (not the lock file, just the lock) if the script dies).
> 
> Jenda
> 

 A Thousand Thanks! As a real "beginner" I appreciate your taking the time to 
help me find a solution to this problem, and explaining the possible reasons. 
I think I now have a better grasp of what's going on and why. Again, many 
Thanks for your patience!




Re: Password Authentication

2003-10-30 Thread Andrew Gaffney
Art Mahanna wrote:
Software error:
Can't locate Authen/SASL.pm in @INC (@INC contains: D:/Perl/lib
D:/Perl/site/lib .) at D:/Perl/lib/Net/SMTP.pm line 101.
For help, please send mail to the webmaster ([EMAIL PROTECTED]
 ), giving this error message and the time
and date of the error. 
I'd say that the Authen::SASL module isn't installed. Try installing it.

--
Andrew Gaffney
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Password Authentication

2003-10-30 Thread Art Mahanna
Hello:

I'm attempting to create a CGI script for password requests that will be
sent to my email address using Perl SMTP in a Windows environment on an
Apache web server.  My SMTP server requires authentication.  I've tried
using the instructions in the documentation, but it's not working.  Here's
the message I'm getting:

Software error:
Can't locate Authen/SASL.pm in @INC (@INC contains: D:/Perl/lib
D:/Perl/site/lib .) at D:/Perl/lib/Net/SMTP.pm line 101.
For help, please send mail to the webmaster ([EMAIL PROTECTED]
 ), giving this error message and the time
and date of the error. 


Here's the script:

#!d:/perl/bin/perl5.8.0.exe

use strict;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);

my $email = param("email");
my $name = param("name");
my $redirect = param("redirect");

use Net::SMTP;

my $smtp = Net::SMTP->new('smtp.sbcglobal.yahoo.com');

$smtp->auth('[EMAIL PROTECTED]','mypasswordhere');
$smtp->mail($ENV{USER});
$smtp->to($email);

$smtp->data();
$smtp->datasend("To: $email\n");
$smtp->datasend("\n");
$smtp->datasend("Password Request\n");
$smtp->dataend();
$smtp->quit;

my $name;
my $value;

print "Location: $redirect\n\n";

exit;

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

RE: Reading a directory and Renaming the file

2003-10-30 Thread Dan Muey
> Hi all 
> 
> I've this Perl script to read all  files in a directory and 
> if it finds a file with a certain then rename  the file to 
> header, but is doesn't search the right directory and doesn't 
> even look for the HPAY header.
> 

What format are these "headers" in in the file?

Assuming the files are relatively small text files (and to simplify the example)
I'd do:
[* untested by the way *]
use warnings;
use strict;
use File::Slurp;

for(read_dir($dir)) {
my $filegust = read_file($dir$_);
my ($hpay) = $fileguts =~ m/HPAY=(\w+)/;
if($hpay) {
write_file("$dir$hpay", $fileguts) or die $!;
unlink("$dir$_") or die $!;
}
}
- This will overwrite files already called $dir$hpay which may or may not be what you 
want.
- There's probably a better way to move or rename the file but hey it works.
- no system() command to make it platform independent, easier to undertsand, etc etc 
is good

HTH

Dmuey

> Ops  forgot to include the script.
> 
> #!/usr/bin/perl -w
> 
> use strict;
> 
> my $dir = "/interfaces/tdbank/test/";
> 
> opendir DIR, $dir;
> 
> my @files = readdir DIR;
> 
> my %hash = ('HPAY' => 'file1' ,
> 
> 'HRET' => 'file2');
> 
>  
> 
> for (my $i=0; $i 
>   open FILE,"$files[$i]" || die "Unable to open file 
> $files[$i] because $!\n"; 
>   my $header = ;
> 
>   print "header -->" , $header, "\n";
> 
>   close FILE;
> 
>   my $command = "mv $files[$i] $hash{$header}";
> 
>   print "command -->", $command, "\n";
> 
>   system $command;
> 
> }
> 
> 
> And I get the following Errors:
>  
> 
> 
> 
> Use of uninitialized value in concatenation (.) or string at 
> ./process_f iles.sh line 14.
> 
> command -->mv ..
> 
> Usage: mv [-i | -f]  [--] src target
> 
>or: mv [-i | -f]  [--] src1 ... srcN directory
> 
> readline() on closed filehandle FILE at ./process_files.sh 
> line 11. 
> Use of uninitialized value in print at ./process_files.sh 
> line 12.  
> header -->
> 
> Use of uninitialized value in hash element at 
> ./process_files.sh line 14 .
> 
> Use of uninitialized value in concatenation (.) or string at 
> ./process_files.sh line 14.
> 
> command -->mv file1
> 
> Usage: mv [-i | -f]  [--] src target
> 
>or: mv [-i | -f]  [--] src1 ... srcN directory
> 
> readline() on closed filehandle FILE at ./process_files.sh 
> line 11. 
> Use of uninitialized value in print at ./process_files.sh 
> line 12.  
> header -->
> 
> Use of uninitialized value in hash element at 
> ./process_files.sh line 14 .
> 
> Use of uninitialized value in concatenation (.) or string at 
> ./process_files.sh line 14.
> 
> command -->mv file2
> 
> Usage: mv [-i | -f]  [--] src target
> 
>or: mv [-i | -f]  [--] src1 ... srcN directory
> 
> etrprodftp /usr/local/sbin
> 
> 
> 
> Any help would be great..
> 
> 
> James Parsons.
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: What is my name

2003-10-30 Thread Dan Muey
> > On Thursday 30 Oct 2003 5:11 pm, Yannick Warnier wrote:
> > > Le jeu 30/10/2003 à 17:56, Gary Stainburn a écrit :
> > > > You can write $0 as well as reading it, which will change what 
> > > > appears when you run ps etc.
> > > >
> > > > This can be usefull for security reasons such as hiding 
> sensitive 
> > > > data passed on the command line, and also for returning status
> information for
> > > > daemons.
> > >
> > > How? Could you explain that for me?
> > >
> > > Thanks,
> > > Yannick
> > 
> > security
> > 
> > if you have the script:
> > 
> > mylogon -u username -p password
> > 
> > and someone (doesn't have to be root) runs
> > 
> > ps ax
> > 
> > they will see the command line that started the process, including 
> > your
> > username and password.
> > 
> > by having the command
> > 
> > $0='mylogon -u  -p ';
> > 
> > near the top of your script the data is hidden from prying eyes.

Except it may be recordfed in a .history file or something similar also 
So if they can do ps and see the xxx version then they can probably see 
An .files that keep your command typing history.

Just another 2cents about why security through obscurity is not good.

> > 
> 
> This should *NOT* be used for security purposes. It is very 
> instance and system dependent, from perldoc perlvar:
> 
> $0  Contains the name of the program being executed.  On 
> some oper-
> ating systems assigning to $0 modifies the argument area that
> the ps program sees.  This is more useful as a way of indicat-
> ing the current program state than it is for hiding 
> the program
> youâre running.  (Mnemonic: same as sh and ksh.)
> 
> Note for BSD users: setting $0 does not completely remove
> "perl" from the ps(1) output.  For example, setting 
> $0 to "foo-
> bar" will result in "perl: foobar (perl)".  This is an operat-
> ing system feature.
> 
> Security through obscurity bad.
> 
http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: What is my name

2003-10-30 Thread Wiggins d Anconia


> On Thursday 30 Oct 2003 5:11 pm, Yannick Warnier wrote:
> > Le jeu 30/10/2003 à 17:56, Gary Stainburn a écrit :
> > > You can write $0 as well as reading it, which will change what appears
> > > when you run ps etc.
> > >
> > > This can be usefull for security reasons such as hiding sensitive data
> > > passed on the command line, and also for returning status
information for
> > > daemons.
> >
> > How? Could you explain that for me?
> >
> > Thanks,
> > Yannick
> 
> security
> 
> if you have the script:
> 
> mylogon -u username -p password
> 
> and someone (doesn't have to be root) runs
> 
> ps ax
> 
> they will see the command line that started the process, including your 
> username and password.
> 
> by having the command
> 
> $0='mylogon -u  -p ';
> 
> near the top of your script the data is hidden from prying eyes.
> 

This should *NOT* be used for security purposes. It is very instance and
system dependent, from perldoc perlvar:

$0  Contains the name of the program being executed.  On some oper-
ating systems assigning to $0 modifies the argument area that
the ps program sees.  This is more useful as a way of indicat-
ing the current program state than it is for hiding the program
youâre running.  (Mnemonic: same as sh and ksh.)

Note for BSD users: setting $0 does not completely remove
"perl" from the ps(1) output.  For example, setting $0 to "foo-
bar" will result in "perl: foobar (perl)".  This is an operat-
ing system feature.

Security through obscurity bad.

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Mainframes

2003-10-30 Thread Bruce_Phillip
Dan,

   Currently I don't have access to a Mainframe. YET!
   To do the same thing I'm doing with opensystems.
   I basically telnet to the systems and run commands
   That will return me information about the configuration
   Of the system.

Phillip

-Original Message-
From: Dan Muey [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 30, 2003 11:24 AM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: RE: Mainframes

> Dan,
> 
>  I'm already using Net::Telnet module right now.
>  What I'd like to see is some examples of those
>  that connect to mainframes. 
> 
>  I appreciate any other link you can provide other than
>  Cpan.

Care to elaborate on exactly wht your trying to do then?
That may help people post examples more specific to your needs.

What do you mean by "connect to mainframe", for instance?

One could argue that you open a browser and go to it's ip address. 
That probably won't help you too much though unless you specify what 
specific tasks are needing done to shed light on the needed process.

So what are you wanting to do and what have you tried so far?

> 
> Phillip
> 
> -Original Message-
> From: Dan Muey [mailto:[EMAIL PROTECTED] 
> Sent: Thursday, October 30, 2003 11:11 AM
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: RE: Mainframes
> 
> > Hi,
> > 
> 
> Howdy
> 
> >Does anyone have any advice about using perl to connect using
> > 
> >telnet or any other TCP/IP protocols to mainframes?
> 
> Yes, use Modules!!
> 
> The Net:: (Net::Telnet for instance) modules have most 
> everything covered, also Socket modules, DBI modules, CGI 
> etc... Modules fo reverythgin you'd ever need and more!
> 
> Check out all of that on search.cpan.org 
> 
> That's where Id start..
> 
> HTH
> DMuey
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Reading files in a directory

2003-10-30 Thread Aman Raheja
didn't get you
what do u need to ask?

Aman Raheja
Systems Analyst
AGF Technologies
www.agftech.com


- Original Message - 
From: "James Parsons" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, October 30, 2003 1:23 PM
Subject: Reading files in a directory 


> Hi all 
> 
> I've this Perl script to read all  files in a directory and if it finds a
> file with a certain then rename  the file to header
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reading a directory and Renaming the file

2003-10-30 Thread James Parsons

Hi all 

I've this Perl script to read all  files in a directory and if it finds a
file with a certain then rename  the file to header, but is doesn't search
the right directory and doesn't even look for the HPAY header.

Ops  forgot to include the script.

#!/usr/bin/perl -w

use strict;

my $dir = "/interfaces/tdbank/test/";

opendir DIR, $dir;

my @files = readdir DIR;

my %hash = ('HPAY' => 'file1' ,

'HRET' => 'file2');

 

for (my $i=0; $i;

  print "header -->" , $header, "\n";

  close FILE;

  my $command = "mv $files[$i] $hash{$header}";

  print "command -->", $command, "\n";

  system $command;

}


And I get the following Errors:
 



Use of uninitialized value in concatenation (.) or string at ./process_f
iles.sh line 14.

command -->mv ..

Usage: mv [-i | -f]  [--] src target

   or: mv [-i | -f]  [--] src1 ... srcN directory

readline() on closed filehandle FILE at ./process_files.sh line 11. 
Use of uninitialized value in print at ./process_files.sh line 12.  
header -->

Use of uninitialized value in hash element at ./process_files.sh line 14
.

Use of uninitialized value in concatenation (.) or string at
./process_files.sh line 14.

command -->mv file1

Usage: mv [-i | -f]  [--] src target

   or: mv [-i | -f]  [--] src1 ... srcN directory

readline() on closed filehandle FILE at ./process_files.sh line 11. 
Use of uninitialized value in print at ./process_files.sh line 12.  
header -->

Use of uninitialized value in hash element at ./process_files.sh line 14
.

Use of uninitialized value in concatenation (.) or string at
./process_files.sh line 14.

command -->mv file2

Usage: mv [-i | -f]  [--] src target

   or: mv [-i | -f]  [--] src1 ... srcN directory

etrprodftp /usr/local/sbin



Any help would be great..


James Parsons.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Reading files in a directory

2003-10-30 Thread Dan Muey

> Hi all 

Howdy

> 
> I've this Perl script to read all  files in a directory and 
> if it finds a file with a certain then rename  the file to header
> 

Sounds like it might be handy.

DMuey

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Mainframes

2003-10-30 Thread Dan Muey
> Dan,
> 
>  I'm already using Net::Telnet module right now.
>  What I'd like to see is some examples of those
>  that connect to mainframes. 
> 
>  I appreciate any other link you can provide other than
>  Cpan.

Care to elaborate on exactly wht your trying to do then?
That may help people post examples more specific to your needs.

What do you mean by "connect to mainframe", for instance?

One could argue that you open a browser and go to it's ip address. 
That probably won't help you too much though unless you specify what 
specific tasks are needing done to shed light on the needed process.

So what are you wanting to do and what have you tried so far?

> 
> Phillip
> 
> -Original Message-
> From: Dan Muey [mailto:[EMAIL PROTECTED] 
> Sent: Thursday, October 30, 2003 11:11 AM
> To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> Subject: RE: Mainframes
> 
> > Hi,
> > 
> 
> Howdy
> 
> >Does anyone have any advice about using perl to connect using
> > 
> >telnet or any other TCP/IP protocols to mainframes?
> 
> Yes, use Modules!!
> 
> The Net:: (Net::Telnet for instance) modules have most 
> everything covered, also Socket modules, DBI modules, CGI 
> etc... Modules fo reverythgin you'd ever need and more!
> 
> Check out all of that on search.cpan.org 
> 
> That's where Id start..
> 
> HTH
> DMuey
> 

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reading files in a directory

2003-10-30 Thread James Parsons
Hi all 

I've this Perl script to read all  files in a directory and if it finds a
file with a certain then rename  the file to header


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Mainframes

2003-10-30 Thread Bruce_Phillip
Dan,

 I'm already using Net::Telnet module right now.
 What I'd like to see is some examples of those
 that connect to mainframes. 

 I appreciate any other link you can provide other than
 Cpan.

Phillip

-Original Message-
From: Dan Muey [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 30, 2003 11:11 AM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: RE: Mainframes

> Hi,
> 

Howdy

>Does anyone have any advice about using perl to connect using
> 
>telnet or any other TCP/IP protocols to mainframes?

Yes, use Modules!!

The Net:: (Net::Telnet for instance) modules have most everything covered,
also Socket modules, DBI modules, CGI etc... Modules fo reverythgin you'd
ever need and more!

Check out all of that on search.cpan.org 

That's where Id start..

HTH
DMuey

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Mainframes

2003-10-30 Thread Dan Muey
> Hi,
> 

Howdy

>Does anyone have any advice about using perl to connect using
> 
>telnet or any other TCP/IP protocols to mainframes?

Yes, use Modules!!

The Net:: (Net::Telnet for instance) modules have most everything covered,  also 
Socket modules, DBI modules, CGI etc... Modules fo reverythgin you'd ever need and 
more!

Check out all of that on search.cpan.org 

That's where Id start..

HTH
DMuey

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Mainframes

2003-10-30 Thread Bruce_Phillip
Hi,

 

   Does anyone have any advice about using perl to connect using

   telnet or any other TCP/IP protocols to mainframes?

 

Phillip Bruce
ISC Consultant, System Architect
Location: Dublin, CA
* Cell: 408-476-8658
* Office: 925-560-7853 
AIM: OkieUnix 

 



Re: complex condition

2003-10-30 Thread Andrew Gaffney
Perry, Alan wrote:
Andrew Gaffney wrote:

Steve Gilbert wrote:

I know there must be a way to do the following:

if (($foobar > 3) || ($foo="t" && $bar = "b")) {print
"yup"}
if (($foobar > 3) || ($foo eq "t" && $bar eq "b")) {print "yup"}

Your problem is that a single '=' is assignment, not equality. '==' could
also be used 

instead of 'eq'.


Actually, no, '==' could not be used.  Witness this code:

$abc="b";
print "yes\n" if ($abc=="b");  # appears that == works
print "yes\n" if ($abc=="e");  # shows that == does not work
Output:
yes
yes
To do string comparisons, you must use 'eq', 'ne', etc.

$abc="b";
print "yes\n" if ($abc eq "b");  # appears that 'eq' works
print "yes\n" if ($abc eq "e");  # and indeed it does
Output:
yes
My mistake. I'm still fairly new to Perl.

--
Andrew Gaffney
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: complex condition

2003-10-30 Thread Perry, Alan
Andrew Gaffney wrote:
>
>Steve Gilbert wrote:
>> I know there must be a way to do the following:
>> 
>> if (($foobar > 3) || ($foo="t" && $bar = "b")) {print
>> "yup"}
>
>if (($foobar > 3) || ($foo eq "t" && $bar eq "b")) {print "yup"}
>
>Your problem is that a single '=' is assignment, not equality. '==' could
also be used 
>instead of 'eq'.

Actually, no, '==' could not be used.  Witness this code:

$abc="b";
print "yes\n" if ($abc=="b");  # appears that == works
print "yes\n" if ($abc=="e");  # shows that == does not work

Output:
yes
yes

To do string comparisons, you must use 'eq', 'ne', etc.

$abc="b";
print "yes\n" if ($abc eq "b");  # appears that 'eq' works
print "yes\n" if ($abc eq "e");  # and indeed it does

Output:
yes


HTH
Alan

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: complex condition

2003-10-30 Thread Andrew Gaffney
Steve Gilbert wrote:
I know there must be a way to do the following:

if (($foobar > 3) || ($foo="t" && $bar = "b")) {print
"yup"}
if (($foobar > 3) || ($foo eq "t" && $bar eq "b")) {print "yup"}

Your problem is that a single '=' is assignment, not equality. '==' could also be used 
instead of 'eq'.

--
Andrew Gaffney
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: IRC bot in perl?

2003-10-30 Thread dan
I'm writing an IRC service in Perl, unfortunately I can't post the source
here because it's over 400k's worth of source code, plus I don't want to
release it to the public, you know what some people are like, modifying the
code and calling it their own.

I can give you a helping hand if you need it though.

Dan

"David O'Dell" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Can anyone recommend the best way to do this in Perl.
> There are a lot of modules out there and also IO::Socket.
> Just looking for a good starting place.
> Thanks
>
>



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



complex condition

2003-10-30 Thread Steve Gilbert
I know there must be a way to do the following:

if (($foobar > 3) || ($foo="t" && $bar = "b")) {print
"yup"}

Of course this is wrong, but what I want is to print
yup if $foobar >3 or $foo=t and $bar=b.

so:
$foobar=4 $foo=a $bar=b is true
$foobar=1 $foo=f $bar=b is true
$foobar=1 $foo=f $bar=a is false

Thanks in advance!

__
Do you Yahoo!?
Exclusive Video Premiere - Britney Spears
http://launch.yahoo.com/promos/britneyspears/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: What is my name

2003-10-30 Thread Brian Gerard
And the clouds parted, and [EMAIL PROTECTED] said...
> Hi,
> 
> I have a little problem. I have script "test.pl" and inside this script I want to 
> know what is "my name" (I mean this "test.pl".
> 
> test.pl script
> ---
> 
> my $this_scripts_name_is = who_am_I();
> 
> sub who_am_I
> {
>   my $my_name = ; # what I have to put to this "" to get "test.pl" scripts 
> name
> 
>   return $my_name;
> }
> 

I ran into exactly this issue, but I wanted to just get the actual script
name.  $0 returns the entire path the script was invoked as.  ie - $0 could
be "../../foo/bar/blarch/scriptname.pl", but I just wanted "scriptname.pl".

Here's a line that will give you exactly that.
($PROGNAME = $0) =~ s|(\.?\.?(/[^/]+)*/)?([^/]+)|$3|;

...or, to put it in the above terms:

my $this_scripts_name_is = who_am_I();

sub who_am_I
{
my $PROGNAME;
($PROGNAME = $0) =~ s|(\.?\.?(/[^/]+)*/)?([^/]+)|$3|;

return $PROGNAME;
}

HTH-
Brian

  /~~\
 | Brian Gerard  Overflow on /dev/null;   |
 | First initial + 'lists'please empty the bit bucket.|
 | at technobrat dot com  |
  \__/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Perl Windows question

2003-10-30 Thread Tim Johnson

Technically, the shebang line doesn't mean anything special in Windows, with
one small exception: any command-line switches like -w you put in the
shebang line will be applied to the script.  But these are rarely necessary,
since there is usually a pragma (use warnings, in this case) that you can
use instead.  Maybe someone can think of another case that proves me wrong.

Really, though, the two things you need in Windows to run a perl script is:

1) Install ActivePerl from ActiveState.  You can compile other distributions
of Perl, but this is the version that works the best and has the most usage
in the Win32 Perl community, so if you run into some Win32-specific issues,
it helps to be on the same distribution.  Also, it comes with the Perl
Package Manager, which will allow you to find modules and install them
without needing a compiler and having to wade through the billions of
modules on CPAN if you know exactly what you want.

2) Just add a .pl extension to your Perl scripts and you're ready to go
(assuming you've done #1)

C) This one is just for Perl in general.  If you're not already doing it,
'use warnings' and 'use strict'.

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 30, 2003 9:23 AM
To: [EMAIL PROTECTED]
Subject: Perl Windows question


Hi,

 

In  any unix system, I know that I need to type 

 

#!/usr/bin/perl or #!/usr/local/bin/perl

 

for my perl scripts to execute.

 

What is needed for windows?

 

#!c:\somepath\perl

 

maybe?

 

Phillip Bruce
ISC Consultant, System Architect
Location: Dublin, CA
* Cell: 408-476-8658
* Office: 925-560-7853 
AIM: OkieUnix 

 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Hash Issue or Understanding

2003-10-30 Thread Bruce_Phillip
Sudarshan,

 Thanks for the info. I understand now and makes sense.

Phillip

-Original Message-
From: Sudarshan Raghavan [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 30, 2003 1:51 AM
To: [EMAIL PROTECTED]
Subject: Re: Hash Issue or Understanding


>The output works but it not in the order I expected:
>
>I expected my output to be:
>
>hostname, IP addrress, OS, Version, Release, Server Type, Model, Memory
>Size, Total CPU's.
>
> 
>
>But what I got was:
>
> 
>
>Model, Server Type, cpu, Release, hostname, OS, Memory Size, Version
>
> 
>
>It seems to me the hash started almost at the bottom of the list instead of
>
>With the hostname and work it way down. Is there any way to force the
>
>Order other than maybe specifying the array itself?.
>

As you have already figured out, there are no guarantees about order in 
a hash. The module Tie::IxHash will interest you.
perldoc -q 'How can I make my hash remember the order I put elements 
into it'

I think Tie::IxHash comes with the standard distribution from 5.8.0 
onwards (not sure though). If not, you can get it from 
http://search.cpan.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Perl Windows question

2003-10-30 Thread Bruce_Phillip
Hi,

 

In  any unix system, I know that I need to type 

 

#!/usr/bin/perl or #!/usr/local/bin/perl

 

for my perl scripts to execute.

 

What is needed for windows?

 

#!c:\somepath\perl

 

maybe?

 

Phillip Bruce
ISC Consultant, System Architect
Location: Dublin, CA
* Cell: 408-476-8658
* Office: 925-560-7853 
AIM: OkieUnix 

 



Re: What is my name

2003-10-30 Thread Gary Stainburn
On Thursday 30 Oct 2003 5:11 pm, Yannick Warnier wrote:
> Le jeu 30/10/2003 à 17:56, Gary Stainburn a écrit :
> > You can write $0 as well as reading it, which will change what appears
> > when you run ps etc.
> >
> > This can be usefull for security reasons such as hiding sensitive data
> > passed on the command line, and also for returning status information for
> > daemons.
>
> How? Could you explain that for me?
>
> Thanks,
> Yannick

security

if you have the script:

mylogon -u username -p password

and someone (doesn't have to be root) runs

ps ax

they will see the command line that started the process, including your 
username and password.

by having the command

$0='mylogon -u  -p ';

near the top of your script the data is hidden from prying eyes.

For the daemon use, I have things like

while (1) {
  $0='mydaemon - sleeping';
  $in=;
  $0='parsing request';


etc.
-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Corrupted Data

2003-10-30 Thread Tore Aursand
On Thu, 30 Oct 2003 09:45:58 -0500, Jimstone77 wrote:
>  open(OLD,">$old") or die "Can't Open File: $!";
> flock OLD, 2;
>   open(NEW,$new) or die "Can't Open File: $!";
>  flock NEW, 2;
>while () {
>   if ($_ =~ /NO_EMAIL/) { 
>$count++;
>   }
>   else {
>   print NEW $_;
>   }
>}
>  close(NEW) or die "Can't Close File: $!";
> close(OLD) or die "Can't Close Old: $!";

First of all:  Post your _actual_ code.  The code above won't even
compile, and it's really easy to see (or find out) why.

Secondly, you're trying to write to a file you opened for reading.


-- 
Tore Aursand <[EMAIL PROTECTED]>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: Hash Issue or Understanding

2003-10-30 Thread Bruce_Phillip
Gary,

 Thanks for the feedback.

Phillip

-Original Message-
From: Gary Stainburn [mailto:[EMAIL PROTECTED] 
Sent: Thursday, October 30, 2003 1:47 AM
To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: Hash Issue or Understanding

On Thursday 30 Oct 2003 8:17 am, [EMAIL PROTECTED] wrote:
> Hi,
>
>
>
>For those of you who helped me with my earlier scripts. Thanks.
>
>
[snip]
>
> It seems to me the hash started almost at the bottom of the list instead
of
>
> With the hostname and work it way down. Is there any way to force the
>
> Order other than maybe specifying the array itself?.
>

Hi Phil,

it states in the perl docs that the sequence of the keys returned from a
hash 
cannot be guaranteed, and even if they always return in the same order in
the 
current version, that may change in a future version of perl.

If you *need* the keys returning in a specific order, you have to code this 
yourself.

One method I use is to have an array (which is always in the order
specified) 
and use that instead of the keys  clause.

For your example I'd use

my 
@keylist=('hostname','os','osver','osrel','srvtype','srvmodel','memory','cpu
');

and then

replace

foreach $CMD (keys %{$commands{$items}}){

with

foreach $CMD (@keylist){


>
>
> Phillip Bruce
> ISC Consultant, System Architect
> Location: Dublin, CA
> * Cell: 408-476-8658
> * Office: 925-560-7853
> AIM: OkieUnix

-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: What is my name

2003-10-30 Thread Yannick Warnier
Le jeu 30/10/2003 à 17:56, Gary Stainburn a écrit :
> You can write $0 as well as reading it, which will change what appears when 
> you run ps etc.
> 
> This can be usefull for security reasons such as hiding sensitive data passed 
> on the command line, and also for returning status information for daemons.

How? Could you explain that for me?

Thanks,
Yannick


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Corrupted Data

2003-10-30 Thread Jenda Krynicky
From: [EMAIL PROTECTED]
>  $old = "oldfile.txt";
>  $new = "newfile.txt";
> 
>  open(OLD,"$old") or die "Can't Open File: $!";
> flock OLD, 2;
>   open(NEW,>$new) or die "Can't Open File: $!";
>  flock NEW, 2;
>while () {
>   if ($_ =~ /NO_EMAIL/) { 
>$count++;
>   }
>   else {
>   print NEW $_;
>   }
>}
>  close(NEW) or die "Can't Close File: $!";
> close(OLD) or die "Can't Close Old: $!";
>rename($old,$new);
> 
>   Is there something inherently wrong with doing it this way? 

Yes there is. (Apart from the typo on the open(NEW,...) line.)

The problem is that things could happened between you close the old 
file and rename the new one. And even more likely there can be a 
process that already has the old file open. So even if you rename the 
files, the process still has the old one. And as soon as you unlock 
it, the other process starts reading ... the old data.

You HAVE to use a separate log file!

Eg. like this (I'm sure someone will be happy to correct me if I 
screw up)

  sysopen(FH, "file.lock", O_WRONLY|O_EXCL|O_CREAT)
or die "can't open  file.lock: $!";
  open(OLD,$old) or die "Can't Open File: $!";
  open(NEW,">$new") or die "Can't Open File: $!";
  while () {
if ($_ =~ /NO_EMAIL/) { 
 $count++;
} else {
 print NEW $_;
}
  }
  close(NEW) or die "Can't Close File: $!";
  close(OLD) or die "Can't Close Old: $!";
  unlink $old or die "cannot unlink the old file\n";
  rename($new => $old) or die "cannot rename\n";
  close FH;
  unlink "file.lock";

or

  open(LCK, ">file.lock")
or die "can't open  file.lock: $!";
# so someone else has it opened as well, who cares
  flock(LCK, LOCK_EX)
or die "can't lock the lock: $!";
   # I am the only one who can have it locked though
  open(OLD,$old) or die "Can't Open File: $!";
  open(NEW,">$new") or die "Can't Open File: $!";
  while () {
if ($_ =~ /NO_EMAIL/) { 
 $count++;
} else {
 print NEW $_;
}
  }
  close(NEW) or die "Can't Close File: $!";
  close(OLD) or die "Can't Close Old: $!";
  unlink $old or die "cannot unlink the old file\n";
  rename($new => $old) or die "cannot rename\n";
  close LCK;

The second seems a little safer to me (the system will remove the 
LOCK (not the lock file, just the lock) if the script dies).

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: What is my name

2003-10-30 Thread Gary Stainburn
On Thursday 30 Oct 2003 12:06 pm, Sudarshan Raghavan wrote:
> [EMAIL PROTECTED] wrote:
> >Hi,
> >
> >I have a little problem. I have script "test.pl" and inside this script I
> > want to know what is "my name" (I mean this "test.pl".
>
> $0 will contain the program name
> perldoc perlvar

You can write $0 as well as reading it, which will change what appears when 
you run ps etc.

This can be usefull for security reasons such as hiding sensitive data passed 
on the command line, and also for returning status information for daemons.

Gary
-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Corrupted Data

2003-10-30 Thread Peter Scott
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] writes:
> $old = "oldfile.txt";
> $new = "newfile.txt";
>
> open(OLD,"$old") or die "Can't Open File: $!";
>flock OLD, 2;
>  open(NEW,>$new) or die "Can't Open File: $!";
> flock NEW, 2;
>   while () {
>  if ($_ =~ /NO_EMAIL/) { 
>   $count++;
>  }
>  else {
>  print NEW $_;
>  }
>   }
> close(NEW) or die "Can't Close File: $!";
>close(OLD) or die "Can't Close Old: $!";
>   rename($old,$new);
>
>
>  Is there something inherently wrong with doing it this way? 

See, when you post something that plainly isn't what you're 
using (because it doesn't compile), how can anyone tell what 
the problem is with what you really are doing, since they can't 
see your real code?

% perl -c
 $old = "oldfile.txt";
 $new = "newfile.txt";

 open(OLD,"$old") or die "Can't Open File: $!";
flock OLD, 2;
  open(NEW,>$new) or die "Can't Open File: $!";
 flock NEW, 2;
   while () {
  if ($_ =~ /NO_EMAIL/) { 
   $count++;
  }
  else {
  print NEW $_;
  }
   }
 close(NEW) or die "Can't Close File: $!";
close(OLD) or die "Can't Close Old: $!";
   rename($old,$new);
^D
syntax error at - line 6, near ",>"
- had compilation errors.

That's twice now.  I'm disinclined to help since I will doubt that whatever
you post is what's really giving you the problem, because you evidently
don't want to show us the real code.

-- 
Peter Scott
http://www.perldebugged.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Corrupted Data

2003-10-30 Thread Kevin Pfeiffer
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] wrote:

>  I'm having problems with corrupted data about every month or so. The
>  problem
> seems to be that the New file sometimes writes only about half the old
> file. I was under the impression that flock would prevent the data from
> being corrupted. Can anyone tel me what I am doing wrong, and what I
> should be doing instead?
[...]
>   open(NEW,$new) or die "Can't Open File: $!";
[...]
>   print NEW $_;

>  Is there something inherently wrong with doing it this way?

Printing to a file handle that was opened for reading?



-- 
Kevin Pfeiffer


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Corrupted Data

2003-10-30 Thread Jimstone77

In a message dated 10/30/03 10:35:08 AM Eastern Standard Time, [EMAIL PROTECTED] 
writes:


> ]
> 
> Why don't you post the actual code since this obviously isn't it...

 $old = "oldfile.txt";
 $new = "newfile.txt";

 open(OLD,"$old") or die "Can't Open File: $!";
flock OLD, 2;
  open(NEW,>$new) or die "Can't Open File: $!";
 flock NEW, 2;
   while () {
  if ($_ =~ /NO_EMAIL/) { 
   $count++;
  }
  else {
  print NEW $_;
  }
   }
 close(NEW) or die "Can't Close File: $!";
close(OLD) or die "Can't Close Old: $!";
   rename($old,$new);


  Is there something inherently wrong with doing it this way? 










Re: Corrupted Data

2003-10-30 Thread Peter Scott
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] writes:
> I'm having problems with corrupted data about every month or so. The problem 
>seems to be that the New file sometimes writes only about half the old file. 
>I was under the impression that flock would prevent the data from being 
>corrupted. Can anyone tel me what I am doing wrong, and what I should be doing 
>instead?
>
>
> open(OLD,">$old") or die "Can't Open File: $!";
>flock OLD, 2;
>  open(NEW,$new) or die "Can't Open File: $!";
> flock NEW, 2;
>   while () {
[snip]

Why don't you post the actual code since this obviously isn't it...

-- 
Peter Scott
http://www.perldebugged.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: finding out my IP address..

2003-10-30 Thread McMahon, Chris

I faced this just a couple of days ago on a FreeBSD system for em0.
Here's what I did: 

($in, $myip, $rest) = split / /,qx/ifconfig|grep 192.168/;   
print "This IP is $myip\n"; 

I used the FreeBSD "ifconfig" system call and parsed the output with
split.  Whatever system you're on will probably have some other systemly way
to find this information. 
-Chris   

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, October 29, 2003 6:41 AM
To: [EMAIL PROTECTED]
Subject: finding out my IP address..

Hi,
   I'm trying to find my IP address from within Perl for eth0 and ppp0.
Currently I run a regex on the output of ifconfig to extract his data -
but, I'd like to do this from within Perl and it strikes me that this
should be possible.

HELP! ANYBODY!

Kev





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Control a non-perl image viewer from perl script

2003-10-30 Thread Harry Putnam
Below is a (non-finished) script that trys to run a linux viewer
called eog (eye of gnome) in a script that will eventually allow me to
power thru long lists of image files and rename them as I go.

The idea was a cmdline tool that would pop up a view of each image
then query user for new name.  Kill that process and move on to next
item in list.

I couldn't think of any better way than to query `ps' for the pid and
run `kill' on it.  However even that isn't working.

But I wondered if there is a better way of doing this that is still
fairly basic?

#!/usr/local/bin/perl -w
$question = "New name please => ";
$ext=shift;
$ls_proc = "ls *.$ext";
open(LS_PROC," $ls_proc|");
while(){
   chomp;
   push @ls_array,$_;
}
for(@ls_array){
   $pic = $_; 
   system("eog $pic &");
   print  $question;
   chomp ($newname = );
   print "<$newname>\n";
   qx(cp -a $pic "$newname.$ext");
##  rename $_ "$newname.$ext";
   open(PS_PROC,"ps wwaux|");
   while(){ 
 chomp;
 if($_ =~ /^$ENV{LOGNAME}.*eog.*\.jpg$/){
my $line = $_;
print "hpdb \$line = $line\n";
;
$pid = (split(/\s+/,$line))[1];
print "hpdb \$pid = $pid\n";
;
print "kill -15 on $pid?\n";
$ans = ;
if ($ans eq "y"){
   print "Killing -15 on pid <$pid>\n";
   qx(kill -15 $pid);   
}
 }
   }
   close(PS_PROC);
} 
close(LS_PROC);


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Range of dates help needed

2003-10-30 Thread Kevin Old
On Thu, 2003-10-30 at 07:06, Rob Dixon wrote:
> Kevin Old" wrote:
> > Basically I'd like a hash (or whatever) that looks like this:
> >
> > %datepairs = (
> > # Saturday to  Following Friday
> > '10/11/2003' => '10/17/2003',
> > '10/18/2003' => '10/24/2003',
> > '10/25/2003' => '10/31/2003',
> > '11/01/2003' => '11/07/2003',
> > '11/08/2003' => '11/14/2003',
> > '11/15/2003' => '11/21/2003',
> > '11/22/2003' => '11/28/2003',
> > );
> >
> 
> This seemed like a fun exercise so I wrote the program below. It builds
> an array of eight elements, each of which is a reference to a two-element
> array containing the start and end dates of that week. I thought that was
> more appropriate than the tied hash you were using.
> 
> Your specification wasn't exact so it may need some tweaking.

Rob,

Thanks for your help, although honestly I'm more confused.  Your output
shows the same dates for all references in the array of dates you
build.  I'm looking for (based on the day it's run) the past 3 week and
next 4 week ranges from Saturday to Friday.  In my hash above, the keys
are Saturdays and the values are their following Fridays.

Thanks for your help though, I've learned about two new modules.

Kevin

-- 
Kevin Old <[EMAIL PROTECTED]>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: What is my name

2003-10-30 Thread Dan Muey

> The $0 variable already has it so no need for a sub or a new 
> variable. One thing is sometimes it reurns path info also 
> /home/joemama/test.pl That may or may not be a bad thign 
> depending on what you're doing.
> 
> Test it out with this suicidal little script (or should I say 
> scripticide)
> 
> #!/usr/bin/perl -w
> use strict;
> print "I am $0 hear me roar.\nGoodbye Cruel world!\n";
> unlink $0 || die $!;

I should probably put in here that having a script modify itself
is a bad idea usually. So here's the disclaimer:
This is an example, it is only an example, had it been an actual 
example you'd want to use it would not have been such a bone headed idea.

Do not try this at home! professional driver on a closed course.

:)

> 
> HTH
> DMuey

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: What is my name

2003-10-30 Thread Dan Muey
> Hi,
> 
> I have a little problem. I have script "test.pl" and inside 
> this script I want to know what is "my name" (I mean this "test.pl".
> 
> test.pl script
> ---
> 
> my $this_scripts_name_is = who_am_I();
> 
> sub who_am_I
> {
>   my $my_name = ; # what I have to put to this "" to 
> get "test.pl" scripts name
> 
>   return $my_name;
> }

The $0 variable already has it so no need for a sub or a new variable.
One thing is sometimes it reurns path info also /home/joemama/test.pl
That may or may not be a bad thign depending on what you're doing.

Test it out with this suicidal little script (or should I say scripticide)

#!/usr/bin/perl -w
use strict;
print "I am $0 hear me roar.\nGoodbye Cruel world!\n";
unlink $0 || die $!;

HTH
DMuey

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: config file: a) what Module ? b) conditionals in config (for multiple hosts)

2003-10-30 Thread Jenda Krynicky
From: "Wiggins d Anconia" <[EMAIL PROTECTED]>
> > b) As I develop one one machine and test/deploy on another, I want
> > constructs in my config file like:
> > 
> >if (`hostname` eq 'dev_box') {
> > mysql_dsn = 'foobar';
> > } elsif ((`hostname` eq 'test_box'}
> > mysql_dsn = 'abracadabra';
> > ...
> > 
> > Any support for that in your module of choice?
> > 
> > I know of the use-just-perl-code approach (with 'do') in the Perl
> Cookbook,
> > but I am wondering if new insights exist.
> > 
> 
> Not that I know of, that is a rather complex deal, where is hostname?
> is it in the path? what about machines that may not supply it?   If
> you want a dev/q-a/prod set of config files i have found it more
> appropriate to use the same structure in a set of 3 different config
> files, then migrate the unique config files to each of the
> environments. Granted when you change the structure you have to update
> 3 copies, but it simplifies the programming, which *should* be the
> expensive part.

To simplify this you may consider using two configs. One "global" 
that contains the settings that are the same everywhere (which will 
probably be most of them) and one "local" that will contain the 
specialties. And then read both the configs and merge them so that 
the "local" overwrites the "global". 

That was if you need to make the same change to all machines you can 
do it in the "global" config and then just copy the file.

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Corrupted Data

2003-10-30 Thread Jimstone77
 I'm having problems with corrupted data about every month or so. The problem 
seems to be that the New file sometimes writes only about half the old file. 
I was under the impression that flock would prevent the data from being 
corrupted. Can anyone tel me what I am doing wrong, and what I should be doing 
instead?


 open(OLD,">$old") or die "Can't Open File: $!";
flock OLD, 2;
  open(NEW,$new) or die "Can't Open File: $!";
 flock NEW, 2;
   while () {
  if ($_ =~ /NO_EMAIL/) { 
   $count++;
  }
  else {
  print NEW $_;
  }
   }
 close(NEW) or die "Can't Close File: $!";
close(OLD) or die "Can't Close Old: $!";

 Is there something inherently wrong with doing it this way? 


Re: config file: a) what Module ? b) conditionals in config (for multiple hosts)

2003-10-30 Thread Wiggins d Anconia


> Hi,
> 
> a) I am looking for a module to handle config files. There are a number of
> these modules, like AppCconig.  Any consensus about The Right Module for
> this?
> 

Whichever module gets the job done the way you want it.  I have used
AppConfig with some success but it fails to handle overly complex
structures (not its claim to fame either) some people (read: myself)
have come to expect in a config file so I switched to using XML::Simple
for more complex tasks.  Since I started out in the web world that
transition was obviously easy for me.  I have found in general the
module that is chosen is based more on the format of the config file,
which is usually left up to the person editing it and how comfortable
they are with doing so, or whether there will be an interface to editing
it. If the config file changes a lot and non-developers will edit it go
with something simple like AppConfig because it is relatively powerful
without complex layout restrictions, if the config file changes in
frequently, is updated by knowledgeable users, and/or has an interface
for making updates then go with a module that is easily written back out
 and allows for arbitrarily complex data structures

> 
> b) As I develop one one machine and test/deploy on another, I want
> constructs in my config file like:
> 
>if (`hostname` eq 'dev_box') {
> mysql_dsn = 'foobar';
> } elsif ((`hostname` eq 'test_box'}
> mysql_dsn = 'abracadabra';
> ...
> 
> Any support for that in your module of choice?
> 
> I know of the use-just-perl-code approach (with 'do') in the Perl
Cookbook,
> but I am wondering if new insights exist.
> 

Not that I know of, that is a rather complex deal, where is hostname? is
it in the path? what about machines that may not supply it?   If you
want a dev/q-a/prod set of config files i have found it more appropriate
to use the same structure in a set of 3 different config files, then
migrate the unique config files to each of the environments. Granted
when you change the structure you have to update 3 copies, but it
simplifies the programming, which *should* be the expensive part.

Just my $.02,

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Hash Issue or Understanding

2003-10-30 Thread Wiggins d Anconia


> On Thursday 30 Oct 2003 8:17 am, [EMAIL PROTECTED] wrote:

> 
> it states in the perl docs that the sequence of the keys returned from
a hash 
> cannot be guaranteed, and even if they always return in the same order
in the 
> current version, that may change in a future version of perl.
> 

Just to point it out, that *has* changed in a future version, or as the
case may be now, a past version that used to be in the future, aka
5.8.1. For more specifics see the first main section here:

http://use.perl.org/articles/03/09/26/2231256.shtml?tid=6

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Range of dates help needed

2003-10-30 Thread Rob Dixon
Kevin Old" wrote:
>
> I have a subroutine below that uses Date::Manip to build a hash with
> keys of the previous Wednesday to the next Tuesday range from the
> beginning of the year until today.  For instance:
>
> %pairs = (
> #didn't want to list the whole year, but you get the point
> '10/15/2003' => '10/21/2003',
> '10/22/2003' => '10/28/2003',
> );
>
> Here's my subroutine:
>
> sub wedToTues() {
> my ($day, $month, $year) = (localtime)[3,4,5];
> $year += 1900;
> $month++;
> my $beginyear = &ParseDate("$year/01/01");
> my $today = &ParseDate("today");
> my $firsttues = &ParseDate("$year/01/07");
> my $endyear = &ParseDate("$year/12/31");
>
> #print "$beginyear $endyear\n";
>
> #Build an array of every Tuesday in the current year
> my @dates =
> &ParseRecur("0:0:1*2:0:0:0",$firsttues,$beginyear,$today);
>
> use Tie::IxHash;
> tie my %pairs, "Tie::IxHash";
>
> foreach my $date (@dates) {
>
> my $lastWed = &DateCalc("$date","- 6 days");
>
> #my $ulastWed = &UnixDate($lastWed, "%Y%m%d");
> #my $udate = &UnixDate($date, "%Y%m%d");
> my $ulastWed = &UnixDate($lastWed, "%m/%d/%Y");
> my $udate = &UnixDate($date, "%m/%d/%Y");
> $pairs{$ulastWed} = $udate;
> }
>
> return \%pairs;
> }
>
> Yes, I understand that to adjust the variables that I pass to
> ParseRecur, but I'm not sure how to go about doing what I need.
>
> I'll try to explain as best as I can.  First, I'll be changing this
> subroutine to be Saturdays to Fridays rather than Wednesdays to
> Tuesdays.  Then based on the day it's run, I need to only get the
> previous 3 weeks and the next 4 weeks.
>
> Basically I'd like a hash (or whatever) that looks like this:
>
> %datepairs = (
> # Saturday to  Following Friday
> '10/11/2003' => '10/17/2003',
> '10/18/2003' => '10/24/2003',
> '10/25/2003' => '10/31/2003',
> '11/01/2003' => '11/07/2003',
> '11/08/2003' => '11/14/2003',
> '11/15/2003' => '11/21/2003',
> '11/22/2003' => '11/28/2003',
> );
>
>
> Can anyone offer suggestions or a more graceful way of doing this?

Hi Kevin.

This seemed like a fun exercise so I wrote the program below. It builds
an array of eight elements, each of which is a reference to a two-element
array containing the start and end dates of that week. I thought that was
more appropriate than the tied hash you were using.

Your specification wasn't exact so it may need some tweaking.

HTH,

Rob


use strict;
use warnings;

use Date::Simple;
use Date::DayOfWeek;

my $date = new Date::Simple;# today
my $dow = dayofweek(reverse split '-', $date);# 0 = Sunday

my $prevsat = $date - $dow - 1;# Last Sat before today

my @dates;
my $first = $prevsat - 3*7;

for (1 .. 8) {

  my $week;

  for my $ymd ($first, $first + 6) {
my $mmdd = sprintf "%02d/%02d/%04d", (split '-', $ymd)[1, 2, 0];
push @$week, $mmdd;
  }

  push @dates, $week;
}

use Data::Dumper;
print Data::Dumper->Dump ([EMAIL PROTECTED], [qw(*dates)]);

**OUTPUT**

@dates = (
   [
 '10/04/2003',
 '10/10/2003'
   ],
   [
 '10/04/2003',
 '10/10/2003'
   ],
   [
 '10/04/2003',
 '10/10/2003'
   ],
   [
 '10/04/2003',
 '10/10/2003'
   ],
   [
 '10/04/2003',
 '10/10/2003'
   ],
   [
 '10/04/2003',
 '10/10/2003'
   ],
   [
 '10/04/2003',
 '10/10/2003'
   ],
   [
 '10/04/2003',
 '10/10/2003'
   ]
 );



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: flock() semantics?

2003-10-30 Thread Rob Dixon
Shaun Fryer wrote:
>
> I'm writing an app which uses a flat file to store a
> *short* list of simple key/value pairs. However having
> read the flock() man page, I'm unsure about whether I
> need to seek() in cases where I'm not merely appending
> to the file (such as when deleting a record).
>
> sub Delete_Record {
> my ($file, $key, $value, @array) = @_;
> open(OUT, ">$file");
> flock(OUT, LOCK_EX);
>
> seek(OUT, 0, 0); # Should I do this?
>
> foreach (@array) { # FYI: $/ = "\n"
>
> seek(OUT, 0, 2); # Or perhaps this?
>
> print OUT $_ unless ( m/^$key\s+$value$/ );
> }
> flock(OUT, LOCK_UN);
> close(OUT);
> }
>
> Btw, the above code is just to illustrate the question,
> thus no error checking and so forth.

Hi Shaum.

No. There's no call to 'seek' required at all. Your 'open'
statement opens a brand new stream into an empty file so
all your output will be written in sequence from the beginning
of the file.

However I would rather see it written in a different way, with
the array as the 'master' copy of the data which is then
flushed to disk when required. Something like the code below.

Also note that you need to pass the array by reference otherwise
you can't manipulate its data within the subroutine.

HTH,

Rob



sub Delete_Record {

  my ($key, $value, $array) = @_;

  my $i = 0;

  foreach (@$array) {
if ( /^$key\s+$value$/ ) {
  splice @$array, $i, 1;
  last;
}
$i++;
  }
}

sub Flush_Data {

  my ($file, $array) = @_;

  open(OUT, ">$file");
  flock(OUT, LOCK_EX);

  foreach (@$array) {
print OUT $_;
  }

  flock(OUT, LOCK_UN);
  close(OUT);
}






-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: What is my name

2003-10-30 Thread Sudarshan Raghavan
[EMAIL PROTECTED] wrote:

Hi,

I have a little problem. I have script "test.pl" and inside this script I want to know what is "my name" (I mean this "test.pl".

$0 will contain the program name
perldoc perlvar


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


What is my name

2003-10-30 Thread Hannu.Hirvonen
Hi,

I have a little problem. I have script "test.pl" and inside this script I want to know 
what is "my name" (I mean this "test.pl".

test.pl script
---

my $this_scripts_name_is = who_am_I();

sub who_am_I
{
  my $my_name = ;   # what I have to put to this "" to get "test.pl" scripts 
name

  return $my_name;
}

Idea is that I read some information from the beginning of this file. There is at 
least lines:

#
# Usage of this script
#
# Here are instructions for usage of this script
#
#

Everything else is under control but I don't know how to get this script's name 
"generally". When I solve this problem I will add this "Usage" fields to all my 
scripts. When running script without parameters (e.g. "test.pl") script print out this 
"Usage fields". 

Br,

- Hannu -

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



flock() semantics?

2003-10-30 Thread Shaun Fryer
Hi all,

I'm writing an app which uses a flat file to store a
*short* list of simple key/value pairs. However having
read the flock() man page, I'm unsure about whether I
need to seek() in cases where I'm not merely appending
to the file (such as when deleting a record).

sub Delete_Record {
my ($file, $key, $value, @array) = @_;
open(OUT, ">$file");
flock(OUT, LOCK_EX);

seek(OUT, 0, 0); # Should I do this?

foreach (@array) { # FYI: $/ = "\n"

seek(OUT, 0, 2); # Or perhaps this?

print OUT $_ unless ( m/^$key\s+$value$/ );
}
flock(OUT, LOCK_UN);
close(OUT);
}

Btw, the above code is just to illustrate the question,
thus no error checking and so forth.

-- 
=
 Shaun Fryer
=
 http://sourcery.ca/
 ph: 905-529-0591
=

Science is like sex: occasionally something useful
comes out of it, but that's not why we do it.
-: Richard Feynmann



pgp0.pgp
Description: PGP signature


config file: a) what Module ? b) conditionals in config (for multiple hosts)

2003-10-30 Thread henq
Hi,

a) I am looking for a module to handle config files. There are a number of
these modules, like AppCconig.  Any consensus about The Right Module for
this?


b) As I develop one one machine and test/deploy on another, I want
constructs in my config file like:

   if (`hostname` eq 'dev_box') {
mysql_dsn = 'foobar';
} elsif ((`hostname` eq 'test_box'}
mysql_dsn = 'abracadabra';
...

Any support for that in your module of choice?

I know of the use-just-perl-code approach (with 'do') in the Perl Cookbook,
but I am wondering if new insights exist.

TIA

~henq



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Module Object and sub module function

2003-10-30 Thread Rob Dixon
Dan Muey wrote:
>
> Sorry for the confusion, I was switching example names on everyone.
>
> I think I've got it.
>
> I've made it object oriented and functional based. (Gulp, kinda scary :-))
>
> I have

This is in your Mymodule.pm presumably?

> package Parent::Module::MyModule;

My only proviso is that in your first post you were using

  use lib '/home/me/modules/';
  use use Parent::Module::MyModule;

in which case your module source should be in

  /home/me/modules/Parent/Module/MyModule.pm

> With simply bare function names like so:
> (IE not Parent::Module::functionname {} so as not to invad namespace) sub 
> funtionname {}

That's exactly the way subclassing should work: remember that the only
access you're supposed to have to a class is through its public
interface. Perl makes it very easy to break rules like this.

> So One can do this:
>
> use Parent::Module::MyModule;
> my $r = Parent::Module::MyModule::functionname($parentobj,$arg);
>
> use Parent::Module::MyModule; qw(functionname);
> my $r = functionname($parentobj,$arg);


Neither of these is the right way to go about things. The first tries to cheat
by pretending to the method function that it's being called as a standard Perl
method call $parentobj->functionname. If you don't want to use it that way it
shouldn't be a method at all.

The second isn't right either. That qw(functionname) is sitting on its own
without making any difference to the world around it. If you had 'use warnings'
it would have told you so. Also you're exporting a method function and calling
it the same way as before.

I'm worried about what your $parentobj is. From its name I would think it's
a Parent::Module object, but your then trying to call a method from your new
subclass on it.

> Or if new() is called each function is "smart" enough to know that the first
> thing is a $self object and not the parent $obj and to use $self->{Parent}
> for the parent $obj.

This doesn't make sense. There should be no 'parent' object, just an object.
There is a parent (base) class and a subclass and all objects should belong
to one or the other. The existence of a $self->{Parent} implies that the
objects can be tree-structured, but this is part of the coding of the module
and nothing to do with class hierarchy.

> use Parent::Module::MyModule;
> my $newobj = new Parent::Module::MyModule($parentobj);
> my $r = $newobj->functionname($arg);
>
> Does that seem about right?

Well yes, it does look about right. But I can't see how you got here from
what's gone before! It still looks like you think you need to pass a
'parent' object to the subclass constructor to create your $newobj. Unless,
like I say, you're creating a fancy object that links to others of the same
type.

> Sorry for the confusion but it's been a fun learning example for me,
> sorry if I made it Monday for you :)

It's always Christmas Day for me Dan!

But I think you need to show us your code. I'm sure you're making things
too hard for yourself. Post it off-group to me if you'd rather and I'll
mark it up.

Cheers,

Rob



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Hash Issue or Understanding

2003-10-30 Thread Gary Stainburn
On Thursday 30 Oct 2003 8:17 am, [EMAIL PROTECTED] wrote:
> Hi,
>
>
>
>For those of you who helped me with my earlier scripts. Thanks.
>
>
[snip]
>
> It seems to me the hash started almost at the bottom of the list instead of
>
> With the hostname and work it way down. Is there any way to force the
>
> Order other than maybe specifying the array itself?.
>

Hi Phil,

it states in the perl docs that the sequence of the keys returned from a hash 
cannot be guaranteed, and even if they always return in the same order in the 
current version, that may change in a future version of perl.

If you *need* the keys returning in a specific order, you have to code this 
yourself.

One method I use is to have an array (which is always in the order specified) 
and use that instead of the keys  clause.

For your example I'd use

my 
@keylist=('hostname','os','osver','osrel','srvtype','srvmodel','memory','cpu');

and then

replace

foreach $CMD (keys %{$commands{$items}}){

with

foreach $CMD (@keylist){


>
>
> Phillip Bruce
> ISC Consultant, System Architect
> Location: Dublin, CA
> * Cell: 408-476-8658
> * Office: 925-560-7853
> AIM: OkieUnix

-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Hash Issue or Understanding

2003-10-30 Thread Sudarshan Raghavan

The output works but it not in the order I expected:

I expected my output to be:

hostname, IP addrress, OS, Version, Release, Server Type, Model, Memory
Size, Total CPU's.


But what I got was:



Model, Server Type, cpu, Release, hostname, OS, Memory Size, Version



It seems to me the hash started almost at the bottom of the list instead of

With the hostname and work it way down. Is there any way to force the

Order other than maybe specifying the array itself?.

As you have already figured out, there are no guarantees about order in 
a hash. The module Tie::IxHash will interest you.
perldoc -q 'How can I make my hash remember the order I put elements 
into it'

I think Tie::IxHash comes with the standard distribution from 5.8.0 
onwards (not sure though). If not, you can get it from 
http://search.cpan.org

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Issue

2003-10-30 Thread Gary Stainburn
On Wednesday 29 Oct 2003 7:35 pm, [EMAIL PROTECTED] wrote:
> Hi,
>
>   It has come to my attention that I need a little understanding
>   of what I'm doing here. Gary has provide some overview but not
>   Technical detail as I would like to have. That isn't his fault.
>   I admire his feedback for sure.
>
>   The code is obvious using hash. This is something I think I need
>   to get a little more clarity on. I would appreciate some feedback
>   Using the declaration I've setup here.
>
> #
> # List of Operating Systems
> #
> my %whichos=('SunOS'=>'sol',
>'Aix'  =>'aix',
>'HP-UX'=>'hpux',
>'Micorsoft'=>'W2K');
>
> #
> # List of Commands OS specific
> #
>
> my %commands = ('sol'=>{'hostname'=>'uname -n',
>   'os'=>'uname -s',
>   'osver' =>'uname -r',
>   'osrel' =>'cat /etc/release | awk \'{print
> $3}\'',
>   'srvtype'   =>'uname -p',
> 'srvmodel'  =>'uname -i | cut -f2 -d ","',
>   'memory'=>'prtconf | grep Memory | awk \'{print
> $3}\'',
>   'cpu' =>'psrinfo | awk \'{print $1}\' | wc -l'}
>   );
>
> With my declared array of whichos and commands. I need to understand
> What is considered the value and what is consider the key.
>
> In whichos I think SunOS is the key and the value is sol.
> In commands I think sol is the key and then a secondardy key is hostname
> with the value of uname -n.
>
> To me it looks as though whichos is a dual deminsioned array while commands
> Is a 3 x 3 deminsioned array.
>
> Have I got this correct so far or am I'm off my rocker?
>
> So if I'm going to search thru this array maybe use the following:
>
>  Foreach $OS (key $whichos){
>Foreach $CMD {key $command{$OS}){
>   Print $CMD;  <=== This should list out the values in commands array.
>}
>  }
>
> I think once I understand that then it be easier for me to understand how
> To assign that $CMD variable properly. Thanks for the feedback.

Hi Phil,
(I'll answer your other post when I can see what's wrong).

You're pretty close.  You are right about the %whichos hash, SunOS is the key 
pointing to 'sol' which is the value.

However, you're not quite there with the %commands.  You're right in that 
'sol' is a key, but not about the data.  The data is actually a pointer 
anonymous hash which then itself contains key/value pairs, 'os' being the key 
and 'uname -n' being the value.

your loop above would be: (not it's 'keys' not 'key', and because you're 
accessing whichos as a hash and not a scalar, you need to use the %)

foreach my $OS (keys (%whichos) { # loop through all whichos
  foreach my $cmd (keys %commands { # loop through commands for one OS
print "$cmd for $OS is '",$commands{$OS}{$cmd},"'.\n";
  }
}

example output would be:

memory for sol is 'prtconf | grep Memory | awk \'{print $3}\'.

to explain the $commands{$OS}{$cmd}:

$ means that we wish to extract a scalar
commands{$OS} gives us a pointer to the hash containg the commands for that OS
{$cms} gives us the hash value for the key $cmd in that hash

HTH

Gary

-- 
Gary Stainburn
 
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Hash Issue or Understanding

2003-10-30 Thread Bruce_Phillip
Hi,

 

   For those of you who helped me with my earlier scripts. Thanks.

 

   But I have a further problem in understanding something. Using 

   The following declaration:

 

my %commands = ('sol'=>{'hostname'  =>'uname -n', 

'os' =>'uname -s',

'osver' =>'uname -r',

 'osrel' =>'cat /etc/release
| awk \'{print $3}\'',

 'srvtype'  =>'uname -p',

 'srvmodel'   =>'uname -i | cut -f2
-d ","',

 'memory'=>'prtconf | grep
Memory | awk \'{print $3}\'',

 'cpu'   =>'psrinfo | awk
\'{print $1}\' | wc -l'}

);

 

 I have my code now as followed:

 

foreach $items (keys %commands) {

  foreach $CMD (keys %{$commands{$items}}){

print "Command: $CMD \n";

$results=(&get_response($commands{$items}{$CMD}))[0];

print OUT_FH "$results,","";

  }

}

 

The output works but it not in the order I expected:

I expected my output to be:

hostname, IP addrress, OS, Version, Release, Server Type, Model, Memory
Size, Total CPU's.

 

But what I got was:

 

Model, Server Type, cpu, Release, hostname, OS, Memory Size, Version

 

It seems to me the hash started almost at the bottom of the list instead of

With the hostname and work it way down. Is there any way to force the

Order other than maybe specifying the array itself?.

 

Phillip Bruce
ISC Consultant, System Architect
Location: Dublin, CA
* Cell: 408-476-8658
* Office: 925-560-7853 
AIM: OkieUnix 

 



Re: initialising a list of variables

2003-10-30 Thread Brian Gerard
And the clouds parted, and Rob Dixon said...
>
> Gary Stainburn wrote:
> >

> 
> Hi Gary.
> 
> Just one more offering:
> 
>$_ = '' foreach my ($fred, $ginger);
> 
> HTH,
> 
> Rob

...and in the spirit of TMTOWTDI...

map {$_=""} my ($fred, $ginger);

:)

  /~~\
 | Brian Gerard   Do not taunt Happy Fun Ball.|
 | First initial + 'lists'|
 | at technobrat dot com  |
  \__/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]