[18557] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 725 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 20 03:07:28 2001

Date: Fri, 20 Apr 2001 00:05:09 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <987750308-v10-i725@ruby.oce.orst.edu>
Content-Type: text

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

Today's topics:
    Re: Can't open file, dies (Tad McClellan)
    Re: Can't open file, dies (Eric Bohlman)
    Re: Combining hierarchical and alphabetical sorting? (Tad McClellan)
        howto not echo a password while reading from stdin (Chris Cera)
    Re: https module <whiteg2000@hotmail.com>
    Re: https module <keesh@users.pleaseremovethisbit.sourceforge.net>
    Re: if equal until loop exit? <nate-news@wiger.org>
    Re: Perl & PHP programmer available. <hafateltec@hotmail.com>
    Re: Placing text over a gif to create new gif? <jgomez@soon.com>
        really strange error... please help (: <ultramafic1@yahoo.com>
    Re: really strange error... please help (: <nate-news@wiger.org>
    Re: two associative arrays printed at the same time (Tad McClellan)
    Re: two associative arrays printed at the same time <justin.devanandan.allegakoen@intel.com>
    Re: Uploading Files via HTTP under NT <chrisw+usenet@dynamite.com.au>
        use Filter::decrypt;  How to encrypt source code first? <johnlin@chttl.com.tw>
    Re: using SYSTEM to run progs <Jonathan.L.Ericson@jpl.nasa.gov>
        weird problem, help? <xris@dont.send.spam>
    Re: weird problem, help? (Rafael Garcia-Suarez)
    Re: What is wrong here? <joe+usenet@sunstarsys.com>
    Re: Why Perl? <cyberjeff@sprintmail.com>
    Re: xoring bits (Jay Tilton)
    Re: xoring bits <tom@hotversion.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 19 Apr 2001 20:30:40 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Can't open file, dies
Message-Id: <slrn9dv0pg.4i6.tadmc@tadmc26.august.net>

Jim Kroger <minorseventhSPAMBLOCK@earthlink.net> wrote:

>then that is just a typo from my
>transcription of my code..


Don't go zipping right past another lesson that can be learned
from that.


>sorry bout that.


Typos waste your time. 

They waste the time of hundreds of others too.

Typos are bad bad bad, so...

 ... do not retype code!

Always use copy/paste or "import" or something, else you'll just end
up getting comments about your typos instead of about your real problem.


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


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

Date: 20 Apr 2001 02:21:48 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Can't open file, dies
Message-Id: <9bo6fs$g3b$2@bob.news.rcn.net>

Jim Kroger <minorseventhSPAMBLOCK@earthlink.net> wrote:
> Thanks everyone for the help....

> Can't help but wonder what a statistician uses Perl for....

An awful lot of statistical work involves re-organizing and grouping data.  
Perl is great at that sort of thing.



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

Date: Thu, 19 Apr 2001 20:24:29 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Combining hierarchical and alphabetical sorting?
Message-Id: <slrn9dv0dt.4i6.tadmc@tadmc26.august.net>

Dan Harding <dharding@uiuc.edu> wrote:
>
>As is not uncommon these days, I found a partial solution
>to a scripting problem via this newgroup.


I am glad you posted this, now many people will get to see the answer.
(I ignore Perl questions via email as a general rule, even real nicely
 asked ones like yours was.)


>Using the original code, I can produce the following example:
>
>Printing Division
>    Bindery
>       Folder
>       Cutter
>    Pressroom
>    Prepress
>    Production Office
>Office of the Director
>Quickcopy Centers
>    Large Format Plotting
>    Digital Imaging

>My question is how can children of the same parent be alphabetized?


By sorting with the sort() function  :-)


>The output I'm looking for is:
>
>Office of the Director
>Printing Division
>    Bindery
>       Cutter
>       Folder
>    Prepress
>    Pressroom
>    Production Office
>Quickcopy Centers
>    Digital Imaging
>    Large Format Plotting
>
>
>Assume data 
 ^^^^^^


Why?

Why not *give* us the data that you used?

(that is, in fact, why I did not break my usual policy as I had
 started to do. When I went to work on it, I didn't have any data
 and was disinclined to generate some, so I just deleted the email.
)

If you had given the data, you would not have gotten incorrect
followups from newsgroup regulars like you did.


>is in the prerequisite delimited
>form being split below.
>
>Thank you very much in advance,


You're welcome.


>========== BEGIN CODE =============
>

>   $channel_hash{$id} = { name   => $name,  
>                          parent => $parent,
>                          kids   => []   # a list of the children node
>IDs


Note that the keys are ID _numbers_, but you want it sorted based
on the name associated with the number, not based on the number
itself.

Note also that it is not apparent that they are numbers from anything
in your post (because your post did not include the data).


>#### collect up a list of children IDs for each node
>foreach my $node ( keys %channel_hash ) {
>   my $parent = $channel_hash{$node}{parent};
>   push @{$channel_hash{$parent}{kids}}, $node;
>}
>
>### output with recursive subroutine
>my $depth = 0;  # for deciding indent level
>foreach my $child ( sort @{$channel_hash{0}{kids}} ) { # children of the


   foreach my $child ( sort by_name @{$channel_hash{0}{kids}} ) {
                            ^^^^^^^

>   walk($child);
>}
>
>
>sub walk {
>   my($id) = @_;
>
>   print '.' x ($depth * 4), $channel_hash{$id}{name}, "\n";
>
>   $depth++;
>   foreach my $child ( @{$channel_hash{$id}{kids}} ) {


   foreach my $child ( sort by_name @{$channel_hash{$id}{kids}} ) {
                       ^^^^^^^^^^^^


>      walk($child);
>   } $depth--;
>}


   sub by_name {
      $channel_hash{$a}{name} cmp $channel_hash{$b}{name};
   }



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


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

Date: Fri, 20 Apr 2001 06:34:04 +0000 (UTC)
From: cera@drexel.edu (Chris Cera)
Subject: howto not echo a password while reading from stdin
Message-Id: <slrn9dvju4.u4d.cera@queen.mcs.drexel.edu>

Could somebody please tell me how to do this.  I want the user to
be able to enter his/her command from a terminal.  I want the
input to be concealed.  Is this possible?
-- 
    _/_/_/  _/_/_/ _/_/_/_    _/_/_    cera@drexel.edu
   _/      _/      _/   _/   _/  _/                            /"\
  _/      _/_/_/  _/ _/     _/_/_/     ASCII RIBBON CAMPAIGN   \ /
 _/      _/      _/  _/    _/  _/       AGAINST HTML MAIL,      X 
_/_/_/  _/_/_/  _/    _/  _/  _/.ws    AND NEWS TOO, dammit!   / \


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

Date: Fri, 20 Apr 2001 02:48:39 GMT
From: "G. White" <whiteg2000@hotmail.com>
Subject: Re: https module
Message-Id: <bsND6.600618$Pm2.9966350@news20.bellglobal.com>

The way I've always done it with http is:

http://username:password@mysite.com

I've never tried this with https but I'm guessing it should work.


"smilepak" <smilepak@hotmail.com> wrote in message
news:BJID6.971$cM1.57429@newsread1.prod.itd.earthlink.net...
> Question:
>
> I need to access a secure http site to pull data on a daily basis. The
site
> request a username/password. Anyone know of a way I can get perl to do a
> https call and passing a username/password when it request for it?
>
> I know perl has a "GET" function, however that doesn't work with secure
http
> server.
>
> Any insight? Thanks,
>
> KN
>
>
>




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

Date: Fri, 20 Apr 2001 08:00:37 +0100
From: "Ciaran McCreesh" <keesh@users.pleaseremovethisbit.sourceforge.net>
Subject: Re: https module
Message-Id: <9bomo6$f3g$1@newsg1.svr.pol.co.uk>

In article <bsND6.600618$Pm2.9966350@news20.bellglobal.com>, "G. White"
<whiteg2000@hotmail.com> wrote:
> http://username:password@mysite.com
> 
> I've never tried this with https but I'm guessing it should work.

Probably not. It might, but it shouldn't. If the site is using https for
security, they should _require_ encrypted transactions. There's a big
diffence between supplying a username and password through HTTP (rfc2616)
using the authorisation stuff in rfc2617 and a full-blown https (rfc2260)
transaction.

Essentially, https is http with some more headers thrown in. The problem
is, the http message usually contains another http message, which can be
encrypted in a number of ways, which contains the stuff you'd actually
want...

Regards,
Ciaran

-- 
Ciaran McCreesh
mail:    keesh@users.sourceforge.net
web:     http://www.opensourcepan.com/


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

Date: Fri, 20 Apr 2001 03:05:12 GMT
From: "Nathan Wiger" <nate-news@wiger.org>
Subject: Re: if equal until loop exit?
Message-Id: <IHND6.191561$GV2.42806110@typhoon.san.rr.com>

> That should work, for anyone who trying to do the same thing as
me...unless
> someone got something better i am willing to use :)

Maybe I'm missing what you're trying to do, but personally I'd do that way
differently. Here's a complete program that should parse what you want:

  #!/usr/bin/perl -w

  use strict;

  my $tmpdir = '/tmp';
  my $file = shift || die "Usage: $0 filename\n";

  open(IN, "<$file") || die "Can't open $file: $!\n";
  while (<IN>) {
     # check if we're in a <RES> tag
     if ( /<\s*RES.*name\s*=\s*"(.*?)".*t\s*=\s*"(\d+)"/ ) {
        open(DST, ">$tmpdir/$1-$2.dat") || die "$1-$2.dat: $!";
        while (<IN> !~ /<\/RES>/) {
           print DST;
        }
        close DST;
     }
  }

This checks for the <RES> tag explicitly, so it follows the XML more
precisely. It'll create files of the form:

  /tmp/www.oscar.com-222.dat
  /tmp/www.oscar.com-346.dat
  /tmp/www.oscar.com-585.dat

If you've got hairy XML that you want to really parse nicely, check out
XML::Twig.

-Nate





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

Date: Fri, 20 Apr 2001 12:49:05 +1000
From: "Michael R. McPherson" <hafateltec@hotmail.com>
Subject: Re: Perl & PHP programmer available.
Message-Id: <9bo8590f3a@enews4.newsguy.com>


"Gil G." <gil@nospam-keskydee.com> wrote in message
news:3adf7e98.3166055@news-server...
> Hello,
>
> I can help you with your scripts.
> Strong work ethics, good references, reasonable rates.
>
> please see my freelance page: http://keskydee.com/freelance.php
>
> Thanks, please excuse this somewhat off-topic post.

No... You are not forgiven :þ

>
> Sincerely,
>
> Gil.




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

Date: 20 Apr 2001 02:03:06 -0500
From: "Jorge E. Gomez" <jgomez@soon.com>
Subject: Re: Placing text over a gif to create new gif?
Message-Id: <20010420.015152.2035417297.7251@thebrain.cable.net.co>

"Ted Wart" <t_wart@hotmail.com> wrote:

>  I'm looking for a tool that will allow me to read in a graphic image,
>  place text on top of it as a label and write the graphic out to a new
>  file. Gif/Jpeg/ maybe tiff  are acceptable formats.  Any one know of a
>  module or method that'd facilitate this? TIA, TW

ImageMagick is exactly what you need. You'll need to use either the annotate or
the draw text functions. All of those formats are supported. The module
is Image::Magick, from CPAN, or visit first 
http://www.imagemagick.org/www/perl.html

--
Jorge


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

Date: Thu, 19 Apr 2001 21:10:49 -0800
From: Steve Wilbur <ultramafic1@yahoo.com>
Subject: really strange error... please help (:
Message-Id: <190420012110499614%ultramafic1@yahoo.com>

I have a program that uses the following:
   use WDDX;
   use HTML::Template;
   use CGI ':standard'

Program runs fine at the command line when I run it as myself or any
other use.  But if I run it as a cgi-script from the web server (its
intended purpose), it craps out. Further, I logged in with the "nobody"
user-id (since that's what the web server runs as) and it craps out. 
So I feel certain that it's not a permissions problem, but maybe
something to do with path setups or something.  I'm at a loss as to
what to try.  

The specific error I get is as follows (truncated):

Can't load
'/net/klang/usr/local/lib/perl5/site_perl/5.6.0/sun4-solaris/auto/XML
/Parser/Expat/Expat.so' for module XML::Parser::Expat: ld.so.1:
/net/klang/usr/local/bin/perl: fatal: libexpat.so.0: open failed: No
such file or directory at
/net/klang/usr/local/lib/perl5/5.6.0/sun4-solaris/DynaLoader.pm line
200. at
/net/klang/usr/local/lib/perl5/site_perl/5.6.0/sun4-solaris/XML/Parser.p
m line 15

Note that the program runs fine as any user except nobody.  The perl
installation is on a machine other than the web server (good reasons
for this), I'm thinking that might have something to do with it, except
that the program runs fine on the web server from the command-line -
just not from the server software as a cgi. 

Anyway - I'm rambling.  I'd appreciate any info I can get (:


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

Date: Fri, 20 Apr 2001 05:47:18 GMT
From: "Nathan Wiger" <nate-news@wiger.org>
Subject: Re: really strange error... please help (:
Message-Id: <G3QD6.192953$GV2.42914357@typhoon.san.rr.com>

> The specific error I get is as follows (truncated):
>
> Can't load
> '/net/klang/usr/local/lib/perl5/site_perl/5.6.0/sun4-solaris/auto/XML
> /Parser/Expat/Expat.so' for module XML::Parser::Expat: ld.so.1:
> /net/klang/usr/local/bin/perl: fatal: libexpat.so.0: open failed: No
> such file or directory at
> /net/klang/usr/local/lib/perl5/5.6.0/sun4-solaris/DynaLoader.pm line
> 200. at
> /net/klang/usr/local/lib/perl5/site_perl/5.6.0/sun4-solaris/XML/Parser.p
> m line 15

Check LD_LIBRARY_PATH (/net => Solaris, right?). Where was libexpat compiled
to live?

This looks like what happens if libexpat is not in /usr/lib and you compile
XML::Parser against it w/o -R/lib/path (it's a standard ld linker error).
I'd reinstall XML::Parser, but if that's not an option, try setting
LD_LIBRARY_PATH in your script:

   $ENV{LD_LIBRARY_PATH} = '/net/klang/usr/local/lib';   # guess

But that's nasty, technically, since you'd have to do this for all your
scripts.

-Nate





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

Date: Thu, 19 Apr 2001 20:35:56 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: two associative arrays printed at the same time
Message-Id: <slrn9dv13c.4i6.tadmc@tadmc26.august.net>

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?


Use the same key to index each of the two hashes.


>Could I do something like this:-
>
>while(($key, $val, $key2, $val2) = each(%hash1, %hash2))
        ^^^^        ^^^^^

Why have the identical value in 2 places? (you said the hashes
have the same keys)


>Yeap, I know that doesn't work, but is there a correct structure?


Sure:

   foreach my $key ( keys %hash1 ) {
      my $val  = $hash1{$key};
      my $val2 = $hash2{$key};
      # do other stuff here
   }

>Justin (Just another nobody who uses PERL (albeit badly), to numb the pain
>of his job.)


I don't know about using Perl badly, but you sure do spell it badly.

"Perl" is used to refer to the language proper.

"perl" is used to refer to the implementation of the language (interpreter).

"PERL" is not used.


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


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

Date: Fri, 20 Apr 2001 10:17:10 +0800
From: "Just in" <justin.devanandan.allegakoen@intel.com>
Subject: Re: two associative arrays printed at the same time
Message-Id: <9bo67k$pga@news.or.intel.com>

> 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.

> Sure:
>
>    foreach my $key ( keys %hash1 ) {
>       my $val  = $hash1{$key};
>       my $val2 = $hash2{$key};
>       # do other stuff here
>    }

This works beautifully - Thanks for your time

> >Justin (Just another nobody who uses PERL (albeit badly), to numb the
pain
> >of his job.)
> I don't know about using Perl badly, but you sure do spell it badly.
> "Perl" is used to refer to the language proper.
> "perl" is used to refer to the implementation of the language
(interpreter).
> "PERL" is not used.

I might want to change my signature then - perhaps to just another nobody
who doesnt appreciate
case sensitivity?

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.





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

Date: Fri, 20 Apr 2001 11:13:00 +1000
From: "Chris W" <chrisw+usenet@dynamite.com.au>
Subject: Re: Uploading Files via HTTP under NT
Message-Id: <64MD6.10$Q32.145491@news.interact.net.au>

"S Warhurst" <s.warhurst@rl.ac.uk> wrote in message
news:9bn0o6$1a2k@newton.cc.rl.ac.uk...
> Hi
> I have searched all over the place for this but am having problems finding
> anything. Everywhere I look I see scripts for uploading files, but they
are
> all big scripts with various options to exclude extensions, password
> protection, html for reporting differennt error conditions.

You have read the CGI module documentation haven't you?

> All I want is the basic core code to upload a file under NT, so I can
> understand exactly how it works. I managed to strip one of those
> aforementioned scripts down to the basic components, but it doesn't work
> properly. Here it is:
> The box on the HTML page is named "FILE" and the file to upload is, say,
> "data.txt"

[ code snipped ]

Your HTML <FORM> tag needs to have a non-default content type:
multipart/form-data.

You access the contents file through a file handle supplied by CGI.pm not by
name:

my $fh = $q->upload( "file" );

Code snippet:

# This is necessary for non-Unix systems; does nothing on Unix
binmode $fh;
binmode OUTPUT;
# Write contents to output file
while ( read( $fh, $buffer, BUFFER_SIZE ) ) {
    print OUTPUT $buffer;
}
close OUTPUT;





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

Date: Fri, 20 Apr 2001 11:28:38 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: use Filter::decrypt;  How to encrypt source code first?
Message-Id: <9boa9b$ik2@netnews.hinet.net>

Dear all,

For a program
print "Hello, world!\n";
I want to use Filter::decrypt, how shall I encrypt it first?  To get

use Filter::decrypt;
JoYfkfGsQiLto    # this line is the encrypted 'print "Hello, world!\n";'

Thank you.

John Lin
--
Could it be Perl's build-in 'crypt' function?
print crypt('print "Hello, world!\n";','John');  # gets 'JoYfkfGsQiLto'
No way.  crypt is "one way", so it can't be "decrypted".

Could it be some Unix utility?  'encrypt' and 'decrypt'?
I didn't find any on my machine.

The document "perldoc Filter::decrypt" is so simple
as if the author thinks this is something trivial.

I also read "perlfilter" but couldn't find a clue.

The search results of "Filter::decrypt" on www.deja.com didn't help either.





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

Date: 20 Apr 2001 01:37:27 +0000
From: Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov>
Subject: Re: using SYSTEM to run progs
Message-Id: <86r8yoic6g.fsf@jon_ericson.jpl.nasa.gov>

Martin Bower <Martin.Bower@ib.bankgesellschaft.de> writes:

> I`m currently running a daemon to check whether files have been created
> in a directory, then running another perl program if they have,
> using....
> 
>    my @args = ("perl", "test.pl", $dateiname, "A string", "market",
> "other", "M");
>    system(@args) == 0 or die "system @args failed: $?";
> 
> is this effecient, or should I be using a different way to shell out
> programs ?

I don't understand your question.  The above perl code looks fine to
me.  I suppose you could put the functionality of "test.pl" (I assume
you have a better name for it) into a Perl module to save a process.
But system is a perfectly acceptable way to "shell out programs".

Jon


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

Date: Fri, 20 Apr 2001 01:06:54 -0500
From: xris <xris@dont.send.spam>
Subject: weird problem, help?
Message-Id: <xris-43BF0C.01065320042001@news.evergo.net>

why does this work:

sub GetErrors {
   if ($WarningString =~ /\w/o) {
      substr($WarningString, 0, 0) = "<p>\n" if ($ErrorString =~ /\w/o);
      $ErrorString =~ s/(<BR>\n)?$/$WarningString/io;
   }
   my ($head, $tail) = &SplitParams(shift);
   return '' unless ($ErrorString =~ /\w/o);
   my $color;
   if ($ThisProgramCode =~ /^edit/o or $ThisProgramCode =~ /login/o) {
      $color = $Colors{ederror};
   }
   else {
      $color = $Colors{error};
   }
   return "$head<Font Color=\"#$color\">$ErrorString</Font>$tail";
}


but this:

sub GetErrors {
   if ($WarningString =~ /\w/o) {
      substr($WarningString, 0, 0) = "<p>\n" if ($ErrorString =~ /\w/o);
      $ErrorString =~ s/(<BR>\n)?$/$WarningString/io;
   }
   return '' unless ($ErrorString =~ /\w/o);
   my ($head, $tail) = &SplitParams(shift);
   my $color;
   if ($ThisProgramCode =~ /^edit/o or $ThisProgramCode =~ /login/o) {
      $color = $Colors{ederror};
   }
   else {
      $color = $Colors{error};
   }
   return "$head<Font Color=\"#$color\">$ErrorString</Font>$tail";
}

does not?

Basically, all I've done is move the

   my ($head, $tail) = &SplitParams(shift);

line down below the "return" statement to save a little cpu time if 
there are no errors to report.  The second sub returns the proper color 
value, etc, but does NOT manage to get $head and $tail.  What's so weird 
about what I'm doing that makes the subroutine lose the @_ value?

Thanks,

-xris



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

Date: 20 Apr 2001 06:38:21 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: weird problem, help?
Message-Id: <slrn9dvmc8.k8o.rgarciasuarez@rafael.kazibao.net>

xris wrote in comp.lang.perl.misc:
} why does this work:
} 
[...]
} 
} but this:
} 
[...]
} 
} does not?
} 
} Basically, all I've done is move the
} 
}    my ($head, $tail) = &SplitParams(shift);
} 
} line down below the "return" statement to save a little cpu time if 
} there are no errors to report.  The second sub returns the proper color 
} value, etc, but does NOT manage to get $head and $tail.  What's so weird 
} about what I'm doing that makes the subroutine lose the @_ value?

Yes, that's weird. Perhaps there's a problem in SplitParams. perlfunc
says about split() :

       In scalar context, returns the number of fields found and
       splits into the "@_" array.  Use of split in scalar
       context is deprecated, however, because it clobbers your
       subroutine arguments.

Can this be the cause of your problem ?

-- 
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/


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

Date: 19 Apr 2001 22:35:27 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: What is wrong here?
Message-Id: <m3eluowb68.fsf@mumonkan.sunstarsys.com>

Ren Maddox <ren@tivoli.com> writes:

> On 19 Apr 2001, joe+usenet@sunstarsys.com wrote:
> 
> >   % cat global.pm
> >   our $test = "http://1.2.3.4"
> >   % perl -wle 'BEGIN{require "global.pm"} print $test'
> >   http://1.2.3.4
> >   %
> 
> While this does work, I think that it gives the mistaken impression
> that having that "our" declaration in the required file has any effect
> -- it really doesn't.  Stick a "use strict" on that script and you
> still have a problem:

Well yes, but AFAICT that's not what OP asked about.  OP's original 
global.pm file contains the "our" declaration, and I understood his 
question to essentially be 

  "My script works fine, but _why_ do I get the 'variable used once' 
  warning?"

While that warning has nothing to do with strictures, a
good-habit-forming fix is to simply declare

  our $test;

in his main script as well.  Now that does make for better programming
habits, but it doesn't explain why the warning occurs in the first place.

> perl -wle 'use strict;BEGIN{require "global.pm"} print $test'
> Variable "$test" is not imported at -e line 1.
> Global symbol "$test" requires explicit package name at -e line 1.
> Execution of -e aborted due to compilation errors.
> 
> 
> This is because, among other things, "our" is lexically scoped.

So are strictures, btw. Just "use vars" has nonlexical behavior,
(which I suppose you are alluding to, albeit somewhat obtusely).
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 :-)

-- 
Joe Schaefer       "If carpenters made buildings the way programmers
                    make programs, the first woodpecker to come along
                    would destroy all of civilization."
                                               --Anonymous


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

Date: Fri, 20 Apr 2001 01:05:52 GMT
From: Jeff Thies <cyberjeff@sprintmail.com>
Subject: Re: Why Perl?
Message-Id: <39D3EA76.779309CF@sprintmail.com>

> >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.

Cheers,
Jeff


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

Date: Fri, 20 Apr 2001 04:04:25 GMT
From: tiltonj@erols.com (Jay Tilton)
Subject: Re: xoring bits
Message-Id: <3adfb076.97669702@news.erols.com>

On Thu, 19 Apr 2001 15:15:20 GMT, "Tom" <tom@hotversion.com> wrote:

>I'm trying to ^ 8bits 10000001 and 10001101, I'd like to have 8bits returned
>as the result but instead I get 420 when I ^ the two is there someway of
>returning the 8bits xor-ed ?

Showing your code could have been used to show what you were doing
wrong and would have helped clarify your goal (do you want the result
as a bit string or as decimal?  Are the bits in ascending or
descending order?).  Another lost opportunity, I guess.  Try this on
for size.

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

  my $bits1 = '10000001';
  my $bits2 = '10001101';

  my ($byte1, $byte2) = unpack 'C2', pack 'B8B8', $bits1, $bits2;
  my $result = unpack 'B8', pack 'C', ($byte1 ^ $byte2);

  print "$result\n";

Post your own code if you get a chance.  I can't figure how 420 could
come out of those bits.  :)


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

Date: Fri, 20 Apr 2001 04:41:30 GMT
From: "Tom" <tom@hotversion.com>
Subject: Re: xoring bits
Message-Id: <_5PD6.21819$BU4.36056@news1.blktn1.nsw.optushome.com.au>

Thanks :)

Tom



"Jay Tilton" <tiltonj@erols.com> wrote in message
news:3adfb076.97669702@news.erols.com...
> On Thu, 19 Apr 2001 15:15:20 GMT, "Tom" <tom@hotversion.com> wrote:
>
> >I'm trying to ^ 8bits 10000001 and 10001101, I'd like to have 8bits
returned
> >as the result but instead I get 420 when I ^ the two is there someway of
> >returning the 8bits xor-ed ?
>
> Showing your code could have been used to show what you were doing
> wrong and would have helped clarify your goal (do you want the result
> as a bit string or as decimal?  Are the bits in ascending or
> descending order?).  Another lost opportunity, I guess.  Try this on
> for size.
>
>   #!/usr/bin/perl -w
>   use strict;
>
>   my $bits1 = '10000001';
>   my $bits2 = '10001101';
>
>   my ($byte1, $byte2) = unpack 'C2', pack 'B8B8', $bits1, $bits2;
>   my $result = unpack 'B8', pack 'C', ($byte1 ^ $byte2);
>
>   print "$result\n";
>
> Post your own code if you get a chance.  I can't figure how 420 could
> come out of those bits.  :)




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

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


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