[22008] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 4230 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Dec 7 14:05:55 2002

Date: Sat, 7 Dec 2002 11:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 7 Dec 2002     Volume: 10 Number: 4230

Today's topics:
    Re: A formating problem (Tad McClellan)
    Re: A formating problem (Jan Fure)
        Bizarre SvTYPE when using HTML::LinkExtor with threads <rune.froysa@usit.uio.no>
    Re: Creating TCP Sockets -- Client Can't Find Server <garry@ifr.zvolve.net>
    Re: Future of Perl as an application server language? (Simon)
    Re: Future of Perl as an application server language? (Simon)
    Re: Future of Perl as an application server language? (Simon)
    Re: Future of Perl as an application server language? <flavell@mail.cern.ch>
    Re: Help Im losing faith! AoH key as a HoH key! (LazyPerfectionist)
    Re: Help Im losing faith! VERY JUICY PROBLEM! (LazyPerfectionist)
    Re: Help Im losing faith! VERY JUICY PROBLEM! (Ben Morrow)
    Re: io::socket::inet / tcp question <spam@thecouch.homeip.net>
    Re: Multi-dimensional hash question <spam@thecouch.homeip.net>
    Re: Multi-dimensional hash question (Ben Morrow)
        Need help with file output/editing - newbie (unixfox)
    Re: Need help with file output/editing - newbie <tassilo.parseval@post.rwth-aachen.de>
    Re: Need help with file output/editing - newbie <dont@want.spam>
        ssh using net::telnet problem <crb@wedesigns.com>
    Re: ssh using net::telnet problem (Ben Morrow)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Sat, 7 Dec 2002 08:43:29 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: A formating problem
Message-Id: <slrnav428h.29c.tadmc@magna.augustmail.com>

Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote:
> On 6 Dec 2002, Jan Fure wrote:
> 
>>A1  0.1233
>>A1  1.234
>>A1  0.34
>>C3  1.4321
>>A5  1.24555
>>A5  23
>>A5  2
>>
>>I am looking for a way to change the data above into the format:
>>@data = (
>>        ["A1", "A5", "C3"],
>>        [ [0.1233, 0.34, 1.234], [1.24555, 2, 23], [1.4321]
>>        );
> 
> Looking at the code you provided, I don't think you have a working
> solution.  Here is the simplest way I see of solving the problem:
> 
>   # step 1 -- read the file into a hash of array-references:
>   my (%data, @points);
> 
>   while (<INFO>) {
>     my ($field, $val) = split;
>     push @{ $data{$field} }, $val;
>   }
> 
>   # step 2 -- convert hash of array-references
>   # into array of array-references


> That's all he wrote!  


Except for the sorting:

  foreach ( sort keys %data ) {
      @{$data{$_}} = sort { $a <=> $b } @{$data{$_}};
      push @{$points[0]}, $_;
      push @{$points[1]}, $data{$_};
  }


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: 7 Dec 2002 09:36:40 -0800
From: jan_may2002_fure@attbi.com (Jan Fure)
Subject: Re: A formating problem
Message-Id: <e47a84bf.0212070936.51135648@posting.google.com>

Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote in message news:
< ------------------------- Snip ----------------------------->
> Looking at the code you provided, I don't think you have a working
> solution.  Here is the simplest way I see of solving the problem:
> 

< ------------------------- Snip ---------------------------- >

> 
> That's all he wrote!

Thanks!

Your code is definetly more Perl'ish than my brute force attempt!

I shall look forwards to test it. Seems like I will benefit if I get
my hash'es straight.

Jan Fure


------------------------------

Date: 07 Dec 2002 13:48:57 +0100
From: Rune Froysa <rune.froysa@usit.uio.no>
Subject: Bizarre SvTYPE when using HTML::LinkExtor with threads
Message-Id: <svlr8cuouyu.fsf@dresden.uio.no>

I have a script that uses LWP to fetch web pages in multiple threads.
When spawning the first worker thread, it dies with a "Bizarre SvTYPE
[24]" (the number varies).

I've tried to isolate the problem, and while the below sample produces
a different error, I guess it is related.  Running the sample below on
perl 5.8.0, I get a number of:

  Attempt to free non-existent shared string 'tr' during global destruction.
  Scalars leaked: -31
  Bad signature in parser state object at 8127e90 during global destruction.


use threads;
use threads::shared;

require HTML::LinkExtor;
my $parser = HTML::LinkExtor->new(sub {});
my %work_threads : shared;

sub testth {
    sleep(rand(5)+1);
    lock %work_threads;
    $work_threads{threads->tid} = 0;
    cond_signal %work_threads;
}

for(0..5) {
    my $thread = new threads (\&testth);
    $work_threads{$thread->tid} = 1;
}
while(&scan != 0) {
    lock %work_threads;
    cond_wait %work_threads;
}

sub scan {
    my $n = 0;
    for(threads->list) {
        if(exists($work_threads{$_->tid})) {
            if($work_threads{$_->tid} == 1) {
                $n++;
            } else {
                $_->join();
            }
        }
    }
    return $n;
}

-- 
Rune Frøysa


------------------------------

Date: Sat, 07 Dec 2002 13:25:32 -0000
From: Garry Williams <garry@ifr.zvolve.net>
Subject: Re: Creating TCP Sockets -- Client Can't Find Server
Message-Id: <slrnav3tmb.ifc.garry@zfw.zvolve.net>

On Thu, 05 Dec 2002 01:12:19 GMT, Hal Vaughan <hal@thresholddigital.com> wrote:

[snip]

> I've copied examples out of the Blue Camel, 

But not flawlessly, it appears.  :-)  

[snip]

>                         Localport => $serverport,

	LocalPort => $serverport,

-- 
Garry Williams


------------------------------

Date: 7 Dec 2002 06:52:31 -0800
From: simonf@simonf.com (Simon)
Subject: Re: Future of Perl as an application server language?
Message-Id: <3226c4d3.0212070652.3001dcd6@posting.google.com>

Hi Todd,

toddrw69@excite.com (trwww) wrote in message news:<d81ecffa.0212051203.1073c54e@posting.google.com>...

> For large inter/intranet apps, IMO CGI is not an option. You are
> looking for object persistence. Its not built in to the CGI framework,
> so you have to find sometimes different ways of emulating it. My
> solution was to find a framework that has persistence built in.
> 
> http://groups.google.com/groups?selm=d81ecffa.0210081039.610de474%40posting.google.com
> 
> has a discussion of how I use apache with mod_perl enabled to
> _get_the_job_done_(tm). The context of the discussion was a question
> about how to develop web apps faster.

Thank you. I definitely think that XForms is the way to go once both
Mozilla and IE implement them. I have not decided to go XML all the
way yet, though. I will look at AxKit.

> mod_perl, Template::Toolkit, Mason, Embperl, ASP, and this is only a
> fraction of the list even if you exclude the newer services that have
> been made possible by XML (like AxKit).
> 
> OTOH, I havent see you mention any of these tools, so perhaps you may
> not be aware of them, in which case I suggest exploring perl culture
> and convention a bit more.

Give me some credit. :) Of course I use mod_perl. Of course I use
Mason - web programming without templates is nuts. But they are only
parts of a web application framework.

> My biggest ( and probably only ) complaint about perl is that there
> are too many ways to _get_the_job_done_(tm). But thats a pretty nice
> complaint to be able to have about a programming language. Its alot
> faster to browse CPAN for all applicable solutions, try them all, glue
> them together and/or modify one or more than it is to develop an
> untested solution from scratch.

Would not it be nicer to have a recommended solution that works in
most of the cases? See my next posting for a rant about commercial vs
technical world.

> > I am not even going to mention thread safety issues, transactions,
> > handling JARs and their dependencies, where Java is way ahead.
> 
> Im no expert in this area, but I would think that the web and database
> servers are mostly responsible for at least the first two, in which
> case I can happily continue extending my applications with the Apache
> API.

I mean thread safety as in calling the same *object* (servlet)
simultaneously from different threads to cut down on the number of
created objects. I don't think Apache does that, and even if it did, I
don't think Perl can handle that (I may be lacking some new info about
thread support). As for transactions, think about multi-database
transactions, as in bank transfers (the money has to be safely taken
from one account and put into another in a different bank). The app
server must support this, as the two databases are independent.

> This is jargon. If you look through other posts on c.l.p.m. or even
> perl.beginners and perl.beginners.cgi on nntp.perl.org you wont find
> much jargon.

What's wrong with jargon? If it's an appropriate term for a
non-obvious concept, it adds to the discussion. You have to know it,
but it may be worth it.
 
> Theres only one way to get persistence over http. Somehow tie an id to
> a client, and be sure they return the id with each request. Then tie
> that id with either a record in a database or a persistent data
> structure in memory on the server.

Of course. :) My complaint was that before XForms, no satisfactory
solution to package CGI parameters existed (other than a hash).

> To get this back on topic, perl has an excellent past, present AND
> future as an application server language. The proof?
> 
> http://perl.oreilly.com/news/success_stories.html

How come there is no "Java success stories" page? Maybe they don't
need one? Again, see posting about commercialization below.

Simon


------------------------------

Date: 7 Dec 2002 06:55:24 -0800
From: simonf@simonf.com (Simon)
Subject: Re: Future of Perl as an application server language?
Message-Id: <3226c4d3.0212070655.5dd3bf39@posting.google.com>

toddrw69@excite.com (trwww) wrote in message news:<d81ecffa.0212051316.59406e54@posting.google.com>...

> Take a look at http://search.cpan.org/modlist/Database_Interfaces/DBIx
> 
> The one that cought my eye immdiately was DBIx::Lookup::Field which
> will "Create a lookup hash from a database table". Ive also used
> Tie::DBI and DBIX::RecordSet which both work fine.

I already wrote something similar that can join more than one table.
But I need still more powerful tools than that. I will probably
migrate to one of SPOPS, Alzabo or Tangram, as they provide more
flexibility.

> Perl and shrink wrap dont mix ;0)

But they should, at least to a reasonable degree, if Perl is to ever
make the next step into the mainstream!

Simon


------------------------------

Date: 7 Dec 2002 07:17:09 -0800
From: simonf@simonf.com (Simon)
Subject: Re: Future of Perl as an application server language?
Message-Id: <3226c4d3.0212070717.2d11c71d@posting.google.com>

merlyn@stonehenge.com (Randal L. Schwartz) wrote in message news:<86lm345glx.fsf@red.stonehenge.com>...
> >>>>> "Simon" == Simon  <simonf@simonf.com> writes:
> 
> Simon> I have recently went to the Software Development Conference/Expo in
> Simon> Boston and was faced with the fact that Java seems to be the language
> Simon> of choice for serious web applications.
> 
> Java is the language of choice of people who put on conferences and
> pay for advertising.  The marketplace is a strange beast.  Nearly
> everyone I know who has had a serious evaluation of Perl vs Java and
> has been free to choose, has gotten the real work done in Perl.  But
> in those shops where the management "manages by magazine", Java has
> been forced down the throats of those poor souls.  Just like M$
> products. :)
> 
> print "Just another Perl hacker,"

Randalph,

I have enormous respect for you. I am proud to be a part of the Perl
culture. My most dog-eared book is "Programming Perl". You are a much
better Perl hacker than I can ever be.

However, there is the technical side of the discussion, and there is
the commercial side. Your MS Windows example is the perfect one to
show that an inferior product can dominate the marketplace. Much more
technically superior Linux has a tremendous uphill struggle, and it
probably would not even get as far without the commercial backing by
Redhat, IBM and others. And Java (with frameworks) does not look as
bad compared to Perl as Windows doss compared to Linux.

It's not the question of which technology is the best. It's the
question of which technology is *perceived* to be the best, and here
the managers' opinion counts. And the bookstore shelves provide a
rough approximation of the crowd's perception. Perl does not look good
there. (And the whole thing about Perl 6 breaking the old syntax and
Perl 5 internals being messy does not help, even though the transition
a good technical decision. Believe me - I heard people say that,
comparing Perl to Python which "was not broken to begin with".)

To other readers - please do not flame me on the above paragraph. I am
simply stating the perception of Perl that a lot of people have.

I dearly hope that Perl will not lose because of the stupid perception
issues. However, I believe that the danger is sufficiently real and
great to merit some action. Without either a strong open-source
standard-based app server or a viable commercial product Perl will
always be on the fringe in the managers' minds. IMHO.

Simon


------------------------------

Date: Sat, 7 Dec 2002 16:33:47 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: Future of Perl as an application server language?
Message-Id: <Pine.LNX.4.40.0212071630560.16301-100000@lxplus071.cern.ch>

On Dec 7, Simon inscribed on the eternal scroll:

> merlyn@stonehenge.com (Randal L. Schwartz) wrote

[...]

> Randalph,

ITYM "Gandalf".  SCNR.

-- 

(or some other wizard...)




------------------------------

Date: 7 Dec 2002 03:57:43 -0800
From: mod3@hotmail.com (LazyPerfectionist)
Subject: Re: Help Im losing faith! AoH key as a HoH key!
Message-Id: <4379a3c8.0212070357.2aa49983@posting.google.com>

Bob Walton <bwalton@rochester.rr.com> wrote in message news:<3DF16D75.8010209@rochester.rr.com>...
> LazyPerfectionist wrote:
> 
> > Im sure Im bieng stupid!
> > Ive read perldoc perltot perllol..etc but no luck..
> > I know Im trying to put a ref of one arrayhash key as a key to another
> > hash and I know I should deref but is there a another solution...
> > 
> > my(@a_header) = (
> > 		 {'a' => '\b[A-Z]+\b'},
> > 		 {'b' => '\b\d{1,2}\b|\b100\b'}
> > 		 );
> > 
> > this works but thats not what I want. I want to get rid of the
> > my(@test)..!
> > for (my($i)=0;$i<@a_header;$i++){
> >    my(@test)= keys %{$a_header[$i]};#####
> >    $h_data{$lineNo}->{$test[0]} =  
> >   defined $values[$i]?$values[$i]:'';
> > }#for
> 
> 
> try:
> 
>     $h_data{$lineNo}->{(keys %{$a_header[$i]})[0]} =
>        defined $values[$i]?$values[$i]:'';


Ooohhh YES! Bob ur a star...
p.s Im using the Array of Hashes as a lookup table so same thing would work with HoH
thanks for the reply on the looping cp...


------------------------------

Date: 7 Dec 2002 06:12:41 -0800
From: mod3@hotmail.com (LazyPerfectionist)
Subject: Re: Help Im losing faith! VERY JUICY PROBLEM!
Message-Id: <4379a3c8.0212070612.402b709a@posting.google.com>

Bob Walton <bwalton@rochester.rr.com> wrote in message news:<3DF16D75.8010209@rochester.rr.com>...
> LazyPerfectionist wrote:
> 
> > Im sure Im bieng stupid!
> > Ive read perldoc perltot perllol..etc but no luck..
> > I know Im trying to put a ref of one arrayhash key as a key to another
> > hash and I know I should deref but is there a another solution...
> > 
> > my(@a_header) = (
> > 		 {'a' => '\b[A-Z]+\b'},
> > 		 {'b' => '\b\d{1,2}\b|\b100\b'}
> > 		 );
> > 
> > this works but thats not what I want. I want to get rid of the
> > my(@test)..!
> > for (my($i)=0;$i<@a_header;$i++){
> >    my(@test)= keys %{$a_header[$i]};#####
> >    $h_data{$lineNo}->{$test[0]} =  
> >   defined $values[$i]?$values[$i]:'';
> > }#for
> 
> 
> try:
> 
>     $h_data{$lineNo}->{(keys %{$a_header[$i]})[0]} =
>        defined $values[$i]?$values[$i]:'';


Here is another one for u...
What if I do this 

$h_data{$lineNo}->{\%{$a_header[$i]}} =
        defined $values[$i]?$values[$i]:'';

The second $h_data key is now a reference to the hashes in the
$a_header!
the problem now is:-

foreach $ky (keys %HoH_data){
    foreach $vl (keys %{$HoH_data{$ky}}){
	print(keys $vl,"--\n");
}};
I cant get access to the hashref contained in the $vl

this works! but again thats not the point..

foreach $ky (keys %HoH_data){
    for (0..$#AoH_header){
	$HoH_data{$ky}{$_};
}};

I know I could make my life very easy using the Tie:: ...
What I eventualy want to do is have the second key evaluate the
data...but lets take it one step at a time...


------------------------------

Date: Sat, 7 Dec 2002 18:28:06 +0000 (UTC)
From: mauzo@mimosa.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: Help Im losing faith! VERY JUICY PROBLEM!
Message-Id: <astejm$1oj$1@wisteria.csv.warwick.ac.uk>

mod3@hotmail.com (LazyPerfectionist) wrote:
>Here is another one for u...
>What if I do this 
>
>$h_data{$lineNo}->{\%{$a_header[$i]}} =

You don't need this ->: it is implied between {} and [] sets.
\%{...} does precisely nothing: it derefs the reference in ... and then
immediately takes it's reference. [1]

>        defined $values[$i]?$values[$i]:'';
>
>The second $h_data key is now a reference to the hashes in the
>$a_header!

No it isn't. A hash key is just a string, not an SV, so it can't be a 
reference. What it will be instead is something like 'HASH(0x9122b38)', from 
which you _cannot_ retreive the original reference.

>the problem now is:-
>
>foreach $ky (keys %HoH_data){
>    foreach $vl (keys %{$HoH_data{$ky}}){
>	print(keys $vl,"--\n");
>}};
>I cant get access to the hashref contained in the $vl

No. It isn't a hashref: it's just a string. (I presume HoH_data is defined 
like h_data above?)

>this works! but again thats not the point..
>
>foreach $ky (keys %HoH_data){
>    for (0..$#AoH_header){
>	$HoH_data{$ky}{$_};
>}};

Er, what exactly does this do? Other than evaluate $HOH_data{$ky}{$_} in a
void context, that is...

>I know I could make my life very easy using the Tie:: ...

No, I don't think you could.

>What I eventualy want to do is have the second key evaluate the
>data...but lets take it one step at a time...

I think perhaps if you explained carefully what you are trying to acheive 
we may be able to see some way of doing it, as the solution you are trying
(storing a ref in a hash key) is impossible :)

Ben

[1] Yes, OK, it checks that $a_header[$i] is indeed either an array or a hash 
ref. Not, I think, the intention here.


------------------------------

Date: Sat, 07 Dec 2002 10:16:12 -0500
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: io::socket::inet / tcp question
Message-Id: <3DF210BC.8070201@thecouch.homeip.net>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1



smackdab wrote:
| I have a non-blocking client/server program.  Since I do "stuff" while
| waiting for
| commands, I use $select->can_read(0) to see if I need to process network
| commands.
|
| So, will I always know if the remote connection died by using this
| technique?
| (I can only test on my local machine right now...which seems to work as
| expected)
|
| I have been reading Effective TCPIP Programming and it says that TCP
is not
| polled, but the author doesn't really address the can_read function.
If the
| client
| exits cleanly or the OS cleans up after a program crash, I should
always be
| able to tell, right?
| Same thing if the client machine loses power? Or does the server not get
| notified and
| have to timeout? (the book talkes about LONG timeouts of 9 minutes,
etc...)
|
| I am looking for a general technique to restart a client if it "crashes"
| And am wondering
| if I would have to use a different technique if the client and server
are on
| different machines...

The book is correct.  TCP/IP does not have any provisions for polling
both sides of the connection, which is why many programs incorporate,
within their internal protocol, a ping-pong command or so.

If that is not feasible in your situation, then another alternative is
to assume (or make) the client always send you something within X amount
of time.  The server then keeps track of when was the last time they've
heard from a client, and drop the inactive ones.


-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE98hC7eS99pGMif6wRAq19AKCcv0eLKV3kS4eLRoJywwwesVkuPQCggyBR
ceoWHxUbOI99jNncAqBVLew=
=8NiM
-----END PGP SIGNATURE-----



------------------------------

Date: Sat, 07 Dec 2002 10:35:45 -0500
From: Mina Naguib <spam@thecouch.homeip.net>
Subject: Re: Multi-dimensional hash question
Message-Id: <3DF21551.7030509@thecouch.homeip.net>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1



Alexander Stremitzer wrote:
| I am trying to build a multi-diemnsional hash for an application. To
| figure out how it works I wrote a small program to test it.However, I
| can't get it to do what I want.
| The hash should have a level1 key which each can have several level2
| keys which holds data in form of a list.
| My first print loop delivers the expected result when assigning the list
| value directly. When going through the hash it does not work. What am I
| doing wrong ?

Hello Alexander

Please see my in-line comments below.  However to fully understand it,
you must read the perl references tutorial, available at "perldoc
perlref" or http://www.perldoc.com/perl5.8.0/pod/perlref.html

| #!/usr/local/bin/perl -w
|
| use strict;
|
| my %myhash = ();
|
| my @array1 = ('mod1','organ1');

It's usually clearer to say:

my @array1 = qw(mod1 organ1);


| my @array2 = ('mod2','organ2');
| my @array3 = ('mod3','organ3');
|
| $myhash{'patid1'}{'acc1'} = @array1;

The value of a hash key can only hold a scalar content, nothing fancier
than that (other hashes or arrays for example).

The way to get around that if you have a fancy data collection, is to
store a reference to it.  Since references are smple scalar strings, you
can store them as hash keys (or values) without a problem.

In the above case, @array1 is treated in scalar content, which is not
what you want.

The correct way to do this is:

$myhash{'patid1'}{'acc1'} = \@array1;

This will store the reference to @array1.


| $myhash{'patid2'}{'acc2'} = @array2;
| $myhash{'patid2'}{'acc3'} = @array3;

Same applies to these also.

|
| my @list = @array3;
|
| for my $i ( 0 .. $#list ) {
|        print "without hash: $list[$i]\n";
| }

*Usually* in perl to iterate over an array, you don't use an index
holder like you do for other languages:

foreach (@list) {
	print "Without hash: $_\n";
}

|
| my @list = $myhash{'patid2'}{'acc3'};

Remember that we stored a reference there ? At this point, you need to
de-reference it to obtain the actual array:

my @list = @{ $myhash{'patid2'}{'acc3'} };

|
| for my $i ( 0 .. $#list ) {
|        print "with hash: $list[$i]\n";
| }

See above for short form of iterating over an array.

Also, here is an easier way to create that complex hash/arrays in the
beginning with just 1 statement:

%myhash = (
	patid1	=>	{
		acc1	=>	[
			'mod1', 'organ1',
		],
	},
	patid2	=>	{
		acc2	=>	[
			'mod2', 'organ2',
		],
	},
	patid3	=>	{
		acc3	=>	[
			'mod3', 'organ3',
		],
	},
);

And finally, here's an easy way to inspect any simple/complex
scalar/array/hash.. The Data::Dumper module:

use Data::Dumper;

print Dumper(\%myhash);
print Dumper(\@list);

etc..

See "perldoc Data::Dumper" or
http://www.perldoc.com/perl5.6/lib/Data/Dumper.html for more information.

Best of luck.

-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQE98hVReS99pGMif6wRAss3AKDCSMMrWuImyNTksXtwoP68bWcyowCgqlvm
2DYnlvXJCZdXjkl/JhdfYrM=
=0fZI
-----END PGP SIGNATURE-----



------------------------------

Date: Sat, 7 Dec 2002 18:36:35 +0000 (UTC)
From: mauzo@mimosa.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: Multi-dimensional hash question
Message-Id: <astf3j$1tg$1@wisteria.csv.warwick.ac.uk>

Mina Naguib <spam@thecouch.homeip.net> wrote:
>The value of a hash key can only hold a scalar content, nothing fancier
>than that (other hashes or arrays for example).
>
>The way to get around that if you have a fancy data collection, is to
>store a reference to it.  Since references are smple scalar strings, you
>can store them as hash keys (or values) without a problem.

Sorry for being pedantic, but having just corrected someone else with this
problem, references are not 'simple scalar strings'. They _are_ SVs, ie.
Scalar Values, but they are not strings. Hash values hold an SV, so you
can store a ref in a hash; hash keys _are_ simple scalar _strings_, so you
can't key a hash on a reference and expect to be able to deref the key.

Ben


------------------------------

Date: 7 Dec 2002 09:08:44 -0800
From: unixfox@planetlink.net (unixfox)
Subject: Need help with file output/editing - newbie
Message-Id: <f914825a.0212070908.65f0517e@posting.google.com>

Hello perl gurus...

I have a data file that I would like the output to be displayed
in a nice neat format. I can make the fields of the file display 
on one line at a time but how do I make those fields display the
way I really want them? In other words, the following code displays
like this:

First Name:  --------------
Middle Name: -------------
Last Name:   ----------------

I would like it to display it like this:

First Name: ------------ Middle Name: ------------- Last Name: ----------



print "<tr valign=top><td>First Name:</td><td><input type=text name=\"fname\"  v
alue=\"$fname\" size=35></td></tr>\n";

print "<tr valign=top><td>Middle Name:</td><td><input type=text name=\"mname\"
value=\"$mname\" size=35></td></tr>\n";

print "<tr valign=top><td>Last Name:</td><td><input type=text name=\"lname\"  va
lue=\"$lname\" size=35></td></tr>\n";


Thanks all for the help in advance.


------------------------------

Date: 7 Dec 2002 17:56:11 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@post.rwth-aachen.de>
Subject: Re: Need help with file output/editing - newbie
Message-Id: <astcnr$h75$1@nets3.rz.RWTH-Aachen.DE>

Also sprach unixfox:

> Hello perl gurus...

Perl indeed, not necessarily HTML.

> I have a data file that I would like the output to be displayed
> in a nice neat format. I can make the fields of the file display 
> on one line at a time but how do I make those fields display the
> way I really want them? In other words, the following code displays
> like this:
> 
> First Name:  --------------
> Middle Name: -------------
> Last Name:   ----------------
> 
> I would like it to display it like this:
> 
> First Name: ------------ Middle Name: ------------- Last Name: ----------
> 
> 
> 
> print "<tr valign=top><td>First Name:</td><td><input type=text name=\"fname\"  v
> alue=\"$fname\" size=35></td></tr>\n";
> 
> print "<tr valign=top><td>Middle Name:</td><td><input type=text name=\"mname\"
> value=\"$mname\" size=35></td></tr>\n";
> 
> print "<tr valign=top><td>Last Name:</td><td><input type=text name=\"lname\"  va
> lue=\"$lname\" size=35></td></tr>\n";

You don't have a Perl question but rather one about how to create tables
in the format you prefer [1]. This is beyond the scope of this newsgroup.

However, some Perl notes. Use here-docs for this kind of thing:

    print <<EOHTML;

        <tr ....>
        ...
        ...
    EOHTML

Thus you can also use quotes within the string without the need for
escaping them.

But perhaps you want to use the HTML::Table module. Like so:

    my $table = HTML::Table->new( [1, 1], [1, 3] );
    $table->setCell(1, 1, "First Name:");
    $table->setCell(1, 2, "Middle Name:");
    $table->setCell(1, 3, "Last Name:");
    $table->print;

Get it from CPAN and read the supplied documentation to learn how to
customize your table further. Fir the input field, put the HTML source
of these input fields into seperate cells, wherever you want them.

Tassilo
-- 
$_=q!",}])(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus;})(rekcah{lrePbus;})(lreP{rehtonabus;})(rehtona{tsuJbus!;
$_=reverse;s/sub/(reverse"bus").chr(32)/xge;tr~\n~~d;eval;


------------------------------

Date: Sat, 07 Dec 2002 18:51:08 +0000
From: Chris Lowth <dont@want.spam>
Subject: Re: Need help with file output/editing - newbie
Message-Id: <9xrI9.1054$iz3.126273@newsfep2-win.server.ntli.net>

unixfox wrote:

> Hello perl gurus...
> 
> I have a data file that I would like the output to be displayed
> in a nice neat format. I can make the fields of the file display
> on one line at a time but how do I make those fields display the
> way I really want them? In other words, the following code displays
> like this:
> 
> First Name:  --------------
> Middle Name: -------------
> Last Name:   ----------------
> 
> I would like it to display it like this:
> 
> First Name: ------------ Middle Name: ------------- Last Name: ----------
> 
> 
> 
> print "<tr valign=top><td>First Name:</td><td><input type=text
> name=\"fname\"  v alue=\"$fname\" size=35></td></tr>\n";
> 
> print "<tr valign=top><td>Middle Name:</td><td><input type=text
> name=\"mname\" value=\"$mname\" size=35></td></tr>\n";
> 
> print "<tr valign=top><td>Last Name:</td><td><input type=text
> name=\"lname\"  va lue=\"$lname\" size=35></td></tr>\n";
> 

You have here a table of three rows and two columns. Each row starts with 
"<tr>" and ends with "</tr>", each cell in the row (hence: column) starts 
"<td>" and ends "</td>". 

What you appear to want is a single row of six columns - so take out all 
"<tr>" except the first one, and all "</tr>" except the last.

Voila!

-- 
My real e-mail address is
chris <at> lowth <dot> com


------------------------------

Date: Sat, 7 Dec 2002 11:59:23 -0500
From: "a2liter" <crb@wedesigns.com>
Subject: ssh using net::telnet problem
Message-Id: <_ypI9.444$X%3.24@news.bellsouth.net>

I am trying to get SSH to work by utilizing Net::Telnet module. Below is the
code that I am using but I keep getting the following error: I think that
the problem is withthe $prompt defination but not sure. Can any one help?

problem connecting to host: Disconnected; authentication cancelled by user
(Authentication cancelled by user.).

Here is the log from the server I am trying to connect to.

Dec  7 11:56:43 FS1 sshd2[661]: connection from "192.168.1.1"
Dec  7 11:56:45 FS1 sshd2[14129]: Remote host disconnected: Authentication
cancelled by user.
Dec  7 11:56:45 FS1 sshd2[14129]: authentication cancelled by user:
'Authentication cancelled by user.'

#!/usr/bin/perl

## Main program.
    {
        my ($pty, $ssh, @lines);
        my $host = "192.168.1.2";
        my $user = "username";
        my $password = "password";
        my $prompt = '/[username@FS1 cboston]$/';

        ## Start ssh program.
        $pty = &spawn("ssh", "-l", $user, $host);  # spawn() defined below

        ## Create a Net::Telnet object to perform I/O on ssh's tty.
        use Net::Telnet;
        $ssh = new Net::Telnet (-fhopen => $pty,
                                -prompt => $prompt,
                                -telnetmode => 0,
                                -cmd_remove_mode => 1,
                                -output_record_separator => "\r");

        ## Login to remote host.
        $ssh->waitfor(-match => '/cboston\'s password: ?$/i',
                      -errmode => "return")
            or die "problem connecting to host: ", $ssh->lastline;
        $ssh->print($password);
        $ssh->waitfor(-match => $ssh->prompt,
                      -errmode => "return")
            or die "login failed: ", $ssh->lastline;

        # Send command, get and print its output.
        @lines = $ssh->cmd("who");
        print @lines;

        exit;
    } # end main program

    sub spawn {
        my(@cmd) = @_;
        my($pid, $pty, $tty, $tty_fd);

        ## Create a new pseudo terminal.
        use IO::Pty ();
        $pty = new IO::Pty
            or die $!;

        ## Execute the program in another process.
        unless ($pid = fork) {  # child process
            die "problem spawning program: $!\n" unless defined $pid;

            ## Disassociate process from existing controlling terminal.
            use POSIX ();
            POSIX::setsid
                or die "setsid failed: $!";

            ## Associate process with a new controlling terminal.
            $tty = $pty->slave;
            $tty_fd = $tty->fileno;
            close $pty;

            ## Make stdio use the new controlling terminal.
            open STDIN, "<&$tty_fd" or die $!;
            open STDOUT, ">&$tty_fd" or die $!;
            open STDERR, ">&STDOUT" or die $!;
            close $tty;

            ## Execute requested program.
            exec @cmd
                or die "problem executing $cmd[0]\n";
        } # end child process

        $pty;
    } # end sub spawn







------------------------------

Date: Sat, 7 Dec 2002 18:43:24 +0000 (UTC)
From: mauzo@mimosa.csv.warwick.ac.uk (Ben Morrow)
Subject: Re: ssh using net::telnet problem
Message-Id: <astfgc$20o$1@wisteria.csv.warwick.ac.uk>

"a2liter" <crb@wedesigns.com> wrote:
>I am trying to get SSH to work by utilizing Net::Telnet module. Below is the
>code that I am using but I keep getting the following error: I think that
>the problem is withthe $prompt defination but not sure. Can any one help?
>
>problem connecting to host: Disconnected; authentication cancelled by user
>(Authentication cancelled by user.).
>
>Here is the log from the server I am trying to connect to.
>
>Dec  7 11:56:43 FS1 sshd2[661]: connection from "192.168.1.1"
>Dec  7 11:56:45 FS1 sshd2[14129]: Remote host disconnected: Authentication
>cancelled by user.
>Dec  7 11:56:45 FS1 sshd2[14129]: authentication cancelled by user:
>'Authentication cancelled by user.'
>
>#!/usr/bin/perl

-T, please.

>
>## Main program.
>    {
>        my ($pty, $ssh, @lines);
>        my $host = "192.168.1.2";
>        my $user = "username";
>        my $password = "password";

This is a _very_ bad idea. You have to be _extremely_ careful about who can
read this script if it's got passwords in it.

I would advise setting up public-key authentication for ssh, if you can, so
you don't need to send the password at all. This will, I guess, solve the 
problem.

Ben


------------------------------

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 4230
***************************************


home help back first fref pref prev next nref lref last post