[18564] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 732 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 20 21:05:30 2001

Date: Fri, 20 Apr 2001 18: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: <987815107-v10-i732@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 20 Apr 2001     Volume: 10 Number: 732

Today's topics:
        Command Piping in Perl (Tom Hoffmann)
    Re: Command Piping in Perl (Craig Berry)
    Re: Command Piping in Perl (Tom Hoffmann)
    Re: Command Piping in Perl (Damian James)
    Re: Command Piping in Perl (Gwyn Judd)
    Re: Command Piping in Perl <Jonathan.L.Ericson@jpl.nasa.gov>
    Re: cutting columns from a text file (Craig Berry)
    Re: cutting columns from a text file <taskiran@ecn.purdue.edu>
        Does Business::FedEx work? <bluearchtop@MailAndNews.com>
    Re: File path not getting resolved correctly. (Gwyn Judd)
        logic programming in perl <mmm_spam@excite.com>
    Re: logic programming in perl <tony_curtis32@yahoo.com>
    Re: LWP, getting the default index page name from a web (Tad McClellan)
    Re: m$ sql server access from perl <gellyfish@gellyfish.com>
    Re: Multi dimensional array dimensions (Tad McClellan)
    Re: Perl & PHP programmer available. (Gil G.)
    Re: Problem with associative array--what am I doing wro (Tad McClellan)
    Re: Problem with associative array--what am I doing wro (Jay Tilton)
    Re: So what do YOU use Perl for? <wayne.keenan@ntlworld.com>
    Re: two associative arrays printed at the same time <mischief@velma.motion.net>
    Re: two associative arrays printed at the same time <mischief@velma.motion.net>
    Re: What is wrong here? <ren@tivoli.com>
    Re: Why Perl? <gellyfish@gellyfish.com>
    Re: Win32::OLE problem -- command line vs. CGI <Jonathan.L.Ericson@jpl.nasa.gov>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 20 Apr 2001 22:38:18 GMT
From: tom.hoffmann@worldnet.att.net (Tom Hoffmann)
Subject: Command Piping in Perl
Message-Id: <slrn9e1ed2.lq.tom.hoffmann@localhost.localdomain>

I want to implement the following shell construct in Perl:

echo "some message" | write jdoe pts/10

so I code:

system ('echo "some message" | write jdoe pts/10');

Is there is another/better way to do this in Perl? Also, how can I
generalize this? If I try:

$message = 'some message';
$user = 'jdoe';
$pty = 'pts/10';
system ('echo $message | write $user $pty');

it returns a usage errro for 'write' since variable interpolation does
not take place in the single quotes. Is there a way to get
interpolation using the system function?


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

Date: Fri, 20 Apr 2001 23:24:48 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Command Piping in Perl
Message-Id: <te1ha02pm4fjb3@corp.supernews.com>

Tom Hoffmann (tom.hoffmann@worldnet.att.net) wrote:
: I want to implement the following shell construct in Perl:
: 
: echo "some message" | write jdoe pts/10
: 
: so I code:
: 
: system ('echo "some message" | write jdoe pts/10');
: 
: Is there is another/better way to do this in Perl?

If you're just sending that single line to that user/terminal, that form
is hard to beat.  If you'll be sending multiple lines, opening to a pipe
(see the doc on open) and sending lines to that filehandle would be a
better bet.

: Also, how can I generalize this? If I try:
: 
: $message = 'some message';
: $user = 'jdoe';
: $pty = 'pts/10';
: system ('echo $message | write $user $pty');
: 
: it returns a usage errro for 'write' since variable interpolation does
: not take place in the single quotes. Is there a way to get
: interpolation using the system function?

Your confused about what does (or doesn't do) the interpolation; it's not
the system()  function, but the quotes.  Write it as

  system("echo $message | write $user $pty");

(note double rather than single quotes) and you'll be in good shape.

One further note:  If any of those variables comes from outside your
program (e.g., from user input), be sure to use taint checking, and be
careful about how you do the checks.  A $message value of 'ouch; rm -rf /'
could ruin your whole day.

Now, for *real* fun, get yourself in the position of writing complex
system arguments with a mix of Perl- and shell-interpolated variables.
This is especially delightful at 2 am, and earns you bonus points if you
have had less than four hours of sleep during the previous two days.
Those who find this too easy may wish to write JSPs containing
a mix of static and dynamically-generated Javascript instead. :)

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "When the going gets weird, the weird turn pro."
   |               - Hunter S. Thompson


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

Date: Fri, 20 Apr 2001 23:29:18 GMT
From: tom.hoffmann@worldnet.att.net (Tom Hoffmann)
Subject: Re: Command Piping in Perl
Message-Id: <slrn9e1hcn.11j.tom.hoffmann@localhost.localdomain>

On Fri, 20 Apr 2001 23:24:48 -0000, Craig Berry <cberry@cinenet.net> wrote:

Thanks, Craig.


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

Date: 20 Apr 2001 23:31:24 GMT
From: damian@qimr.edu.au (Damian James)
Subject: Re: Command Piping in Perl
Message-Id: <slrn9e1hjf.636.damian@puma.qimr.edu.au>

Tom Hoffmann chose Fri, 20 Apr 2001 22:38:18 GMT to say this:
>...
>system ('echo "some message" | write jdoe pts/10');
>
>Is there is another/better way to do this in Perl?...

Well, you could avoid starting a shell process (and echo) by using the pipe
variant of open():

	open( WRITE, '|write jdoe pts/10' ) or die $!;
	print WRITE 'some message';

See

	perldoc -f open

for details

>... Also, how can I
>generalize this? If I try:
>
>$message = 'some message';
>$user = 'jdoe';
>$pty = 'pts/10';
>system ('echo $message | write $user $pty');
>
>it returns a usage errro for 'write' since variable interpolation does
>not take place in the single quotes. Is there a way to get
>interpolation using the system function?

To get interpolation, use double quotes. Ths applies to the piped open
above, as well :-).

HTH,

Cheers,
Damian
-- 
@:=grep!($;+=m!$/|#!),split//,<DATA>;@;=0..$#:;while(@;){for($;=@;;--$;;)
{@;[$;,$:]=@;[$:,$;]if($:=rand$;+$|)!=$;}push@|,shift@;if$;[0]==@|;select
$,,$,,$,,1/80;print qq x\bxx((@;+@|)*$|++),@:[@|,@;],!@;&&$/} __END__
Just another Perl Hacker # rev 3.1 -- a JAPH in progress, I guess...


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

Date: Fri, 20 Apr 2001 23:38:18 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Command Piping in Perl
Message-Id: <slrn9e1lvl.2it.tjla@thislove.dyndns.org>

In article <slrn9e1ed2.lq.tom.hoffmann@localhost.localdomain>,
Tom Hoffmann <tom.hoffmann@worldnet.att.net> wrote:
>I want to implement the following shell construct in Perl:
>
>echo "some message" | write jdoe pts/10
>
>so I code:
>
>system ('echo "some message" | write jdoe pts/10');
>
>Is there is another/better way to do this in Perl? Also, how can I
>generalize this? If I try:

<snip>

I recommend using Perl's "piped open" function:

open WRITE, '|write jdoe pts/10' or die "Cannot fork: $!";

print WRITE <<EOP;
some message
EOP

If you have them in variables, then you can do that too:

open WRITE, "|write $user $pty" or die "Cannot fork: $!";

print WRITE <<EOP;
$some_message
EOP

>it returns a usage errro for 'write' since variable interpolation does
>not take place in the single quotes. Is there a way to get
>interpolation using the system function?

Yes, simply place them in double qutes as I did. Interpolation has
nothing at all to do with the system function, it is merely a function
of the quotes itself.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
"Absolutely nothing should be concluded from these figures except that
no conclusion can be drawn from them."
(By Joseph L. Brothers, Linux/PowerPC Project)


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

Date: 20 Apr 2001 23:39:18 +0000
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: Command Piping in Perl
Message-Id: <86elunkuop.fsf@jon_ericson.jpl.nasa.gov>

tom.hoffmann@worldnet.att.net (Tom Hoffmann) writes:

> $message = 'some message';
> $user = 'jdoe';
> $pty = 'pts/10';
> system ('echo $message | write $user $pty');
> 
> it returns a usage errro for 'write' since variable interpolation does
> not take place in the single quotes. Is there a way to get
> interpolation using the system function?

Double quotes (".." or qq{..}) were designed for interpolation.  Take
a look at the the Regexp Quote-Like Operators entry in the perlop
manpage.

Jon



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

Date: Fri, 20 Apr 2001 23:05:00 -0000
From: cberry@cinenet.net (Craig Berry)
Subject: Re: cutting columns from a text file
Message-Id: <te1g4sulcj13b@corp.supernews.com>

Cuneyt M Taskiran (taskiran@ecn.purdue.edu) wrote:
: What I actually want is to have each row to be an element of @fileLines,
: i.e.,
: if the file contains
: a1 a2 a3
: b1 b2 b3
: and if we have @mask = (0, 1) then I want to have $fileLines[0]=(a1,a2) and
: $fileLines[1]=(b1,b2).

Well, then you can modify my

: >   push @fileLines, (split)[@mask]

to

  push @fileLines, [ (split)[@mask] ];

But be aware that you now have an array of references to arrays, and
you'll have to access it accordingly.  For example, the second saved
column of the third saved line would be

  $fileLines[2]->[1];

(Perl syntax allows you to omit the arrow operator, but I sometimes leave
it in to emphasize the ref-ness.)

-- 
   |   Craig Berry - http://www.cinenet.net/~cberry/
 --*--  "When the going gets weird, the weird turn pro."
   |               - Hunter S. Thompson


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

Date: Fri, 20 Apr 2001 18:23:33 -0500
From: Cuneyt M Taskiran <taskiran@ecn.purdue.edu>
Subject: Re: cutting columns from a text file
Message-Id: <3AE0C4F5.B9E4575C@ecn.purdue.edu>

Thanks a lot Craig, I finally solved it using

  while( <INPUTFILE> ) {
   chomp;
   push @featureLines, join " ", (split)[@mask];
  }

I really appreciate the help :-)

Cuneyt


Craig Berry wrote:

>
> Well, then you can modify my
>
> : >   push @fileLines, (split)[@mask]
>
> to
>
>   push @fileLines, [ (split)[@mask] ];
>
> But be aware that you now have an array of references to arrays, and
> you'll have to access it accordingly.  For example, the second saved
> column of the third saved line would be
>
>   $fileLines[2]->[1];
>
> (Perl syntax allows you to omit the arrow operator, but I sometimes leave
> it in to emphasize the ref-ness.)
>
> --
>    |   Craig Berry - http://www.cinenet.net/~cberry/
>  --*--  "When the going gets weird, the weird turn pro."
>    |               - Hunter S. Thompson



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

Date: Fri, 20 Apr 2001 19:04:51 -0400
From: asdf <bluearchtop@MailAndNews.com>
Subject: Does Business::FedEx work?
Message-Id: <3B029035@MailAndNews.com>

I can't seem to get this module to connect to the FedEx API. I'm wondering 
if 
anyone actually got this module to work? I can't seem to get a response from 
the authors. It dies whenever it tries the Win32::API calls to the FedEx 
DLLs.

DIED: The specified module could not be found at 
F:/Perl/lib/Business/FedEx/Ship
API.pm line 59.


Any insight is appreciated.

------------------------------------------------------------
 Get your FREE web-based e-mail and newsgroup access at:
                http://MailAndNews.com

 Create a new mailbox, or access your existing IMAP4 or
 POP3 mailbox from anywhere with just a web browser.
------------------------------------------------------------



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

Date: Fri, 20 Apr 2001 23:48:33 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: File path not getting resolved correctly.
Message-Id: <slrn9e1mit.2it.tjla@thislove.dyndns.org>

In article <9bpmcs$3r5$1@news.netmar.com>,
tmerenes.dontspam@sybase.com <tmerenes.dontspam@sybase.com> wrote:
>I'm running MKS perl in a WinNT 4.0 SP 6a DOS session.
>
>The file path in the following statement does not get resolved correctly:
>
>system ("isql -SDB2SOL -Utmerenes -PCOGRULES
>-iD:\DC\12.00.03\236669\repro.sql");

Perl interprets a backslash '\' as being a single character escape.  It
affects the next character along. For example, "\r" is a carriage
return. Windows in braindead in that it uses backslashes rather than
forward slashes as path element separators since this means you have to
write your paths like this:

system ("isql -SDB2SOL -Utmerenes -PCOGRULES
-iD:\\DC\\12.00.03\\236669\\repro.sql");

By escaping the backslashes, they come through as single backslashes.
Alternatively, Perl supports unix style forward slashes as path
separators, so you can do this:

system ("isql -SDB2SOL -Utmerenes -PCOGRULES
-iD:/DC/12.00.03/236669/repro.sql");

Alternativley, you can just use single quotes as another poster appeared
to be suggesting. Down that path lies madness, however.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Don't go around saying the world owes you a living.  The world owes you
nothing.  It was here first.
		-- Mark Twain


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

Date: Fri, 20 Apr 2001 19:10:53 -0400
From: "Mark" <mmm_spam@excite.com>
Subject: logic programming in perl
Message-Id: <9bqfj202oeg@enews2.newsguy.com>

I have heard that Perl can be written in different programming styles..
from the standard syntax to something that has the look and feel of a
functional language... but what I want to know is can it be used in a
logic programming style?  I've searched the web and can't find anything
on it, but that doesn't mean it can't be done!

-Mark


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

Date: 20 Apr 2001 19:05:04 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: logic programming in perl
Message-Id: <877l0frubz.fsf@limey.hpcc.uh.edu>

>> On Fri, 20 Apr 2001 19:10:53 -0400,
>> "Mark" <mmm_spam@excite.com> said:

> I have heard that Perl can be written in different
> programming styles..  from the standard syntax to
> something that has the look and feel of a functional
> language... but what I want to know is can it be used in
> a logic programming style?  I've searched the web and
> can't find anything on it, but that doesn't mean it
> can't be done!

There's a prolog module of sorts,

    http://search.cpan.org/

and search for "prolog".  I don't know how good it is or
if it meets your needs.

You could use XS to gain access to an external Prolog
interpreter I suppose.

hth
t
-- 
Just reach into these holes.  I use a carrot.


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

Date: Fri, 20 Apr 2001 17:52:41 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: LWP, getting the default index page name from a web directry.
Message-Id: <slrn9e1bt9.7uo.tadmc@tadmc26.august.net>

Steve <steve@zeropps.uklinux.net> wrote:
>On 20 Apr 2001 18:05:35 +0100, nobull@mail.com wrote:

>>This has nothing to do with Perl.
>
>If you're trying to get the results with perl it has everything to
>do with perl! 


So long then!

*plonk*


>-- 

[snip 10-line signature]


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


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

Date: 20 Apr 2001 23:45:12 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: m$ sql server access from perl
Message-Id: <9bqhm8$5a7$1@plutonium.btinternet.com>

Timour Ezeev <timour@pivotaldynamics.com> wrote:
> Hello all,
> Need to query M$ SQL Server from perl script running on Solaris box...
> Please hlp to find correct module. Tnx.
> 

You might want to look at FreeTDS and DBD::FreeTDS - or alternatively
pay for some expensve ODBC on unix thing ...

/J\
-- 
Jonathan Stowe                      |
<http://www.gellyfish.com>          |      This space for rent
                                    |


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

Date: Fri, 20 Apr 2001 17:26:20 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Multi dimensional array dimensions
Message-Id: <slrn9e1abs.7pr.tadmc@tadmc26.august.net>

Bart Lateur <bart.lateur@skynet.be> wrote:
>Randal L. Schwartz wrote:
>
>>It's VERY RARE to ever need an array slice (@...[]) with a single element
>>in the slice.  It's so rare that it's a warnable (-w) offense.
>
>It also triggers this very annoying warning for
>
>	@them = @foo{qw'ONE TWO THREE'};
>
>(still in 5.6.0), i.e. thinking that qw'A B C' is just one item.


Surely that is a bug, right?  Has it been reported yet?

I see that

   @them = @foo{qw#ONE TWO THREE#};

also makes the warning. I could not find any other alternate delimiters
that trigger the warning (so the work-around seems straightforward :-)


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


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

Date: Fri, 20 Apr 2001 22:30:29 GMT
From: gil@nospam-keskydee.com (Gil G.)
Subject: Re: Perl & PHP programmer available.
Message-Id: <3ae0b816.261725@news-server>

On 20 Apr 2001 19:11:50 GMT, dha@panix2.panix.com (David H. Adler)
wrote:

>In article <3adf7e98.3166055@news-server>, Gil G. wrote:
>> 
>> I can help you with your scripts.
>
>You have posted a job posting or a resume in a technical group.
>
>Longstanding Usenet tradition dictates that such postings go into
>groups with names that contain "jobs", like "misc.jobs.offered", not
>technical discussion groups like the ones to which you posted.
>
>Had you read and understood the Usenet user manual posted frequently to
>"news.announce.newusers", you might have already known this. :)  (If
>n.a.n is quieter than it should be, the relevent FAQs are available at
>http://www.faqs.org/faqs/by-newsgroup/news/news.announce.newusers.html)
>Another good source of information on how Usenet functions is
>news.newusers.questions (information from which is also available at
>http://www.geocities.com/nnqweb/).
>
>Please do not explain your posting by saying "but I saw other job
>postings here".  Just because one person jumps off a bridge, doesn't
>mean everyone does.  Those postings are also in error, and I've
>probably already notified them as well.
>
>If you have questions about this policy, take it up with the news
>administrators in the newsgroup news.admin.misc.
>
>http://jobs.perl.org may be of more use to you
>
>Yours for a better usenet,
>
>dha

Hello,

Well, usually I post this once in a while on
alt.comp.perlcgi.freelance. My present ISP doesn't have this group
though, I guess I'll have to ask them to add it to their list!

Sincerely,

Gil.


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

Date: Fri, 20 Apr 2001 17:17:25 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Problem with associative array--what am I doing wrong here?
Message-Id: <slrn9e19r5.7pr.tadmc@tadmc26.august.net>

Bill Weissborn <bweissbo@lucent.com> wrote:
>
>For the life of me, I can't figure out why this code is not working.  


This is some pretty bad code. Did you grab this from the 'net somewhere?


>I have
>an associative array 


Nobody has called them that for over 5 years now.

Where did you learn that term? If from a Perl book, then you very
likely have one of the many rip-off Perl books.

Nowadays it is called just a "hash".


>and I want to see if a value, passed on the command
>line, is in the array.  


Most folks can filter "associative array" into "hash", but an
unqualified "array" means a completely different data structure.


>If found, then I want to do more processing based on
>that fact.  However, it doesn't work UNLESS, I enter the value, via the
>debugger, manually into the variable $pooltouse.  


Have you tried debugging it with simple print statements yet?

   print "\$pooltouse is '$pooltouse'\n";

   print "$_ => $foundit{$_}\n" for keys %foundit;


>What am I doing wrong?  Any thoughts, better-ways of doing this, etc would
>be greatly appreciated.


>#!/usr/local/bin/perl


Ask for all of the help that you can get:

   #!/usr/local/bin/perl -w
   use strict;



>%tpool = (); #...declare an associative array
>open(POOL, "<$masdir/tape-pool");


You should always, yes *always*, check the return value from open():

   open(POOL, "<$masdir/tape-pool") or 
      die "could not open '$masdir/tape-pool' $!";


>while (<POOL>)
>{
>   chop;


Another piece of 5-year old Perl code, suspicions mount...

   chomp;   


>   ($poolname, $restofline) = split /,/,$_,2;
>   $tpool{$poolname} = "$restofline";


Useless use of quotes, worser and worser...

   $tpool{$poolname} = $restofline;


>}
>close (POOL);
>#..Get the contents of the jukebox
>$i=0;
>open(JBOX, "<$masdir/jukebox");


You should always, yes *always*, check the return value from open().


>while (<JBOX>)
>{
>   chop;
>   $jukebox[$i] = $_;
>   $i++;
>}


That is C code written in Perl. You should write Perl when writing
in Perl:

   while ( <JBOX> ) {     # Look Ma!  No explicit indexing needed!
      chomp;
      push @jukebox, $_;
   }



>#..This came from www.perldoc I think.


I think probably not, it is some strange code too...


>for $item (%tpool)


Sometimes $item will be a key.

Sometimes $item will be a value.

Is that what you want?

Did you instead want to walk over only the keys?

   foreach my $item ( keys %tpool ) {



>{
>#..Strip off trailing spaces
>   StripTSpace($item);
>   print "item = $item..\n";
>   print "pool = $pooltouse..\n";
>   $foundit{StripTSpace($item)}++;
             ^^^^^^^^^^^^^^^^^^

Didn't you just call that 3 lines earlier?

What is the point of calling it a second time?

What does StripTSpace($item) return?

Whatever it is, that is what you are using as the hash key,
I think you want to be using $item as the hash key instead
of StripTSpace()'s return value.


>}
>
>#..Now check to see if it is in the "authorized" pool
>#..BUT it never works!!!!
>if ( $foundit{$pooltouse} )


That does NOT check if it is "in" the authorized pool.

It checks that it has a true value in the authorized pool.

That is, if

   $foundit{$pooltouse} == 0

then the above will not "find" it either.

   if ( exists $foundit{$pooltouse} )

Now _that_ tests if the key exists in the hash.


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


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

Date: Fri, 20 Apr 2001 23:07:42 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: Problem with associative array--what am I doing wrong here?
Message-Id: <3ae0be6b.166789298@news.erols.com>

On Fri, 20 Apr 2001 11:00:45 -0500, "Bill Weissborn"
<bweissbo@lucent.com> wrote:

>What am I doing wrong?  Any thoughts, better-ways of doing this, etc would
>be greatly appreciated.

Actually, from a few brief tests here, it does work, but there are
still things that aren't kosher.  The biggest problem is that it
blindly assumes that files are being opened correctly.  That oversight
will bite you in the ass every time.

[snip]
>getopt('s:d:t:ho:c:L:p:');

It looks like you would want 'getopts' instead of 'getopt'.
The two behave differently.

[...]
>open(POOL, "<$masdir/tape-pool");

Always check the return on an attempt to open a file.
  open(POOL, "<$masdir/tape-pool") or die "Cannot open: $!";

>while (<POOL>)
>{
>   chop;

'chomp' is the appropriate tool for removing the record separator when
reading from a file.

>   ($poolname, $restofline) = split /,/,$_,2;

You go through extra work later to compensate for trailing spaces in
the hash keys when you could instead remove them during the split.
  ($poolname, $restofline) = split /\s*,/, $_, 2;

>   $tpool{$poolname} = "$restofline";

The quotes are not needed.

>}
>close (POOL);

>#..Get the contents of the jukebox
>$i=0;
>open(JBOX, "<$masdir/jukebox");
>while (<JBOX>)
>{
>   chop;
>   $jukebox[$i] = $_;
>   $i++;
>}
>close (JBOX);

Blecch.
Since you're basically slurping the file, go ahead and do just that.
  open(JBOX, "<$masdir/jukebox") or die "Cannot open: $!";
  chomp (@jukebox = <JBOX>);
  close JBOX;

>for $item (%tpool)

That will iterate over all hash keys *and* values in %tpool.
You would most likely want...
  for $item (keys %tpool)

>{
>#..Strip off trailing spaces
>   StripTSpace($item);
>   print "item = $item..\n";
>   print "pool = $pooltouse..\n";
>   $foundit{StripTSpace($item)}++;
>}
>#..Now check to see if it is in the "authorized" pool
>#..BUT it never works!!!!
>if ( $foundit{$pooltouse} )
>{
>#...Then the value exists
>   print "Continueing...\n";
>   print "pooltouse = $foundit{$pooltouse}\n";
>}

You're doing a big song and dance to check whether the value of
$pooltouse is a valid key in %tpool.  It would be easier to do that
directly, assuming trailing spaces were removed from the keys while
creating the hash.

  if ( exists $tpool{$pooltouse} ) {
     print "Continuing...\n";
  }



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

Date: Fri, 20 Apr 2001 22:58:30 +0100
From: "wayne.keenan" <wayne.keenan@ntlworld.com>
Subject: Re: So what do YOU use Perl for?
Message-Id: <3AE0B106.5D0EBC77@ntlworld.com>



Abigail wrote:

> Chris Stith (mischief@velma.motion.net) wrote on MMDCCLXXXVII September
> MCMXCIII in <URL:news:tds7ccn0vdtoa6@corp.supernews.com>:
> ''
> '' I haven't reinvented the newsreader yet, but i have a Perl script
> '' that configures and launches my newsreader for me.
>
> My newsreader calls a Perl program when I want to post something.
>

I might spend some time getting my preferred new reader to do the opposite,
execute some posters (JAPE) .sigs.
But then that would be a case of M$ dumb foundry, and I might
not have any files left,  well, maybe just a  4 byte kernel image. :)


>
> Abigail
> --
> sub _'_{$_'_=~s/$a/$_/}map{$$_=$Z++}Y,a..z,A..X;*{($_::_=sprintf+q=%X==>"$A$Y".
> "$b$r$T$u")=~s~0~O~g;map+_::_,U=>T=>L=>$Z;$_::_}=*_;sub _{print+/.*::(.*)/s};;;
> *_'_=*{chr($b*$e)};*__=*{chr(1<<$e)};                # Perl 5.6.0 broke this...
> _::_(r(e(k(c(a(H(__(l(r(e(P(__(r(e(h(t(o(n(a(__(t(us(J())))))))))))))))))))))))



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

Date: Fri, 20 Apr 2001 22:15:44 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: two associative arrays printed at the same time
Message-Id: <te1d8gr5vg8fd9@corp.supernews.com>

Please don't post your response above the text you quote. It's annoying
and wastes time and bandwidth. Jeopardectomy performed.

> "brian d foy" <comdog@panix.com> wrote in message
> news:comdog-645808.20370319042001@news.panix.com...
>> In article <9bnv06$kh7@news.or.intel.com>, "Just in"
>> <justin.devanandan.allegakoen@intel.com> wrote:
>>
>> > Say if I had two associative arrays with the same keys (but different
>> > values).
>> > How could I print them at the same time?

>> of course.  if they have the same keys just pull out the
>> keys from one then print the value from each.
>>
>>     foreach my $key ( keys %castaway )
>>         {
>>         print "$castaway{$key} $coconet{$key}\n";
>>         }
>>

This is a good way to do it. :-)

Just in <justin.devanandan.allegakoen@intel.com> wrote:
> Err . . . yeah, thats the solution.

> I really do have a bad understanding of associative arrays - i previously
> thought that would print the keys - silly me

This _would_ print the keys:

    foreach my $key ( keys %castaway )
    {
        print "$key $key\n";
    }

However, what brian did is different. By comparing the two, you
might gain some understanding.

The whole idea behind an associative array is that you give it the
name of the associative array (hash in perlspeak, since that's how
they are implemented) then the subscript, just like a regular array.
Just note that a regular array uses square brackets where an associative
array (hash) uses curly ones.

Chris

-- 
Christopher E. Stith
Where there's a will, there's a lawyer.



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

Date: Fri, 20 Apr 2001 22:43:09 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: two associative arrays printed at the same time
Message-Id: <te1ert8f8j31b5@corp.supernews.com>

Just in <justin.devanandan.allegakoen@intel.com> wrote:
>> Why have the identical value in 2 places? (you said the hashes
>> have the same keys)

> Err, no the values are distinct, but the keys match. Whats the point of
> doing that?
> Well I'm incrementing the value with the += operator if the key matches, and
> I'm not
> sure how to assign/push two values on to a key while incrementing it.

You can't give a key two values, but you can give a key a value which
is a reference to an array or a hash.

    foreach my $key ( keys %hash ) {
        %foo = ( key1 => value1, key2 => value2 );
        $hash{$key} = \%foo;
    }

Then you access those like this:

    $value = ${$hash{$key}}{'key1'};

Actually, TMTOWTDI, but that's OWTDI. 

> Actually what I'm getting at is the fact that PERL is an acronym for
> Pratical Extraction Report Language, or
> Pathologically Eclectic Rubbish Lister (both of which are endorsed by the
> venerable master himself [LW]).

> Not one to argue, I'll go along with Perl.

> Thanks again for your solution, and highlighting my case insensitivity.

Actually, I don't think Larry himself likes that 'PERL' spelling.
Lots of acronyms fall by the wayside as the word they form becomes
easily identifiable (like laser, maser, radar, NT -- which MS even
claims doesn't stand for anything and never did,  BP, BT --
which are probably just so Americans won't realize they're British
companies, and AOL -- which is so that Europeans won't realize it's
an American company). Other acronyms are simply backwards formations
(backronyms) because people are so accustomed to acronyms that they
make ones for names that aren't originally from acronyms.[1] I don't
recall exactly which applies to Perl. 

Chris

-- 
Christopher E. Stith
You must not lose faith in humanity. Humanity is an ocean;
if a few drops of the ocean are dirty, the ocean does not
become dirty.  -- Mohandas K. Gandhi

[1] In my etymological studies, it seems the word 'imp' to mean
    a small, cunning creature is probably a backwards formation.
    An 'imp' was originally connoted to be a devious, immoral, or
    evil bugbear or hobgoblin of sorts. This would mean that someone
    acting like an 'imp' would be acting in an 'impish', 'impy', or
    'impious' way. This last form, however, is the same word as would
    be used to mean opposite of 'pious'. Since '-ish' is of Germanic
    origins and '-y' traditionally is indicative of an adjective and
    not an adverb, 'impious' would probably be the form used in the
    distant past for actions fitting an 'imp'. Therefore, it might
    be that when the word 'impious' was described to certain groups
    as meaning 'said of someone acting in a devious or mischievous
    way', they thought that an  'imp' was something which acted this
    way of its own nature.


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

Date: 20 Apr 2001 17:11:33 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: What is wrong here?
Message-Id: <m34rvj1asq.fsf@dhcp9-172.support.tivoli.com>

On 19 Apr 2001, joe+usenet@sunstarsys.com wrote:

> If you are arguing that he could/should have solved the problem by 
> writing
> 
>   use global;
>   our $test;
> 
>   print $test;
> 
> in his main script, then I'll concede the point (but not without
> first complaining about global.pm's lack of both packaging and the
> use of Exporter :-)

Actually, all I was trying to say was that people often mistake "our"
for a global declaration, which it certainly isn't.  In the absence of
strict "vars", the only reason for the OP to have included "our"
within global.pm in the first place was in the mistaken belief that it
declared the variable as a global.

Your solution, which was fine, did not address this point of
confusion.  In fact, removing "our" from your solution is still just
as effective a solution, as I'm sure you know.

This question has come up a lot lately, and frankly, I've yet to see a
solution that I found to be correct, concise and elegant.

Invoking the programmer-overhead of using a package and Exporter seems
like overkill when all you really want to do is initialize some common
values across multiple files.  It isn't concise.

Using "do" or "require" breaks down under strict "vars", so I don't
consider it correct.

Using package notation ($::test) works, but certainly isn't elegant.

There is the solution of using a single hash with all of the
configuration data stored as keys.  And perhaps that is the right
solution.  It is correct, reasonably elegant, and even borders on being
concise.  The minor burden of reference the hash elements is probably
even compensated by the increased maintainability of having all of the
configuration data clearly marked.

  % cat global.pl
  our %global;
  $global{test} = "http://1.2.3.4";
  % perl -wl <<'__END__'
  use strict;
  our %global;
  require "global.pl";
  print $global{test};
  __END__
  http://1.2.3.4
  %

-- 
Ren Maddox
ren@tivoli.com


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

Date: 20 Apr 2001 23:22:47 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: Why Perl?
Message-Id: <9bqgc7$7t6$1@neptunium.btinternet.com>

Paul the Nomad <taka@yarn.demon.co.uk> wrote:
> Jeff Thies <cyberjeff@sprintmail.com> writes:
> 
>> > >How do you add (missing) quotes to html values?
>> > 
>> > I run 'htmltidy' on it.
>> > 
>> >    http://www.w3.org/People/Raggett/tidy/
>> 
>> That's what I was thinking (until I read that post!), I'll have to
>> install it.
>> > 
>> <snip>
>> > 
>> > That wheel has already been invented, spend your grey-matter cycles
>> > on something else  :-)
>> 
>> Sounds like good advice.
> 
> Yeah, but it would be useful to have a script which goes through to
> make your HTML XML compliant, e.g. quotes, closing </p>, etc...
> 

HTML tidy can in fact do this.

/J\
-- 
Jonathan Stowe                      |
<http://www.gellyfish.com>          |      This space for rent
                                    |


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

Date: 20 Apr 2001 23:32:35 +0000
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: Win32::OLE problem -- command line vs. CGI
Message-Id: <86itjzkuzw.fsf@jon_ericson.jpl.nasa.gov>

"Uday Murthy" <murthy@cox-internet.com> writes:

> I have a Perl script using Win32::OLE that interacts with an Excel
> spreadsheet.  The script works perfectly from the command line on the
> server, but fails when run as a CGI program.  Any ideas?

Have you tried http://www.perl.com/pub/doc/FAQs/cgi/perl-cgi-faq.html?
If it works from the command line but not through CGI, it is almost
certainly a CGI issue -- not a perl problem.

Jon


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

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


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