[12830] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 240 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Jul 23 22:07:31 1999

Date: Fri, 23 Jul 1999 19: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)

Perl-Users Digest           Fri, 23 Jul 1999     Volume: 9 Number: 240

Today's topics:
    Re: a bit of a bind.. (Sitaram Chamarty)
    Re: a bit of a bind.. <keithmur@mindspring.com>
    Re: a bit of a bind.. <tchrist@mox.perl.com>
        ARGV validation of command line options (Steve .)
        bite-me <keithmur@mindspring.com>
        Can anyone explain concepts of Perl Objects? <ramanika@flashmail.com>
    Re: Can anyone explain concepts of Perl Objects? <tchrist@mox.perl.com>
    Re: CGI:New window opens w/ NN, not w/ IE (Anno Siegel)
        DBD::Filemaker? <tortuga@leland.stanford.edu>
        frames (JJcoParks4)
    Re: glob spawning problem <northsky@ix.netcom.com>
    Re: look for: a script that dectects when a new file ar (Anno Siegel)
    Re: My newbie solution - is this the best? <cassell@mail.cor.epa.gov>
    Re: My newbie solution - is this the best? (Anno Siegel)
    Re: Perl 4 Source Code or Binaries (Anno Siegel)
        Positioning in file? <bogus@razorback.uark.edu>
        Possible to pass Hash's? Please Help. <ramanika@flashmail.com>
    Re: Possible to pass Hash's? Please Help. <jeffp@crusoe.net>
    Re: Problem dereferencing hash (Larry Rosler)
    Re: Problem dereferencing hash <lfriedl@genome.wi.mit.edu>
    Re: Problem dereferencing hash (Larry Rosler)
    Re: sort routines <cassell@mail.cor.epa.gov>
    Re: sort routines (Anno Siegel)
    Re: strict vars and local (Anno Siegel)
    Re: Telnet via CGI? <cs2400@hotmail.com>
        Digest Administrivia (Last modified: 1 Jul 99) (Perl-Users-Digest Admin)

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

Date: 23 Jul 1999 10:58:47 -0700
From: sitaram@diac.com (Sitaram Chamarty)
Subject: Re: a bit of a bind..
Message-Id: <slrn7ph6kq.2t0.sitaram@diac.com>

On Fri, 23 Jul 1999 04:54:47 GMT, Dave Meyer
<dmeyer@news.bellatlantic.net> wrote:

Partly as a self-test, let me try.  Beginners: please note well -
what follows may have errors!  Experts will respond with
corrections and suitable slaps to my wrist which will be
cheerfully accepted :-)

>Could you enlighten me about the difference between
>    my $fh=do { local *FH };

    Makes the FH glob local to the block you see there.  The glob
    is "returned" by the "do".  Since you then exit the block, the
    localisation is lost, and whatever symbols you had called FH
    are restored.

    This gets you a reference to an anonymous glob which you then
    store in $fh.

>    my $fh=local *FH;

    Same thing as above, but your localisation persists till the
    end of the block or file in which this statement appears.  For
    reasons which Tom explained just prior to your post, this may
    cause unexpected side-effects.  If your block is *very* small
    it's probably OK, but keep in mind that the scope of the $fh
    is actually even smaller than that of the localisation you did
    on the FH symbol.

    This is because your $fh is only valid in this lexical scope,
    while the localisation is valid there as well as dynamically
    to any subroutines that may be called from within this lexical
    scope.

    So the previous method (Tom's original) is much better.  (Did
    you doubt that?  Just kidding!)

>    my $fh=\*FH;

    A globref being assigned to $fh.  This can be used to pass
    around filehandles just as well.

    The difference between this and the first one above is that
    the first one is used to "generate a brand new handle" that
    can then be used in an open (as the original code had).

    This one, on the other hand, can be used when the FH has
    already been assigned to (like from an open statement)

>    my $fh=*FH;

    Similar to above.

    A typeglob being assigned to $fh.  You can use both this and
    the above as filehandles.

    The previous one is "use strict 'refs'" safe, this one isn't.

>    my $fh=gensym;

    No idea.  Another way to do what #1 does?  (Note to myself:
    read perldoc Symbol)


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

Date: Fri, 23 Jul 1999 15:30:29 -0500
From: "Keith G. Murphy" <keithmur@mindspring.com>
Subject: Re: a bit of a bind..
Message-Id: <3798D0E5.27564030@mindspring.com>

Tom Christiansen wrote:
> 
>      [courtesy cc of this posting mailed to cited author]
> 
> In comp.lang.perl.misc,
>     keithmur@mindspring.com writes:
> :Why the extra level of indirection?  What's wrong with:
> :       my $fh = local *FH;
> :       open($fh, $filename) || die "can't open $filename: $!";
> 
> Well, what if you want to make two of them?  Or what if you want to call
> a function named &FH?  Or what if you want to call a function that wants
> to call a function named &FH?
> 
On the 2nd point, why does this not work:

my $fh = do { local *FH };
&FH;
sub FH {
  print "In the sub\n";
}

I thought the point of the do block was to "hide" the typeglob, but I
can't tell that it does it; the name of the subroutine still seems to
get tromped on.


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

Date: 23 Jul 1999 19:09:16 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: a bit of a bind..
Message-Id: <3799123c@cs.colorado.edu>

     [courtesy cc of this posting mailed to cited author]

In comp.lang.perl.misc, 
    keithmur@mindspring.com writes:
:On the 2nd point, why does this not work:
:
:my $fh = do { local *FH };
:&FH;
:sub FH {
:  print "In the sub\n";
:}

What do you mean, "doesn't work"?  It works fine for me, printing out

    In the sub

as you expect.  

--tom
-- 
"OSI: Same day service in a nanosecond world" Van Jacobsen.
T-shirt he produced for an Interop, a few years ago.


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

Date: Sat, 24 Jul 1999 00:28:51 GMT
From: syarbrou@nospam.enteract.com (Steve .)
Subject: ARGV validation of command line options
Message-Id: <379907cf.37145285@news.enteract.com>

say I have multiple options for a command lines.  They can be used or
not.  How do I validate if they are there or not?

For example:  

can use:  progname -r -h -x infile outfile

or can use progname or infile outfile

or can ue progname infile outfile

How do I do checking on what the user types in with these variations?
Thanks.

Steve

Newsgroup replies preferred.  Remove nospam from address when
responding thru email.


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

Date: Fri, 23 Jul 1999 15:51:28 -0500
From: "Keith G. Murphy" <keithmur@mindspring.com>
Subject: bite-me
Message-Id: <3798D5D0.95EE8EB9@mindspring.com>

 


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

Date: Fri, 23 Jul 1999 18:13:22 -0600
From: Ramanika <ramanika@flashmail.com>
Subject: Can anyone explain concepts of Perl Objects?
Message-Id: <37990522.2EE12D5A@flashmail.com>


What does bless do? (yes I have read all about it and still do not
understand)
Under what circumstances do you need it (bless)?
Under what circumstances do you leave it out (bless)?
What is the equivalent of bless in regards to C++ objects?

What is the best way to represent member data in an object? Hash?
What is the equilavent of "a pointer to an object" in Perl?
How do you create and manipulate one (pointer to an object)?

I have read all the man pages and perl books and still am struggling
with a few basic concepts.

Please CC: me on email if you respond to the list.

Thanks

Ramanika



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

Date: 23 Jul 1999 18:39:43 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Can anyone explain concepts of Perl Objects?
Message-Id: <37990b4f@cs.colorado.edu>

     [courtesy cc of this posting mailed to cited author]

(comp.lang.perl is dead.  I deleted it from the newsgroups line
in order to post this.)

In comp.lang.perl.modules, 
    Ramanika <ramanika@flashmail.com> writes:
:I have read all the man pages and perl books and still am struggling
:with a few basic concepts.

First a check.

I'll assume you read perlobj.  Did you also read perltoot?  And did you
*also* read the new perltootc?  I'll assume you read Camel:5, but did
you also read Ram:13?

--tom
-- 
Remember why the good Lord made your eyes -- Pla-gi-a-rize! --Tom Lehrer


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

Date: 24 Jul 1999 00:18:57 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: CGI:New window opens w/ NN, not w/ IE
Message-Id: <7nb0ph$2c2$1@lublin.zrz.tu-berlin.de>

Abigail <abigail@delanet.com> wrote in comp.lang.perl.misc:

>Document authors trying to open extra windows on a users screen should be
>skinned alive, dipped in a barrel of salt, then fed to the sharks.

Objection on behalf of the shark community.  Gah.

Anno


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

Date: Fri, 23 Jul 1999 14:43:11 -0700
From: Josh Suarez <tortuga@leland.stanford.edu>
Subject: DBD::Filemaker?
Message-Id: <3798E1EF.81092499@leland.stanford.edu>

Does anyone know if its possible to access a FileMaker (Pro 4.0)
database from a perl script? Is there a DBD::Filmaker module?

Thanks,
    Jim



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

Date: 24 Jul 1999 01:58:53 GMT
From: jjcoparks4@aol.com (JJcoParks4)
Subject: frames
Message-Id: <19990723215853.20895.00000868@ng-fe1.aol.com>

Hello I am trying to make a perl cgi script and I wan't part of it to be in a
frame. Is this posibble? And if so how the heck do I do it?


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

Date: Fri, 23 Jul 1999 19:33:16 -0400
From: Ewan Dunbar <northsky@ix.netcom.com>
Subject: Re: glob spawning problem
Message-Id: <932772918.853815614@nntp.netcom.ca>

On Fri, 23 Jul 1999, Anno Siegel wrote:
>Ewan Dunbar  <northsky@ix.netcom.com> wrote in comp.lang.perl.misc:
>>Every time I try to use glob, it says glob failed (child exited with status
>>126). Am I missing something? What child process is glob spawning? And why
>>won't it work for me?
>
>Your question about the child process has been answered.  As for
>why it isn't working for you, how should we know?  Post your code
>and tell us what OS you're on.  Sheesh.

Generally, those would be my sentiments exactly, however, I wasn't sure if my
first post had reached its destination, and I didn't see it when I checked.
Sorry.


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

Date: 24 Jul 1999 01:28:45 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: look for: a script that dectects when a new file arrives in a directory
Message-Id: <7nb4sd$2gp$1@lublin.zrz.tu-berlin.de>

Nollekens  <info@nollekens.be> wrote in comp.lang.perl.misc:
>look for: a script that dectects when a new file arrives in a directory
>
>Hi,
>
>OS: DOS
>PERL FOR DOS
>
>I need to write a script that 
>will detect when a new file is written
>to a subdirectory. the script then outputs 
>the file to my com port.
>I tried the following pseudo-code procedure.
>
>for (;;)
>{
> open directory
> read dir
> close directory
> 
> for each file in dir
> {
>  if file does not begins with "."
>  {
>   system "printcom.bat".
>  }
> }
>}
>
>the program stops after a while with
>the message "out of memory!".
>this could be a message that comes from 
>the bat file of from perl.
>
>Is this loop system the wrong way to go?

Not necessarily. But:

Pseudo-code is fine and dandy, but this is a bit too pseudo for my
taste.  We don't see any variables or their scope, so it's hard to
say where a memory leak may occur.  Further questions:

- What is done to check that a file is newly created in the directory?

- Is there some delay in the loop?  As it looks, it will print all
  files in your directory, and immediately start to print them again.

- How does printcom.bat know which file to print?

- What have you done to determine where the error message comes from?

Post (parts of) your real code, then we can talk.

Anno


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

Date: Fri, 23 Jul 1999 16:09:12 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
To: breslow_marty@tandem.com
Subject: Re: My newbie solution - is this the best?
Message-Id: <3798F618.D1144095@mail.cor.epa.gov>

[courtesy cc emailed to poster]

breslow_marty@tandem.com wrote:
> 
> I found that after the strip of STDIN the field had a beginning and
> trailing quote so I used substr to remove them.  Then I used
> substitution with the g modifier to substitute "" for " and that
> worked.  I then concatenated the result to get the final product
> i.e., '"' . $newstring . '",'
> Is this best way?  I guess I was hoping for the opposite of tr's
> duplicate removal but that's not automated in the language.

Well, clearly you didn't *really* want unattended duplicate
insertion, since you had to strip off delimiting quotes.  So
several lines of code seem to be a reasonable way to do this.

But an answer about the 'best' way would require more background.
Without knowing *why* you want/need to double those quotes
and then surround the string with more quotes, it's pretty
hard to guess what would be optimal.

David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: 24 Jul 1999 01:44:02 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: My newbie solution - is this the best?
Message-Id: <7nb5p2$2i6$1@lublin.zrz.tu-berlin.de>

David Cassell  <cassell@mail.cor.epa.gov> wrote in comp.lang.perl.misc:
>[courtesy cc emailed to poster]
>
>breslow_marty@tandem.com wrote:
>> 
>> I found that after the strip of STDIN the field had a beginning and
>> trailing quote so I used substr to remove them.  Then I used
>> substitution with the g modifier to substitute "" for " and that
>> worked.  I then concatenated the result to get the final product
>> i.e., '"' . $newstring . '",'
>> Is this best way?  I guess I was hoping for the opposite of tr's
>> duplicate removal but that's not automated in the language.
>
>Well, clearly you didn't *really* want unattended duplicate
>insertion, since you had to strip off delimiting quotes.  So
>several lines of code seem to be a reasonable way to do this.
>
>But an answer about the 'best' way would require more background.
>Without knowing *why* you want/need to double those quotes
>and then surround the string with more quotes, it's pretty
>hard to guess what would be optimal.

With due respect, but what has "why" got to do with anything?  It
doesn't matter if an external program needs this setup, or his
boss has told him to do so, or he just likes the sight.  The problem
is clearly stated (a rare enough occurrence to deserve extra credit).
What we need to know is what to optimize: cpu time, memory, programmer
time, maintainability, style, or golf strokes (hi Larry), to name a few.
Then optimize away.

Anno


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

Date: 24 Jul 1999 01:49:12 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Perl 4 Source Code or Binaries
Message-Id: <7nb62o$2jf$1@lublin.zrz.tu-berlin.de>

Inge <ingej@mnl.com> wrote in comp.lang.perl.misc:
>Where can I find source code for Perl 4, or even better, binaries?
>We're upgrading to Solaris 2.6 and have legacy Perl 4 modules (which
>we will upgrade to Perl 5 soon, but not right now).

Have you tried cpan (http://theory.uwinnipeg.ca/search/cpan-search.html
for one)?  I haven't checked but I'd be surprised if they had no
department of perl archaeology.

Anno


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

Date: Fri, 23 Jul 1999 20:16:41 -0500
From: Lab User <bogus@razorback.uark.edu>
Subject: Positioning in file?
Message-Id: <379913F9.83C28EAF@razorback.uark.edu>

      Ok, I'm trying to write a perl script that'll make log entries in
a text file in FILO order.  That is, the first entry in the text file
should be the last entry submitted by the script.  My first thought was
to use the "seek FILEHANDLE, 0, 0;" function and then write the entry.
It doesn't work, though.  The last entry made is always last in the log
file, and I need this to be reversed.  What do I do?



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

Date: Fri, 23 Jul 1999 18:08:14 -0600
From: Ramanika <ramanika@flashmail.com>
Subject: Possible to pass Hash's? Please Help.
Message-Id: <379903EE.CDFA05BC@flashmail.com>

Does anyone have an example of passing a hash to an object, having the
object modify the values and then returning the hash to the calling
procedure?  I am new to perl and have been playing around with this have

read everything I can be my hands on but still no luck.

Please CC: me on email if you reply back to the group.

Thanks

Ramanika



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

Date: Fri, 23 Jul 1999 20:23:52 -0400
From: japhy <jeffp@crusoe.net>
Subject: Re: Possible to pass Hash's? Please Help.
Message-Id: <Pine.GSO.4.10.9907232016170.7448-100000@crusoe.crusoe.net>

[posted & mailed]

> Does anyone have an example of passing a hash to an object, having the
> object modify the values and then returning the hash to the calling
> procedure?  I am new to perl and have been playing around with this have

For a function to modify a hash, you can do it using prototypes:

  sub modhash (%){
    my $href = $_[0];
    # modify through $href
    # or %hash = %$href; and then $_[0] = \%hash
  }

  modhash %somehash;

or pass by reference:

  sub modhash {
    my $href = $_[0];
    # modify through $href
    # or %hash = %$href; and then $_[0] = \%hash
  }

  modhash \%somehash;


Read more about this in perlref.

As for your next post, what is bless?  Bless "labels" a reference as
belonging to a certain package (or "class").  Variables may be DEFINED in
a package, but that doesn't make them BLESSED into it.  And the actual
variable isn't blessed, it's the contents it REFERS to that get blessed.

-- 
jeff pinyan    japhy@pobox.com
japhy's little hole in the (fire) wall:   http://www.pobox.com/~japhy
perl stuff     japhy+perl@pobox.com
japhy's perl supposit^Wrepository:        http://www.pobox.com/~japhy/perl



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

Date: Fri, 23 Jul 1999 16:02:19 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Problem dereferencing hash
Message-Id: <MPG.120294553b8fdd52989d2e@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <3798CB00.490F@publiconline.co.uk> on Fri, 23 Jul 1999 
21:05:20 +0100, Michael O'Connor <moconnor@publiconline.co.uk> says...
> I'm hoping someone can tell me how to scan a hash which has been passed
> to a subroutine as a reference e.g.
> 
>  sub1(\%hash1);
> 
>  ...
> 
> sub sub1
> {
> my $hash = $_[0];
> my @keys = keys $$hash;
> ...
> }
> 
> The last line of code above gives the error "Type of arg 1 to keys must
> be hash (not scalar deref)" yet something like the following works fine
> in its place:
> 
>  $$hash{'key'} = value;
> 
> I'm unable to find the syntax that allows the erroneous line to work.

Do what it says -- give it a hash!

  my @keys = keys %$hash;

As for the scalar dereference that works fine, what you show is often 
written this way:

   $hash->{'key'} = value;

I think a rereading of perlref might help you.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 23 Jul 1999 19:43:14 -0400
From: Lisa Friedland <lfriedl@genome.wi.mit.edu>
To: Michael O'Connor <moconnor@publiconline.co.uk>
Subject: Re: Problem dereferencing hash
Message-Id: <3798FE12.387A979B@genome.wi.mit.edu>


>  sub1(\%hash1);
> 
>  ...
> 
> sub sub1
> {
> my $hash = $_[0];
> my @keys = keys $$hash;

you mean: @keys = keys %$hash;

for the same reason you say:
my %hash2;
@a = keys %hash2;
and not
@a = keys $hash2;

($hash2 is equivalent to the subroutine's $hash)


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

Date: Fri, 23 Jul 1999 17:08:05 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Problem dereferencing hash
Message-Id: <MPG.1202a3bf51522c2a989d2f@nntp.hpl.hp.com>

In article <3798FE12.387A979B@genome.wi.mit.edu> on Fri, 23 Jul 1999 
19:43:14 -0400, Lisa Friedland <lfriedl@genome.wi.mit.edu> says...
> >  sub1(\%hash1);
> > 
> >  ...
> > 
> > sub sub1
> > {
> > my $hash = $_[0];
> > my @keys = keys $$hash;
> 
> you mean: @keys = keys %$hash;
> 
> for the same reason you say:
> my %hash2;
> @a = keys %hash2;
> and not
> @a = keys $hash2;

No.  Not for the same reason at all.  %hash2 and $hash2 are different 
symbols, with no relaionship to each other.  %hash2 is a hash; $hash2 is 
a scalar that may contain any scalar value, including a reference to a 
hash.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 23 Jul 1999 16:18:41 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: sort routines
Message-Id: <3798F851.46DFC90E@mail.cor.epa.gov>

Lisa Friedland wrote:
> 
> I have some commonly used sort subroutines I'd like to put in a
> package.  However, as the perl book points out, "You do need to make
> sure your sort routine is in the same package though, or qualify $a and
> $b with the package name of the caller."  How do I get at that?
> 
> Instead of
> sub in_order {
>         my @a = split(/(\d+)/, $a);
>         my @b = split(/(\d+)/, $b);
> [snip]

Hmmmm.  Are you doing split()s and stuff with every comparison
within your sort routine?  That's not A Good Thing (tm, Martha
Stewart).  This will cost you a lot as your array gets larger,
since you end up doing a lot more comparisons than there are
array elements.  And you're doing 2 split()s per comparison
too.

I suggest you look at perlfaq4, specifically the question:
"How do I sort an array by (anything)?"  That also has the
link to the FMTEYEWTK article on sorting.  You might also
get some benefit from going to Larry Rosler's webpage and
reading the recent paper he and Uri Guttman presented on
sorting in Perl.  After you read those, if you decide you
still don't want to go the route of the Schwartzian Transform,
you still might want to read Mark-Jason Dominus' recent
The Perl Journal article on memoizing for speeding up
programs.

After you get your sorting process whipped into shape, you'll
probably have a very different question to ask in this ng.

HTH,
David
-- 
David Cassell, OAO                     cassell@mail.cor.epa.gov
Senior computing specialist
mathematical statistician


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

Date: 24 Jul 1999 01:13:35 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: sort routines
Message-Id: <7nb3vv$2eo$1@lublin.zrz.tu-berlin.de>

Lisa Friedland  <lfriedl@genome.wi.mit.edu> wrote in comp.lang.perl.misc:
>
>I have some commonly used sort subroutines I'd like to put in a
>package.  However, as the perl book points out, "You do need to make
>sure your sort routine is in the same package though, or qualify $a and
>$b with the package name of the caller."  How do I get at that?
>
>Instead of 
>sub in_order {
>        my @a = split(/(\d+)/, $a);
>        my @b = split(/(\d+)/, $b);
>
>I must need something like:
>        my @a = split(/(\d+)/, MAIN::$a);
>        my @b = split(/(\d+)/, MAIN::$b);
>but I don't know what it's called.

In another reply David has pointed out why it may be a bad idea to
split on each comparison.

Apart from that, this raises a few questions.  First off, you probably
mean main (Perl's default package), not MAIN.  Secondly, the syntax
to access a scalar variable in package main is $main::a.  But more
importantly, why would you want to put your sort routines in a
separate package at all?  From your wording "commonly used" it seems
that a number of programs need to use the same comparison routine.
You can achieve this by putting the routine in a library file
(Sort.pm, say) and have the various programs use (or require) that library.

While most examples you find will at the same time use a package
to put the contents of the library in their own name space, this
is by no means necessary.  If the library is only used for a single
project (whatever that may mean), it may be more convenient to share
the name space and not bother with packages.

If you really want to use a package, here is a demo of how to go
about it.  It assumes that the actual sort will always be done in
package main.  If that isn't the case, more wizardry is required than
I want to muster at the moment.

File Sort.pm:
-------------------------------
package Sort;
use strict;
use Exporter;
use vars qw( @ISA @EXPORT);
@ISA = qw( Exporter);
@EXPORT = qw( numeric);

sub numeric { $main::a <=> $main::b }

1;  # to keep require happy
__END__

File test:
-------------------------------
#!/usr/bin/perl -w
use strict;
use Sort;

my @raw = map int( rand( 100)), 1 .. 20;

my @sorted = sort numeric @raw;

print "@sorted\n";
__END__

Anno


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

Date: 24 Jul 1999 00:04:21 -0000
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: strict vars and local
Message-Id: <7navu5$2aa$1@lublin.zrz.tu-berlin.de>

Eric L. Brine <q2ir@unb.ca> wrote in comp.lang.perl.misc:
>
>To my dismay, the following is not possible:
>
>use strict;
>sub test {
>  local *huge_arg = \$_[0];  # Pass by reference.
>  print($huge_arg, "\n");    # ack! strict error!
>}
>...
>test(\$huge_arg);

This is incomplete and probably doesn't correspond to what you really
tested.  Where does $huge_arg outside the sub come from?
If it is declared and assigned

my $huge_arg = 'x' x 9999999;

it doesn't matter much what you assign to the typeglob inside the
subroutine, the print will use the lexical $huge_arg from outside
it.  You won't see a strict error this way.

Now, if you force the print to use your typeglob, like so

  print $main::huge_arg, "\n";

you'll see a printout like

SCALAR(0x80cac3c)

That is because you construct a reference twice, once when you call
the subroutine (test(\$huge_arg)), and a second time inside
(local *huge_arg = \$_[0]).  Take away one of the "\", and it will
print whatever you assigned to $huge_arg.

Now, you probably didn't mean to use $huge_arg both inside and outside
the sub, but there are too many possibilities to reconstruct what
you probably did... I give up at this point.

>My question:
>  Is it possible to make a local var not strict (while the global one does
>remain strict)? or is there a way to alias to $_[0] with strict on?

There is no such thing as a "strict variable" in Perl.  When strict
is in effect, there are limitations on how you can use variables, namely
that you must either declare a variable before you use it (in one of
various ways) or you must access it fully qualified with an explicit
package name, as in $main::huge_arg above.  The variables themselves
are exactly the same, with or without strict.

>I can do the following, but I'd rather not.
>sub test {
>  my ($huge_arg_ref) = @_;
>  print(${$huge_arg_ref}, "\n");
>}
>...
>test(\$huge_arg);

Why not?  This is currently the Perl way to pass arguments by reference.

Please re-state your problem with complete code, so we don't have to
guess what you really mean.

Anno


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

Date: Fri, 23 Jul 1999 19:05:11 -0400
From: "c.s." <cs2400@hotmail.com>
Subject: Re: Telnet via CGI?
Message-Id: <932771233.179.65@news.remarQ.com>


wrote in message <7namju$vi6$1@nnrp1.deja.com>...
>You can use Comm.pl module. This comes with samlpe
>code - how to telnet into remote machine via a
>script. It uses "expect" commands to do this.
>Harish M.


What is an "expect command"?




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

Date: 1 Jul 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 1 Jul 99)
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 V9 Issue 240
*************************************


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