[7301] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 926 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 26 16:08:15 1997

Date: Tue, 26 Aug 97 13:01:33 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 26 Aug 1997     Volume: 8 Number: 926

Today's topics:
     Re: Perl FAQ site has changed! <rootbeer@teleport.com>
     Perl for Win32 - Capturing output from backticks <cdumas@ibm.net>
     Re: perl modules and OOP (dmouse)
     Re: perl modules and OOP (dmouse)
     Re: Problem with sub and my <rootbeer@teleport.com>
     Re: Returning a hash list (associative array) (Mike Stok)
     Re: Returning a hash list (associative array) <bsugars@sunpub.com>
     Re: Returning a hash list (associative array) (Jot Powers)
     Re: sort - help needed <rootbeer@teleport.com>
     Re: spell checking <rootbeer@teleport.com>
     What is ~// ? was(Re: Perl Regular Expression has a bug (Colin Kuskie)
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Tue, 26 Aug 1997 12:30:57 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Cameron Dorey <camerond@mail.uca.edu>
Subject: Re: Perl FAQ site has changed!
Message-Id: <Pine.GSO.3.96.970826122316.13463X-100000@julie.teleport.com>

On Mon, 25 Aug 1997, Cameron Dorey wrote:

> Several people have referred newbies (like myself) to
> http://www.perl.com/faq or /idiots-guide to answer their questions.
> Unfortunately, this URL no longer exists (at least according to my
> machine), and there is no redirection from the page. 

Thanks for pointing that out. You _can_ still get the FAQ via perl.com:

    http://www.perl.com/CPAN/doc/FAQs/FAQ/html/

 ...and that page comes with a link to the "Idiot's" guide and other useful
stuff. (The FAQ also comes with 5.004.) But you're right; many old links
to www.perl.com are broken. :-(

> Now, having actually given information in my first post here, some of
> you old-timers please give me some slack when I ask my first really dumb
> question. 

As the Camel says, no question is too silly to ask - but some are too
silly to answer (especially if they're already answered in the docs and
FAQs).  :-)

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Tue, 26 Aug 1997 18:47:49 GMT
From: Chris Dumas <cdumas@ibm.net>
Subject: Perl for Win32 - Capturing output from backticks
Message-Id: <340324D5.BF84FF00@ibm.net>

Dear All:
 I am trying to calculate the freespace on a directory. The only way I
can think of doing it is to capture the output from the DIR command and
process the output.

$dir_out = 'dir';

This however fails.  Does anyone know why?????

Thanks,
Chris
cdumas @ ibm.net



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

Date: 26 Aug 1997 18:04:37 GMT
From: gt1535b@acmex.gatech.edu (dmouse)
Subject: Re: perl modules and OOP
Message-Id: <5tv5rl$on9@catapult.gatech.edu>

M.J.T. Guy (mjtg@cus.cam.ac.uk) wrote:
: dmouse <gt1535b@acmex.gatech.edu> wrote:
: >I just want to import the subroutines.  This is the line I used to
: >import them:
: >
: >  use Scti (scti ls cat rm md);

:    use Scti qw(scti ls cat rm md);
: or
:    use Scti ('scti', 'ls', 'cat', 'rm', 'md');

thanks, that helped, but I'm still getting some other errors.  When you call
the subroutines to you have to qualify them with 'Scti::' every time or can
you just say '&ls' or such.  I was under the impression that the latter was
the case because I imported the symbols into the main package with Exporter.
Yet I still get errors like "Undefined subroutine &main::scti called at
showp.bat line 32."

Any ideas?

: Mike Guy

--
<>< Daryl Bowen	<><
Georgia Institute of Technology
E-mail: gt1535b@prism.gatech.edu
Siemens Stromberg-Carlson Co-op


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

Date: 26 Aug 1997 18:21:49 GMT
From: gt1535b@acmez.gatech.edu (dmouse)
Subject: Re: perl modules and OOP
Message-Id: <5tv6rt$p1d@catapult.gatech.edu>

M.J.T. Guy (mjtg@cus.cam.ac.uk) wrote:
: dmouse <gt1535b@acmex.gatech.edu> wrote:
: >I just want to import the subroutines.  This is the line I used to
: >import them:
: >
: >  use Scti (scti ls cat rm md);

:    use Scti qw(scti ls cat rm md);
: or
:    use Scti ('scti', 'ls', 'cat', 'rm', 'md');

thanks, that helped, but I'm still getting some other errors.  When you call
the subroutines do you have to qualify them with 'Scti::' every time or can
you just say '&ls' or such.  I was under the impression that the latter was
the case because I imported the symbols into the main package with Exporter.
Yet I still get errors like "Undefined subroutine &main::scti called at
showp.bat line 32."

Any ideas?

: Mike Guy

--
<>< Daryl Bowen	<><
Georgia Institute of Technology
E-mail: gt1535b@prism.gatech.edu
Siemens Stromberg-Carlson Co-op


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

Date: Tue, 26 Aug 1997 11:23:28 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: "Jeffrey A. F. Hittinger" <jhitt@engin.umich.edu>
Subject: Re: Problem with sub and my
Message-Id: <Pine.GSO.3.96.970826111811.13463O-100000@julie.teleport.com>

On Mon, 25 Aug 1997, Jeffrey A. F. Hittinger wrote:

> #!/usr/um/bin/perl -w
> use_diagnostics;
> use_strict;

Those underscores shouldn't be in there. (But I bet you put them in when
omitting them gave you an error message, right?)

> I get the following compilation errors:
> 
> syntax error in file hello at line 6, next 2 tokens "say_hello("
> "my" may clash with future reserved word at hello line 9.

Those look like Perl 4 error messages. (And the same goes for an error
message for saying 'use strict'.)

> I am rusing Perl 5.004 on an HP-UX 10.20 machine. 

Hmmm.... Just to be absolutely sure, could you try this command? 

    /usr/um/bin/perl -v

It might be that that's a different version than the one you get from
'perl' on the command line. Similarly, if you use a command like 'perl -w
myscript', does that do something different? Hope this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: 26 Aug 1997 18:34:58 GMT
From: mike@stok.co.uk (Mike Stok)
Subject: Re: Returning a hash list (associative array)
Message-Id: <5tv7ki$ifk@news-central.tiac.net>

In article <wjkoh6knabb.fsf@bitsrfr.cnd.hp.com>,
Jacob Miner <jacob@bitsrfr.cnd.hp.com> wrote:
>Hi All,
>
>    How can I return a hash list, the following won't work
>and I have tried many different permutations...
>
>sub Families {
>   local(%Name);
>
>
>   $Name["Fred"]="Flinstone";
>   $Name["Barney]="Rubble";
>
>   return %Name;
>}
>
>%Test = GetMachines();
>print %Test["Fred"];

You want to use {} around the key into a hash e.g.

  sub Families {
    local (%Name);

    $Name{'Fred'} = 'Flintstone';
    $Name{'Barney'} = 'Rubble';

    return %Name;
  }

  %Test = &Families;
  print "$Test{'Fred'}\n";

prints the expected result for me.

Hope this helps,

Mike

-- 
mike@stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       |   PGP fingerprint FE 56 4D 7D 42 1A 4A 9C
http://www.tiac.net/users/stok/    |                   65 F3 3F 1D 27 22 B7 41
stok@psa.pencom.com                |      Pencom Systems Administration (work)


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

Date: Tue, 26 Aug 1997 14:54:44 -0400
From: Benjamin Sugars <bsugars@sunpub.com>
Subject: Re: Returning a hash list (associative array)
Message-Id: <34032674.7FFC@sunpub.com>

Jacob Miner wrote:
> 
> Hi All,
> 
>     How can I return a hash list, the following won't work
> and I have tried many different permutations...
> 
> sub Families {
>    local(%Name);
> 
>    $Name["Fred"]="Flinstone";
>    $Name["Barney]="Rubble";
> 
>    return %Name;
> }
> 
> %Test = GetMachines();
> print %Test["Fred"];
> 
> This prints nothing.  I have tried using references as well, but
> to no avail...

It prints nothing because the code is replete with syntax errors.  I
can't even get it to compile.  Here is a corrected version; use it and
the documentation to find your mistakes.

sub Families {
    my %name;
    $name{'Fred'} = 'Flintstone';
    $name{'Barney'} = 'Rubble';
    return %name;
}

%test = Families();
print "$test{'Fred'}\n";

Don't be offended if I sound terse.  I think many people around here
will less charitable than me.

-Ben

--
Ben Sugars <bsugars@canoe.ca>
Senior Webmaster,
CANOE Canadian Online Explorer,
http://www.canoe.ca/


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

Date: 26 Aug 1997 19:33:59 GMT
From: news@bofh.com (Jot Powers)
Subject: Re: Returning a hash list (associative array)
Message-Id: <5tvb37$ruf$1@gazette.corp.medtronic.com>

In article <wjkoh6knabb.fsf@bitsrfr.cnd.hp.com>, Jacob Miner wrote:
>Hi All,
>
>    How can I return a hash list, the following won't work
>and I have tried many different permutations...
>
>sub Families {
>   local(%Name);
>
>
>   $Name["Fred"]="Flinstone";
>   $Name["Barney]="Rubble";
>
>   return %Name;
>}
>
>%Test = GetMachines();
>print %Test["Fred"];
>
>
>This prints nothing.  I have tried using references as well, but
>to no avail...

For me, this code won't even compile.

node127% perl -c /tmp/test.pl
Bareword found where operator expected at /tmp/test.pl line 7, 
near ""Barney]="Rubble"
        (Missing operator before Rubble?)
syntax error at /tmp/test.pl line 7, near ""Barney]="Rubble"
String found where operator expected at /tmp/test.pl line 13, 
near "print %Test[""
  (Might be a runaway multi-line "" string starting on line 7)
        (Missing semicolon on previous line?)
Bareword found where operator expected at /tmp/test.pl line 13, 
near "print %Test["Fred"
        (Do you need to predeclare print?)
String found where operator expected at /tmp/test.pl line 13, at end of line
        (Missing semicolon on previous line?)
Can't find string terminator '"' anywhere before EOF at /tmp/test.pl line 13.

There are a couple of problems:

>   $Name["Fred"]="Flinstone";

This is not a hash array.  You want:

$Name{"Fred"}="Flinstone";
     ^      ^

>   $Name["Barney]="Rubble";
         ^       ^^

You're missing a closing quote here, and it's still not an associate array.  :)

>%Test = GetMachines();

I assume you meant Families, not GetMachines.

>print %Test["Fred"];

To (loosely) quote Princess Bride:  "I do not think that word means what
you think it means."

First, fix the []'s and then, if you want to address an element of
an array, use $, and for the whole array, use %.

So, it should be

print $test{"Fred"};

Here is my version of your program, where I have cleaned up the
stuff I mentioned above, changed the variables and quotes to
my preference, and added two all important lines to the top.

#!/usr/local/bin/perl -w
use strict;
 
my (%test);
 
sub families {
   my(%name);
 
 
   $name{'Fred'}="Flinstone";
   $name{'Barney'}="Rubble";
    
   return %name;
}
 
%test = &families();
print "Output was:" . $test{"Fred"} . "\n";

And, running it gets:

Output was:Flinstone

Now, that appears to solve your problem, but I don't believe it 
does:

To quote perlsub:
     The Perl model for function call and return values is
     simple: all functions are passed as parameters one single
     flat list of scalars, and all functions likewise return to
     their caller one single flat list of scalars.  Any arrays or
     hashes in these call and return lists will collapse, losing
     their identities--but you may always use pass-by-reference
     instead to avoid this.  Both call and return lists may


So, I think you need to do the following, to work in the general case:

#!/usr/local/bin/perl -w
use strict;
 
my ($temp);
 
sub families {
   my(%name);
 
   $name{'Fred'}="Flinstone";
   $name{'Barney'}="Rubble";
    
   return \%name;
}
 
$temp = &families();
print "Output was:" . $temp->{'Fred'} . "\n";

Which, again returns:

Output was:Flinstone

HTH, and if it doesn't, try posting again.

-Jot "Wonder what I said wrong in this one" Powers
-- 
Jot Powers  news@bofh.com
Unix System Administrator
"Sometimes you just have to grab the bull by the tail and face the situation."


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

Date: Tue, 26 Aug 1997 11:57:27 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: denis@mathi.uni-heidelberg.de
Subject: Re: sort - help needed
Message-Id: <Pine.GSO.3.96.970826115158.13463U-100000@julie.teleport.com>

On Mon, 25 Aug 1997 denis@mathi.uni-heidelberg.de wrote:

> i have an array (@xx) with fields such as these:
> 
> $xx[]="text1 text2 number text3";

You seem to have left out the subscript, but I think we can overlook that
for an example. :-)  (I'm assuming that you're meaning that each element
looks something like that line, although I have trouble generalizing
from one data point. :-)

> and i want so sort it by the numbers.  so i tries something like this:
> 
> sub numb
> {
> 	@tmp=split(/\s+/);

So @tmp (which should really be a my() variable) gets a series of words
formed by splitting $_. (Is that what you wanted? A sort sub doesn't have
a documented value for $_.)

> 	$tmp[2]{$a} <=> $tmp[2]{$b};

But now you're acting as if @tmp has a series of hashrefs. That can't be
right.

> }
> 
> @xx2=sort numb @xx

You may want the Schwartzian transform, but since I can't see what you're
trying to do, I can't help you any more than this. Good luck!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: Tue, 26 Aug 1997 11:40:11 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Danny LaPrade <dannyl@computize.com>
Subject: Re: spell checking
Message-Id: <Pine.GSO.3.96.970826113912.13463R-100000@julie.teleport.com>

On Mon, 25 Aug 1997, Danny LaPrade wrote:

> Is there a way to somehow use perl to do spell checking?

Sure! Perl can do anything! :-)

> or link or use an existing spell checker?

Well, that's certainly easier than writing your own. Yes, you can do that
as well.

For more information, check out system in the perlfunc(1) manpage. Hope
this helps!

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/



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

Date: 26 Aug 1997 10:33:07 -0700
From: colink@latticesemi.com (Colin Kuskie)
Subject: What is ~// ? was(Re: Perl Regular Expression has a bug?)
Message-Id: <5tv40j$5ss@sarek.latticesemi.com>

In article <5tup1n$cnd$1@news.ncu.edu.tw>,  <dennis@csie.nctu.edu.tw> wrote:
>See my program:
>#!/usr/bin/perl
>$date = localtime();
>print "$date\n";
>if($date = ~/(..):(..):(..)/)
          ^^^
Here's your problem.
What you want is:
if ($date =~ /(..):(..):(..)/)

Note the difference in spacing around the =~.  Your code assigns
the return value of whatever ~/(..):(..):(..)/ to $date, overwriting
what it used to have.  Now the interesting question that remains is:

What in the world is ~// ?

Colin Kuskie

p.s. Running your program with the -w switch told me that
an uninitialized variable was used in line 5, which should
have told you that something was screwy in your code ;)


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 926
*************************************

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