[19467] in Perl-Users-Digest
Perl-Users Digest, Issue: 1662 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Aug 30 21:05:33 2001
Date: Thu, 30 Aug 2001 18:05:09 -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: <999219909-v10-i1662@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 30 Aug 2001 Volume: 10 Number: 1662
Today's topics:
Re: =?iso-8859-1?Q?I=B4m?= from Spain, if you are from (Martien Verbruggen)
Re: can this perl script be more elegant/shorter ? <uri@sysarch.com>
Re: can this perl script be more elegant/shorter ? <krahnj@acm.org>
Re: Can't locate misc.pl in @INC <gnarinn@hotmail.com>
Re: combining varibles <somewhere@in.paradise.net>
Re: Comparing two dates! Is there an easy way? <godzilla@stomp.stomp.tokyo>
Re: Deleting files? <pilsl_@goldfisch.at>
Re: Difference between .pl, .cgi, and .pm File Extensio <bob@eawf.nospam.com>
HASH question <Javad>
Re: HASH question <Tassilo.Parseval@post.rwth-aachen.de>
Re: HASH question <samneric@tigerriverOMIT-THIS.com>
Re: HASH question <Jon.Ericson@jpl.nasa.gov>
Re: HASH question <Javad>
Re: HASH question <Javad>
Re: HASH question <pilsl_@goldfisch.at>
Re: HASH question <Jon.Ericson@jpl.nasa.gov>
Re: help understanding this snippet <samneric@tigerriverOMIT-THIS.com>
Re: help understanding this snippet (Tad McClellan)
Re: help understanding this snippet <davidhilseenews@yahoo.com>
Re: Help with script <mbudash@sonic.net>
How to connect to Oracle DB using perl <mr_ocp@yahoo.com>
Re: Performance : Shell X Perl <andrew.savige@ir.com>
Re: PerlFS again? (Malcolm Dew-Jones)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Thu, 30 Aug 2001 23:58:09 GMT
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: =?iso-8859-1?Q?I=B4m?= from Spain, if you are from Spain could you help me starting PERL. Thanks
Message-Id: <slrn9otkoh.1jv.mgjv@verbruggen.comdyn.com.au>
On Thu, 30 Aug 2001 13:56:56 GMT,
sin las dos x antes de la @ <xesquiogx@pobox.com> wrote:
>
[Nothing, but this was in the Subject line:]
Subject: I´m from Spain, if you are from Spain could you help me
starting PERL. Thanks
I'm not from Spain, and I don't know what PERL is, but since you
posted to clp.misc, I feel like telling you how to start perl.
First, you get the Perl distribution from CPAN (www.cpan.org), and you
install it. If you're on Windows, you may prefer to get the
Activestate distribution (www.activestate.com).
Once Perl is installed, you make sure that the perl binary is in your
path.
Get yourself a shell prompt (or one of those command or cmd window
thingies on Windows), and you type
perl
And presto: it's started.
Martien
PS. If you really meant that you wanted to learn to program in Perl:
Andrew Johnson's /Elements of programming with Perl/ is a good
introduction to Perl as well as to programming. /Learning Perl/,
third edition (Randal Schwartz and Tom Phoenix), is good too.
--
Martien Verbruggen |
Interactive Media Division | The four horsemen of the apocalypse
Commercial Dynamics Pty. Ltd. | are called Abort, Retry, Ignore and
NSW, Australia | Fail.
------------------------------
Date: Thu, 30 Aug 2001 22:31:18 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: can this perl script be more elegant/shorter ?
Message-Id: <x7lmk1goxu.fsf@home.sysarch.com>
>>>>> "T" == Tim <tvn007@hotmail.com> writes:
T> #!/usr/local/bin/perl5 -w
lose the perl5. it should be perl unless you have some crack addicted
sysadmin who keeps perl4 around as perl.
i don't see use strict. use it.
T> $input1 = 'chaintest.scan';
T> $output= "OUT";
T> $output2= "OUT.out";
some better use of whitespace, like before the =.
also why use "" and ''? pick one. i prefer '' for strings that aren't
being interpolated. others differ.
T> open (INFILE,"$input1")||die "cannot open $input1";
T> open(OUTFILE,">$output")||die "canoot\n";
T> open(OUTFILE2,">$output2")||die "canoot\n";
whitespace again. put $! in the die messages.
T> #######################################################
T> &preprocess;
no need for & in perl5.
T> open (INFILE2,"$output")||die "cannot open $input1";
T> $/=";";
never set $/ globally. localize it and set it.
local( $/ ) = ';'
T> $ct_scanout = 0;
T> while (<INFILE2>){
T> chomp;
T> $ct_scanout = 1 if (/apply\s*\"grp[0-9]_unload\"/);
T> $chain_test=1 if (/CHAIN_TEST/);
some comment on WHY you setthose flags would be nice.
T> if (( /\t*chain\s+\"chain([0-9])\"/) && ($chain_test)){
T> $chain_number = $1;
T> &cleanup;
T> $chain_input = (split /=/,$_)[1];
T> $chain_input =~ tr/\"//d;
T> SWITCH: {
T> $chain_number==1 && do {
T> @chain1 = split (//,$chain_input);
T> $scan_chain_length1 = @chain1; };
T> $chain_number==2 && do {
T> @chain2 = split (//,$chain_input);
T> $scan_chain_length2 = @chain2; };
T> $chain_number==3 && do {
T> @chain3 = split (//,$chain_input);
T> $scan_chain_length3 = @chain3; };
T> $chain_number==4 && do {
T> @chain4 = split (//,$chain_input);
T> $scan_chain_length4 = @chain4; };
T> $chain_number==5 && do {
T> @chain5 = split (//,$chain_input);
T> $scan_chain_length5 = @chain5; };
T> $chain_number==6 && do {
T> @chain6 = split (//,$chain_input);
T> $scan_chain_length6 = @chain6; };
T> $chain_number==7 && do {
T> @chain7 = split (//,$chain_input);
T> $scan_chain_length7 = @chain7;
T> &printout;
T> };
T> }#END SWITCH
OUCH!! you should use a LoL data structure rather than hardcoding names
(based on an integer) and then faking a switch. something like (untested):
@{$chains[$chain_number]} = split( //, $chain_input ) ;
that replaces the entire switch if i get your needs correctly.
T> }
T> } #end of While statement
T> sub printout {
T> if ($ct_scanout ){
T> for ($i=0;$i<$scan_chain_length3;$i++){
gack!
first, why is $scan_chain_length3 used and not any other length?
in general, index loops like that are never needed in perl.
foreach my $chain_ref ( @chains ) {
T> $chain1[$i] =~ s/0/L/g; $chain1[$i] =~ s/1/H/g;
T> $chain2[$i] =~ s/0/L/g; $chain2[$i] =~ s/1/H/g;
T> $chain3[$i] =~ s/0/L/g; $chain3[$i] =~ s/1/H/g;
T> $chain4[$i] =~ s/0/L/g; $chain4[$i] =~ s/1/H/g;
T> $chain5[$i] =~ s/0/L/g; $chain5[$i] =~ s/1/H/g;
T> $chain6[$i] =~ s/0/L/g; $chain6[$i] =~ s/1/H/g;
T> $chain7[$i] =~ s/0/L/g; $chain7[$i] =~ s/1/H/g;
tr/01/LH/ foreach @{$chain_ref} ;
T> print OUTFILE2 "\n(ct_so
T> $chain1[$i]$chain2[$i]$chain3[$i]$chain4[$i]$chain5[$i]$chain6[$i]$chain7[$i]
T> )";
print OUTFILE2 @{$chain_ref} ;
T> for ($i=0;$i<$scan_chain_length3;$i++){
same thing
T> $chain1[$i] =~ s/X/0/g; $chain2[$i] =~ s/X/0/g;
T> $chain3[$i] =~ s/X/0/g; $chain4[$i] =~ s/X/0/g;
T> $chain5[$i] =~ s/X/0/g; $chain6[$i] =~ s/X/0/g;
T> $chain7[$i] =~ s/X/0/g;
T> print OUTFILE2 "\n(ct_si $ct_si{tdi}
T> $chain1[$i]$chain2[$i]$chain3[$i]$chain4[$i]$chain5[$i]$chain6[$i]$chain7[$i]
T> )";
and again as above.
T> sub cleanup{
T> s/^\s+|\s*\n+$//g;
that is a slower and more confusing way. just make 2 separate s///
calls.
s/^\s+// ;
s/\s*\n+$// ;
T> tr/\t //d;
T> s/\n//g;
T> s/\\//g;
hmm, you know about tr///d so why do you then do s///?
tr/\t\n \\//d
T> }
poor idea to have a sub work on the global $_. pass in an arg and return
a result.
T> sub preprocess{
T> while (<INFILE>){
T> chomp;
T> s/$/;/g if (/apply/);
T> print OUTFILE ("$_\n");
T> last if ( /^SCAN_CELLS/);
T> }
T> close OUTFILE;
T> }
<snip of massive input example>
don't do that. a few lines of data would have been fine. in fact i
didn't even look at the data as i could help with the code without it.
uri
--
Uri Guttman --------- uri@sysarch.com ---------- http://www.sysarch.com
SYStems ARCHitecture and Stem Development ------ http://www.stemsystems.com
Search or Offer Perl Jobs -------------------------- http://jobs.perl.org
------------------------------
Date: Fri, 31 Aug 2001 00:44:31 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: can this perl script be more elegant/shorter ?
Message-Id: <3B8EDE5F.643A4ECF@acm.org>
Tim wrote:
>
> Hi,
>
> Could some one help me to make this script more elegant and shorter ?
>
> Here is my PERL script:
>
> [snip]
This should get you started.
#!/usr/local/bin/perl5 -w
use strict;
$/ = ';';
my $input1 = 'chaintest.scan';
my $output2 = 'OUT.out';
my $ct_scanout = 0;
my @chain;
open INFILE, "< $input1" or die "cannot open $input1: $!";
open OUTFILE, "> $output2" or die "cannot open $output2: $!";
while ( <INFILE> ) {
next unless /CHAIN_TEST/ .. /^SCAN_CELLS/;
chomp;
$ct_scanout = 1 if /apply\s*"grp[0-9]_unload"/;
if ( /chain\s+"chain([0-9])"\s*=\s*"([^"]*)"/ ) {
my $chain_number = $1;
$_ = $2;
s/^\s+//;
s/\s+$//;
tr/\\\n\t //d;
if ( $ct_scanout ) {
tr/01/LH/;
}
else {
tr/X/0/;
}
@{ $chain[ $chain_number ] } = split //;
if ( $chain_number == 7 ) {
if ( $ct_scanout ) {
for ( my $i = 0; $i < @{ $chain[ $chain_number ] }; $i++
) {
print OUTFILE "\n(ct_so
$chain[1][$i]$chain[2][$i]$chain[3][$i]$chain[4][$i]$chain[5][$i]$chain[6][$i]$chain[7][$i]
)";
}
$ct_scanout=0;
}
else {
for ( my $i = 0; $i < @{ $chain[ $chain_number ] }; $i++
) {
print OUTFILE "\n(ct_si
$chain[1][$i]$chain[2][$i]$chain[3][$i]$chain[4][$i]$chain[5][$i]$chain[6][$i]$chain[7][$i]
)";
}
}
}
}
}
__END__
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 30 Aug 2001 22:14:59 +0000
From: gnari <gnarinn@hotmail.com>
Subject: Re: Can't locate misc.pl in @INC
Message-Id: <999209699.514561090152711.gnarinn@hotmail.com>
In article <999188978.2133.0.nnrp-14.3e31b93c@news.demon.co.uk>,
Michael Ditum <Mike.Ditum@Doulos.com> wrote:
>I have perl (activePerl) set up on my Windows2000 Server and it can run
>simple perl scripts fine.
>I'm trying to run a perl script that uses a package i've created which is in
>the same directory as the
>script. I've got it to work on another (Windows 2000 Pro) computer which has
>apache and activeperl
>installed and that worked fine. but when i run it on the Win2K server i get
>this message.
>
>CGI Error
>The specified CGI application misbehaved by not returning a complete set of
>HTTP headers. The headers it did return are:
>
>
>Can't locate misc.pl in @INC (@INC contains: C:/Program Files/Internet
>Utils/Perl/lib
>C:/Program Files/Internet Utils/Perl/site/lib .) at
>C:\Inetpub\wwwroot\cgi-bin\Time_Keeping\addEntryIntro.pl line 4.
>
>i know its not in any of the stated paths as its held in
>c:\inetpub\wwwroot\cgi-bin\time_keeping.
>it doesn't seem to be checking the current working directory and i can't
>work out how to change it.
well actually it does check the current working directory (the sigle
period at the end of the @INC listing), but you are just assuming
that you know what the CWD is. it depends on the webserver, and
perhaps on its configuration, and is not defined by the CGI standard.
>
>any help would be greatly appreciated!
use FindBin;
use lib "$FindBin::Bin";
gnari
------------------------------
Date: Fri, 31 Aug 2001 08:21:11 +1000
From: "Tintin" <somewhere@in.paradise.net>
Subject: Re: combining varibles
Message-Id: <Y0zj7.1$nD1.66626@news.interact.net.au>
"Alex Green" <alexdgreen@hotmail.com> wrote in message
news:9mljba$2r1m3$1@ID-106172.news.dfncis.de...
[top posting corrected]
> "Tony Curtis" <tony_curtis32@yahoo.com> wrote in message
> news:87g0a9fwgl.fsf@limey.hpcc.uh.edu...
> > >> On Thu, 30 Aug 2001 16:08:36 +0200,
> > >> "Alex Green" <alexdgreen@hotmail.com> said:
> >
> > > I've spent to much timein tcsh and i have forgotten how
> > > to take to varibles and input them into a single varible
> > > in perl.
> >
> > Far too vague. Try again with some examples.
> Hi,
>
> Right well basically I have a perl/cgi script retreiving values from an
html
> form, with a first name and a last name field and what I need is these to
> vars, lets say $fn and $ln to become combined to become $owner.
>
> Not really sure whether combine is the right word, but basically I need to
> be able to print them as an entire text string. Does that make sense?
Do you mean like with tcsh where you would do something like
echo "$fn$ln"
or in sh/ksh/bash
echo "$fn$ln"
or in perl
print "$fn$ln\n";
------------------------------
Date: Thu, 30 Aug 2001 16:36:54 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Comparing two dates! Is there an easy way?
Message-Id: <3B8ECE16.753163D1@stomp.stomp.tokyo>
Vinny Murphy wrote:
> Godzilla! wrote:
> > Peter Mann wrote:
(snipped)
> The cargo cult module of Date::Manip would be better served than the
> incorrect data below. Case in point - if you change 04/01/2001 to
> 04/01/3030 it wouldn't sort correctly.
http://la.znet.com/~callgirl/vinny.wav
Godzilla!
------------------------------
Date: Fri, 31 Aug 2001 02:28:18 +0200
From: peter pilsl <pilsl_@goldfisch.at>
Subject: Re: Deleting files?
Message-Id: <3b8eda27@e-post.inode.at>
Nathan Randle wrote:
> I am writing a script which uses an installation file to prevent people
> creating errors in the script and I want the installion file to be
> automatically deleted off the server once configured. How do I do this?
>
you are looking for the perl-command to delete files on your computer ?
well, its named unlink and take filename or even list of filenames as
parameter.
I personally use system('rm -f myfile'); on unix-machines instead, dont
know why.
To the other postings of you two cool guys: please go playing outside ;)
peter
--
mag. peter pilsl
pilsl_@goldfisch.at
http://www.goldfisch.at
------------------------------
Date: Thu, 30 Aug 2001 15:51:24 -0700
From: Bob Holden <bob@eawf.nospam.com>
Subject: Re: Difference between .pl, .cgi, and .pm File Extensions.
Message-Id: <eggtotchhrv1q267ri1h0nj32lvlqr91kb@4ax.com>
But I thought that that was what the use command was for in a
script...to add-in features/modules when they are needed. Since Perl
is interpretive, I assumed that this happens on the fly, so why
"Install" or "Make" the files?
On Thu, 30 Aug 2001 14:57:13 -0400, brian d foy <comdog@panix.com>
wrote:
>In article <h1usotogbc2s5vrftjvmf2r6s1cqe53k94@4ax.com>,
>bob@eawf.nospam.com wrote:
>
>> What I'm starting to glean out of this is that Perl Modules need to be
>> Installed onto a server or into Perl itself. Is that right?
>
>well, any code that you intend to pull into your scripts need
>to be available for perl to read. that commonly means that
>the code needs to be installed with perl. this is true for
>any sort of file, including perl libraries, modules, Data::Dumper
>files, or anything else.
>
>until something like Autoloader can fetch code over the net
>somehow, you're stuck with installing what you need locally
>or on a shared drive.
------------------------------
Date: Thu, 30 Aug 2001 15:39:36 -0700
From: <Javad>
Subject: HASH question
Message-Id: <3b8ec0d1$0$151@wodc7nh6.news.uu.net>
I am getting the following when I print my value: Value: HASH(0x1cec120)
using the following code:
my $val=$self->{'parts'}{$attribute};
print "\tValue: ", $val, "\n";
1) what does that mean?
2) how do I look at those values if it is really a hash array? what is the
syntax
thanks
------------------------------
Date: Fri, 31 Aug 2001 01:13:56 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: HASH question
Message-Id: <3B8EC8B4.1050807@post.rwth-aachen.de>
Javad wrote:
> I am getting the following when I print my value: Value: HASH(0x1cec120)
> using the following code:
> my $val=$self->{'parts'}{$attribute};
> print "\tValue: ", $val, "\n";
>
> 1) what does that mean?
> 2) how do I look at those values if it is really a hash array? what is the
> syntax
This rather looks to me like hash of hashes of hashes...if I counted
correctly. Either reconsider your data-structures. I don't think this is
ever necessary. However in your case:
print "\tValue: ", %{$val}, "\n"; # will give you the raw hash
Hence nicer:
while ( my ($key, $value) = each %{$val} ) {
print "Key: $key\tValue: $value\n;
}
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: Thu, 30 Aug 2001 19:38:19 -0400
From: Samneric <samneric@tigerriverOMIT-THIS.com>
Subject: Re: HASH question
Message-Id: <MPG.15f89827fe8e7cfb9896a4@news.onemain.com>
<Javad> wrote:
> I am getting the following when I print my value: Value: HASH(0x1cec120)
> using the following code:
> my $val=$self->{'parts'}{$attribute};
> print "\tValue: ", $val, "\n";
>
> 1) what does that mean?
It means that somewhere earlier in your code you did this:
$self->{'parts'}{$attributes} = { key1 => val1, key2 => val2 };
or something comparable. Perl created, populated and returnd a reference to a
new hash HASH(0x1cec120)
> 2) how do I look at those values if it is really a hash array? what is the
> syntax
my $attref = $self->{'parts'}{$attributes};
foreach my $attkey (keys %$attref) {
print "\tKey: $attkey\tValue: $attref->{$attkey}\n";
}
------------------------------
Date: 30 Aug 2001 15:25:25 +0000
From: Jon Ericson <Jon.Ericson@jpl.nasa.gov>
Subject: Re: HASH question
Message-Id: <86ae0hbme2.fsf@jon_ericson.jpl.nasa.gov>
<Javad> writes:
> I am getting the following when I print my value: Value: HASH(0x1cec120)
> using the following code:
> my $val=$self->{'parts'}{$attribute};
> print "\tValue: ", $val, "\n";
>
> 1) what does that mean?
It means that $val is a hash reference.
> 2) how do I look at those values if it is really a hash array? what is the
> syntax
A hash is _not_ an array. Calling it a `hash array' is really
confusing the issue. You really need to read perldata. You should
also read about the `keys' function in perlfunc.
Jon
------------------------------
Date: Thu, 30 Aug 2001 17:04:13 -0700
From: <Javad>
Subject: Re: HASH question
Message-Id: <3b8ed4a3$0$144@wodc7nh6.news.uu.net>
Just more clarification and questions;
0) I didn't create this massive hash of hashes, it is someone else's code
that represents a complex tree. There is lots of info that gets parsed
into the tree.
0) I tried both the replies posted(thanks to all):
1:
while ( my ($key, $value) = each %{$val} ) {
print "Key: $key\tValue: $value\n;
}
2:
my $attref = $self->{'parts'}{$attributes};
foreach my $attkey (keys %$attref) {
print "\tKey: $attkey\tValue: $attref->{$attkey}\n";
}
They do nothing. No output!
0) Another issue is that some of the values are HASH and some are not. Perl
complains
"Can't use string ("xyc") as a HASH ref while "strict refs" in use at
../xyz.pm line 2445.
How do I know which one to traverse or not?
thanks
<Javad> wrote in message news:3b8ec0d1$0$151@wodc7nh6.news.uu.net...
> I am getting the following when I print my value: Value: HASH(0x1cec120)
> using the following code:
> my $val=$self->{'parts'}{$attribute};
> print "\tValue: ", $val, "\n";
>
> 1) what does that mean?
> 2) how do I look at those values if it is really a hash array? what is
the
> syntax
>
> thanks
>
>
------------------------------
Date: Thu, 30 Aug 2001 17:10:04 -0700
From: <Javad>
Subject: Re: HASH question
Message-Id: <3b8ed602$0$140@wodc7nh6.news.uu.net>
> print "\tValue: ", %{$val}, "\n"; # will give you the raw hash
This produces an empty string for %{$val}. ie: Value:
> Hence nicer:
>
> while ( my ($key, $value) = each %{$val} ) {
> print "Key: $key\tValue: $value\n;
> }
>
That loop also empty, no output.
Still the line " print "\tValue: ", $val, "\n";" produces the output:
"Value: HASH(..)
I am baffled at this.
Thanks anyway!
Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de> wrote in message
news:3B8EC8B4.1050807@post.rwth-aachen.de...
> Javad wrote:
>
> > I am getting the following when I print my value: Value: HASH(0x1cec120)
> > using the following code:
> > my $val=$self->{'parts'}{$attribute};
> > print "\tValue: ", $val, "\n";
> >
> > 1) what does that mean?
> > 2) how do I look at those values if it is really a hash array? what is
the
> > syntax
>
> This rather looks to me like hash of hashes of hashes...if I counted
> correctly. Either reconsider your data-structures. I don't think this is
> ever necessary. However in your case:
>
> print "\tValue: ", %{$val}, "\n"; # will give you the raw hash
>
> Hence nicer:
>
> while ( my ($key, $value) = each %{$val} ) {
> print "Key: $key\tValue: $value\n;
> }
>
> 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: Fri, 31 Aug 2001 02:19:31 +0200
From: peter pilsl <pilsl_@goldfisch.at>
Subject: Re: HASH question
Message-Id: <3b8ed81f@e-post.inode.at>
<Javad> wrote:
> I am getting the following when I print my value: Value: HASH(0x1cec120)
> using the following code:
> my $val=$self->{'parts'}{$attribute};
> print "\tValue: ", $val, "\n";
>
> 1) what does that mean?
> 2) how do I look at those values if it is really a hash array? what is
> the syntax
>
You need to read more about anonymous structures and hashes and arrays.
This can all be quite confusing. Best you create a dump of your structure
using the Dumper-Module from cpan.
I use a lot of very deep anonymous structures (the kind of
$a->{key}->{subkey}->[4]->{subsubsubkey}... and this is very userful for
maintaining loads of information. To give you an idea, this is a recursive
subroutine that will destroy such a structure. It may answer some of your
questions.
best,
peter
sub dest
#
# delete the whole delivered structure
#
{
my $ptr=shift;
my $ptype=ref($ptr);
if (not $ptype) # no pointer
{
# print "+";
}
else
{
if ($ptype eq 'ARRAY')
{
# print "array : ";
foreach (@{$ptr})
{
# print ".[";
dest($_);
# print "]-";
}
@{$ptr}=();
};
if ($ptype eq 'HASH')
{
# print "hash : ";
foreach (keys %{$ptr})
{
# print ".[";
dest($ptr->{$_});
delete($ptr->{$_});
# print "]-";
}
%{$ptr}=(); }
}
}
--
mag. peter pilsl
pilsl_@goldfisch.at
http://www.goldfisch.at
------------------------------
Date: 30 Aug 2001 16:22:38 +0000
From: Jon Ericson <Jon.Ericson@jpl.nasa.gov>
Subject: Re: HASH question
Message-Id: <8666b5bjqp.fsf@jon_ericson.jpl.nasa.gov>
<Javad> writes:
> Just more clarification and questions;
>
> 0) I didn't create this massive hash of hashes, it is someone else's code
> that represents a complex tree. There is lots of info that gets parsed
> into the tree.
Perhaps you should ask that `someone' to help you out.
> 0) I tried both the replies posted(thanks to all):
>
> 1:
> while ( my ($key, $value) = each %{$val} ) {
> print "Key: $key\tValue: $value\n;
> }
>
> 2:
> my $attref = $self->{'parts'}{$attributes};
> foreach my $attkey (keys %$attref) {
> print "\tKey: $attkey\tValue: $attref->{$attkey}\n";
> }
>
> They do nothing. No output!
Probably because the hash is empty.
> 0) Another issue is that some of the values are HASH and some are not. Perl
> complains
> "Can't use string ("xyc") as a HASH ref while "strict refs" in use at
> ../xyz.pm line 2445.
> How do I know which one to traverse or not?
A tool that should be mentioned here is the Data::Dumper module. Read
all about it with perldoc Data::Dumper.
By the way, it's bad form to put the quoted text _under_ your
additions. Notice how I intespersed my comments in this message.
Jon
------------------------------
Date: Thu, 30 Aug 2001 20:07:09 -0400
From: Samneric <samneric@tigerriverOMIT-THIS.com>
Subject: Re: help understanding this snippet
Message-Id: <MPG.15f89f362cfff5a49896a6@news.onemain.com>
uNcONvEntiOnaL wrote:
>
You could get many opinions here, and perhaps even an accurate one.
Or you could find the actual answer where it is best found.
Dump it to STDOUT (or to a file):
> $oldline = substr($line,86,721);
print "Substr(): $oldline\n";
> @nbrs = reverse(($oldline =~ m".(1,12)"sg));
print "Numbers: @nbrs\n";
> for (x$=0;$x < 24; $x++) {
> $newline = sprintf ("%s\t%09d",newline$,int(pop(@nbrs)));
print "NewLine: $newline\n";
<STDIN>; # HIT A KEY
> }
I'm assuming that x$ and newline$ are your typos...
------------------------------
Date: Thu, 30 Aug 2001 19:24:19 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: help understanding this snippet
Message-Id: <slrn9otip3.192.tadmc@tadmc26.august.net>
uNcONvEntiOnaL <tomcat@visi.com> wrote:
>
>$oldline = substr($line,86,721);
>@nbrs = reverse(($oldline =~ m".(1,12)"sg));
>for (x$=0;$x < 24; $x++) {
There is a syntax error in the previous line.
This would seem more clear to me:
foreach my $x ( 0..24 ) {
> $newline = sprintf ("%s\t%09d",newline$,int(pop(@nbrs)));
There is a syntax error in the previous line (again).
>I think this used to read in whole numbers,
It _would_ "read in" strings that are 1 to 12 characters long. The
characters are NOT restricted to only digit characters, so
they can not be assumed to be "whole numbers".
Of course, it doesn't do anything of the sort, because it is
not even a Perl program, it has multiple syntax errors.
Please do not post pseudo code. Post Perl code.
>now it needs to read in
>decimals to
>two places.
I thought from your Subject that you wanted help understanding
what the code does, hope the above helped.
Seems like that last part should go in a post with:
Subject: help modifying this snippet
The first modification would be to get it to compile...
I suggest completely replacing the above with code that you
can understand yourself.
What have you tried so far?
perldoc perlre
might be helpful in understanding regex stuff.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Fri, 31 Aug 2001 01:03:06 GMT
From: "David Hilsee" <davidhilseenews@yahoo.com>
Subject: Re: help understanding this snippet
Message-Id: <enBj7.40868$hT4.10921152@news1.rdc1.md.home.com>
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrn9otip3.192.tadmc@tadmc26.august.net...
> uNcONvEntiOnaL <tomcat@visi.com> wrote:
> >
> >$oldline = substr($line,86,721);
> >@nbrs = reverse(($oldline =~ m".(1,12)"sg));
> >for (x$=0;$x < 24; $x++) {
>
>
> There is a syntax error in the previous line.
>
>
> This would seem more clear to me:
>
> foreach my $x ( 0..24 ) {
>
>
You mean
foreach my $x ( 0..23 ) {
David Hilsee
------------------------------
Date: Thu, 30 Aug 2001 23:47:17 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Help with script
Message-Id: <mbudash-E8A469.16471830082001@news.sonic.net>
In article <9mm4800bk4@drn.newsguy.com>, Nigel Heinsius
<Nigel_member@newsguy.com> wrote:
> I need help writing a script that will do the following:
>
> I have a framed web page. In one frame I want a button that will activate
> a CGI
> script that saves a filled out form in the other frame as a text file on
> the web
> server which can be emailed to any email address.
>
> Possible to do this? Hope so...
>
since there's already a form in a frame, then why not put the submit
button there (in that frame) too??
anyway, you'd need to use javascript to do the job... look into the
submit() method and call it with an onclick event on the button...
hth-
--
Michael Budash ~~~~~~~~~~ mbudash@sonic.net
------------------------------
Date: Thu, 30 Aug 2001 18:10:38 -0400
From: "Mr_Ocp" <mr_ocp@yahoo.com>
Subject: How to connect to Oracle DB using perl
Message-Id: <aRyj7.46$Wo4.12988@brie.direct.ca>
Hi Folks
I am very new at perl, I am creating an intranet web site which would
retrieve data from Oracle 8i Datbase. I have no clue how to configure
connection to oracle using Perl5.
Can you please help do this, would appreciate if you can provide some
examples.
Thanks for your help
Mike
------------------------------
Date: Fri, 31 Aug 2001 10:58:24 +1000
From: "Knob" <andrew.savige@ir.com>
Subject: Re: Performance : Shell X Perl
Message-Id: <QiBj7.4$ms2.1581@news0.optus.net.au>
"Abigail" <abigail@foad.org> wrote in message
news:slrn9ornu8.u7l.abigail@alexandra.xs4all.nl...
> Knob (andrew.savige@ir.com) wrote on MMCMXX September MCMXCIII in
> <URL:news:R%ej7.5$7W4.1083@news0.optus.net.au>:
> }} "Abigail" <abigail@foad.org> wrote in message
> }} news:slrn9oq4j6.t86.abigail@alexandra.xs4all.nl...
> }} >
> }} > Why don't you just say "Prerequisite: perl 5.X.Y". Just as you might
have
> }} > a requirement of a minimum amount of diskspace or physical memory.
You
> }} > don't ship disks or RAM with your product either, do you?
> }} >
> }} > Abigail
> }}
>
First, I appreciate hearing your point of view of this stuff, and I will
mull it over.
I have a related question and would appreciate advice/opinions etc.
The standard Perl library is inadequate for many serious applications.
It lacks, for example, basic things like Graham Barr's libnet modules.
Should you just say: prerequisite libnet-1.07 and above and expect the
customer to install it? Or should you bundle libnet with your application?
Andrew.
------------------------------
Date: 30 Aug 2001 15:08:52 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: PerlFS again?
Message-Id: <3b8eb974@news.victoria.tc.ca>
Brian Wallis (Brian.Wallis@ot.com.au) wrote:
: abigail@foad.org (Abigail) writes:
: > PerlFS was a nice idea, but it wasn't patented. Applesoft saw
: > the potential and quickly filed for a patent. After they got it,
: > they succesfully sued the original developers and closed down the
: > website. Which also explains the looping mail.
: How come I cannot find any other references to this travesty? Are you
: sure the patent didn't pre-date the perlfs implementation. I didn't
: thnik you could get a patent on something that is already in the
: public domain (such as an open source implementation)
: Seems very odd that you can get a patent on something someone else has
: already published.
You can get a patent on anything the patent office will give you a patent
on.
If the patent office is not aware of something that exists, or doesn't
appreciate how the existing thingy is similar, then they will give you a
patent.
At that point the true originator would need to spend money on lawyers to
have the patent invalidated - but of course since the true originator does
not not normally have any money to speak of they effectively loose their
invention.
I believe that publishing an idea prevents it being patented - but I'm not
sure what counts as "publishing" - if you print a few copies of a document
and give them to a few people then it's not clear if you have "published"
the idea - e.g. that level of distribution may not count as "publishing"
in a libel suit, so I don't think it's obvious just what counts as
publishing for patents.
There is also an issue of whether something is in common use or obvious to
someone involved in the trade. Even if you invent something, if it not in
common use or obvious then someone else can still patent it! That is why
companies patent things as soon as possible - if someone else invents it
later but patents it before you then you-lose/they-win and too bad.
(However I'm not a lawyer, this is just my understanding.)
------------------------------
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 1662
***************************************