[19305] in Perl-Users-Digest
Perl-Users Digest, Issue: 1500 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Aug 12 06:05:39 2001
Date: Sun, 12 Aug 2001 03:05:08 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <997610708-v10-i1500@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Sun, 12 Aug 2001 Volume: 10 Number: 1500
Today's topics:
Re: Extract the relative sorting of items from multiple <krahnj@acm.org>
FAQ: How can I write() into a string? <faq@denver.pm.org>
Get rid of some ratio ftp <crud_alex@yahoo.com>
Re: Get rid of some ratio ftp <murat.uenalan@gmx.de>
Re: my final word - i'll listen, though [Re: Pattern Ma <gimi@psico.ch>
Need help with error trying to use string as ARRAY ref. <hinson@home.com>
Re: Need help with error trying to use string as ARRAY <krahnj@acm.org>
Re: Need help with error trying to use string as ARRAY <shutupsteve@awdang.no.thanks.com>
Re: Need help with error trying to use string as ARRAY <hinson@home.com>
Re: Need help with error trying to use string as ARRAY <hinson@home.com>
Re: Need help with error trying to use string as ARRAY <Tassilo.Parseval@post.rwth-aachen.de>
Re: Need help with error trying to use string as ARRAY <krahnj@acm.org>
Newbie Question: Can't write file in data directory of <trx32@home.com>
Parsing java bytecode, generating perl opcodes <goldbb2@earthlink.net>
Re: Save memory and measure used memory??? (David Combs)
Shouldn't sub foo {} be equivalent to sub foo {return} (John Lin)
Re: string extraction <krahnj@acm.org>
Re: telnet session through perl <Tassilo.Parseval@post.rwth-aachen.de>
Using the Term::ANSIColor <w.a.vogel@t-online.de>
Web page as a filehandle? <dscarlett@optushome.com.au>
Re: Web page as a filehandle? <pne-news-20010812@newton.digitalspace.net>
Re: Web page as a filehandle? <Tassilo.Parseval@post.rwth-aachen.de>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Sun, 12 Aug 2001 05:30:37 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Extract the relative sorting of items from multiple lists
Message-Id: <3B76147C.1FBD0B8B@acm.org>
David Combs wrote:
> [snip]
>
> Myself, I collect these things.
>
> Now, if we could only Knuth to do his vol 4!
>
> (I am not holding my breath for that one -- if so, I would have
> been dead from lack of oxygen some 30 years ago!)
Get the first section of volume four here:
http://Sunburn.Stanford.EDU/~knuth/fasc2a.ps.gz
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sun, 12 Aug 2001 06:17:01 GMT
From: PerlFAQ Server <faq@denver.pm.org>
Subject: FAQ: How can I write() into a string?
Message-Id: <xbpd7.57$V3.175063552@news.frii.net>
This message is one of several periodic postings to comp.lang.perl.misc
intended to make it easier for perl programmers to find answers to
common questions. The core of this message represents an excerpt
from the documentation provided with every Standard Distribution of
Perl.
+
How can I write() into a string?
See the section on "Accessing Formatting Internals" in the perlform
manpage for an swrite() function.
-
Documents such as this have been called "Answers to Frequently
Asked Questions" or FAQ for short. They represent an important
part of the Usenet tradition. They serve to reduce the volume of
redundant traffic on a news group by providing quality answers to
questions that keep coming up.
If you are some how irritated by seeing these postings you are free
to ignore them or add the sender to your killfile. If you find
errors or other problems with these postings please send corrections
or comments to the posting email address or to the maintainers as
directed in the perlfaq manual page.
Answers to questions about LOTS of stuff, mostly not related to
Perl, can be found by pointing your news client to
news:news.answers
or to the many thousands of other useful Usenet news groups.
Note that the FAQ text posted by this server may have been modified
from that distributed in the stable Perl release. It may have been
edited to reflect the additions, changes and corrections provided
by respondents, reviewers, and critics to previous postings of
these FAQ. Complete text of these FAQ are available on request.
The perlfaq manual page contains the following copyright notice.
AUTHOR AND COPYRIGHT
Copyright (c) 1997-1999 Tom Christiansen and Nathan
Torkington. All rights reserved.
This posting is provided in the hope that it will be useful but
does not represent a commitment or contract of any kind on the part
of the contributers, authors or their agents.
05.09
--
This space intentionally left blank
------------------------------
Date: Sun, 12 Aug 2001 14:31:06 +0800
From: "Foot" <crud_alex@yahoo.com>
Subject: Get rid of some ratio ftp
Message-Id: <9l57t8$fdr4@rain.i-cable.com>
Is there any way to check how many percentage of a file is completed while
retrieveing it using Net:FTP?
Then kill the process once the file's completion reach 99%?
Thanks in advance
------------------------------
Date: Sun, 12 Aug 2001 10:39:30 +0200
From: "Murat Uenalan" <murat.uenalan@gmx.de>
Subject: Re: Get rid of some ratio ftp
Message-Id: <9l5f6b$6ug3c$1@ID-71895.news.dfncis.de>
Hi,
this was a "solution" i used for downloading. Look at the dataconn object,
perhaps this helps somehow
Murat
__PERL__
use Net::FTP;
my $obj_ftp = new Net::FTP( ... );
my ( $file, $destfile ) = qw(blabla.txt blabla.txt);
ftp_dl($obj_ftp, $file, $destfile );
sub ftp_dl($$$)
{
my $ftp = shift;
my $file = shift;
my $dest = shift;
my $all_data = '';
my $readed = 0;
my $helper = 0;
my $size = $ftp->size( $file );
print "\nDownloading $file ($size bytes): ";
if( $size > 0 )
{
$blocksize = 2048;
my $dataconn = $ftp->retr( $file );
my $data_chunk;
my $prozent = 0;
my $loaded = 0;
while( $loaded = $dataconn->read( $data_chunk,
$blocksize ) )
{
$readed += $loaded;
$helper += $loaded;
if( $helper >= ($size/10) && $prozent < 10 )
{
print '##';
$prozent ++;
$helper = 0;
}
$all_data .= $data_chunk;
}
if( $readed >= $size )
{
for( $prozent .. 10 )
{
print '##';
}
print " 100% finished.\n";
}
else
{
print " transfer error ( only $readed of
$size bytes read ).\n";
}
$dataconn->close();
}
else
{
print " 0 byte file created.\n";
}
if( open ( DST, ">$dest" ) )
{
print DST $all_data;
close( DST );
}
return;
}
"Foot" <crud_alex@yahoo.com> schrieb im Newsbeitrag
news:9l57t8$fdr4@rain.i-cable.com...
> Is there any way to check how many percentage of a file is completed while
> retrieveing it using Net:FTP?
>
> Then kill the process once the file's completion reach 99%?
>
> Thanks in advance
>
>
------------------------------
Date: Sun, 12 Aug 2001 07:11:08 +0200
From: gimi <gimi@psico.ch>
Subject: Re: my final word - i'll listen, though [Re: Pattern Matching: Which subpattern (rather than substring) was matched?]
Message-Id: <3B760FEC.33C8D941@psico.ch>
hi
Simon Best wrote:
[snip]
> Thanks for your offerings, but I've pretty much settled on something
> like this:
>
> sub MatchyThing( $@ )
> {
> my ( $string, @patterns ) = @_;
^^^^^^^^^ ??
hmm.. i'd expect a warning here: '.. only used once.. typo'
use warnings;
>
> for( my $offset = 0; $offset <= length $string; ++$offset )
> {
> foreach $pattern ( @_ )
$string is still the first element of @_
> {
> if( substr( $string, $offset ) =~ m/^$pattern/ )
> {
> return ( $pattern, $offset );
> }
> }
> }
> return ();
> }
>
> It works through the string gradually, checking all the patterns at each
> offset from the start of the string. That way, the amount of pattern
> searching is reduced to something like the amount of pattern searching
> that would be done with:
>
> my $patterns = '(' . join( ')|(', @patterns ) . ')';
> $string =~ m/$patterns/;
>
> The pattern match /^$pattern/ is the key to it, as it limits each
> pattern match attempt to the start of each substring. (Though it
> doesn't work with patterns that already start with ^, but it wouldn't be
> difficult to add an extra bit to the function to handle such cases.)
i'd _much_ prefer the latter attempt, though i did not
benchmark any of these solutions, i strongly believe that
this is the fastest - you only do one single match!
i also think that your first version above will be slower
because you do not only one loop through all patterns, but
also through the strings (up to the end even, when $pattern
isn't there), and you do not only have a regex, but a
substr in every iteration, too!
but i have to agree that it heavily depends on your input
data; if a match is made early in the string, it will be
faster. otoh, if chances for finding any of the patterns
are small, you might lose.. :)
that's just a little more than guessing for now.. maybe
i'll have it loop some examples using benchmark - or are
you already doing that? :D
cheers,
gimi
--
distributed rendering with perl:
http://www.psico.ch/prs.shtml
------------------------------
Date: Sun, 12 Aug 2001 05:17:22 GMT
From: "Roger Hinson" <hinson@home.com>
Subject: Need help with error trying to use string as ARRAY ref...
Message-Id: <Cjod7.46055$MC1.14603349@news1.elcjn1.sdca.home.com>
Hi all,
Here is my current script.
#!G:/perl -w
use strict;
my @bcvgroups = ("CD","F");
my @bcvset1CD = ("071","072");
my @bcvset1F = ("06F","070");
my $group = "0";
my $ERRORLEVEL = "0";
open (LOG, ">>g:/scripts/error.log");
foreach $group (@bcvgroups) {
foreach my $bcvset1 (@{'bcvset1'.$group}) {
system "echo PRODDB1_$group establish DEV001 BCV dev $bcvset1";
if ($ERRORLEVEL) {
print LOG "Error: $ERRORLEVEL with Group $group and BCV
$bcvset1\n";
}
}
}
close LOG;
I am trying to get output of:
PRODDB1_CD establish DEV001 BCV dev 071
PRODDB1_CD establish DEV001 BCV dev 072
PRODDB1_F establish DEV001 BCV dev 06F
PRODDB1_F establish DEV001 BCV dev 070
Instead, I am getting:
Can't use string ("bcvset1CD") as an ARRAY ref while "strict refs" in use at
est
-inc-set1.pl line 15.
I see the error on line 15 where I try to change the @bcvset1XX to the
current value of @bcvgroups and end up setting it to a string.
Unfortunately, I don't know how to fix it, other the "no strict 'refs'"
which isn't the right way to go... All help is appreciated..
Roger
------------------------------
Date: Sun, 12 Aug 2001 06:19:22 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Need help with error trying to use string as ARRAY ref...
Message-Id: <3B762042.3173B595@acm.org>
Roger Hinson wrote:
>
> Here is my current script.
>
> [snip script]
>
> I am trying to get output of:
>
> PRODDB1_CD establish DEV001 BCV dev 071
> PRODDB1_CD establish DEV001 BCV dev 072
> PRODDB1_F establish DEV001 BCV dev 06F
> PRODDB1_F establish DEV001 BCV dev 070
>
> Instead, I am getting:
>
> Can't use string ("bcvset1CD") as an ARRAY ref while "strict refs" in use at
> est
> -inc-set1.pl line 15.
>
> I see the error on line 15 where I try to change the @bcvset1XX to the
> current value of @bcvgroups and end up setting it to a string.
> Unfortunately, I don't know how to fix it, other the "no strict 'refs'"
> which isn't the right way to go... All help is appreciated..
#!G:/perl -w
use strict;
my %proddb1 = ( CD => [ '071', '072' ],
F => [ '06F', '070' ],
);
my $ERRORLEVEL = 0;
open LOG, '>> g:/scripts/error.log' or die "Cannot open
'g:/scripts/error.log': $!";
for my $group ( keys %proddb1 ) {
for my $bcvset1 ( @{$proddb1{$group}} ) {
system "echo PRODDB1_$group establish DEV001 BCV dev $bcvset1";
if ( $ERRORLEVEL ) {
print LOG "Error: $ERRORLEVEL with Group $group and BCV
$bcvset1\n";
}
}
}
close LOG;
__END__
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sat, 11 Aug 2001 23:24:44 -0700
From: "Stephen Deken" <shutupsteve@awdang.no.thanks.com>
Subject: Re: Need help with error trying to use string as ARRAY ref...
Message-Id: <tnc88pdhsocg6e@corp.supernews.com>
"Roger Hinson" <hinson@home.com> wrote:
> I see the error on line 15 where I try to change the @bcvset1XX
> to the current value of @bcvgroups and end up setting it to a string.
> Unfortunately, I don't know how to fix it, other the "no strict
> 'refs'" which isn't the right way to go... All help is appreciated..
Just stuff your arrays into hashes, as shown below. I have made the
following changes to your code:
major change:
- moved @bcvsetX into a hash named %bcvsets. Notice the [brackets] used
for the
values, e.g.:
my %bcvsets = ( 'CD' => [ '071', '072' ],
'F' => [ '06F', '070' ],
);
The [brackets] create an anonymous array reference. Using (parens) here
would
cause unexpected behavior.
minor changes:
- moved definition of my $group into foreach for scoping's sake
- removed quotes from $ERRORLEVEL definition
- formatting with braces into a style no one seems to like
- changed doublequotes (") to single quotes (') where you're not
interpolating anything
Here's the code. It could be further improved by testing the return value
of the open() and close(), if you're looking for ruggedness.
HTH,
--sjd;
__DATA__
#!G:/perl -w
use strict;
my @bcvgroups = ('CD','F');
my %bcvsets = ( 'CD' => [ '071', '072' ],
'F' => [ '06F', '070' ],
);
my $ERRORLEVEL = 0;
open( LOG, '>>g:/scripts/error.log' );
foreach my $group (@bcvgroups)
{
foreach my $bcvset1 (@{$bcvset{$group}})
{
system( 'echo', "PRODDB1_$group establish DEV001 BCV dev $bcvset1" );
if ($ERRORLEVEL)
{
print LOG "Error: $ERRORLEVEL with Group $group and BCV $bcvset1\n";
}
}
}
close LOG;
------------------------------
Date: Sun, 12 Aug 2001 08:26:20 GMT
From: "Roger Hinson" <hinson@home.com>
Subject: Re: Need help with error trying to use string as ARRAY ref...
Message-Id: <M4rd7.46535$MC1.14710699@news1.elcjn1.sdca.home.com>
"John W. Krahn" <krahnj@acm.org> wrote in message
news:3B762042.3173B595@acm.org...
> Roger Hinson wrote:
> >
> > Here is my current script.
> >
> > [snip script]
> >
> > I am trying to get output of:
> >
> > PRODDB1_CD establish DEV001 BCV dev 071
> > PRODDB1_CD establish DEV001 BCV dev 072
> > PRODDB1_F establish DEV001 BCV dev 06F
> > PRODDB1_F establish DEV001 BCV dev 070
> >
> > Instead, I am getting:
> >
> > Can't use string ("bcvset1CD") as an ARRAY ref while "strict refs" in
use at
> > est
> > -inc-set1.pl line 15.
> >
> > I see the error on line 15 where I try to change the @bcvset1XX to
the
> > current value of @bcvgroups and end up setting it to a string.
> > Unfortunately, I don't know how to fix it, other the "no strict 'refs'"
> > which isn't the right way to go... All help is appreciated..
>
>
> #!G:/perl -w
> use strict;
>
> my %proddb1 = ( CD => [ '071', '072' ],
> F => [ '06F', '070' ],
> );
> my $ERRORLEVEL = 0;
>
> open LOG, '>> g:/scripts/error.log' or die "Cannot open
> 'g:/scripts/error.log': $!";
>
> for my $group ( keys %proddb1 ) {
> for my $bcvset1 ( @{$proddb1{$group}} ) {
> system "echo PRODDB1_$group establish DEV001 BCV dev $bcvset1";
>
> if ( $ERRORLEVEL ) {
> print LOG "Error: $ERRORLEVEL with Group $group and BCV
> $bcvset1\n";
> }
> }
> }
>
> close LOG;
>
> __END__
Thanks for the help.. It worked perfectly, although I have one
question. When I run the script, it doesn't output in the order that it's
been put into the hashes. It prints F before CD, not a problem, but I was
curious as to why.
Roger
------------------------------
Date: Sun, 12 Aug 2001 08:27:54 GMT
From: "Roger Hinson" <hinson@home.com>
Subject: Re: Need help with error trying to use string as ARRAY ref...
Message-Id: <e6rd7.46537$MC1.14711303@news1.elcjn1.sdca.home.com>
"Stephen Deken" <shutupsteve@awdang.no.thanks.com> wrote in message
news:tnc88pdhsocg6e@corp.supernews.com...
> "Roger Hinson" <hinson@home.com> wrote:
> > I see the error on line 15 where I try to change the @bcvset1XX
> > to the current value of @bcvgroups and end up setting it to a string.
> > Unfortunately, I don't know how to fix it, other the "no strict
> > 'refs'" which isn't the right way to go... All help is appreciated..
>
> Just stuff your arrays into hashes, as shown below. I have made the
> following changes to your code:
>
>
> major change:
> - moved @bcvsetX into a hash named %bcvsets. Notice the [brackets] used
> for the
> values, e.g.:
>
> my %bcvsets = ( 'CD' => [ '071', '072' ],
> 'F' => [ '06F', '070' ],
> );
>
> The [brackets] create an anonymous array reference. Using (parens)
here
> would
> cause unexpected behavior.
>
> minor changes:
> - moved definition of my $group into foreach for scoping's sake
> - removed quotes from $ERRORLEVEL definition
> - formatting with braces into a style no one seems to like
> - changed doublequotes (") to single quotes (') where you're not
> interpolating anything
>
>
> Here's the code. It could be further improved by testing the return value
> of the open() and close(), if you're looking for ruggedness.
>
> HTH,
>
> --sjd;
>
> __DATA__
>
> #!G:/perl -w
>
> use strict;
>
> my @bcvgroups = ('CD','F');
> my %bcvsets = ( 'CD' => [ '071', '072' ],
> 'F' => [ '06F', '070' ],
> );
>
> my $ERRORLEVEL = 0;
>
> open( LOG, '>>g:/scripts/error.log' );
>
> foreach my $group (@bcvgroups)
> {
> foreach my $bcvset1 (@{$bcvset{$group}})
> {
> system( 'echo', "PRODDB1_$group establish DEV001 BCV dev $bcvset1" );
> if ($ERRORLEVEL)
> {
> print LOG "Error: $ERRORLEVEL with Group $group and BCV $bcvset1\n";
> }
> }
> }
>
>
> close LOG;
>
>
Thanks for the help.. I was even able to debug one very small error. I
got to change bcvset to bcvsets. :) I also took your advice and added the
or die to the open file.
Roger
------------------------------
Date: Sun, 12 Aug 2001 11:07:07 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Need help with error trying to use string as ARRAY ref...
Message-Id: <3B76473B.4090308@post.rwth-aachen.de>
Roger Hinson wrote:
> "John W. Krahn" <krahnj@acm.org> wrote in message
> news:3B762042.3173B595@acm.org...
>
>>Roger Hinson wrote:
>>
>>> Here is my current script.
>>>
>>>[snip script]
>>>
>>> I am trying to get output of:
>>>
>>>PRODDB1_CD establish DEV001 BCV dev 071
>>>PRODDB1_CD establish DEV001 BCV dev 072
>>>PRODDB1_F establish DEV001 BCV dev 06F
>>>PRODDB1_F establish DEV001 BCV dev 070
>>>
>>> Instead, I am getting:
>>>
>>>Can't use string ("bcvset1CD") as an ARRAY ref while "strict refs" in
>>>
> use at
>
>>>est
>>>-inc-set1.pl line 15.
>>>
>>> I see the error on line 15 where I try to change the @bcvset1XX to
>>>
> the
>
>>>current value of @bcvgroups and end up setting it to a string.
>>>Unfortunately, I don't know how to fix it, other the "no strict 'refs'"
>>>which isn't the right way to go... All help is appreciated..
>>>
>>
>>#!G:/perl -w
>>use strict;
>>
>>my %proddb1 = ( CD => [ '071', '072' ],
>> F => [ '06F', '070' ],
>> );
>>my $ERRORLEVEL = 0;
>>
>>open LOG, '>> g:/scripts/error.log' or die "Cannot open
>>'g:/scripts/error.log': $!";
>>
>>for my $group ( keys %proddb1 ) {
>> for my $bcvset1 ( @{$proddb1{$group}} ) {
>> system "echo PRODDB1_$group establish DEV001 BCV dev $bcvset1";
>>
>> if ( $ERRORLEVEL ) {
>> print LOG "Error: $ERRORLEVEL with Group $group and BCV
>>$bcvset1\n";
>> }
>> }
>> }
>>
>>close LOG;
>>
>>__END__
>>
>
> Thanks for the help.. It worked perfectly, although I have one
> question. When I run the script, it doesn't output in the order that it's
> been put into the hashes. It prints F before CD, not a problem, but I was
> curious as to why.
That is due to the nature of a hash. Internally a hash may look like an
array but depending on the key of the value to be inserted, an array
element is computed using a hash-function. A key named 'abc' might be
computed thus (assuming we initially have 10 array elements):
(ord(a) + ord(b) + ord(c)) % 10 = (97 + 98 + 99) % 10 = 4
And so: $hash[4] = 'abc'.
This is of course very much simplified. You may get collisions between
keys since the number of all possible keys is so much bigger than the
number of available memory-cells in which case you need to find an
alternate address. There are serval ways of doing this...for instance,
by incrementing the index by one till a new cell is found or by using a
second hash-function etc.
Anyways:
To read out the hash, one iterates over the hash-array from beginning
till end and as you can see the order in which they come out does not
depend on the order in which they were put into the hash.
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: Sun, 12 Aug 2001 09:17:00 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Need help with error trying to use string as ARRAY ref...
Message-Id: <3B76498A.6A967ED6@acm.org>
Roger Hinson wrote:
>
> "John W. Krahn" <krahnj@acm.org> wrote in message
> news:3B762042.3173B595@acm.org...
> > Roger Hinson wrote:
> > >
> > > Here is my current script.
> > >
> > > [snip script]
> > >
> > > I am trying to get output of:
> > >
> > > PRODDB1_CD establish DEV001 BCV dev 071
> > > PRODDB1_CD establish DEV001 BCV dev 072
> > > PRODDB1_F establish DEV001 BCV dev 06F
> > > PRODDB1_F establish DEV001 BCV dev 070
> > >
> > > Instead, I am getting:
> > >
> > > Can't use string ("bcvset1CD") as an ARRAY ref while "strict refs" in
> use at
> > > est
> > > -inc-set1.pl line 15.
> > >
> > > I see the error on line 15 where I try to change the @bcvset1XX to
> the
> > > current value of @bcvgroups and end up setting it to a string.
> > > Unfortunately, I don't know how to fix it, other the "no strict 'refs'"
> > > which isn't the right way to go... All help is appreciated..
> >
> >
> > #!G:/perl -w
> > use strict;
> >
> > my %proddb1 = ( CD => [ '071', '072' ],
> > F => [ '06F', '070' ],
> > );
> > my $ERRORLEVEL = 0;
> >
> > open LOG, '>> g:/scripts/error.log' or die "Cannot open
> > 'g:/scripts/error.log': $!";
> >
> > for my $group ( keys %proddb1 ) {
> > for my $bcvset1 ( @{$proddb1{$group}} ) {
> > system "echo PRODDB1_$group establish DEV001 BCV dev $bcvset1";
> >
> > if ( $ERRORLEVEL ) {
> > print LOG "Error: $ERRORLEVEL with Group $group and BCV
> > $bcvset1\n";
> > }
> > }
> > }
> >
> > close LOG;
> >
> > __END__
>
> Thanks for the help.. It worked perfectly, although I have one
> question. When I run the script, it doesn't output in the order that it's
> been put into the hashes. It prints F before CD, not a problem, but I was
> curious as to why.
Hash keys are not stored in any particular order so either sort them or
store the correct order in an array.
#!G:/perl -w
use strict;
my %proddb1 = ( CD => [ '071', '072' ],
F => [ '06F', '070' ],
);
my $ERRORLEVEL = 0;
open LOG, '>> g:/scripts/error.log'
or die "Cannot open 'g:/scripts/error.log': $!";
for my $group ( sort keys %proddb1 ) {
# ^^^^ keys now sorted
for my $bcvset1 ( @{$proddb1{$group}} ) {
system "echo PRODDB1_$group establish DEV001 BCV dev $bcvset1";
if ( $ERRORLEVEL ) {
print LOG "Error: $ERRORLEVEL with Group $group and BCV
$bcvset1\n";
}
}
}
close LOG;
__END__
#!G:/perl -w
use strict;
my %proddb1;
my @keys = ( 'CD', 'F' );
@proddb1{ @keys } = ( [ '071', '072' ], [ '06F', '070' ] );
my $ERRORLEVEL = 0;
open LOG, '>> g:/scripts/error.log'
or die "Cannot open 'g:/scripts/error.log': $!";
for my $group ( @keys ) {
for my $bcvset1 ( @{$proddb1{$group}} ) {
system "echo PRODDB1_$group establish DEV001 BCV dev $bcvset1";
if ( $ERRORLEVEL ) {
print LOG "Error: $ERRORLEVEL with Group $group and BCV
$bcvset1\n";
}
}
}
close LOG;
__END__
John
--
use Perl;
program
fulfillment
------------------------------
Date: 11 Aug 2001 20:09:08 -0500
From: tonyc <trx32@home.com>
Subject: Newbie Question: Can't write file in data directory of a Win2000 server
Message-Id: <belbnt4u83civqbei8uscl5hmck9duddd8@4ax.com>
I'm new to Perl and am trying to get a simple counter script to work.
It seems to be able to read the counter.txt file ok (it's in the data
directory) but I can't get it to write the new file count to the file.
When I open the file handle and code it for a warning, I get nothing
at all and the file isn't written with the new value. I thought I
should have gotten a warning or something that it could not
open the file.....
Anybody ever seen this happen?
I am perplexed.
here is the code:
The input routine works fine. The graphix routines work fine.
The counter get's incremented just fine, But I cannot get the
darned thing to write back out to the counter.txt file with the
new value. My file permissions seem to be ok. It reads the
counter.txt file but will not write to it.
thankx in advance.....!
Duh, here is the code this time.....
#!/usr/bin/perl
######################################################################
# BEFORE TRYING TO EDIT THIS SCRIPT, READ THE README FILE
######################################################################
#
# The Dream Catcher's Web Free CGI Scripts
# Simple Counter
#
# Created by Seth Leonard
#
# http://dreamcatchersweb.com/scripts/
#
# (c)2000 Seth Leonard
# All Rights Reserved
#
######################################################################
# ONLY EDIT THIS PART OF THE SCRIPT!!
$number_of_digits = "4";
$end = ".gif";
$pathtocounter = "data/counter.txt";
# images work ok - they are in the cgi-bin directory...
$pathtoimages = "";
$graphics = "yes";
# DO NOT EDIT BELOW THIS LINE!!
############################################################################
# Tell Browser
print ("Content-type: text/html\n\n");
# Get Count
open (COUNTER, "$pathtocounter") or warn "Cannot open file
$pathtocounter";
$count = <COUNTER>;
chop ($count) if $count =~ /\n$/;
close (COUNTER) or warn "Cannot close file $pathtocounter";
# Increase Count
$count += 1;
# write the new count back to the file:
open (COUNTER, ">$pathtocounter") or warn "Cannot open file
$pathtocounter";
print COUNTER "$count" ;
close (COUNTER);
@digits = split(//, $count);
if ($number_of_digits eq "") {
$howmany = @digits;
} else {
$howmany = $number_of_digits;
}
# Give empty digits a value
$spline = '%0' . $howmany . 'd';
$count = sprintf("$spline", $count);
@digitimages = split(//, $count);
# Print Output Counter
foreach $digitimage (@digitimages) {
if ($graphics eq yes) {
$image = "<img src=$pathtoimages" . "$digitimage" . "$end>";
print ("$image");
} else {
$plain = $digitimage;
print ("$plain");
}
}
exit;
------------------------------
Date: Sun, 12 Aug 2001 03:58:25 -0400
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Parsing java bytecode, generating perl opcodes
Message-Id: <3B763721.42D8ED24@earthlink.net>
This is a silly question [asked for curiosity's sake], but is there even
a remote possibility of doing the following:
Convert java bytecode to perl or perl bytecode, so a compiled java class
might be converted to a perl module (outputed either in perl source
form, or in .pmc form).
Or better yet, something which could, on the fly (or "Just in time", if
you like), take java bytecode, turn it into perl opcodes, and load it
into perl, to be used as ordinary perl modules.
Imagine doing:
perl -MJVM sun.applet.AppletViewer http://blah/app.html
or
perl -MO=java -e'javac' /path/sun/applet/AppletViewer.class
perl /path/sun/applet/AppletViewer.pmc http://blah/app.html
or
perl -MJVM -e '
sun::applet::AppletViewer::main "http://blah/app.html";
JVM->eventloop;
exit; '
This wouldn't really be running the java virtual machine in perl, but
merely translating java virtual machine code to perl virtual machine
code. I know that there are modules for interacting with a JVM, but
none of them pretending to simulate one.
--
I need more taglines. This one is getting old.
------------------------------
Date: 12 Aug 2001 05:17:32 GMT
From: dkcombs@panix.com (David Combs)
Subject: Re: Save memory and measure used memory???
Message-Id: <9l53hb$rt7$1@news.panix.com>
In article <9kll0v$1vmu$1@agate.berkeley.edu>,
Ilya Zakharevich <nospam-abuse@ilyaz.org> wrote:
>[A complimentary Cc of this posting was sent to
>Eric Bohlman
><ebohlman@omsdev.com>], who wrote in article <9kirtm$s0m$1@bob.news.rcn.net>:
>> > or this:
>> > $rules{'A MPN NP'} = 1;
>> > $rules{'A MPN NP $.'} = 1;
>> > $rules{'A MPN NP CARD $.'} = 1;
>>
>> That's going to be rather awkward to work with; if you need something like
>> it, you might as well use an array rather than a hash.
>
>Let me remind a handy syntax
>
> $rules{'A','MPN','NP'} = 1;
>
>It is a pity it is not supported by the tied API (but see my RFC)...
>
*What* RFC?
Thanks
David
------------------------------
Date: 12 Aug 2001 01:45:27 -0700
From: johnlin@chttl.com.tw (John Lin)
Subject: Shouldn't sub foo {} be equivalent to sub foo {return} or sub foo {()} ?
Message-Id: <a73bcad1.0108120045.57f3e26d@posting.google.com>
Dear all,
Today, I encountered a bug and fixed it.
I imputed this bug to either my misconception or a Perl's bug:
package X;
sub new {
my $self = bless {};
for($self->using) { push @{$self->{objects}},$_ }
return $self;
}
sub using {}
sub load {
my $self = shift;
$_->load for @{$self->{objects}};
}
package main;
X->new->load;
It died in a deep recursion at $_->load
The bug can be eliminated by modifying the
sub using {}
into
sub using {()}
or
sub using {return}
"perldoc -f return" says the sub using {} will return
the value of the last expression evaluated. My opinion is,
considering the above case, it should add a condition:
"Except that when the sub is empty, return ()". Otherwise the
result is useless, unexpectable, meaningless and buggy.
What do you think about it?
John Lin
------------------------------
Date: Sun, 12 Aug 2001 06:39:32 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: string extraction
Message-Id: <3B7624A2.7464321D@acm.org>
David Combs wrote:
>
> In article <m3ofptf60u.fsf@dhcp9-161.support.tivoli.com>,
> Ren Maddox <ren@tivoli.com> wrote:
> >On Sat, 04 Aug 2001, krahnj@acm.org wrote:
> >
> >> I don't think so.
> >>
> >> perl -le'$string = "one xxx two xxx three xxx four xxx\n";
> >> $number_xxx_found = $string =~ m!xxx!g; print $number_xxx_found'
> >> 1
> >
> >The idiom of interposing a set of empty parens in the assignment
> >solves this problem:
> >
> >perl -le'$string = "one xxx two xxx three xxx four xxx\n";
> >$number_xxx_found = () = $string =~ m!xxx!g; print $number_xxx_found'
> >4
>
> Ren, could explain just what's happening there?
>
> Sure looks strange, that idiom (which, like most,
> I've never seen before).
>
> ie, that " = () = ". VERY strange-looking.
It's the same as:
$number_xxx_found = @array = $string =~ m!xxx!g;
where @array = $string =~ m!xxx!g fills @array with all the matches from
$string and then $number_xxx_found = @array puts the number of elements
from @array into $number_xxx_found. The only difference is that perl
allows us to use () instead of @array to achieve the same effect without
declaring and extra variable (since we only need the number and not the
list itself.)
John
--
use Perl;
program
fulfillment
------------------------------
Date: Sun, 12 Aug 2001 09:12:42 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: telnet session through perl
Message-Id: <3B762C6A.6090905@post.rwth-aachen.de>
Antoine Hall wrote:
> You can go to CPAN and download the Net::Telnet module...it allows you to
> telnet to another machine and execture commands, etc.
Of course, one _can_ use Net::Telnet. But in this context we were
talking about a client that talks to a server via CGI. The client is not
supposed to have any Perl at all installed. Doing a telnet over http is
virtually impossible. Certainly: You can present a form to the client in
which he enters some commands, send it to the server while the server
relays these commands via telnet to another machine. But you'll never
get instant response from the server....think of command completion with
Tab. How do that over http?
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: Sun, 12 Aug 2001 03:25:39 +0200
From: "Wolfgang Vogel" <w.a.vogel@t-online.de>
Subject: Using the Term::ANSIColor
Message-Id: <9l4lrj$21l$06$1@news.t-online.com>
High group,
can someone give me a hint how I can realize colored text output in
a WIN2000 DOSBOX.
Thanks for any constructive hint
Wolfgang Vogel
------------------------------
Date: Sun, 12 Aug 2001 04:49:31 GMT
From: "David Scarlett" <dscarlett@optushome.com.au>
Subject: Web page as a filehandle?
Message-Id: <vVnd7.18528$A5.53053@news1.eburwd1.vic.optushome.com.au>
Is it possible to open a webpage as a filhandle in perl? I want to be able
to grab data off a web page, and I was wondering if it would be possible to
somehow open the website as a filehandle and grab the source code one line
at a time.... is it?
TiA,
--
David Scarlett
dscarlett@optushome.com.au
http://www.listen.to/artifice/
http://members.optushome.com.au/dscarlett/
"Look, coupons. I can get 2 oil changes for the price of 1! Now if I could
only afford the one......... and a car."
-Dr Zoidberg, Futurama
------------------------------
Date: Sun, 12 Aug 2001 09:24:29 +0200
From: Philip Newton <pne-news-20010812@newton.digitalspace.net>
Subject: Re: Web page as a filehandle?
Message-Id: <akbcntsj3s26tmhvdvr0tl4hv23m44tq3u@4ax.com>
On Sun, 12 Aug 2001 04:49:31 GMT, "David Scarlett"
<dscarlett@optushome.com.au> wrote:
> Is it possible to open a webpage as a filhandle in perl? I want to be able
> to grab data off a web page, and I was wondering if it would be possible to
> somehow open the website as a filehandle and grab the source code one line
> at a time.... is it?
Well, you could use a tied filehandle with LWP behind it...
The easiest way is probably to use LWP::UserAgent to fetch the document.
If it's not too large, fetch it all at once and then split the document
on newlines and iterate through the lines with foreach. If the document
is larger, pass a code ref to $ua->request and handle the data a chunk
at a time (you won't get lines at a time this way, however).
Or if you're into pain, you could open a socket to the web server, talk
HTTP over it, and then read from the socket a line at a time.
Cheers,
Philip
--
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.
------------------------------
Date: Sun, 12 Aug 2001 09:20:40 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Web page as a filehandle?
Message-Id: <3B762E48.8070605@post.rwth-aachen.de>
David Scarlett wrote:
> Is it possible to open a webpage as a filhandle in perl? I want to be able
> to grab data off a web page, and I was wondering if it would be possible to
> somehow open the website as a filehandle and grab the source code one line
> at a time.... is it?
Not so easily. For that you'd have to use sockets. Thus you create a
filehandle to a remote host, write a http request to this socket (GET
/index.html HTTP/1.0 etc) and read the response just as you would read
it from a file (eg while(<$socket>) { ... }).
Read several manpages about that, notably the perldocs of Socket,
IO::Socket, IO::Socket::INET and perlipc.
Yet, more comfortable would be using LWP or at least one of the
HTTP-modules, perhaps HTTP::Request.
Tassilo
--
$a=[(74,116)];$b=[($a->[1]-1,$a->[1]++,0x20)];$c=[(97,110)];$d=[($c->
[1]+1,$b->[1],"her")];for(@{[$a,$b,$c,$d]}){for(@{$_}){$_=~/\d+/?print
(chr($_)):print;}}$c=sub{$l=shift;[(0x20+$l-1,0x50,0x65,0x73-0x01,108
),(0x20,0x68,0x61,)]};print(map{chr($_)}@{($c->(1))});$h={a=>33*3,b=>
10**2+7,c=>"1"."0"."1",d=>0162};@h=sort(keys(%$h));for(@h){print(chr(
ord(chr($h->{$_}))))};
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 1500
***************************************