Silverfox
Aug 17 2003, 05:25 PM
David Storrs wrote:
QUOTE |
On Mon, Aug 11, 2003 at 09:42:40AM -0400, Stephen Gilbert wrote: -----Original Message----- From: SilverFox [mailto:[Email Removed]] Sent: Sunday, August 10, 2003 4:58 PM To: [Email Removed] Subject: Net::Telnet
hey anyone know how to check if a file exists using the Telnet module?
-- To unsubscribe, e-mail: [Email Removed] For additional commands, e-mail: [Email Removed]
try: $file_exists = $t->cmd("perl -e 'print 1 if (-s "file")'") or warn "Unable to execute command: $!n"; if ($file_exists) { # do whatever }
'if (-s)' will actually check that the file has non-zero size (-s returns the size; if the size if 0, it is false).
If you simply want to know whether it exists, but you don't care what size it is, then use -e.
--Dks
|
You guys are the best...thx
Bernhard Van Staveren
Aug 17 2003, 06:18 PM
Localtime takes it's input either from the time() function if you call it
without parameters, or from a timestamp you supply. So, if I wanted the
current date and time, but 10 minutes into the future I'd do:
my $mydate=localtime( time() + 600 );
(600 seconds being 10 minutes, added to the current time).
--
Bernhard van Staveren - madcat(at)ghostfield.com
GhostField Internet -
http://www.ghostfield.com/"A witty saying proves nothing, but damn it's funny!" - me, 1998
Silverfox
Aug 17 2003, 08:04 PM
Jeff 'Japhy' Pinyan wrote:
QUOTE |
On Aug 17, SilverFox said:
Hi all...how can I pull the number from the given path??
/Machine4/dir/dir/dir
Well, it's a little vague, but perhaps all you want is
my ($num) = $path =~ /(d+)/;
Or perhaps
my ($num) = $path =~ /Machine(d+)/;
Cool...that did the trick |
Marcos Rebelo
Aug 18 2003, 05:55 AM
the eseast way is having all the arrays in a hash.
map{$hash{$_}->[$index]="xxxx" if /^xyz/}(keys(%hash));
-----Original Message-----
From: T.S.Ravi Shankar [mailto:[Email Removed]]
Sent: Monday, August 18, 2003 8:51 AM
To: [Email Removed]
Cc: Ravi
Subject: get all the arrays with names starting with xyz
Hi all :
I have few arrays with names starting with "xyz_". After the initial
definitions I want to change values of a particular index of all arrays
whose names start with "xyz_". It would be cumbersome for me to do
something like :
$xyz_blahblah[$index] = "ldfhdlf";
$xyz_blooblooh[$index] = "dfhdlkfhdkf";
$xyz_foofoo[$index] = 27;
....
...
& so on...
particularly when the number of arrays are many !!
Is there any method to do this easily ?? Or could I get the names of all
arrays with a particular starting string & then group them in a array
and proceed ??
Thanks in advance !!
Regards,
Ravi
--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
Tassilo Von Parseval
Aug 18 2003, 11:07 AM
On Mon, Aug 18, 2003 at 07:34:41AM -0400 Kipp, James wrote:
QUOTE |
I have a file cointaing 1024 hex numbers . I want to convert them to Bin. Please help
try something like this:
$hex = 0xff; $bin = unpack("B32", pack("N", hex $hex));
|
The above assumes big-endian byteorder. For little-endian use "V" instead
of "N". Or just use "L" when the file has the same byteorder as the
machine you are running this script on.
Btw, the hex() above is probably wrong. hex() converts a string into a
numeric value by intepreting it as hexadecimal. Essentially, you do it
twice resulting in:
$hex = 0xff == 255 => hex(255) == 597
Whereas:
$hex = "0xff" => hex($hex) == 255
Tassilo
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.t$&."'!#+sexisexiixesixeseg;y~n~~dddd;eval
James Kipp
Aug 18 2003, 11:57 AM
QUOTE |
$hex = 0xff; $bin = unpack("B32", pack("N", hex $hex));
The above assumes big-endian byteorder. For little-endian use "V" instead of "N". Or just use "L" when the file has the same byteorder as the machine you are running this script on.
Btw, the hex() above is probably wrong. hex() converts a string into a numeric value by intepreting it as hexadecimal. Essentially, you do it twice resulting in:
|
woops, you are correct. the 'hex $hex' assumes it is passed as a string.
other than that it works as expected on both my Win2k (intel, little endian)
and Solaris (sparc, big endian). The bin result is returned in big endian on
both machines, so one would have to be cognizant that the result is not
returned in the native format for little endian machines. And yes it depends
on how the file is formatted. so we can make some adjustments:
--
$hex = '0xff'; #passed as a string
$bin = unpack("B32", pack("N", hex $hex));
print $bin;
---
$hex = 0xff;
$bin = unpack("B32", pack("N", $hex)); #passed as a hex number
print $bin;
----
# print in correct order for little endian machines
$hex = '0xff';
$bin = unpack("B32", pack("L", hex $hex));
print $bin;
-----
Thanks Tassilo !
Dan Muey
Aug 18 2003, 01:23 PM
QUOTE |
Hi Dan,
I don't think that is actually what he is asking for.Unless I misunderstand, he is referring to a pass-through program. Of
|
That's why I asked what he meant. The absolut simpleest would be:
#!/usr/bin/perl -w
use strict;
use CGI qw(header);
use File::Slurp;
pritn header();
print read_file("./index.html");
Pretty pointless unless you did something with the file:
my $file = read_file("./index.html");
$file =~ s/Joemama/Monkey/g;
print $file;
Now what I assumed he probably meant was:
print header();
if(whatever) { process formand output html results )
else { print formhtml }
Whatever.
Dan
QUOTE |
course, a pure passthrough program would be pointless--it would be quicker to serve the page up directly through a http GET. OTOH, if you have some simple insertion magic to do on a template page, this is a very goo strategy, and one I use:
open (WEATHERPAGE, "Current_Vantage_Pro.htm") || die ("can't open source file"); my $CurrentLine = ""; while (!(($CurrentLine = <WEATHERPAGE>) =~ /head/i)) {;} # the head section is sent elsewhere, as is the CGI header while (!(($CurrentLine = <WEATHERPAGE>) =~ //table/i)) { print "$CurrentLine"; } print "$CurrentLine"; if (my $Test = GetConditions ($contents)) { InsertWarning ($contents); } while ($CurrentLine = <WEATHERPAGE>) { print "$CurrentLine"; } close WEATHERPAGE; }
Of course this presumes that either:
The source file has the CGI Content-type header, or that the program has already sent it. Once the proper header is sent, it is perfectly easy to pass through a local file.
As to style, this was one of my ealry scripts. I now use choo_choo_train rather than CamelBack for identifiers other than class names. May have to do some "Replace All" magic on my work from this period..
Joseph
|
------------------------------------------------
On Sun, 17 Aug 2003 19:26:53 +0200, Bjrn_Brombach <[Email Removed]> wrote:
QUOTE |
I wanted to add some more details: When i use this skript:
my $supported = Net::SSH::Perl::Cipher::supported(); for my $cipher (sort @$supported) { printf " [%d] %sn", $ciph, Net::SSH::Perl::Cipher::name($cipher); }
I get only [5] RC4 as a result. So maybe thats why i always get that not supported cipher type message when trying to use des or 3des. Where could i change or add the supported cipher types? And still makes me wonder as the shell ssh command works fine and all cipher types are supported. Am i missing a module?
|
Net::SSH::Perl relies on a number of modules for the different cipher types, DES as well. The local SSH client has nothing to do with the module as it handles the whole process internally rather than shelling out or using an external client. If it is telling you all you have available is RC4 then that is probably correct and you need to install the other modules.
If my records are correct you should only need Crypt::DES to add DES support. You might try installing using CPAN rather than the SUSE package (if that is how you installed it) so that you are prompted for the compatibilities you want in Net::SSH::Perl and to make sure the dependencies are satisfied as there are a lot of them (if you installed from CPAN did it not prompt you?). I will attach the dependency chart I generated before (though it may not be complete, for all ciphers, etc.) (There is also a bug in Math::PARI/pari if you have a long running application that causes a memory leak that generates weird results - it takes about 2 hours to generate running about 30 commands every minute)
Does this help?
http://danconia.orgDependency list:
- Net::SSH::Perl (requires
- Digest::HMAC_MD5 (requires Digest::MD5, Digest::SHA1)
- Digest::MD5 (requires N/A)
- Digest::SHA1 (requires N/A)
- Crypt::DSA (requires Crypt::Random, Math::Pari, Digest::SHA1, prefers Data::Buffer
for (ssh2))
- Crypt::Random (requires Math::Pari, Class::Loader)
- Class::Loader (requires N/A)
- Math::Pari (requires pari C libraries)
- Math::Pari (requires pari C libraries)
- Digest::SHA1 (requires N/A)
- Data::Buffer (requires N/A)
- Crypt::RSA (requires Digest::MD2, Convert::ASCII::Armour, Crypt::Primes, Tie::EncryptedHash, Crypt::Blowfish, Sort::Versions)
- Digest::MD2 (requires N/A)
- Convert::ASCII::Armour (requires Digest::MD5, Compress::Zlib)
- Digest::MD5 (requires N/A)
- Compress::Zlib (requires N/A)
- Crypt::Primes (requires Crypt::Random, Math::Pari)
- Crypt::Random (requires Math::Pari, Class::Loader)
- Class::Loader (requires N/A)
- Math::Pari (requires pari C libraries)
- Math::Pari (requires pari C libraries)
- Tie::EncryptedHash (requires Crypt::Blowfish, Crypt::CBC, Crypt::DES)
- Crypt::Blowfish (requires N/A)
- Crypt::CBC (requires Digest::MD5, Crypt::Rijndael)
- Digest::MD5 (requires N/A)
- Crypt::Rijndael (requires N/A)
- Crypt::DES (requires N/A, prefers Crypt::CBC)
- Crypt::CBC (requires Digest::MD5, Crypt::Rijndael)
- Digest::MD5 (requires N/A)
- Crypt::Rijndael (requires N/A)
- Crypt::Blowfish (requires N/A)
- Sort::Versions (requires N/A)
- Convert::PEM (requires Digest::MD5, Convert::ASN1, Crypt::DES_EDE3)
- Digest::MD5 (requires N/A)
- Convert::ASN1 (requires N/A)
- Crypt::DES_EDE3 (requires Crypt::DES)
- Crypt::DES (requires N/A, prefers Crypt::CBC)
- Crypt::CBC (requires Digest::MD5, Crypt::Rijndael)
- Digest::MD5 (requires N/A)
- Crypt::Rijndael (requires N/A)
- Crypt::DH (requires Crypt::Random, Math::Pari)
- Crypt::Random (requires Math::Pari, Class::Loader)
- Class::Loader (requires N/A)
- Math::Pari (requires pari C libraries)
- Math::Pari (requires pari C libraries)
- Math::Pari (requires pari C libraries)
- Crypt::DES (requires N/A, prefers Crypt::CBC)
- Digest::SHA1 (requires N/A)
? Math::GMP (requires gmp C libraries) (ssh1 only)
QUOTE |
Furthermore i wanted to add the debug output:
server: Reading configuration data /root/.ssh/config server: Reading configuration data /etc/ssh_config server: Allocated local port 1023. server: Connecting to 192.168.30.4, port 22. server: Remote protocol version 1.99, remote software version OpenSSH_3.5p1 server: Net::SSH::Perl Version 1.23, protocol version 1.5. server: No compat match: OpenSSH_3.5p1. server: Connection established. server: Waiting for server public key. server: Received server public key (768 bits) and host key (1024 bits). server: Host '192.168.30.4' is known and matches the host key. Selected cipher type des not supported by server. at ./test.pl line 14
Thanks -bb
-----Ursprngliche Nachricht----- Von: Bjrn Brombach [mailto:[Email Removed]] Gesendet: Sonntag, 17. August 2003 18:22 An: perl Betreff: SSH Problem
Hi, I have installed SuSE 8.2, perl-Net-SSH-Perl-1.23, String-CRC32-1.2. I am trying to make an SSH connection to a remote SuSe 8.2 computer. And the perl skript is where i am having the problem. Trying to use it produces the following error: "selected cipher type DES not supported by server."
I tried 3DES as well, same error. This is what i used:
# !/usr/bin/perl use Net::SSH::Perl;
$host="host"; $passwd="passwd"; $user="user";
my $ssh=Met::SSH::Perl->new($host); my $ssh=Net::SSH::Perl->new($host,cipher=>'DES'); $ssh->login($user,$passwd); $ssh->cmd("who");
When i use >ssh -c des -l user ip_add from the command prompt the connection to the other Linux boxes works perfect. So i dont understand where the error is. I hope someone has a clue or can point me to a link where i can get further help.
Thanks for any replies -bb
|
James Edward Gray II
Aug 18 2003, 02:38 PM
On Monday, August 18, 2003, at 10:29 AM, awards wrote:
QUOTE |
Hi,
I have no idea how to do this. I have a name Anthony Bob I want to put each letter in an array (no space)
|
my $name = 'Anthony Bob';
$name =~ tr/ //d; # remove the space
my @letters = split //, $name;
QUOTE |
for(0..$numbersofletters){ @letters[c]= A LETTER } so when i do print @letters i get
|
print "$_n" foreach @letters;
Hope that helps.
James
QUOTE |
A N T H O N Y B O B something like that, any help is appreciated. Anthony
-- To unsubscribe, e-mail: [Email Removed] For additional commands, e-mail: [Email Removed]
|
Awards
Aug 18 2003, 02:46 PM
Hi,
That is quite simple. I tought it would be more difficult than that :-)
Thank you both of you
Anthony
Dan Muey
Aug 18 2003, 02:47 PM
Howdy
QUOTE |
That is quite simple. I tought it would be more difficult than that :-)
|
It's cuz Perl rocks!!
QUOTE |
Thank you both of you Anthony
-- To unsubscribe, e-mail: [Email Removed] For additional commands, e-mail: [Email Removed]
|
Rob Hanson
Aug 18 2003, 02:49 PM
Just to throw out another idea, you can also do this...
my $name = "Anthony Bob";
my @letters = grep {!/s/} split('', $name);
# to test
print "@letters";
It also looks like you wanted upper case. You can do that with this...
my $name = "Anthony Bob";
my @letters = grep {!/s/} split('', uc($name));
In both cases the split cuts it up into a list of characters, and grep
filters out the spaces (also newlines & tabs).
Rob
-----Original Message-----
From: awards [mailto:[Email Removed]]
Sent: Monday, August 18, 2003 11:30 AM
To: [Email Removed]
Subject: need help decompose word
Hi,
I have no idea how to do this.
I have a name
Anthony Bob
I want to put each letter in an array (no space)
for(0..$numbersofletters){
@letters[c]= A LETTER
}
so when i do print @letters i get
A
N
T
H
O
N
Y
B
O
B
something like that, any help is appreciated.
Anthony
--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
Rob Hanson
Aug 18 2003, 03:17 PM
Like this...
$string="1
blabla";
my @lines = split("n", $string);
# testing...
print "1: $lines[0]n";
print "2: $lines[1]n";
See perldoc -f split if you want more info on the command.
Rob
-----Original Message-----
From: Pablo Fischer [mailto:[Email Removed]]
Sent: Monday, August 18, 2003 11:58 AM
To: [Email Removed]
Subject: Split NewLines
Hi!
I have in $string something like:
$string="1
blabla";
When Im printing $string I get a new line between 1 and blabla, now I needt
o
split that.. in
my($number, $real_string) = split...
How can I split it?
Thanks!
Pd. Its a scalar variable
Pablo
--
Pablo Fischer Sandoval ([Email Removed])
http://www.pablo.com.mxhttp://www.debianmexico.orgGPG FingerTip: 3D49 4CB8 8951 F2CA 8131 AF7C D1B9 1FB9 6B11 810C
Firma URL:
http://www.pablo.com.mx/firmagpg.txt--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
Bob Showalter
Aug 18 2003, 04:10 PM
awards wrote:
QUOTE |
Hi,
I have no idea how to do this. I have a name Anthony Bob I want to put each letter in an array (no space) for(0..$numbersofletters){ @letters[c]= A LETTER } so when i do print @letters i get A N T H O N Y B O B something like that, any help is appreciated. Anthony
|
Rather than using split and grep, you can use a capturing regex with /g in
list context to return a list of matches:
@letters = uc($word) =~ /([A-Z])/g;
David
Aug 18 2003, 07:14 PM
T.S.Ravi Shankar wrote:
QUOTE |
Hi all :
I have few arrays with names starting with "xyz_". After the initial definitions I want to change values of a particular index of all arrays whose names start with "xyz_". It would be cumbersome for me to do something like :
$xyz_blahblah[$index] = "ldfhdlf"; $xyz_blooblooh[$index] = "dfhdlkfhdkf"; $xyz_foofoo[$index] = 27;
& so on...
particularly when the number of arrays are many !!
Is there any method to do this easily ?? Or could I get the names of all arrays with a particular starting string & then group them in a array and proceed ??
|
depends on how you declare (global or lexical), you might go to the symbol
table and ask for a certain type of variables (array, hash, scalar, etc)
and update their values. the following assumes that you declare your
variables as global with 'our' and update the third element (to have the
value of 99) of all arrays whose name begines with 'xyz':
#!/usr/bin/perl -w
use strict;
#--
#-- the following 3 arrays are declared with 'our' which makes
#-- them global and thus visible in the symbol table. the third
#-- element of those arrays will be updated to have the value of 99
#--
our @xyz_var1 = 1 .. 5;
our @xyz_var2 = 2 .. 6;
our @xyz_change_me = 12 .. 16;
#--
#-- the following is not updated:
#--
#-- @dont_change_me: because it doesn't start with xyz
#-- %xyz_dont_change_me: because it's a hash, not array
#-- $xyz_dont_change_me: because it's a sclar, not array
#-- @xzy_not_global: because it's declared with 'my' which makes it lexical
#--
our @dont_change_me = 7 .. 11;
our %xyz_dont_change_me = 50 .. 53;
our $xyz_dont_change_me = 100;
my @xzy_not_global = 17 .. 21;
#--
#-- this asks the symbol table for all globol variables declared so far
#-- and update the array's 3rd element to 99
#--
$::{$_}->[2] = 99 for(grep {/^xyz/} keys %::);
#--
#-- demo to show their values are indeed changed
#--
print join(" ",@xyz_var1),"n";
print join(" ",@xyz_var2),"n";
print join(" ",@xyz_change_me),"nn";
#--
#-- demo to show that this is not changed
#--
print join(" ",@dont_change_me),"n";
print join(" ",@xzy_not_global),"n";
__END__
prints:
1 2 99 4 5
2 3 99 5 6
12 13 99 15 16
7 8 9 10 11
17 18 19 20 21
generally, this is a poor approach especially if you are new to Perl. you
might accidentally change something that you are not intended to change.
other disadvantages include:
* it's slow because it walks the entire symbol table each time it's called.
you can improve this by caching the variables in a hash but you must be
careful that you don't declare more arrays after you cache them because the
cache version won't see those.
* it's dangerous because we might change something that you don't really
want to change. this is especially important if you are new to Perl.
* if your arrays are declared with 'my', they won't be changed at all.
david
John W. Krahn
Aug 18 2003, 07:56 PM
Awards wrote:
Hello,
QUOTE |
I have no idea how to do this. I have a name Anthony Bob I want to put each letter in an array (no space) for(0..$numbersofletters){ @letters[c]= A LETTER } so when i do print @letters i get A N T H O N Y B O B something like that, any help is appreciated.
|
my $text = ' Anthony Bob ';
my @letters = $text =~ /[[:alpha:]]/g;
print "$_n" for @letters;
John
--
use Perl;
program
fulfillment
Christopher X66156 McMahon
Aug 18 2003, 07:58 PM
I'll take this a step further. Search Google for "de icaza .net".
Miguel de Icaza produced the GNOME desktop and founded Ximian/Mono. He's
quoted all over the place discussing what .NET has to offer beyond the MS
arena, for Open Source and wide interoperability. I think that de Icaza
explains .NET better than Microsoft has... at least from a developer's point
of view.
ActiveState has a Perl environment "Visual Perl" that seems to be
capable of interacting in a .NET sort of way with other .NET languages,
which is pretty cool.
.NET is worth investigating if for no other reason than that it
seems to be the MS answer to Sun's Java *and* IBM's WebSphere. And it has
a lot of room to grow.
I'm interested because I just got a job with an all-Windows shop
migrating apps from C++ to .NET. Except for Windows workstations and a
little bit of MS ODBC, all my professional experience has been on Tandem,
Solaris, and AIX. I hope .NET is as cool as de Icaza says it is, because
Windows kinda creeps me out. It's just very weird having all of that
abstraction/secret code between me and what the OS is doing.
-Chris
-----Original Message-----
From: [Email Removed] [mailto:[Email Removed]]
Sent: Monday, August 18, 2003 1:45 PM
To: Rich Parker; [Email Removed]
Subject: RE: New to list, question.
------------------------------------------------
On Mon, 18 Aug 2003 12:40:02 -0700, Rich Parker <[Email Removed]>
wrote:
QUOTE |
Hi, I've been involved with Perl for many years (too many to count right now). One question has been bugging me lately, and maybe it's because I don't know enough about it, or maybe it's because I've been "Not the biggest fan" of Mr. Bill and his org... Either way, I'm attempting to learn about .NET (Don't panic here, I'm just looking for some information).
Mainly, how does, or can the .NET framework be of benefit to the Perl developer at large? Am I going to get any "Bang for my buck" using Perl in the .NET environment? But WAIT, I'm working on Linux Systems, how does that effect what I am asking?? If someone could provide me a link to some articles about .NET from many different perspectives, preferably NOT by MS (If you catch my drift here). I want to see if this framework is going to be something of use to me.
Thanks for ANY help you can provide.
|
You may want to check out the MONO project:
http://go-mono.org/http://danconia.org_
This message and any attachments are intended only for the use of the addressee and
may contain information that is privileged and confidential. If the reader of the
message is not the intended recipient or an authorized representative of the
intended recipient, you are hereby notified that any dissemination of this
communication is strictly prohibited. If you have received this communication in
error, please notify us immediately by e-mail and delete the message and any
attachments from your system.
Bob Showalter
Aug 18 2003, 08:03 PM
John W. Krahn wrote:
QUOTE |
... my @letters = $text =~ /[[:alpha:]]/g;
|
I never knew you could leave the parens off in a case like this. I just went
and looked it up. Neat!
Bernhard Van Staveren
Aug 18 2003, 08:12 PM
QUOTE |
my $text = ' Anthony Bob ';
my @letters = $text =~ /[[:alpha:]]/g;
print "$_n" for @letters;
|
This works too (at least, works for me):
my $text='Anthony Bob';
my @letters=split(//, $text);
print(join("n", @letters));
--
Bernhard van Staveren - madcat(at)ghostfield.com
GhostField Internet -
http://www.ghostfield.com/"A witty saying proves nothing, but damn it's funny!" - me, 1998
Rich Parker
Aug 18 2003, 09:43 PM
Very interesting reading, Thanks,
Actually, it "Could be" great reading to "Sleep by". But I have a
concern about all of this, be that a MS "Controlled" .NET or even an
"OPEN source" Mono. Who is going to "control" where all of this resides?
Let's take the MS idea of .NET for a moment, remember WHEN the Justice
dept tried to "Go after" MS because they had too much control of things?
Regardless of my personal opinions on this (Bill who?) doesn't this
whole idea give Mr. Gates more of the opportunity that IF anyone tries
"That" again, the HE could "Pull the plug" and everyone who is using
..NET now can't make their programs run? Isn't that a REAL possibility?
Or let's look at it from the OPEN Source side, if ALL of this "common
code" (For lack of a better word right now) was at one or a "Handful" of
sites, and let's just say there was a "Power outage" (Remember the great
power outage of 2003?), then what? The rest of us are still working, but
WE can't access the needed files to make our Internet or Intranet sites
work, so now we start having a cascade failure of the NET (No DOT here,
everyone). From a company perspective, the concept of .NET is wonderful,
as long as "Our source code" is just that, "OURS". But from the poor guy
who suddenly NOW has to pay MS (Back to .NET again) a monthly fee just
to OPEN a Word Doc, I don't see the public going for that. Do I have
this wrong? Don't tell me Mr. Gates is going to keep the basic modules
for MS-Word free for everyone?? Yea right. I'm just concerned, that's
all, I love the idea of "Every developer" getting his "Fair share" for
the bits & pieces he creates, and YES, we are NOT reusing our code
enough, but is THIS the correct solution??
Anyone got anymore links for me? I noticed that when I did that search
on the "de icaza .net" (without the quotes, duh?) that the TOP article
was on O'Reilly, I like their books, don't get me wrong, but will they
publish someone else's "Point of view", even though de Icaza seems like
a "Sharp cookie" and admittedly, this is this first time I've heard of
him. I'd like to hear what others have to say. I've been developing Perl
based web sites for a long time, what I've always liked about it was/is
the fact that it actually works and it's included with the O/S's like
Linux (Ok, use the word - FREE) and I just feel that if Bill gets His
way, that we'll all loose out on the word FREE. Now if this idea was
like a "Newsgroup" where the various news servers got reloaded from time
to time and the code wasn't just in ONE spot, I might be willing to
really support it, but the more I learn about this, the more questions I
have. Somebody HELP me understand why this is the NEXT thing in
software. I just don't get it.
Thanks.
McMahon, Christopher x66156 wrote:
QUOTE |
I'll take this a step further. Search Google for "de icaza .net". Miguel de Icaza produced the GNOME desktop and founded Ximian/Mono. He's quoted all over the place discussing what .NET has to offer beyond the MS arena, for Open Source and wide interoperability. I think that de Icaza explains .NET better than Microsoft has... at least from a developer's point of view. ActiveState has a Perl environment "Visual Perl" that seems to be capable of interacting in a .NET sort of way with other .NET languages, which is pretty cool. .NET is worth investigating if for no other reason than that it seems to be the MS answer to Sun's Java *and* IBM's WebSphere. And it has a lot of room to grow. I'm interested because I just got a job with an all-Windows shop migrating apps from C++ to .NET. Except for Windows workstations and a little bit of MS ODBC, all my professional experience has been on Tandem, Solaris, and AIX. I hope .NET is as cool as de Icaza says it is, because Windows kinda creeps me out. It's just very weird having all of that abstraction/secret code between me and what the OS is doing. -Chris
-----Original Message----- From: [Email Removed] [mailto:[Email Removed]] Sent: Monday, August 18, 2003 1:45 PM To: Rich Parker; [Email Removed] Subject: RE: New to list, question.
------------------------------------------------ On Mon, 18 Aug 2003 12:40:02 -0700, Rich Parker <[Email Removed] wrote:
Hi, I've been involved with Perl for many years (too many to count right now). One question has been bugging me lately, and maybe it's because I don't know enough about it, or maybe it's because I've been "Not the biggest fan" of Mr. Bill and his org... Either way, I'm attempting to learn about .NET (Don't panic here, I'm just looking for some
information).
Mainly, how does, or can the .NET framework be of benefit to the Perl developer at large? Am I going to get any "Bang for my buck" using Perl in the .NET environment? But WAIT, I'm working on Linux Systems, how does that effect what I am asking?? If someone could provide me a link to some articles about .NET from many different perspectives, preferably NOT by MS (If you catch my drift here). I want to see if this framework is going to be something of use to me.
Thanks for ANY help you can provide.
You may want to check out the MONO project:
http://go-mono.org/
http://danconia.org
_ This message and any attachments are intended only for the use of the addressee and may contain information that is privileged and confidential. If the reader of the message is not the intended recipient or an authorized representative of the intended recipient, you are hereby notified that any dissemination of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail and delete the message and any attachments from your system.
|
Ramprasad A Padmanabhan
Aug 19 2003, 07:06 AM
Voodoo Raja wrote:
QUOTE |
Sorry for not posting it in the first place.
Will this sub.. chew memory if I run it a number of times.. or does it overwrite it.
sub read { print "nreading data"; $db = DBI->connect("DBI:mysql:$dbase:$hostname", $username, $password); $query = $db->prepare("SELECT * FROM cash where f1 = '1002'"); $query->execute; $numrows = $query->rows; while (@array = $query->fetchrow_array ) { ($field1, $field2, $field3, $field4, $field5, $field6, $field7, $field8, $field9, $field10, $field11, $field12, $field13, $field14, $field15, $field16, $field17, $field18) = @array;} $query->finish; $db->disconnect; print "nf1 is $field1"; $lasttrans = "$field1"; $newtrans = ($lasttrans+1); }
this is the exact sub where I feel that I am doing something wrong.. Should this leave memory occupied if I run this loop a number of times What happans if I runn this a number of times...
I am sorry if I cant explain it anybetter.. I am trying my best to learn this. please take me as a very begginer..
Regards Sam
From: Ramprasad A Padmanabhan <[Email Removed] To: [Email Removed], Samuel Shankar <[Email Removed] CC: [Email Removed] Subject: Re: Display realtime data As it changes in the databse - TK Date: Tue, 19 Aug 2003 11:32:33 +0530
Samuel Shankar wrote:
Hi List
I was wandering if someone can help me out in displaying database data in a TK window.
please wander a little more, on google if you are looking for readymade script
I have tried a number of ways but I am loosing memory eventually.. I vet all "my"'s are not really mine..
All I need to do is fetch from a database and display it In a GUI based window. Or some ones has got a a better ways to flush ..
Display real time database data without losing memory in perl TK
Best Regards SAM
How can any one help if you dont post your code
Ram
|
What you seem to be doing is not very clear. Why are you running this loop
while (@array = $query->fetchrow_array ) {
($field1, $field2, $field3, $field4, $field5, $field6, $field7, $field8,
$field9, $field10,
$field11, $field12, $field13, $field14, $field15, $field16, $field17,
$field18) = @array;}
If you just want the last transaction id change the query
to "select max($field1) from cash where $x = $y ";
This will give you the last transaction id directly
BTW
1) Have you considered using an autoincrement field
2) Do not connect to the database in every function of yours .
Make one connection in the beginning and pass the handle to all functions.
3) And when you post a reply to a newsgroup post your reply *at the
bottom* avoid top posting
Ram
Gary Stainburn
Aug 19 2003, 10:38 AM
On Tuesday 19 Aug 2003 12:25 pm, Gary Stainburn wrote:
QUOTE |
Hi folks,
I'm getting:
Use of uninitialized value in hash element at /home/gary/bin/svcimport line 188, <FIN> line 4301.
when running my program, of which like 188 is:
$addr4=$abbrevs{$addr4} if (defined $abbrevs{$addr4}); # expand abbreviations
Surely the 'if defined' should prevent this from happening by checking that it is in fact initialized. BTW, I'm not getting it for every input line, but for a significant number.
|
I've sussed it, I hand an empty pair (''=>'') in the hash from when I was
keying in the key/value pairs.
--
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
James D. Durick
Aug 19 2003, 12:27 PM
I wanted to test the bandwidth for my website every 15 minutes (to verify my
ISP was getting me 1.5 like they say)and was wondering if there are any
modules that make the job easier. Any help would be appreciated.
Currently, there are tools out there that do what I want but I wanted to
write my own and was wondering if anyone had any ideas.
tia
-----Original Message-----
From: Gabriel Cooper [mailto:[Email Removed]]
Sent: Tuesday, August 19, 2003 9:01 AM
To: Voodoo Raja
Cc: [Email Removed]
Subject: Re: Display realtime data As it changes in the databse - TK
Ramprasad A Padmanabhan wrote:
QUOTE |
Voodoo Raja wrote:
Sorry for not posting it in the first place.
Will this sub.. chew memory if I run it a number of times.. or does it overwrite it.
sub read { print "nreading data"; $db = DBI->connect("DBI:mysql:$dbase:$hostname", $username, $password);
as Ramprasad said, you should pass in your db connection if you use it |
in more than one function...
QUOTE |
$query = $db->prepare("SELECT * FROM cash where f1 = '1002'");
Generally speaking, if you're selecting " * " then you're doing |
something wrong. You should only select exactly what you want from a
database rather than "just give me it all and I'll figure it out later".
Especially because--judging from the loop below--you don't appear to use
anything in the db except the first field, but also because this method
doesn't take into account changing database structure. Ramprasad
suggested "select max($field1) from cash where $x = $y " but keep in
mind you should do this using placeholders where any user input is
involved to protect yourself from SQL injection attacks. =]
QUOTE |
$query->execute; $numrows = $query->rows; while (@array = $query->fetchrow_array ) { ($field1, $field2, $field3, $field4, $field5, $field6, $field7, $field8, $field9, $field10, $field11, $field12, $field13, $field14, $field15, $field16, $field17, $field18) = @array;} $query->finish; $db->disconnect;
Don't disconnect yourself from the database in the middle of a while |
loop that's iterating through database query results!
Move finish and disconnect out of the loop.
QUOTE |
print "nf1 is $field1"; $lasttrans = "$field1"; $newtrans = ($lasttrans+1); }
[...]
What you seem to be doing is not very clear. Why are you running this loop while (@array = $query->fetchrow_array ) { ($field1, $field2, $field3, $field4, $field5, $field6, $field7, $field8, $field9, $field10, $field11, $field12, $field13, $field14, $field15, $field16, $field17, $field18) = @array;}
If you just want the last transaction id change the query to "select max($field1) from cash where $x = $y ";
This will give you the last transaction id directly
BTW 1) Have you considered using an autoincrement field 2) Do not connect to the database in every function of yours . Make one connection in the beginning and pass the handle to all functions. 3) And when you post a reply to a newsgroup post your reply *at the bottom* avoid top posting
Ram
|
--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
Dan Muey
Aug 19 2003, 01:56 PM
Howdy,
When starting a new thread don't top post on another thread.
QUOTE |
I wanted to test the bandwidth for my website every 15 minutes (to verify my ISP was getting me 1.5 like they say)and was wondering if there are any modules that make the
|
That would depend on how you plan to measure the speed. Are you downloading
a file and calulating the speed like "bandwidth testing" places do?
Are you keeping track of packets in a datatbase, interfacing a QOS system, etc?
The method you use to figure that will decide how you go about doing it with Perl.
QUOTE |
job easier. Any help would be appreciated. Currently, there are tools out there that do what I want but I wanted to write my own and was wondering if anyone had any ideas. Tia\
|
What tools are they? Maybe we can find a way to do what they do in Perl.
James Willmore
Aug 20 2003, 04:37 AM
Shawn Milochik <[Email Removed]> wrote in message news:<[Email Removed]>...
QUOTE |
Here's the project: I want to download my mail, and optionally do zero or more of the following:
1. Forward certain messages to another e-mail address. 2. Send a particular auto-response, depending upon sender. 3. E-mail a list of all e-mail senders/subjects to another e-mail address.
Then, I want to filter all messages through a Bayesian filter, probably Spamassassin, then place the good messages back into my original e-mail account, except in another box, such as "unread" instead of back into the inbox, and spam into another box, such as "spam"
|
Okay, so far the only thing you need to do is read the documentation
for spammassassin. There's a few ways to do it. I personally use
MH-mail, procmail, postfix, and fetchmail. Fetchmail picks up the
mail, forwards it to the SMTP server on the box, checks for viruses
(yes, you CAN check mail for viruses on Linux - not that it would harm
anything - but my wife enjoys Windows, so I have to keep her safe and
get her mail - then she grabs the mail off my system ... where was I
.... oh, ya), then it goes through procmail, which has a "recipe" to
filter it using spamassassin (to pick up "stray" spam - read on). So
far, the only thing Perl is spamassassin.
QUOTE |
I do not want to use any of the user mail functionality of my Linux server -- I just want to use my pop3/smtp e-mail account, and I want everything to be put back into my pop3/smtp e-mail account after it's been filtered, so that I can check it with webmail.
|
Well, this again is not Perl, but you can set fetchmail NOT to mark
messages as being read when you get them. Not exactly what you
wanted, but to send mail BACK to your webmail account seems redundent
- but that's my opinion and the fact that I'm spoilled by my ISP
(which does use spamassassin). However, if you want to 'roll your
own' solution, there are several Perl modules to aid you in this task.
Check
http://search.cpan.org/Just a side note: if you are responsible about testing, you're going
to need to set up a mail server anyway. I can speak from experience
that it's a bad idea to use a script (or fetchmail for that matter)
and not test it in a controled environment first. You end up lossing
mail if you don't test first ;)
QUOTE |
So the question is, should I use a hobbled together combination of fetchmail, procmail, and sendmail (hereafter referred to as "FPS"), or a Perl script?
|
IMHO, use the tools on your system. They are proven, maintained, and
work. That's not a reflection of any Perl scripts you may find/write
- but why re-invent the wheel? Unless that what's you want to do. I
mean, why write say, a web server in Perl, unless you think you can do
better than Apache -or- want the experience. HOWEVER, I'd ditch
sendmail and start using postfix ... but here again, not Perl and just
my opinion.
If you decide to 'roll your own', you're going to have a monumental
task ahead of you.
HTH
Jim
Cowboy
Aug 20 2003, 06:03 AM
"Horace Franklin Jr." <[Email Removed]> glsD
:01a201c2f2eb$d2fcbb90$ada5d043@mrsp3e1puadvh3...
Help!
I need help using %hashes to receive input from the form below.
What changes would I make to the syntax of the commented lines
below to do this?.
my $form = <<E_FORM;
<h3>Hello!</h3>
<form action="$url" method="post">
# <p><b>My name is</b>: <input type="text" name="name"/></p>
# <p><b>My E-mail is</b>: <input type="text" name="email"/></p>
<p><b>Message</b>:</p>
# <p><textarea cols="30" rows="6" wrap="virtual" name="message"></p>
<p>Type your message here.
</textarea>
<input type="submit"></p>
</form>
E_FORM
$form;
Marcos Rebelo
Aug 20 2003, 02:26 PM
old_script.pl | perl -e "while (<>) {print $_; warn $_}" 2> $logFile
Or redefine the print
-----Original Message-----
From: mark sony [mailto:[Email Removed]]
Sent: Wednesday, August 20, 2003 3:11 PM
To: [Email Removed]
Cc: [Email Removed]
Subject: create log as well as print on screen
Hi All,
I wrote a script which is running perfectly fine providing
many outputs on the screen . Only glitch is that it does not print
in a log file . Now what I want is that it would print on the
screen as well as create a log file . At the end of the program I
will output that the above output can also be seen at the
$log_File_position . Hope I am clear with my question . Any type
of pointers and I would be over the moon ;)
Thanx in advance
Mark
___________________________________________________
Meet your old school or college friends from
1 Million + database...
Click here to reunite www.batchmates.com/rediff.asp
--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
Jenda Krynicky
Aug 20 2003, 05:36 PM
From: "mark sony" <[Email Removed]>
QUOTE |
I wrote a script which is running perfectly fine providing many outputs on the screen . Only glitch is that it does not print in a log file . Now what I want is that it would print on the screen as well as create a log file . At the end of the program I will output that the above output can also be seen at the $log_File_position . Hope I am clear with my question . Any type of pointers and I would be over the moon ;)
|
http://search.cpan.org/dist/IO-Tee/http://jenda.krynicky.cz/#Local::TeeOutputHTH, Jenda
===== [Email Removed] ===
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
James Edward Gray II
Aug 20 2003, 11:57 PM
On Wednesday, August 20, 2003, at 04:30 PM, Erich Musick wrote:
QUOTE |
I'm having trouble doing multiple inheritance...I want to inherit not only the subroutines from two classes, but also the instance variables. how do i do this?
|
Methods are the easy part:
our @ISA = qw(ClassOne ClassTwo Etc);
Perl doesn't really provide a method for instance variable inheritance
(even for single inheritance), but you can generally roll your own easy
enough. Here's one possible method:
sub new {
my $class = shift;
my $object = { };
$object = $_->new(%$object) foreach @ISA;
# class specific initialization here...
return bless $object, ref($class) || $class;
}
This is heavily dependent on the classes you are trying to inherit from
though, so you may have to get a little more creative. Watch for
parent classes stomping on each others' member data with this too, it
could happen.
If you need something more robust, you might create instances of the
parent classes as store them internally as private instance data. You
could then basically use your class as a proxy for them, passing what
is needed, to who, when. You probably need to do a little more
subroutine work for this method, though I imagine most of them would
just be one-liners calling the appropriate parent method on the
internal object. A good AUTOLOAD with a little can() magic should even
get you around this, if you're Lazy.
Well, hopefully that at least gives you a couple of ideas. Good luck.
James
Bryan Harris
Aug 21 2003, 12:17 AM
I often have a line like this at the beginning of my scripts:
@ARGV or die "Usage: blahn";
.... but I've seen:
@ARGV || die "Usage: blahn";
Could someone explain the difference?
- Bryan
John W. Krahn
Aug 21 2003, 01:35 AM
Shahzad A Khalid wrote:
Hello,
QUOTE |
I have a similar problem that someone just asked about reading specific columns from a file and writing to another file. Eventually, I want to read the written file to be loaded into Matlab. Im having trouble writing the regular expression for this file. The format of the file looks like this:
Cell1=481 13 N control AFFX-MurIL2_at 0 13 A A A 0 8801 -1 -1 99 Cell2=481 12 N control AFFX-MurIL2_at 0 13 A T A 0 8161 -1 -1 99
I want to read the column mentioning 481 and leaving Cell?= portion. Then second col. ie 13/12, third col, 5th(AFFX-KurIL2_at) and 7th(13/13). Please suggest how do i do that. The code i tried is as follows:
$writefilename = 'final.txt'; open(READFILE1,$writefilename); open(WRITEFILE1,">>cdf.txt");
|
You should _ALWAYS_ verify that your files were opened correctly:
open( READFILE1, $writefilename ) or die "Cannot open $writefilename:
$!";
open( WRITEFILE1, ">>cdf.txt" ) or die "Cannot open cdf.txt: $!";
QUOTE |
@array=<READFILE1>; $len=scalar(@array); print $len; #foreach $lineblock(@array){ # @colarray=split(/w+=d+s+d+s+ws+w+s+w+-w+-w+s+ds+d+s+ws+ws+ws+ds+d+s+ds+ds+d+/, $lineblock); # print WRITEFILE1 @colarray[1];
#} foreach$lineblock(@array){ @colarray=split(/s*/,$lineblock);
|
You are telling split() to split on zero or more whitespace which is the
same as splitting the string into individual characters and removing the
whitespace.
$ perl -le'print ">$_<" for split /s*/, "one two"'
QUOTE |
$colarray[0]=~ s/Celld=//ig; foreach $col(@colarray){ print WRITEFILE1 $col; } }
|
According to your code, this should do the same thing:
for ( @array ) {
s/Celld=//i;
s/s+//g;
print WRITEFILE1;
}
QUOTE |
close READFILE1; close WRITEFILE1; exit;
|
John
--
use Perl;
program
fulfillment
Jenda Krynicky
Aug 21 2003, 09:07 AM
From: "Yupapa.com" <[Email Removed]>
QUOTE |
If you are transfering file from a local machine to a remote machine, you do not use File::Copy module to copy files. File::Copy is used for copying files locally. You can use Net::FTP to transfer files from one machine to another. And of course, you will need a FTP server for the machine receiving the file.
|
This aint entirely true. You can use File::Copy to copy files to
remote shares (Windows Networking), remote drives mounted via NFS ,
.... basicaly anything that the OS allows you to treat like a local
disk.
Jenda
===== [Email Removed] ===
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
Paul Kraus
Aug 21 2003, 01:09 PM
Without more specifics I can show you how to get the data. This is
assuming a lot because I am confused about what you want to do.
Here is what I gathered.
Read file if line is not all numeric, '-', and spaces then skip.
I am not sure what you want to do with columns that contain 999.999 so I
am going to leave them in the array. That way your subroutines can
account for the 999.999 and do what ever you need to the missing data.
open (IN, "<filename" ) or die ("Could not open file $!n");
While (<IN>){
next unless /^d+/; # if line does not start with numeric skip
my @array = split /s+/;
}
This is untested. But each column should now be in the @array. Column 1
being $array[0].
Hope that helps.
Paul
-----Original Message-----
From: Antonio Jose [mailto:[Email Removed]]
Sent: Thursday, August 21, 2003 9:51 AM
To: [Email Removed]
Subject: Here you have a sample
Here you have a sample of my data:
Column 1 correspond a depth and the rest correspond to diferent
variables
1500.0000 12.6740 -999.2500 0.2204
-999.1.4471
1500.5000 9.1897 -999.2500 0.2200
-999.1.4526
1501.0000 6.5566 -999.2500 0.2161
0.1.4835
1501.5000 4.7251 -999.2500 -999.2500 0.6541
-999.2500 1.7951
1502.0000 3.5049 -999.2500 -999.2500
0.2.2192
1502.5000 3.0459 0.9990 0.0010 1.0000
0.0001 0.0309
1503.0000 2.9346 0.9990 0.0010
1.0000 0.0000 0.0118
1503.5000 2.9598 0.9990 0.0010 1.0000
0.0000 0.0056
1504.0000 3.0054 0.9990 0.0010
1.0000 0.0000 0.0057
1504.5000 3.0642 0.9990 0.0010
1.0000 0.0000 0.0090
1505.0000 3.3259 0.9990 0.0010
1.0000 0.0001 0.0236
1505.5000 4.2054 0.9766 0.0234
1.0000 0.0074 0.0719
1506.0000 5.4658 0.8294 0.1428
1.0000 0.2796 0.2179
1506.5000 6.4538 0.6971 0.1754
0.9981 1.9523 0.5869
We don't have the same lenght by variable, example: we can have 3456
values to variable 1 and 3460 to the second and so for.
Thanks
==============Original message text===============
On Thu, 21 Aug 2003 09:10:01 -0400 "Paul Kraus" wrote:
Can you send some sample data
-----Original Message-----
From: Antonio Jose [mailto:[Email Removed]]
Sent: Thursday, August 21, 2003 8:58 AM
To: [Email Removed]
Subject: Reading columns, Missing data and more
Hello....
I am just learning a bit of Perl but I have some questions;
I have to read a file (numbers of rows variable), to obviate the first
lines until I find only columns with numbers, after, I have to create
vectors with each of this columns (indenpendent columns) but obviating
missing data (represented by the specific number -999.999). After I need
to process this vectors using iteractive method, subroutines, etc. I am
just working but after I define a new vector containing non missing
values I don't know how to read them, the languaje give an error like:
Use of uninitialized value in array element at columnas.pl line xx,
<filename> line YYY
The program is too long to send you but if you want I could
Thanks and excuse my english
Antonio
--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed] ===========End
of original message text===========
Rob Hanson
Aug 21 2003, 05:13 PM
I'm not well versed in awk, but you could use cut instead...
command | grep bf1 | cut -d ' ' -f 1
....Or just use Perl
# untested
my @var = map {/^w+/;$&} grep {/bf1/} `command`;
QUOTE |
on the command line I get exactly what I need, why doesn't this work during an external call?
|
Hmmm... my guess is the $1. The `` interpolates. You need to escape the
dollar sign with a backslash... otherwise it puts the value of $1 into your
command before executing it.
You might want to use strict, it would have caught that.
Rob
-----Original Message-----
From: Bill Akins [mailto:[Email Removed]]
Sent: Thursday, August 21, 2003 2:01 PM
To: [Email Removed]
Subject: Split on white space from `command` return?
Hi!
I would like to grab the first column (variable width) of data in each
line that will be returned from an external command.
I tried @PSARRAY = `command | grep bf1`; and got just the lines with
data I wanted. The returned data looks like this:
EHCFS001 Booted Down bf1/p20 Windows/MU Yes,Opt,0 12:55:29
VMDFS Booted Up bf1/p14 VM25AS21e16/MU Yes,Opt,0
12:52:12
ORA_1 Booted Up bf1/p18 VM25AS21e16/MU Yes,Opt,0
12:56:25
ps3 Booted Up bf1/p3 custom/MU Yes,Opt,0 12:51:56
ps4 Booted Up bf1/p4 custom/MU Yes,Opt,0 12:51:42
ps5 Booted Up bf1/p5 custom/MU Yes,Opt,0 12:51:22
I need to capture just EHCFS001, VMDFS, ORA_1, PS3, PS4 and PS5 in a
var, array, hash, whatever and I don't care about any of the other data.
A variable would be preferable over array, I think.
I then tried @PSARRAY = `command | grep bf1 | awk -F " " '{print $1}'`
but got the same exact results. Anyone know why it didn't like the awk
command or just decided to ignore it?
If I run command | grep bf1 | awk -F " " '{print $1}' on the command
line I get exactly what I need, why doesn't this work during an external
call?
Running on Linux, Perl 5.6.1
Thanks all.
Bill Akins
SSS III
Emory Healthcare
( - Office
12674 - PIC
[Email Removed]
--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
Bill Akins
Aug 21 2003, 06:26 PM
I did have use strict; on but it didn't complain... Thanks for the input! I'll use Perl.
QUOTE |
"Hanson, Rob" <[Email Removed]> 08/21/03 14:14 PM I'm not well versed in awk, but you could use cut instead... |
command | grep bf1 | cut -d ' ' -f 1
....Or just use Perl
# untested
my @var = map {/^w+/;$&} grep {/bf1/} `command`;
QUOTE |
on the command line I get exactly what I need, why doesn't this work during an external call?
|
Hmmm... my guess is the $1. The `` interpolates. You need to escape the
dollar sign with a backslash... otherwise it puts the value of $1 into your
command before executing it.
You might want to use strict, it would have caught that.
Rob
-----Original Message-----
From: Bill Akins [mailto:[Email Removed]]
Sent: Thursday, August 21, 2003 2:01 PM
To: [Email Removed]
Subject: Split on white space from `command` return?
Hi!
I would like to grab the first column (variable width) of data in each
line that will be returned from an external command.
I tried @PSARRAY = `command | grep bf1`; and got just the lines with
data I wanted. The returned data looks like this:
EHCFS001 Booted Down bf1/p20 Windows/MU Yes,Opt,0 12:55:29
VMDFS Booted Up bf1/p14 VM25AS21e16/MU Yes,Opt,0
12:52:12
ORA_1 Booted Up bf1/p18 VM25AS21e16/MU Yes,Opt,0
12:56:25
ps3 Booted Up bf1/p3 custom/MU Yes,Opt,0 12:51:56
ps4 Booted Up bf1/p4 custom/MU Yes,Opt,0 12:51:42
ps5 Booted Up bf1/p5 custom/MU Yes,Opt,0 12:51:22
I need to capture just EHCFS001, VMDFS, ORA_1, PS3, PS4 and PS5 in a
var, array, hash, whatever and I don't care about any of the other data.
A variable would be preferable over array, I think.
I then tried @PSARRAY = `command | grep bf1 | awk -F " " '{print $1}'`
but got the same exact results. Anyone know why it didn't like the awk
command or just decided to ignore it?
If I run command | grep bf1 | awk -F " " '{print $1}' on the command
line I get exactly what I need, why doesn't this work during an external
call?
Running on Linux, Perl 5.6.1
Thanks all.
Bill Akins
SSS III
Emory Healthcare
( - Office
12674 - PIC
[Email Removed]
--
To unsubscribe, e-mail: [Email Removed]
For additional commands, e-mail: [Email Removed]
Bill Akins
Aug 21 2003, 06:28 PM
Awesome! Thanks Bob!
QUOTE |
Bob Showalter <[Email Removed]> [SNIP] Variables are expanded in backticks, so you need to protect the $ on $1, or |
use qx'' around your command (but then you have to protect the single quotes
But there's no need for the awk or grep, since perl has functions to handle
that kind of thing. Try something like:
@PSARRAY = map +(split)[0], grep /bf1/, `command`;
John W. Krahn
Aug 21 2003, 06:29 PM
Ronen Kfir wrote:
QUOTE |
I need to delete oldest modified file in a directory. I find this file with this:
my $oldest= printf "%sn", (sort{ (-M $b) <=> (-M$a) } glob("v:*")); print $oldest;
unlink "$oldest";
What I get in response is:
oldest_filename 1
File is not deleted.
How would I do it?
|
As you have observed, printf returns true if it worked (or false if it
didn't.) You
could do it like this:
my ( $oldest ) = sort { (-M $b) <=> (-M $a) } glob "v:*";
unlink $oldest or warn "Cannot delete $oldest: $!";
Or like this:
my $oldest = ( sort { (-M $b) <=> (-M $a) } glob "v:*" )[ 0 ];
unlink $oldest or warn "Cannot delete $oldest: $!";
But both of those methods use an inefficient sort because you are
stat()ing each
file more than once. Here are two methods that only stat()s each file
once.
my ( $oldest ) = map $_->[ 0 ],
sort { $b->[ 1 ] <=> $a->[ 1 ] }
map [ $_, -M ],
glob "v:*";
unlink $oldest or warn "Cannot delete $oldest: $!";
This is the most efficient as it only stat()s each file once and it
doesn't have to sort.
my $oldest = [ '', 0 ];
for my $file ( glob "v:*" ) {
my $date = -M $file;
$oldest = [ $file, $date ] if $oldest->[ 1 ] < $date;
}
unlink $oldest->[ 0 ] or warn "Cannot delete $oldest->[0]: $!";
John
--
use Perl;
program
fulfillment
Trina Espinoza
Aug 21 2003, 10:38 PM
Does anyone know how to set an shell enviroment using perl? I have tried using the backticks, the system command, but they
don't seem to be working. I found ENV{'FLEE'} = 'FLEE'; online, but I don't understand how that works. It sets your enviroment for
a child process but won't change your current environment, is that right? If anyone has suggestions I am all ears.
thanks,
-T
sub setEnviro {
my($var1, $var2) = @_;
print "INSIDE FLEE: $var1n";
print "INSIDE FLAA: $var2n";
#system ("FLEE=$var1"); ##ALL lines below don't seem to work. .. .
#system("FLAA=$var2");
#$ENV{'FLEE'} = 'FLEE';
#$ENV{'FLOO'} = 'FLAA';
`echo $FLEE`;
`echo $FLAA`;
Zsdc
Aug 21 2003, 11:51 PM
Trina Espinoza wrote:
QUOTE |
Does anyone know how to set an shell enviroment using perl? I have tried using the backticks, the system command, but they don't seem to be working. I found ENV{'FLEE'} = 'FLEE'; online, but I don't understand how that works. It sets your enviroment for a child process but won't change your current environment, is that right? If anyone has suggestions I am all ears.
|
$ENV{FLEE} = 'FLEE';
^remember about the '$' sigil.
See perlvar(1) manpage:
http://www.perldoc.com/perl5.8.0/pod/perlvar.html#%25ENV"The hash %ENV contains your current environment. Setting a value in ENV
changes the environment for any child processes you subsequently fork()
off."
"Perl programming is an *empirical* science" after all, so you can ckeck
out if it changes the real environment:
#!/usr/bin/perl -wl
print "Old PATH: $ENV{PATH}";
$ENV{PATH} .= ':/ABCDEF';
print "%ENV PATH: $ENV{PATH}";
$/ = "