how to get and convert time

2004-09-17 Thread Franklin
Hello:
My operating system is freebsd and its time is GMT time which I can't
change. How can I write a perl script to get the exact
time(Hour,minute,second) and change it to US ET?

Thank you very much!
Franklin

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




Moving between hashes.

2004-09-17 Thread Michael S. Robeson II
I have two sets of data that have been stored in hashes. The first hash 
has amino-acid (protein) sequence data. The second hash has the 
corresponding DNA sequence of those amino-acids:

Hash 1
key:value:
cat   = mfgdhf
doq =   mfg--f
mouse =   mf-d-f
Hash 2
key:value:
cat = agtcatgcacactgatcg
dog = agtcatgcatcg
mouse = agtcatcactcg
And I need to insert gaps (missing or absent data) proportionally into 
the DNA sequence (Hash 2) so that the output is as follows:

Hash 3
key:value:
cat =   agtcatgcacactgatcg
dog =   agtcatgca--tcg
mouse = agtca---tca---ctcg
It doesn't look right here, but all the lines should end up being the 
same length with courier font. Basically, I am having trouble scanning 
though, say...  hash1{cat} and for every  dash found there being 
finally represented as  three dashes in hash2{cat}. Also, every 
amino-acid is represented by 3 DNA letters. This is why I need to move 
in increments of 3 and add in increments of 3 for my final data to 
appear as it does in Hash 3.

Example of relationship:
M F DF  = amino-acid
agt tca --- act --- tcg  = dna
I have everything else set up I just need a few suggestions on how to 
do the above. Any help will be greatly appreciated.

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



command line option with -ne to print newline

2004-09-17 Thread Ramprasad A Padmanabhan
Quick question,

  I want to run 
  
   perl -ane '/REMARKS/ && print $F[1]' FILE1 FILE2 

the problem is that there is no newline at the end of the every print.

so I have to do 

perl -ane '/REMARKS/ && print $F[1] . "\n"' FILE1 FILE2 

I thought there is a switch in perl by which I could auto print newlines
I am not able to find any ? 

Thanks
Ram





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




Taint mode in Windows (U)

2004-09-17 Thread Meidling, Keith, CTR, ISD
UNCLASSIFIED

I seem to recall that the shebang line is generally ignored in Windows,
except if you are using it with apache... Please correct me if I'm wrong
here... 

Now, if that is so, is there a way to turn on taint ( -T at end of shebang
line) for perl scripts in Windows if the line is ignored? 

Would this only apply if the scripts were being run within apache?

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




Re: command line option with -ne to print newline

2004-09-17 Thread John W. Krahn
Ramprasad A Padmanabhan wrote:
Quick question,
  I want to run 
  
   perl -ane '/REMARKS/ && print $F[1]' FILE1 FILE2 

the problem is that there is no newline at the end of the every print.
so I have to do 

perl -ane '/REMARKS/ && print $F[1] . "\n"' FILE1 FILE2 

I thought there is a switch in perl by which I could auto print newlines
I am not able to find any ? 
Yes there is one, the -l switch.
perl -lane '/REMARKS/&&print$F[1]' FILE1 FILE2

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Need Help regarding training centres in INDIA

2004-09-17 Thread Anish Kumar K.
Hi

This is regarding PERL training centres in INDIA. Please let me know about
this.

Thanks
Anish




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




Re: how to get and convert time

2004-09-17 Thread John W. Krahn
Franklin wrote:
Hello:
Hello,
My operating system is freebsd and its time is GMT time which I can't
change. How can I write a perl script to get the exact
time(Hour,minute,second) and change it to US ET?
All Unix systems (AFAIK) run on UTC (GMT for you old timers, Zulu Time for you 
military types) so you don't want to change it to something else.  What you 
want to do is set your timezone file to the correct timezone.  On my Linux 
system that file is /etc/timezone and the timezone data files are in the 
/usr/share/zoneinfo directory.

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: insert data with Perl into multiple MySQL tables

2004-09-17 Thread Bob Showalter
Maxipoint Rep Office wrote:
> How insert data with Perl into multiple MySQL tables?

You need multiple INSERT statements. Use a transaction if they all need to
complete or fail together. I don't use MySQL, so I don't know how
transactions work for it specifically, but typically you just use a
combination of $dbh->{AutoCommit} and $dbh->commit.

> 
> I can not find any clear advice..
> 
> 
> this is for TABLE1:
> 
> # Connect to the database.
> my $dbh = DBI->connect("DBI:mysql:database=;host=localhost",
>"username", "pass",
>{'RaiseError' => 1});
> 
> 
> # now first make that sql statement the right way - use placeholders
> 
> my $sql = "INSERT INTO TABLE1 (xxx1, xxx2, xxx3) VALUES (?,?,?)";
> 
> 
> #now prepare it
> my $sth = $dbh->prepare($sql);
> 
> 
> # now simply execute it
> 
> $sth->execute($f->{xxx1},$f->{xxx2},$f->{xxx3});
> 
> 
> $sth->finish();

finish() is only needed for statements that return rows.

Also the prepare/execute can all be simplified to

$dbh->do(q[
insert into table1 (xxx1, xxx2, xxx3) values (?, ?, ?)
], undef, @{$f}{qw(xxx1 xxx2 xxx3)});

Using prepare separately is handy if you need to repeat the insert multiple
times for different data; otherwise, using $dbh->do is usually simpler.

> 
> $dbh->disconnect();
> 
> 
> 
> How insert into TABLE1 and TABLE2 at same time?

You need to prepare/execute (or $dbh->do) another statement for that.

   $dbh->do(q[insert into table2 ...blah blah], undef, @params);

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




Re: Moving between hashes.

2004-09-17 Thread Gunnar Hjalmarsson
Michael S. Robeson II wrote:
I have two sets of data that have been stored in hashes. The first
hash has amino-acid (protein) sequence data. The second hash has
the corresponding DNA sequence of those amino-acids:
Hash 1
key:value:
cat   =  mfgdhf
doq = mfg--f
mouse =   mf-d-f
Hash 2
key:value:
cat= agtcatgcacactgatcg
dog = agtcatgcatcg
mouse = agtcatcactcg
And I need to insert gaps (missing or absent data) proportionally
into the DNA sequence (Hash 2) so that the output is as follows:
Hash 3
key:value:
cat= agtcatgcacactgatcg
dog = agtcatgca--tcg
mouse = agtca---tca---ctcg
It doesn't look right here, but all the lines should end up being
the same length with courier font. Basically, I am having trouble
scanning though, say...  hash1{cat} and for every  dash found there
being finally represented as  three dashes in hash2{cat}. Also,
every amino-acid is represented by 3 DNA letters. This is why I
need to move in increments of 3 and add in increments of 3 for my
final data to appear as it does in Hash 3.
Shifting from temporary arrays is one possibility:
my %hash3;
for ( keys %hash1 ) {
my @tmp1 = split //, $hash1{$_};
my @tmp2 = $hash2{$_} =~ /.../g;
while ( my $aa = shift @tmp1 ) {
$hash3{$_} .= $aa eq '-' ? '---' : shift @tmp2;
}
}
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: failure with: system("dir /b"); exec("dir /b"); `dir /b`

2004-09-17 Thread Bob Showalter
A B C wrote:
> Greetings,
> 
> Does anyone know how to get perl to run windows
> commands like "dir /b". Specifically, perl doesn't
> accept any type of argument switches. I've tried
> system(), exec() and backticks in my script.
> 
> However, If I remove the switch, for example:
> system("dir"). This works fine. But I need those
> switches for many of my command utilites on windows. I
> can't figure it out.

All these constructs are working fine for me with ActiveState 5.8 on Win XP.

Post the code that's causing problems. What's happening? Any error messages?
What version of Windows? What version of Perl (perl -v). What happens if you
run a command not built-in to CMD.EXE? (something like "mem /c" perhaps?)

> 
> I've spent hours on google trying to find a code
> snippet or comment with someone trying to use a
> switch. nada. I started experimenting with open(FH,
> $command|) but it doesn't seem to work either.

That's also working fine for me.

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




RE: how to get and convert time

2004-09-17 Thread Bob Showalter
Franklin wrote:
> Hello:
> My operating system is freebsd and its time is GMT time which I can't
> change. How can I write a perl script to get the exact
> time(Hour,minute,second) and change it to US ET?

As John said, the internal clock is always UTC. On FreeBSD, you use the
tzsetup(8) program to set the default time zone. If you're in US Eastern
time zone, your sysadmin should go ahead an set this. Once set, Perl's
localtime() function will return Eastern time, while gmtime() will return
UTC.

If you want to temporarily override the default time zone, you can set the
TZ variable.

Here's an example from my FreeBSD system (default time zone is
America/New_York):

   $ perl -de0
   main::(-e:1):   0
   DB<1> x scalar localtime
   0  'Fri Sep 17 08:21:30 2004'<--- default (Eastern) time
   DB<2> $ENV{TZ}='America/Los_Angeles' <--- set TZ to a different time
zone

   DB<3> x scalar localtime
   0  'Fri Sep 17 05:21:46 2004'<--- Pacific time
   DB<4>

To see all the time zone names, look at the file
/usr/share/zoneinfo/zone.tab

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




Re: Taint mode in Windows (U)

2004-09-17 Thread Gunnar Hjalmarsson
Keith wrote:
I seem to recall that the shebang line is generally ignored in
Windows,
Even if the path to perl is, the flags are not. (Disclaimer: There may 
be exceptions...)

Now, if that is so, is there a way to turn on taint ( -T at end of
shebang line) for perl scripts in Windows
Yes: The -T flag.
Would this only apply if the scripts were being run within apache?
No.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



the x operator

2004-09-17 Thread c r
Hi!
 
Is it possible to avoid another loop by using the x operator? I.e.
 
push(@list, rand(4));
 
gives me one element in @list.
 
Can I somehow use the x operator to produce two different elements in the @list?


Re: the x operator

2004-09-17 Thread Sid
To get $n random numbers into @list, use:

@list = (rand(4)) x $n;

~Sid


On Fri, 17 Sep 2004 15:02:55 +0200 (CEST), c r <[EMAIL PROTECTED]> wrote:
> Hi!
> 
> Is it possible to avoid another loop by using the x operator? I.e.
> 
> push(@list, rand(4));
> 
> gives me one element in @list.
> 
> Can I somehow use the x operator to produce two different elements in the @list?
> 
> 



-- 
http://www.upster.blogspot.com

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




Re: the x operator

2004-09-17 Thread Sid
To get $n random numbers into @list, use:

@list = (rand(4)) x $n;

~Sid


On Fri, 17 Sep 2004 15:02:55 +0200 (CEST), c r <[EMAIL PROTECTED]> wrote:
> Hi!
> 
> Is it possible to avoid another loop by using the x operator? I.e.
> 
> push(@list, rand(4));
> 
> gives me one element in @list.
> 
> Can I somehow use the x operator to produce two different elements in the @list?
> 
> 



-- 
http://www.upster.blogspot.com

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




Re: the x operator

2004-09-17 Thread Jenda Krynicky
From: Sid <[EMAIL PROTECTED]>
> To get $n random numbers into @list, use:
> 
> @list = (rand(4)) x $n;
> 
> ~Sid

Nope. This way you get $n times the same random number. Try:

print join(', ', (rand(4)) x 5);

You need to do something like this:

@list = map rand(4), (1..$n);
or
push @list, rand(4) for (1..$n);
or
@list = map rand(4), (1) x $n;

That is you have to make sure the rand(4) is called repeatedly.

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: Net ::FTP and subroutine calls

2004-09-17 Thread DBSMITH
Right thanks forgot about that!  So how do I out this failed info to 
STDOUT (ftplog), b/c if it does fail I would want to know!
As far as the $^ I variable, yes I have tried just opening the files and 
reading and writing from them!  Thanks for the tips and I am still GREEN ! 
:)
What could be wrong with the in place editor ??? I am running this program 
as UID = 0.Any ideas? 

thanks.

Here is what I have but it still not working.


sub ftpme {

my $remotehost="ftp.digitalarchives.com";
my $remotedir="archive";
my $user=";
my $pass="xxx;
my $data=$scratchtps;
my $ftplog="/usr/local/log/ftp_IrMt_scratchtapes.log";

my $ftp = Net::FTP->new($remotehost, Debug => 10)
|| die "Cannot connect to $remotehost: IronMt: $!, print 
($ftplog)";
$ftp->login($user, $pass) or die "Login failed!: $!, print 
($ftplog)";
$ftp->ascii();
$ftp->cwd($remotedir);
$ftp->put($data) or die "FTP put to IrMt failed!: $!, print ($ftplog)";
$ftp->quit;

}


Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams
614-566-4145





Chris Devers <[EMAIL PROTECTED]>
09/16/2004 04:59 PM
Please respond to Perl Beginners List

 
To: [EMAIL PROTECTED]
cc: Perl Beginners List <[EMAIL PROTECTED]>
Subject:Re: Net ::FTP and subroutine calls


On Wed, 15 Sep 2004 [EMAIL PROTECTED] wrote:

> no nothing is showing up in the file. 

Okay then, so this logging code is all hand-written ?

It seems then that nothing in this script is actually writing to the log 
file you've asked for, because there's no such thing as "$ftp->$ftplog"
(or "$ftp->/usr/local/log/ftp_IrMt_scratchtapes.log" as it ends up.) 

Let's keep this simple and remove the log entirely for now. Does a 
stripped down version like what I have here work for you ?

my $scratchtps = qq[ whatever ];
ftpme( $scratchtps );

sub ftpme {

my $data   = shift;

my $remotehost = "ftp.digitalarchives.com";
my $user   = "cb100524";
my $pass   = "xxx";

my $ftp= Net::FTP->new(
   $remotehost, Debug => 10
) or die "cannot connect to $remotehost: IronMt: $!";
$ftp->login($user, $pass)
  or die "cannot login: $!";
$ftp->ascii();
$ftp->cwd('archive');
$ftp->put($data)
  or die "FTP put to IrMt failed: $!";
$ftp->quit;

}

This version should produce better diagnostic information, because it's 
adding $! to the `die` phrases to output any error messages. 

> Here is where I looked for information on Net::FTP
> 
> http://search.cpan.org/~gbarr/libnet-1.19/Net/libnetFAQ.pod
> 
> ok I will look in perldoc -f package.  Is there a better place though?

If you're old-fashioned and like books, Damian Conway's _Object Oriented 
Perl_ is an excellent manual for this side of Perl, and Randal Schwartz 
and Tom Phoenix's _Perl Objects, References, and Modules_ is another. 

Alternately, look over any Perl Object Oriented documentation online -- 
packages are a basic foundation of writing OO code.


-- 
Chris Devers




Re: $ ^ I in place editor

2004-09-17 Thread DBSMITH
ok sorry... must of missed that about the in place editor and is 
restrictions !  Please ignore that last part of my last email!







[EMAIL PROTECTED] (Peter Scott)
Sent by: [EMAIL PROTECTED] (Peter Scott)
09/16/2004 06:14 PM
Please respond to Peter

 
To: [EMAIL PROTECTED]
cc: 
Subject:Re: $ ^ I   in place editor


In article 
<[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] writes:
>its not that I do not understand its purpose, but maybe how to use it??? 
I 
>am curious b/c this has worked for me before in other programs.  I will 
>send this whole code.

Posting hundreds of lines of code that have nothing to do with what
you're trying to understand will only make it harder to understand it.
And the full code doesn't match the sample code you posted below in
a crucial respect: You don't even set @ARGV at all in the full code. 
And still don't use the diamond operator.

Take a look at what I wrote before:
  --
Nowhere do you use the contents of @ARGV.  In-place edit only works
when you use the diamond operator (<>) for I/O, and you haven't.
So, having defined $^I and set @ARGV, you then need a loop:

while (<>) {
# Do something with $_
# print something to default filehandle
}

Whatever you print to the default filehandle inside that loop will
go to the new file.
  --

Here's a sample program, run it and see what it does, and experiment
with it if need be.  Then you will understand how to use $^I.

#!/usr/local/bin/perl
use strict;
use warnings;

my $file = "INSERT NAME OF FILE TO MODIFY HERE";
print "Starting in-place edit of $file\n";

($^I, @ARGV) = (".bak", $file);
while (<>)
{
  s/e/x/g;
  print;
}

print "Done in-place edit, now look at $file\n";


Look also at "perldoc perlrun" under "-i".


>In article 
><[EMAIL PROTECTED]>,
> [EMAIL PROTECTED] writes:
>>In my code I am not understanding why my in place edit does not work? 
>Here 
>>is my code:
>>
>>use strict;
>>use diagnostics;
>>use warnings;
>
>Good!
>
>>my stps="/usr/local/log/scratchtps";
>>
>>   open (TP, ">$stps") || die "could not open file:$!";
>>open (TP2, ">$irmt ") || die "could not open file:$!";
>>open (D, "$logf") || die "could not open file:$!";
>>($^I, @ARGV) = ('.bak', $scratchtps);
> 
>I think you copied this line from somewhere without understanding it.
[snip]

-- 
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/

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






Re: $ ^ I in place editor

2004-09-17 Thread DBSMITH
ok so $^ I is only for the diamond operator.  Understood.  So for 
situations when not using the diamond operator, $^ I for making backup 
copies is useless, so thr rename function will have to suffice.

Is this the best way?

thanks, 






[EMAIL PROTECTED] (Peter Scott)
Sent by: [EMAIL PROTECTED] (Peter Scott)
09/16/2004 06:14 PM
Please respond to Peter

 
To: [EMAIL PROTECTED]
cc: 
Subject:Re: $ ^ I   in place editor


In article 
<[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] writes:
>its not that I do not understand its purpose, but maybe how to use it??? 
I 
>am curious b/c this has worked for me before in other programs.  I will 
>send this whole code.

Posting hundreds of lines of code that have nothing to do with what
you're trying to understand will only make it harder to understand it.
And the full code doesn't match the sample code you posted below in
a crucial respect: You don't even set @ARGV at all in the full code. 
And still don't use the diamond operator.

Take a look at what I wrote before:
  --
Nowhere do you use the contents of @ARGV.  In-place edit only works
when you use the diamond operator (<>) for I/O, and you haven't.
So, having defined $^I and set @ARGV, you then need a loop:

while (<>) {
# Do something with $_
# print something to default filehandle
}

Whatever you print to the default filehandle inside that loop will
go to the new file.
  --

Here's a sample program, run it and see what it does, and experiment
with it if need be.  Then you will understand how to use $^I.

#!/usr/local/bin/perl
use strict;
use warnings;

my $file = "INSERT NAME OF FILE TO MODIFY HERE";
print "Starting in-place edit of $file\n";

($^I, @ARGV) = (".bak", $file);
while (<>)
{
  s/e/x/g;
  print;
}

print "Done in-place edit, now look at $file\n";


Look also at "perldoc perlrun" under "-i".


>In article 
><[EMAIL PROTECTED]>,
> [EMAIL PROTECTED] writes:
>>In my code I am not understanding why my in place edit does not work? 
>Here 
>>is my code:
>>
>>use strict;
>>use diagnostics;
>>use warnings;
>
>Good!
>
>>my stps="/usr/local/log/scratchtps";
>>
>>   open (TP, ">$stps") || die "could not open file:$!";
>>open (TP2, ">$irmt ") || die "could not open file:$!";
>>open (D, "$logf") || die "could not open file:$!";
>>($^I, @ARGV) = ('.bak', $scratchtps);
> 
>I think you copied this line from somewhere without understanding it.
[snip]

-- 
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/

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






Re: HoH not building as expected

2004-09-17 Thread Wiggins d Anconia


> 
> - Original Message - 
> From: "Wiggins d Anconia" <[EMAIL PROTECTED]>
> To: "Mark Goland" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> Sent: Thursday, September 16, 2004 1:27 PM
> Subject: Re: HoH not building as expected
> 
> 
> > 
> >
> > > > >
> > > > > I expact the output to be
> > > > >
> > > > > Unknown =>:
> > > > > VENDOR :Unknown
> > > > > CPU-MODEL :model1
> > > > > Unknown =>:
> > > > > VENDOR :Unknown
> > > > > CPU-MODEL :Unknown
> > > > >
> >
> > I am confused as to why you think you need a HoHoH, when what you
> > originally displayed above is really a HoAoH because the first 'Unknown'
> > has multiple entries, which is impossible to replicate with a Hash since
> > it is a one-to-one relationship, one key to one value.  If you still
> > feel so and are having problems, provide us more of the data and a
> > larger example of what you expect and we will be able to get it sorted.
> >  Fast access through a hash is good, but correct access even if
> > requiring a loop is always better than the wrong structure for the data.
> 
> Hello again my friends,
> Basicly what I'll have a large set of input data that I need to match
> against a static list.
> 
> I want to have following structure
> Vendor Model Atributes
> 

This doesn't seem to match at all the code you provided, either the data
you are showing us (which still isn't really enough for us to tell since
you have given us data with lots of "Unknown" etc. in it.  Give us real
data.

> So once I have my HoHoH I can say something like
> if exists $RATING{Vendor}{Type}{Quntity} and $RATING{Vendor}{Type}{Color}
> 

I think I have it now, but the biggest problem with the code is that you
are using the wrong array indices and you have data on a different line
than you are "currently interpreting.  Your spacing and comments also
make it very hard (at least for me, I know this is a style issue) to
read what you are actually doing

> Here is an example with more data...
> 
> #!PERL
> use warnings;
> use strict;
> 
> my (@te,%RATING,$debug,$attrib,$key,$CPU_ATTR);

Again, declaring all of these here defeats the purpose of strictures,
and is probably one of the reasons why your code is so confusing.

> $debug=0;
> 
> @te = (   "CREATE   CPU-MODEL UNKNOWN_CPU VENDOR Unknown, GENERIC_CPU
VENDOR
> SUN\n" ,
>   "Quntity 5\n" ,
>   "Color Blue\n" ,
> 
>"CREATE   CPU-MODEL model1 VENDOR Unknown, GENERIC_CPU VENDOR
Unknown\n",
>   "Quntity 6\n" ,
>   "Color Blue\n" ,
>  );
>

Both of the above declarations can have the C moved onto them, it is
just a good habit to get into.
 
> s/,|^\t//g for @te;
> 
> 
> foreach ( @te ){
> my $input = $_;
> 

If you are going to name the variable you can do it all in one shot, the
above can be written:

foreach my $input (@te) {

> my @fields= split /\s+/,$input;
> print "LINE=$input" if $debug;
> 
> 
> if( $fields[0] eq 'CREATE' ){
> $CPU_ATTR= {};
> $RATING{$fields[5]} = $CPU_ATTR;#

What is the extra # mark for? Index 5 maps to 'GENERIC_CPU' in your
data, should this be 4?  You also need to build your 'type' into the
hash structure at this point.

> $CPU_ATTR->{$fields[2]}=$fields[3]; #processor [EMAIL PROTECTED]
> $CPU_ATTR->{$fields[4]}=$fields[5]; #processor [EMAIL PROTECTED]
> 

I have no idea what the above are doing, I think this is the problem
with the structure, and would be at least a little bit indicated if you
used better scoping rules.

> }
> if( $fields[0] eq 'Quntity' ){
>  $CPU_ATTR->{$fields[0]}=$fields[1];
> }
> if( $fields[0] eq 'Color' ){
>  $CPU_ATTR->{$fields[0]}=$fields[1];
> }

The problem is that $CPU_ATTR really shouldn't still be alive here,
because you have transitioned to a new line, so the problem is that at
this point you can't index by type, which means your structure is one
level flatter than it should be.

> 
> }# end of while
> 

Wrong comments are much worse than superfluous comments which are much
worse than no comments. Personally I can't stand comments telling me
that i have ended a loop, it should be obviuos (and that is what code
folding is for), but that is a style issue.  But it isn't the end of the
'while' it is the end of a 'foreach', *especially* since the next
statement is a 'while'.

> while ( my ($key, $value) = each(%RATING) ) {
> print "$key =>:\n";
> for $attrib ( keys %$value ){
> print "$attrib :";print $value->{$attrib} . "\n";
> }
> print "\n\n";
> }
> 

This will need to be improved once the structure is corrected, but I
will leave that to you, again Data::Dumper is your friend.

Assuming I understand the spec correctly, this is what I would probably
produce:

-- UNTESTED --

#!/usr/local/bin/perl
use strict;
use warnings;

my $debug=0;

my @te = ( "CREATE   CPU-MODEL UNKNOWN_CPU VENDOR Unknown, GENERIC_CPU
VENDOR SUN\n" ,
   "Quntity 5\n" ,
   "Color Blue\n" ,

   "CREATE   CPU-MODEL model1 VENDOR Unknown, GENERIC_CPU VENDOR
Unknown\n",
   "Q

cp command error check

2004-09-17 Thread Urs Wagner
Hello
This does not work.
`cp $srcfile $dstfile`; || do {
 print "cannot copy $srcfile to $dstfile";
   };
do is also execute if cp working fine. Whz is this so? The next thing I 
would like to
know how I can print the cp's error message.

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



Re: cp command error check

2004-09-17 Thread Wiggins d Anconia
> Hello
> 
> This does not work.
> 
>  `cp $srcfile $dstfile`; || do {
>   print "cannot copy $srcfile to $dstfile";
> };
> 
> do is also execute if cp working fine. Whz is this so? The next thing I 
> would like to
> know how I can print the cp's error message.
> 
> Thanks
> 
> Urs

This isn't really a normal use of C, you don't really need it at all
you can just use the C<||> or better C to do the same thing.  The
reason that it is always executed is because the backticks are capturing
STDOUT, but the error is likely sent on STDERR. I would dispense with
the backticks completely, and switch to using the File::Copy module and
its C function.  It will be much more portable, and easier to
handle error conditions, more secure, etc.

perldoc File::Copy

http://danconia.org


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




Re: cp command error check

2004-09-17 Thread u235sentinel
I believe you want to print $!.  Give it a try.


> Hello
> 
> This does not work.
> 
>  `cp $srcfile $dstfile`; || do {
>   print "cannot copy $srcfile to $dstfile";
> };
> 
> do is also execute if cp working fine. Whz is this so? The next thing I 
> would like to
> know how I can print the cp's error message.
> 
> Thanks
> 
> Urs
> 
> -- 
> 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: Net ::FTP and subroutine calls

2004-09-17 Thread Chris Devers
On Fri, 17 Sep 2004 [EMAIL PROTECTED] wrote:

> Right thanks forgot about that!  So how do I out this failed info to 
> STDOUT (ftplog), b/c if it does fail I would want to know!

First things first: does the version I sent yesterday work? Focus on 
getting the FTP transaction to finish properly, then start thinking 
about adding in logging code. 

> As far as the $^ I variable, yes I have tried just opening the files 
> and reading and writing from them!  Thanks for the tips and I am still 
> GREEN ! :) What could be wrong with the in place editor ??? I am 
> running this program as UID = 0.  Any ideas?

I assume you must be replying to someone else here.
 
> Here is what I have but it still not working.

Delete the logging code. 

Get things to work without it.

Then start adding it back in.

Hint: when you get to that point -- which you haven't yet, it seems -- a 
common way to do logging is something like this

  $status = do_something_risky( @args );
  $time   = set_timestamp;
  print LOG "$time - did something risky: $status";
  ( $status eq "OK" ) or die "Bad things happened! $status\n$!";

Or something like that -- the point being that the logging should happen 
before the die statement, not after it. The whole point of the die 
statement is to halt the program and throw an error message back, so 
anything that happens after that doesn't end up running.


-- 
Chris Devers

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




Re: Net ::FTP and subroutine calls

2004-09-17 Thread DBSMITH
yes my ftp code has always worked, so lets move on!

thanks, 

Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams
614-566-4145





Chris Devers <[EMAIL PROTECTED]>
09/17/2004 11:14 AM
Please respond to Perl Beginners List

 
To: [EMAIL PROTECTED]
cc: Perl Beginners List <[EMAIL PROTECTED]>
Subject:Re: Net ::FTP and subroutine calls


On Fri, 17 Sep 2004 [EMAIL PROTECTED] wrote:

> Right thanks forgot about that!  So how do I out this failed info to 

> STDOUT (ftplog), b/c if it does fail I would want to know!

First things first: does the version I sent yesterday work? Focus on 
getting the FTP transaction to finish properly, then start thinking 
about adding in logging code. 

> As far as the $^ I variable, yes I have tried just opening the files 
> and reading and writing from them!  Thanks for the tips and I am still 
> GREEN ! :) What could be wrong with the in place editor ??? I am 
> running this program as UID = 0.  Any ideas?

I assume you must be replying to someone else here.
 
> Here is what I have but it still not working.

Delete the logging code. 

Get things to work without it.

Then start adding it back in.

Hint: when you get to that point -- which you haven't yet, it seems -- a 
common way to do logging is something like this

  $status = do_something_risky( @args );
  $time   = set_timestamp;
  print LOG "$time - did something risky: $status";
  ( $status eq "OK" ) or die "Bad things happened! $status\n$!";

Or something like that -- the point being that the logging should happen 
before the die statement, not after it. The whole point of the die 
statement is to halt the program and throw an error message back, so 
anything that happens after that doesn't end up running.


-- 
Chris Devers




Re: Net ::FTP and subroutine calls

2004-09-17 Thread Chris Devers
On Fri, 17 Sep 2004 [EMAIL PROTECTED] wrote:

> yes my ftp code has always worked, so lets move on!

Ok -- you didn't actually say that, you just said things don't work.

The way you're using the die statement won't work.

Go back to the docs and usual manuals to look for other ways to do this.

The `eval` command may be useful for you as well.



-- 
Chris Devers

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




Re: $ ^ I in place editor

2004-09-17 Thread Peter Scott
In article <[EMAIL PROTECTED]>,
 [EMAIL PROTECTED] writes:
>ok so $^ I is only for the diamond operator.  Understood.  So for 
>situations when not using the diamond operator, $^ I for making backup 
>copies is useless, so thr rename function will have to suffice.
>
>Is this the best way?

Usually you can use the diamond operator in any circumstances.  Just
put the filename in @ARGV and make the loop.  See the example program below.

Now, if you wonder, "But what if I want to print something to the usual
default filehandle during that loop, e.g., to track progress?" then you can
explicitly name the filehandle, usually STDOUT:

print STDOUT "Reached line $. of input\n";

Note that <> will empty @ARGV when the loop is done.

I can't think of any case where an in-place edit is intended that the diamond
operator and $^I can't be used to accomplish it.

>[EMAIL PROTECTED] (Peter Scott)

>Take a look at what I wrote before:
>  --
>Nowhere do you use the contents of @ARGV.  In-place edit only works
>when you use the diamond operator (<>) for I/O, and you haven't.
>So, having defined $^I and set @ARGV, you then need a loop:
>
>while (<>) {
># Do something with $_
># print something to default filehandle
>}
>
>Whatever you print to the default filehandle inside that loop will
>go to the new file.
>  --
>
>Here's a sample program, run it and see what it does, and experiment
>with it if need be.  Then you will understand how to use $^I.
>
>#!/usr/local/bin/perl
>use strict;
>use warnings;
>
>my $file = "INSERT NAME OF FILE TO MODIFY HERE";
>print "Starting in-place edit of $file\n";
>
>($^I, @ARGV) = (".bak", $file);
>while (<>)
>{
>  s/e/x/g;
>  print;
>}
>
>print "Done in-place edit, now look at $file\n";
>
>
>Look also at "perldoc perlrun" under "-i".


-- 
Peter Scott
http://www.perldebugged.com/
*** NEW *** http://www.perlmedic.com/

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




Re: HoH not building as expected

2004-09-17 Thread mgoland


- Original Message -
From: Wiggins d Anconia <[EMAIL PROTECTED]>
Date: Friday, September 17, 2004 10:20 am
Subject: Re: HoH not building as expected

> 
> 
> > 
> > - Original Message - 
> > From: "Wiggins d Anconia" <[EMAIL PROTECTED]>
> > To: "Mark Goland" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
> > Sent: Thursday, September 16, 2004 1:27 PM
> > Subject: Re: HoH not building as expected
> > 
> > 
> > > 
> > >
> > > > > >
> > > > > > I expact the output to be
> > > > > >
> > > > > > Unknown =>:
> > > > > > VENDOR :Unknown
> > > > > > CPU-MODEL :model1
> > > > > > Unknown =>:
> > > > > > VENDOR :Unknown
> > > > > > CPU-MODEL :Unknown
> > > > > >
> > >
> > > I am confused as to why you think you need a HoHoH, when what you
> > > originally displayed above is really a HoAoH because the first 
> 'Unknown'> > has multiple entries, which is impossible to 
> replicate with a Hash since
> > > it is a one-to-one relationship, one key to one value.  If you 
> still> > feel so and are having problems, provide us more of the 
> data and a
> > > larger example of what you expect and we will be able to get 
> it sorted.
> > >  Fast access through a hash is good, but correct access even if
> > > requiring a loop is always better than the wrong structure for 
> the data.
> > 
> > Hello again my friends,
> > Basicly what I'll have a large set of input data that I need 
> to match
> > against a static list.
> > 
> > I want to have following structure
> > Vendor Model Atributes
> > 
> 
> This doesn't seem to match at all the code you provided, either 
> the data
> you are showing us (which still isn't really enough for us to tell 
> sinceyou have given us data with lots of "Unknown" etc. in it.  
> Give us real
> data.
> 
> > So once I have my HoHoH I can say something like
> > if exists $RATING{Vendor}{Type}{Quntity} and 
> $RATING{Vendor}{Type}{Color}> 
> 
> I think I have it now, but the biggest problem with the code is 
> that you
> are using the wrong array indices and you have data on a different 
> linethan you are "currently interpreting.  Your spacing and 
> comments also
> make it very hard (at least for me, I know this is a style issue) to
> read what you are actually doing
> 
> > Here is an example with more data...
> > 
> > #!PERL
> > use warnings;
> > use strict;
> > 
> > my (@te,%RATING,$debug,$attrib,$key,$CPU_ATTR);
> 
> Again, declaring all of these here defeats the purpose of strictures,
> and is probably one of the reasons why your code is so confusing.
> 
> > $debug=0;
> > 
> > @te = (   "CREATE   CPU-MODEL UNKNOWN_CPU VENDOR Unknown, 
> GENERIC_CPUVENDOR
> > SUN\n" ,
> >   "Quntity 5\n" ,
> >   "Color Blue\n" ,
> > 
> >"CREATE   CPU-MODEL model1 VENDOR Unknown, GENERIC_CPU VENDOR
> Unknown\n",
> >   "Quntity 6\n" ,
> >   "Color Blue\n" ,
> >  );
> >
> 
> Both of the above declarations can have the C moved onto them, 
> it is
> just a good habit to get into.
> 
> > s/,|^\t//g for @te;
> > 
> > 
> > foreach ( @te ){
> > my $input = $_;
> > 
> 
> If you are going to name the variable you can do it all in one 
> shot, the
> above can be written:
> 
> foreach my $input (@te) {
> 
> > my @fields= split /\s+/,$input;
> > print "LINE=$input" if $debug;
> > 
> > 
> > if( $fields[0] eq 'CREATE' ){
> > $CPU_ATTR= {};
> > $RATING{$fields[5]} = $CPU_ATTR;#
> 
> What is the extra # mark for? Index 5 maps to 'GENERIC_CPU' in your
> data, should this be 4?  You also need to build your 'type' into the
> hash structure at this point.
> 
> > $CPU_ATTR->{$fields[2]}=$fields[3]; #processor [EMAIL PROTECTED]
> > $CPU_ATTR->{$fields[4]}=$fields[5]; #processor [EMAIL PROTECTED]
> > 
> 
> I have no idea what the above are doing, I think this is the problem
> with the structure, and would be at least a little bit indicated 
> if you
> used better scoping rules.
> 
> > }
> > if( $fields[0] eq 'Quntity' ){
> >  $CPU_ATTR->{$fields[0]}=$fields[1];
> > }
> > if( $fields[0] eq 'Color' ){
> >  $CPU_ATTR->{$fields[0]}=$fields[1];
> > }
> 
> The problem is that $CPU_ATTR really shouldn't still be alive here,
> because you have transitioned to a new line, so the problem is 
> that at
> this point you can't index by type, which means your structure is one
> level flatter than it should be.
> 
> > 
> > }# end of while
> > 
> 
> Wrong comments are much worse than superfluous comments which are much
> worse than no comments. Personally I can't stand comments telling me
> that i have ended a loop, it should be obviuos (and that is what code
> folding is for), but that is a style issue.  But it isn't the end 
> of the
> 'while' it is the end of a 'foreach', *especially* since the next
> statement is a 'while'.
> 
> > while ( my ($key, $value) = each(%RATING) ) {
> > print "$key =>:\n";
> > for $attrib ( keys %$value ){
> > print "$attrib :";print $value->{$attrib} . "\n";
> > }
> > print "\n\n";
> > }
> > 
> 
> This will need to be improved 

Re: HoH not building as expected

2004-09-17 Thread Wiggins d Anconia


> > 
> > Though the use of C<$current> could be avoided if you could read
> > multiple lines at a time, if that is possible I would switch to that
> > method. If not the above should do.
> > 
> > If you are confused or this doesn't work, give it another shot and
> > provide at least 10 entries of data.

>  You hit it on the Spot !!! I am begining to understand where I was
going wrong. I do have anotehr QCan you exaplain why this is correct
scope, and why here unlike in my code Vendor is not recreated ??
> 
>  $rating->{$fields[4]}->{$fields[2]} = $current = {};
> 

Normally the scope of C<$current> shouldn't need to be outside of the
foreach, but in this case since the following lines need to be added to
the same hash we are currently working on, but we will no longer have
access to C<$fields[4]> and C<$fields[2]>, we have to have some way to
access that value (a reference) of the "middle" hash.  So rather than
keeping track of two temp variables, namely which vendor and type we are
acting on, I just keep track of the current reference and manipulate it
instead.  Either way would work, but to follow better (read: stricter)
scoping rules you would have to be able to read the 3 lines of input at
once, which you could do pretty easily, especially with a C loop
instead where you advance the iterator by 2 when you slurp in the lines,
but you didn't go that direction so I avoided it too.

Your code was continually clobbering the value in the Vendor code, and
was setting the type as one of the values of the 2nd level hash. Mine
sets the value of the Vendor code to a hash, but then sets within that
hash (the middle or 2nd level) the type code to a value to a 3rd level
hash which is where the quantity (which was misspelled before by the
way) and color then get set. So you end up with a list of all properties
(qty and color) for each type for each vendor. Obviously I am doing a
pretty poor job of describing it :-)... seriously check out the data
structure/reference docs I mentioned before, they should be able to
clear things up much better than I.

perldoc perldsc
perldoc perllol
perldoc perlreftut
perldoc perlref

http://danconia.org

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




Re: the x operator

2004-09-17 Thread Randal L. Schwartz
> "Sid" == Sid  <[EMAIL PROTECTED]> writes:

Sid> To get $n random numbers into @list, use:
Sid> @list = (rand(4)) x $n;

You mean, to get the same random number $n times into a list, correct?

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

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




Re: cp command error check

2004-09-17 Thread John W. Krahn
Urs Wagner wrote:
Hello
Hello,
This does not work.
`cp $srcfile $dstfile`; || do {
 print "cannot copy $srcfile to $dstfile";
   };
do is also execute if cp working fine. Whz is this so? The next thing I 
would like to
know how I can print the cp's error message.
use File::Copy;
copy( $srcfile, $dstfile ) or die "cannot copy $srcfile to $dstfile: $!";

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Moving between hashes 2.

2004-09-17 Thread Michael Robeson
**Sorry, if this is a repeat. Wasn't sure if the mail went through. If you already replied can you re-send it to my e-mail address above as well? Thanks!***

I have two sets of data that have been stored in hashes. The first hash 
 has amino-acid (protein) sequence data. The second hash has the 
 corresponding DNA sequence of those amino-acids: 

 Hash 1 
 key: value: 
 cat   =   mfgdhf 
 doq = mfg--f 
 mouse =   mf-d-f 

 Hash 2 
 key: value: 
 cat = agtcatgcacactgatcg 
 dog = agtcatgcatcg 
 mouse = agtcatcactcg 

 And I need to insert gaps (missing or absent data) proportionally into 
 the DNA sequence (Hash 2) so that the output is as follows: 

 Hash 3 
 key: value: 
 cat = agtcatgcacactgatcg 
 dog = agtcatgca--tcg 
 mouse = agtca---tca---ctcg 

 It doesn't look right here, but all the lines should end up being the 
 same length with courier font. Basically, I am having trouble scanning 
 though, say...  hash1{cat} and for every  dash found there being 
 finally represented as  three dashes in hash2{cat}. Also, every 
 amino-acid is represented by 3 DNA letters. This is why I need to move 
 in increments of 3 and add in increments of 3 for my final data to 
 appear as it does in Hash 3. 

 Example of relationship: 
 M F DF  = amino-acid 
 agt   tca --- act --- tcg  = dna 

 I have everything else set up I just need a few suggestions on how to 
 do the above. Any help will be greatly appreciated. 


<>

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


RE: Moving between hashes 2.

2004-09-17 Thread Bob Showalter
Michael Robeson wrote:

Don't post MIME or HTML to the list. Plain text only.

> 
> I have two sets of data that have been stored in hashes. The first
> hash 
> has amino-acid (protein) sequence data. The second hash has the
> corresponding DNA sequence of those amino-acids:
> 
> 
> Hash 1
> key: value:
> cat   =   mfgdhf
> doq = mfg--f
> mouse =   mf-d-f
> 
> 
> Hash 2
> key: value:
> cat = agtcatgcacactgatcg
> dog = agtcatgcatcg
> mouse = agtcatcactcg
> 
> 
> And I need to insert gaps (missing or absent data) proportionally into
> the DNA sequence (Hash 2) so that the output is as follows:
> 
> 
> Hash 3
> key: value:
> cat = agtcatgcacactgatcg
> dog = agtcatgca--tcg
> mouse = agtca---tca---ctcg
> 
> 
> It doesn't look right here, but all the lines should end up being the
> same length with courier font. Basically, I am having trouble scanning
> though, say...  hash1{cat} and for every  dash found there being
> finally represented as  three dashes in hash2{cat}. Also, every
> amino-acid is represented by 3 DNA letters. This is why I need to move
> in increments of 3 and add in increments of 3 for my final data to
> appear as it does in Hash 3.
> 
> 
> Example of relationship:
> M F DF  = amino-acid
> agt tca --- act --- tcg  = dna
> 
> 
> I have everything else set up I just need a few suggestions on how to
> do the above. Any help will be greatly appreciated.

Here's one approach:

#!/usr/bin/perl

use strict;

while () {
my ($key, $mask, $src) = split;
my @mask = $mask =~ /./g;
my @src = $src =~ /.../g;
print "$key: ";
print $_ eq '-' ? '---' : shift @src for @mask;
print "\n";
}

__DATA__
cat mfgdhf agtcatgcacactgatcg
dog mfg--f agtcatgcatcg
mouse mf-d-f agtcatcactcg

Outputs:

cat: agtcatgcacactgatcg
dog: agtcatgca--tcg
mouse: agtcat---cac---tcg

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




RE: failure with: system("dir /b"); exec("dir /b"); `dir /b`

2004-09-17 Thread A B C
Hi, 

I'm using ActiveState v5.8.4 on Windows XP Home03. 

Here is the entire script...
print `dir /s`;
print "\n-\n";
system('dir /b');
print "\n-\n";
exec("dir /w");
print "\n-\n";

===
Here is the result after executing...
C:\~p>perl test.pl
dir: /s: No such file or directory
-
dir: /b: No such file or directory
-
C:\~p>dir: /w: No such file or directory
C:\~p>

No problems when I run system("mem /c"). 



--- Bob Showalter <[EMAIL PROTECTED]>
wrote:

> A B C wrote:
> > Greetings,
> > 
> > Does anyone know how to get perl to run windows
> > commands like "dir /b". Specifically, perl doesn't
> > accept any type of argument switches. I've tried
> > system(), exec() and backticks in my script.
> > 
> > However, If I remove the switch, for example:
> > system("dir"). This works fine. But I need those
> > switches for many of my command utilites on
> windows. I
> > can't figure it out.
> 
> All these constructs are working fine for me with
> ActiveState 5.8 on Win XP.
> 
> Post the code that's causing problems. What's
> happening? Any error messages?
> What version of Windows? What version of Perl (perl
> -v). What happens if you
> run a command not built-in to CMD.EXE? (something
> like "mem /c" perhaps?)
> 
> > 
> > I've spent hours on google trying to find a code
> > snippet or comment with someone trying to use a
> > switch. nada. I started experimenting with
> open(FH,
> > $command|) but it doesn't seem to work either.
> 
> That's also working fine for me.
> 




__
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail 

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




RE: failure with: system("dir /b"); exec("dir /b"); `dir /b`

2004-09-17 Thread Bakken, Luke
> I'm using ActiveState v5.8.4 on Windows XP Home03. 
> 
> Here is the entire script...
> print `dir /s`;
> print "\n-\n";
> system('dir /b');
> print "\n-\n";
> exec("dir /w");
> print "\n-\n";

Since dir is a built-in, you should do this:

use strict;

print qx!cmd /c dir /s!;
print "\n-\n";
system('cmd /c dir /b');
print "\n-\n";
system("cmd /c dir /w");
print "\n-\n";


I do hope this is for testing, and that you won't be shelling out to dir
in your script, as anything dir does can be done in pure Perl.

Luke

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




Re: Moving between hashes 2.

2004-09-17 Thread Gunnar Hjalmarsson
Michael Robeson wrote:
**Sorry, if this is a repeat. Wasn't sure if the mail went through.
If you already replied can you re-send it to my e-mail address
above as well? Thanks!***
Aren't you subscribed to the list? And if there is a problem with your
receiving of email, how about checking the list archive
http://www.mail-archive.com/beginners%40perl.org/msg61879.html
or nntp.perl.org?
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Moving between hashes 2.

2004-09-17 Thread Gunnar Hjalmarsson
Bob Showalter wrote:
while () {
my ($key, $mask, $src) = split;
my @mask = $mask =~ /./g;
my @src = $src =~ /.../g;
print "$key: ";
print $_ eq '-' ? '---' : shift @src for @mask;
print "\n";
}
__DATA__
cat mfgdhf agtcatgcacactgatcg
dog mfg--f agtcatgcatcg
mouse mf-d-f agtcatcactcg
I see that you also made use of arrays. It struck me that, since the 
starting point is strings and not lists, using substr() would be more 
straight-forward:

  my %hash3;
  for ( keys %hash1 ) {
while ( my $aa = substr $hash1{$_},0,1,'' ) {
  $hash3{$_} .= $aa eq '-' ? '---' : substr $hash2{$_},0,3,'';
}
  }
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: failure with: system("dir /b"); exec("dir /b"); `dir /b`

2004-09-17 Thread A B C
Luke, Thanks! Your code works, you are a fantastic
help. I've been surfing (and surfing and surfing)
google for hours trying to find the answer. Your code
works and now my testing can proceed :-) -Mark 



--- "Bakken, Luke" <[EMAIL PROTECTED]> wrote:

> > I'm using ActiveState v5.8.4 on Windows XP Home03.
> 
> > 
> > Here is the entire script...
> > print `dir /s`;
> > print "\n-\n";
> > system('dir /b');
> > print "\n-\n";
> > exec("dir /w");
> > print "\n-\n";
> 
> Since dir is a built-in, you should do this:
> 
> use strict;
> 
> print qx!cmd /c dir /s!;
> print "\n-\n";
> system('cmd /c dir /b');
> print "\n-\n";
> system("cmd /c dir /w");
> print "\n-\n";
> 
> 
> I do hope this is for testing, and that you won't be
> shelling out to dir
> in your script, as anything dir does can be done in
> pure Perl.
> 
> Luke
> 
> --
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> 
> 
> 
> 
> 




__
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail

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




Re: Net ::FTP and subroutine calls

2004-09-17 Thread Colegate Spinks
  OhioHealth.com> writes:

..snip..

I'm fairly new to Perl, but have been working on a similar typ problem and
monitoring the success of my Net::FTP session.  I used logic similarm to the
following:

my ftp;
if($ftp = Net::FTP->new($remotehost)) {
   print "Initial FTP successful\n";
} else {
   print "Initial FTP failed\n"; die; }
if($ftp->login($user, $pass)) {
   print "Login Successful\n";
} else {
   print "Login failed!\n"; die; }
if($ftp->ascii()) {
   print "Mode set to ASCII successful\n";
} else {
   print "Mode set to ASCII failed\n"; die; }
if($ftp->cwd($remotedir)) {
   print "Change working directory successful\n";
} else {
   print "Change working directory failed\n"; die; }
if($ftp->put($data)) {
   print "Put was successful\n"; 
} else {
   print "Put failed\n"; die; }
if($ftp->quit) {
   print "FTP session terminated successfully\n";
} else {
   print "FTP session termination failed\n"; die; }

You can add to or remove as much logging as desired. I used it this way for a
script that a non-technical user would be running so that when it failed, I wold
know why if failed. You could also set it up as a series of cascading elsif's as
well. If you want to produce a log file that is redirected somewhere else other
than stdout, open up a filehandle and direct your prints to it. Hode this helps.


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




Re: how to get and convert time

2004-09-17 Thread Franklin
Thank you very much.
The problem is: My perl program will run on a hosting virtual server
and the system admin won't allow me to do so. So I must write a perl
script to get the computer's GMT time and convert it to US ET.:(


On Fri, 17 Sep 2004 08:28:33 -0400, Bob Showalter
<[EMAIL PROTECTED]> wrote:
> Franklin wrote:
> > Hello:
> > My operating system is freebsd and its time is GMT time which I can't
> > change. How can I write a perl script to get the exact
> > time(Hour,minute,second) and change it to US ET?
> 
> As John said, the internal clock is always UTC. On FreeBSD, you use the
> tzsetup(8) program to set the default time zone. If you're in US Eastern
> time zone, your sysadmin should go ahead an set this. Once set, Perl's
> localtime() function will return Eastern time, while gmtime() will return
> UTC.
> 
> If you want to temporarily override the default time zone, you can set the
> TZ variable.
> 
> Here's an example from my FreeBSD system (default time zone is
> America/New_York):
> 
>   $ perl -de0
>   main::(-e:1):   0
>   DB<1> x scalar localtime
>   0  'Fri Sep 17 08:21:30 2004'<--- default (Eastern) time
>   DB<2> $ENV{TZ}='America/Los_Angeles' <--- set TZ to a different time
> zone
> 
>   DB<3> x scalar localtime
>   0  'Fri Sep 17 05:21:46 2004'<--- Pacific time
>   DB<4>
> 
> To see all the time zone names, look at the file
> /usr/share/zoneinfo/zone.tab
> 
> 
> 
> --
> 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]
 




compare the content of a hash

2004-09-17 Thread Budi Santosa
Hi All,
I have a problem like this. Suppose I access a web and
save the head line new and summary of this web as a
hash.
For the next access to the same web, before saving the
news I have to check if the same news already in my
database.What is the best way to compare our databasse
and the most recent head line news that I just got
from the web?


thanks,
Budi

  



___
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com

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




Re: Need Help regarding training centres in INDIA

2004-09-17 Thread Ishwor
On Fri, 17 Sep 2004 17:18:10 +0530, Anish Kumar K.
<[EMAIL PROTECTED]> wrote:
> Hi
> 
> This is regarding PERL training centres in INDIA. Please let me know about
> this.

Don't know about any Perl Training Centres in india but theres a nice
thing called "books".  U can grab one called "Learning Perl" by
Schwartz & Phoenix (Oreilly).

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



-- 
::Ishwor::

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




Re: compare the content of a hash

2004-09-17 Thread Edward WIJAYA
perldoc -q hash compare
On Fri, 17 Sep 2004 10:20:14 -0700 (PDT), Budi Santosa 
<[EMAIL PROTECTED]> wrote:

Hi All,
I have a problem like this. Suppose I access a web and
save the head line new and summary of this web as a
hash.
For the next access to the same web, before saving the
news I have to check if the same news already in my
database.What is the best way to compare our databasse
and the most recent head line news that I just got
from the web?
thanks,
Budi


___
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com

--
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]