[17790] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5210 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 28 03:05:32 2000

Date: Thu, 28 Dec 2000 00:05:09 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <977990708-v9-i5210@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 28 Dec 2000     Volume: 9 Number: 5210

Today's topics:
    Re: Code Review? (Colin Watson)
    Re: Code Review? <emerald-arcana@home.com>
        convert decimal to hex??? <hengst.1@osu.edu>
    Re: convert decimal to hex??? eric@taedium.com
    Re: Different handles in a variable <bart.lateur@skynet.be>
    Re: FAQ 6.5:   How do I substitute case insensitively o <johnlin@chttl.com.tw>
    Re: FAQ 6.5:   How do I substitute case insensitively o <uri@sysarch.com>
        Free win32 Perl IDE+easiest way to start learning Perl (Neerav)
    Re: Free win32 Perl IDE+easiest way to start learning P simplitia@my-deja.com
        in C++, multiple interpreterts w/ extension <tonghang@transmeta.com>
    Re: NEED SCRIPTING DONE (Martien Verbruggen)
    Re: Our question - Possible Legacy code question... <bart.lateur@skynet.be>
    Re: Perl's BigInts/BigFloats <rwan@cs.mu.OZ.AU>
    Re: Perl's BigInts/BigFloats <rwan@cs.mu.OZ.AU>
    Re: Perl's BigInts/BigFloats (Ilya Zakharevich)
        Piping output from one script into another <emerald-arcana@home.com>
    Re: Piping output from one script into another (Bernd Giegerich)
        References (I'm not sure if the old message posted) <sNiOgmSa@PmAaMth.net>
    Re: References (I'm not sure if the old message posted) egwong@netcom.com
    Re: Sending Zero Values from Forms georgebailey@my-deja.com
        Setting locale failed <nkavecan@Eunet.yu>
    Re: Setting locale failed (Rafael Garcia-Suarez)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 28 Dec 2000 02:02:52 GMT
From: cjw44@flatline.org.uk (Colin Watson)
Subject: Re: Code Review?
Message-Id: <92e70c$mo7$1@riva.ucam.org>

Arcana <emerald-arcana@home.com> wrote:
>Does anyone here mind doing a review of my script and making appropriate 
>comments?  I don't have specific problems, but I'd like to perhaps be 
>enlightened in some of the finer points of programming.  My script seems 
>(to me) very rudimentary and I'd like to become aware of different 
>techniques I could use when solving further problems.

I'll have a go. You have the right idea, though there are a few places
that could be tightened up a bit, and a few style nits.

>{ # Main block

This looks somewhat odd in Perl. Typically, top-level code goes outside
any block, or at least goes in a sub which is then called; an ordinary
block is redundant. If the main flow of code gets too large, you can
always split it up into smaller subs.

>    my $F_name = quotemeta "**Name (or alias):" ;
>    my $F_email = quotemeta "**E-mail Address:";
>    my $F_pname = quotemeta "**Name:";
>    my $F_age = quotemeta "**Age:";
>    my $F_gender = quotemeta "**Gender:";
>    my $F_occupation = quotemeta "**Occupation:";
>    my $F_appearance = quotemeta "**General Appearance:";
>    my $F_personality = quotemeta "**Personality:";

Hmm. The quotemeta() here is an interesting approach, but I think I'd
prefer to do the quoting in each regex where one of these is used, using
something like /^\Q$F_name\E/ (though the \E is redundant here).

I'd also tend to write this as a hash:

  my %fields = (
    name        => '**Name (or alias):',
    email       => '**E-mail Address:',
    ...,
    personality => '**Personality:',
  )

 ... and do /^\Q$fields{name}/ or whatever, simply because I think it's
tidier to group related variables together like this.

>    # Argument handling.
>    if ( $ARGV[0] eq "") {

Perhaps 'if (@ARGV)'?

>        die "Argument: <filename>  (A P-sheet file.)\n";

I wouldn't want a backtrace in this situation. Just a print() followed
by an exit() (or a usage() sub if you need it in several places) would
be better.

>    # SHEET is filehandle for the P-sheet
>    open(SHEET, $sheetfile) || die "ERROR opening $sheetfile\n";

When die() is used in response to some kind of library call failing, you
should also print $! to get the system error message:

  open(SHEET, $sheetfile) || die "ERROR opening $sheetfile: $!";

>    # Streams file into $_ and parses
>    while (<SHEET>) {
>
>        # must strip newlines at end
>        s/\s+$//;

'chomp;' is better, or else your comment is inaccurate and it's more
trailing whitespace in general that concerns you.

>        # Get player name
>        if ( /^$F_name/ ) {
>
>            s/^$F_name\s+//;

You could write this more concisely as:

  if ( s/^$F_name\s*// ) {

(+ changed to * just in case, although perhaps you want to check for
empty fields.)

>            $pdata{"name"} = $_;

Style nit: no need to quote hash keys if they're just words.

[snip a certain amount of repetition]

If you wanted to be more clever, you could have a hash from fields to
code references, where the referenced code does any special actions
required for individual fields. You could then iterate through that hash
with a 'foreach (keys %actions)' loop, grab each field value in turn,
have the code ref - if it's defined - modify that value, and set the
element in %pdata. It might be overkill, but on the other hand it might
make your code less repetitive and therefore easier to maintain.

Having lots of variables and segments of code that do much the same
thing - effectively, cut-and-paste programming - is an easy way to get a
quick tool started, but in the long run they need to be consolidated.

>            # Male if user typed "male, Male, M, m, Mail, etc.
>            if ( $genderline =~/^[Mm](\w*)/ ) {

You don't use the captured bit of the regex here. Just /^[Mm]/ is
enough.

>        # Get occupation
>        # Multiple line-input?

Remember 'redo' when you're doing this (i.e. read until you decide
you've reached the end of the field, by which time you've probably read
one line too many, so use redo to jump back to the start of the loop
without doing another read).

>## This section is dull and not well-extendible: edit soon
>    # Create a data record for P-data
>    # print out hashtable line-by-line with | separators
>    print $pdata{"pname"};
>    print "|";
>    print $pdata{"age"};
>    print "|";
>    print $pdata{"gender"};
>    print "|";
>    print $pdata{"occupation"};
>    print "|";
>    print $pdata{"name"};
>    print "|";
>    print $pdata{"email"};

Well, as long as you know no-one will ever want a name with a | in it
 ... you might want to think about escaping those. Using interpolation
would make this easier to read, too, so:

  print "$pdata{pname}|$pdata{age}|$pdata{gender}|...";

 ... or at least:

  print "$pdata{pname}|";
  print "$pdata{age}|";
  print "$pdata{gender}|";
  ...

 ... or even use a hash slice (and here you do need to quote the keys):

  printf '%s|%s|%s|%s|%s|%s',
         @pdata{'pname', 'age', 'gender', 'occupation', 'name', 'email'};

Of course, you'll want either a here-doc or some kind of iteration if it
gets much more complex.

For lookup speed, you might end up using a Real Database, or at least a
DBM file. For clarity and ease of post-processing, text is good.

-- 
Colin Watson                                     [cjw44@flatline.org.uk]
"Engfeh ngggg *znork*"
"Was that a zombie?" "It's 9:30 in the morning."
"Ahhhh. That was a kernel hacker." - http://www.userfriendly.org/


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

Date: Thu, 28 Dec 2000 04:09:57 GMT
From: Arcana <emerald-arcana@home.com>
Subject: Re: Code Review?
Message-Id: <p2z26.30373$59.9342665@news3.rdc1.on.home.com>

Colin Watson wrote:

> Arcana <emerald-arcana@home.com> wrote:
> >Does anyone here mind doing a review of my script and making appropriate
> >comments?  I don't have specific problems, but I'd like to perhaps be
> >enlightened in some of the finer points of programming.  My script seems
> >(to me) very rudimentary and I'd like to become aware of different
> >techniques I could use when solving further problems.
> 
> I'll have a go. You have the right idea, though there are a few places
> that could be tightened up a bit, and a few style nits.

Thanks for taking the time to do so!  I'm still trying to understand a few 
of the comments you made, but I think I'll be a better developer as a 
result of your help.  Right now, I'm sort of "wanting to get the project 
done", but comments like this help like you wouldn't believe.

> This looks somewhat odd in Perl. Typically, top-level code goes outside
> any block, or at least goes in a sub which is then called; an ordinary
> block is redundant. If the main flow of code gets too large, you can
> always split it up into smaller subs.

I follow a little bit from the C and Pascal tradition of having a top-level 
block.  The "main()" thing.

Perhaps I should section the script into subs, then.
 
> I'd also tend to write this as a hash:
> 
>   my %fields = (
>     name        => '**Name (or alias):',
>     email       => '**E-mail Address:',
>     ...,
>     personality => '**Personality:',
>   )
> 
> ... and do /^\Q$fields{name}/ or whatever, simply because I think it's
> tidier to group related variables together like this.

Ahhh, I see!  :)  That's much better.
 
> >    # Streams file into $_ and parses
> >    while (<SHEET>) {
> >
> >        # must strip newlines at end
> >        s/\s+$//;
> 
> 'chomp;' is better, or else your comment is inaccurate and it's more
> trailing whitespace in general that concerns you.

Actually, when I tried "chomp" the patterns wouldn't match.  I'd get blank 
lines in the output.
But yes, whitespace in general is a concern so I will change the comment 
accordingly :)
 
> If you wanted to be more clever, you could have a hash from fields to
> code references, where the referenced code does any special actions
> required for individual fields. You could then iterate through that hash
> with a 'foreach (keys %actions)' loop, grab each field value in turn,
> have the code ref - if it's defined - modify that value, and set the
> element in %pdata. It might be overkill, but on the other hand it might
> make your code less repetitive and therefore easier to maintain.

Here I'm lost.  What I sense here is that the hashtable would store code 
such that the code would execute based on which case?

Do you have a reference or two for documentation I can look at?  I think I 
need to do some research.  Thank you for your time!
 

-- 
-- Arcana


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

Date: Thu, 28 Dec 2000 01:20:07 -0500
From: "ben~" <hengst.1@osu.edu>
Subject: convert decimal to hex???
Message-Id: <92em6f$n1j$1@charm.magnus.acs.ohio-state.edu>

sorry i'm new to perl, but i cant find a way to convert an integer to a hex
value. I can do hex to integer but i need to go the other way. this is
something that should be obvious but i just spent the last hour and a half
looking through all the FAQ's that i can find and all the documentation that
i could dig up on perl monks and the o'reilly site but i still couldnt find
any thing??? there has to be a way to convert, please help. thanks so much.
ben hengst.1@osu.edu




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

Date: Thu, 28 Dec 2000 06:45:00 GMT
From: eric@taedium.com
Subject: Re: convert decimal to hex???
Message-Id: <MjB26.24579$bw.1724217@news.flash.net>

ben~ <hengst.1@osu.edu> wrote:
> sorry i'm new to perl, but i cant find a way to convert an integer to a hex
> value. I can do hex to integer but i need to go the other way. this is
> something that should be obvious but i just spent the last hour and a half
> looking through all the FAQ's that i can find and all the documentation that
> i could dig up on perl monks and the o'reilly site but i still couldnt find
> any thing??? there has to be a way to convert, please help. thanks so much.
> ben hengst.1@osu.edu

Use 'sprintf'.

	% perl -e '$,="\n"; @a=(0..20); print map { sprintf "%x", $_ } @a;'



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

Date: Thu, 28 Dec 2000 02:10:06 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Different handles in a variable
Message-Id: <468l4tcblnjvdijcnmsh5gshg83h7j82ui@4ax.com>

Simon Stiefel wrote:

>I'm writing a perl-script which allows to choose whether to print the
>result on the STDOUT or in a file.
>
>
>If the user want to print it on STDOUT, the script shall use:
>
>print STDOUT "Something...";
>
>
>And if the user want to write it in a file it uses a file-handle:
>
>print FILEXYZ "Something...";

You could just select() the handle, and simply print.

	select STDOUT;
	print "Something...";  # prints to STDOUT

	select FILEXYZ;
	print "Something...";  # prints to FILEXYZ

Need I add that these statements need not be right under each other, and
that you indeed may use many print statements for one select()?

-- 
	Bart.


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

Date: Thu, 28 Dec 2000 09:26:09 +0800
From: "John Lin" <johnlin@chttl.com.tw>
Subject: Re: FAQ 6.5:   How do I substitute case insensitively on the LHS, but preserving case on the RHS?
Message-Id: <92e4vm$3ji@netnews.hinet.net>

>         $_= "this is a TEsT case";
>
>         $old = 'test';
>         $new = 'success';
>
>         s{(\Q$old\E}
>          { uc $new | (uc $1 ^ $1) .
>             (uc(substr $1, -1) ^ substr $1, -1) x
>                 (length($new) - length $1)
>          }egi;
>
>         print;

/(test/: unmatched () in regexp at line 6.

Correction:

>         s{(\Q$old\E}

           s{(\Q$old\E)}

John Lin




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

Date: Thu, 28 Dec 2000 04:49:00 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: FAQ 6.5:   How do I substitute case insensitively on the LHS, but preserving case on the RHS?
Message-Id: <x7zohh9mmb.fsf@home.sysarch.com>

>>>>> "JL" == John Lin <johnlin@chttl.com.tw> writes:

  JL> Correction:

  >> s{(\Q$old\E}

  JL>            s{(\Q$old\E)}

do an email reply to the OP so that can get fixed.

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Thu, 28 Dec 2000 02:40:43 GMT
From: nb-news@Xusa.netREMOVEX (Neerav)
Subject: Free win32 Perl IDE+easiest way to start learning Perl
Message-Id: <3a4aa817.1000589@news.optusnet.com.au>

hi

I have looked extensively on the Net for a free IDE to use with the
ActiveState Perl 5.6 i just downloaded and have been unable to find
one. i tried CodeMagic but found it was a 30 day demo which is
useless.

I Also, I would appreciate it if someone could tell me a good way to
learn Perl, and how Perl works is it eg: compiled like C++ or
interpreted on the fly by a web browser or what?



Cya L8er

Neerav :-]

Webmaster of the Adextinguisher homepage.
Adextinguisher is a freeware banner ad blocking program
located at http://adext.magenet.com


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

Date: Thu, 28 Dec 2000 07:07:22 GMT
From: simplitia@my-deja.com
Subject: Re: Free win32 Perl IDE+easiest way to start learning Perl
Message-Id: <92eor8$o6h$1@nnrp1.deja.com>

In article <3a4aa817.1000589@news.optusnet.com.au>,
  nb-news@Xusa.netREMOVEX wrote:
> hi
>
> I have looked extensively on the Net for a free IDE to use with the
> ActiveState Perl 5.6 i just downloaded and have been unable to find
> one. i tried CodeMagic but found it was a 30 day demo which is
> useless.

###############################

try using perl scripting tool, its free if and has a really good
interface-even has a very nice html converter.


> I Also, I would appreciate it if someone could tell me a good way to
> learn Perl, and how Perl works is it eg: compiled like C++ or
> interpreted on the fly by a web browser or what?

there are ways to compile perl to .exe such as perl2exe but mostly it
is scripting language that gets intepreted everytime it runs.  for web
use cgi-or build into apache module etc.

learning perl like learning any language requires a few good books, but
mostly you need to really get your feet wet and dive right into it!
hope this helps.


Sent via Deja.com
http://www.deja.com/


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

Date: Wed, 27 Dec 2000 19:35:11 -0800
From: Tonghang Zhou <tonghang@transmeta.com>
Subject: in C++, multiple interpreterts w/ extension
Message-Id: <977976186.745602@palladium.transmeta.com>

I need someone tell me how to do this or that it cannot be done.
I am embedding multiple perl interpreters in my C++ program.
This works fine.  I then put in an extension to the perl interpreter,
say an Add function, in C++ to be called from the perl programs that
are interpreted.  I then run 2 perl programs like this:

    myprog 1.pl 2.pl

If only one of them uses the extension (Add), then this works.
However, if both uses Add, then it does not work.  E.g., if
1.pl and 2.pl are identical like this

    use Add;
    print add(1, 2), "\n";

I get a seg fault, right at the second perl_parse() call.

Please advice me on how to deal with this problem.  Please copy
me (tonghang@transmeta.com).

The main program is something like:

     PerlInterpreter *one_perl = perl_alloc();
     PerlInterpreter *two_perl = perl_alloc();

     char *one_args[] = { "one_perl", argv[1] };
     char *two_args[] = { "two_perl", argv[2] };

     perl_construct(one_perl);
     perl_construct(two_perl);

     perl_parse(one_perl, xs_init, 2, one_args, 0);
     perl_parse(two_perl, xs_init, 2, two_args, 0);

     perl_run(one_perl);
     perl_run(two_perl);
     ...

and I use these to generate the wrapper and loader

    h2xs -O -n Add -x `pwd`/add.h
    perl -MExtUtils::Embed -e xsinit -- -o xsinit.c -std Add

Thanks,
Tonghang



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

Date: Thu, 28 Dec 2000 16:59:33 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: NEED SCRIPTING DONE
Message-Id: <slrn94llm5.2ud.mgjv@martien.heliotrope.home>

[Cc sent to ppdc@home.com, posted to comp.lang.perl.misc]

On Thu, 28 Dec 2000 00:40:43 GMT,
	alan feiler <ppdc@home.com> wrote:
> can work remote.
> thanks ppdc@ppdc.net

Will you PLEASE stop posting this crud in this newsgroup? You were told
the first time around to go to one of the groups with job in the name
somewhere, and hire someone from there. Do not post here. This group is
for discussions about Perl, not for job seeking or offering.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | In a world without fences, who needs
Commercial Dynamics Pty. Ltd.   | Gates?
NSW, Australia                  | 


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

Date: Thu, 28 Dec 2000 02:07:36 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Our question - Possible Legacy code question...
Message-Id: <828l4tsagi2vgs8s8mg8l97ckukuf48g7b@4ax.com>

Joel Ricker wrote:

>our() never comes up as an error.

In an old 5.004 Perl, I'm not surprised. Look at this:

	our($x, $y, $z);

If "our" isn't recoginized as a keyword, this looks just like a sub
call. So it's not a syntax error. Hence, "strict" will just complain
about undeclared variables.

-- 
	Bart.


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

Date: Thu, 28 Dec 2000 14:11:43 +1100
From: Raymond WAN <rwan@cs.mu.OZ.AU>
Subject: Re: Perl's BigInts/BigFloats
Message-Id: <Pine.LNX.3.96.1001228105425.16975B-100000@vike.cs.mu.OZ.AU>


Hello,

On 27 Dec 2000, Ilya Zakharevich wrote:
> who wrote in article <3A4A09C2.F9F87BF6@penvision.com>:
> > In the above code, $a is just a regular Perl scalar which Perl converts
> > to a string or number depending on context.  To get a true "BigFloat",
> > you MUST do this:
> > 	use Math::BigFloat;
> > 	$a = new Math::BigFloat "3.45e+1000";
> Apparently, nobody cares much about BigFloat to make

	Well, that isn't true since at least one person (me, the person
who posted the original question) is interested in this discussion.  I
don't know why no one else other than Dan has replied to my query, but
perhaps no one else uses BigFloats or BigInts in Perl as much as I do.
Or, maybe others feel that Dan has given a good enough reply to answer my
query.  :)  Either way, his replies (or your replies, if you're reading,
Dan), is very much appreciated...as is your's Ilya.

	However,

>   perl -MMath::BigFloat=:constant -wle '$a = (1+1e-20)**1e20; print $a'

	I don't know what you're trying to do here, but it looks like
you're assuming that I need to calculate a number at a time.  I can't run
perl on the command line like that because my entire program with all its
loops and stuff needs BigInts.

	I guess my mistake was that I've used perl for months now but have
only learned what I needed.  I never knew how to create objects, but I
needed BigInts...so I'm now stuggling with this problem.  Always thought
that the cool part about Perl was that you didn't have to learn a lot to
get a decent program working -- something that isn't true with C/C++/etc.

	Thank you for your reply!

Ray





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

Date: Thu, 28 Dec 2000 14:18:09 +1100
From: Raymond WAN <rwan@cs.mu.OZ.AU>
Subject: Re: Perl's BigInts/BigFloats
Message-Id: <Pine.LNX.3.96.1001228141343.17125C-100000@vike.cs.mu.OZ.AU>


Hi Dan,

On Wed, 27 Dec 2000, Dan Harasty wrote:
> >         $a = "4000000000000";
> >         And it knew $a was a BigFloat as opposed to doing the same without
> > quotes....
> You are observing two things, and coming to the wrong conclusion:
> 	1) Perl converts strings to numbers when it needs to
> 	2) Perl (somehow) implements integers > 2**32

	Oh...then maybe I've been ahead of myself all this time.  If Perl
implements integers > 2^32, what is the purpose of creating BigInts?

	However, if I had:

$a = 2^32 + 1

	I would get overflow.  In order not to overflow, I have to write
"2^32" with quotes as a string.  Then, adding 1 is ok.  That is, even
though it converts strings to numbers as needed, when the computer
architecture's limit is reached, a little `push' is needed by me to tell
Perl there might be overflow.

	Of course, you pointed out something important to me and I think
it would be safer to just new BigInts; my current solution seems a bit
hacky...  =)

	Thanks for your replies!  :)

Ray




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

Date: 28 Dec 2000 04:41:44 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Perl's BigInts/BigFloats
Message-Id: <92ega8$kop$1@charm.magnus.acs.ohio-state.edu>

[A complimentary Cc of this posting was sent to Raymond WAN 
<rwan@cs.mu.OZ.AU>],
who wrote in article <Pine.LNX.3.96.1001228105425.16975B-100000@vike.cs.mu.OZ.AU>:
> >   perl -MMath::BigFloat=:constant -wle '$a = (1+1e-20)**1e20; print $a'
> 
> 	I don't know what you're trying to do here, but it looks like
> you're assuming that I need to calculate a number at a time.  I can't run
> perl on the command line like that because my entire program with all its
> loops and stuff needs BigInts.

If it is BigInt, and not BigFloat, then :constant *is* available.

Ilya


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

Date: Thu, 28 Dec 2000 03:29:26 GMT
From: Arcana <emerald-arcana@home.com>
Subject: Piping output from one script into another
Message-Id: <qsy26.30103$59.9269492@news3.rdc1.on.home.com>

Hi,

I have a Perl script that prints stuff to the screen using "print".  (It 
prints a variable-length record to the screen).  The script is called 
"psheet.pl" and it accepts 1 argument, a filename.

I want to be able to pipe this output into the arguments of another Perl 
script (so that the record from Script 1 becomes the arguments for Script 
2).  This script is called "pdata.pl" and is supposed to accept the record 
as an argument.

I'm running a GNU-Linux system with Bash 2.03.19, and I have tried the 
following:

1)      ./psheet.pl p-sheet.txt | ./pdata.pl
                (Arguments aren't recognized)
2)      ./psheet.pl p-sheet.txt > data
        ./pdata.pl < data

I've also tried a code change so that there would be a return inside the 
main block, but Perl doesn't like that either.  :|

I've tried modifing the code in Script 2 (./pdata.pl) so that it reads from 
STDIN rather than arguments and it works fine like that if I use
        while (<STDIN>)

Maybe I'm going about this the wrong way?  Comments and suggestions would 
be appreciated!  Thank you very much for your time.
-- 
-- Arcana


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

Date: Thu, 28 Dec 2000 07:30:54 +0000
From: bgi4711-for-news-use-only@this-is-a-valid-mailaddress-but-please-do-not-spam-me.de (Bernd Giegerich)
Subject: Re: Piping output from one script into another
Message-Id: <e7qe29.bao.ln@news.b-giegerich.de>

Hi,

your queston is more about bash than perl...

>I have a Perl script that prints stuff to the screen using
>"print".  (It prints a variable-length record to the screen).  The
>script is called "psheet.pl" and it accepts 1 argument, a
>filename. 

If you want pdata.pl to get the output of psheet.pl as a command line 
argument, you should use backticks:

 ./pdata.pl `./psheet.pl p-sheet.txt`

Regards,
Bernd


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

Date: Thu, 28 Dec 2000 05:15:51 GMT
From: Rajiv Eranki <sNiOgmSa@PmAaMth.net>
Subject: References (I'm not sure if the old message posted)
Message-Id: <281220000015517997%sNiOgmSa@PmAaMth.net>

'lo all.

I have a slight problem with references.

Here's the situation:
I have a hash of areas, %world. This hash is blessed later and return
as a reference.

Now, each key in that hash is a scalar string, like "Venus".
Each value to that hash is a reference to another hash, which contains
information on that particular hash. So that the key "Venus" might
point to a hash which contains keys like albedo or mass.

e.g.
world = {
"Venus" => \%info
etc.
}

The problem is, I need to create a "new" info hash, edit it, and point
the planet to it each time I want to add a planet to the list.

This is all in a loop. The first time I tried it, obviously all the
planets pointed to the same hash, because I was modifying _that_ hash
all through the loop. How can I make the %info hash reference to a new
generic hash each time?

Ugh. I hope I made myself clear. If not, here's an example of what I
want to do:


#!/usr/bin/perl

for ($a = 0; $a < 5; $a++) {
        $b = rand;
        $hash{$a} = \$b;
}

foreach (keys %hash) {
        print "$_    ${$hash{$_}}\n";
}


So each value $a in the hash needs to point to a new $b. In my program,
$b happens to be an array, but that shouldn't make much of a
difference. The principle is the same.



Thanks a bunch!


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

Date: Thu, 28 Dec 2000 06:33:46 GMT
From: egwong@netcom.com
Subject: Re: References (I'm not sure if the old message posted)
Message-Id: <e9B26.24569$bw.1724217@news.flash.net>

You have a scoping problem.  If you want to be referencing a new
(different) variable in every iteration of a loop, you want to be using
'my'.

Run this code and compare the output:

    #!/usr/bin/perl -w

	use strict;

    my %hash1 = ();
    my %hash2 = ();

	my $value1 = 'foo';
    
    foreach my $key ( 1..5 ) {
       $value1 = 'foo';
       $hash1{$key} = \$value1;
    
       my $value2 = 'foo';
       $hash2{$key} = \$value2;
    }
    
    foreach my $key ( keys %hash1 ) {
       printf( "%s: %p %p\n", $key, ${$hash1{$key}}, ${$hash2{$key}} );
    }

What you're doing is exactly like what happening to %hash1, every
value in %hash1 is assigned a refernce to the same variable.  What
you want is like what's happening to %hash2, every value in %hash2
has a ref to its own var.

There used to be a pretty good article about scopes on www.perl.com,
but I can't seem to find it anymore.   The "perlsyn" manpage probably
has something to say about this (look for the section on "Foreach
Loops")

By the way, you should always be using 'strict'.  Not only does it help
you keep your code clean, it also makes this sort of scoping problem
immediately obvious.





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

Date: Thu, 28 Dec 2000 02:54:56 GMT
From: georgebailey@my-deja.com
Subject: Re: Sending Zero Values from Forms
Message-Id: <92ea1u$dje$1@nnrp1.deja.com>

In article <i47l4t4pmo32c7nfaqb6op54bjk2ct1iqg@4ax.com>,
  Bart Lateur <bart.lateur@skynet.be> wrote:
> >I'm sure I'm missing something obvious. I used the parse_form
> >subroutine from FormMail.pl, one of the scripts from Matt Wright.
>
> Oh dear. A good recipe for a certain disaster.
>
> I've grabbed the source ...

> and this snippet here looks like a good candidate for a culprit:
>
>             if ($Form{$name} && $value) {
>                 $Form{$name} = "$Form{$name}, $value";
>             }
>             elsif ($value) {
>                 push(@Field_Order,$name);
>                 $Form{$name} = $value;
>             }
>
> I don't know what you made of this. As you might have guessed by now,
> $value = "0" is false. Therefore, neither of the above will catch it.

Yeah you know what, I feel foolish but that's indeed what I realised
about twenty minutes after my original post! I didn't exactly figure it
out, but I deleted it and everything was fine. How embarrassing.

The value is "0", and the if clause says "if($value)" and it returns a
"false". Oh well. I'm learning. Thanks for your help.

--
~~ ...and dance by the light of the moon


Sent via Deja.com
http://www.deja.com/


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

Date: Thu, 28 Dec 2000 08:37:42 +0100
From: "Nikola" <nkavecan@Eunet.yu>
Subject: Setting locale failed
Message-Id: <92eqq0$peg$1@SOLAIR2.EUnet.yu>

This is not maybe for this group, but maybe it is.

I had Linux Red Hat 6.2. When I enter command Perl, the answer is next:

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
 LANGUAGE = (unset),
 LC_ALL = (unset),
 LANG = "en_US"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

How can I set this?


Nikola




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

Date: Thu, 28 Dec 2000 08:01:21 GMT
From: rgarciasuarez@free.fr (Rafael Garcia-Suarez)
Subject: Re: Setting locale failed
Message-Id: <slrn94lt6u.eae.rgarciasuarez@rafael.kazibao.net>

Nikola wrote in comp.lang.perl.misc:
> This is not maybe for this group, but maybe it is.
> 
> I had Linux Red Hat 6.2. When I enter command Perl, the answer is next:
> 
> perl: warning: Setting locale failed.
> perl: warning: Please check that your locale settings:
>  LANGUAGE = (unset),
>  LC_ALL = (unset),
>  LANG = "en_US"
>     are supported and installed on your system.
> perl: warning: Falling back to the standard locale ("C").

Read the perllocale manpage (the section on 'LOCALE PROBLEMS'.) Your
problem is described here and some fixes are suggested.

-- 
# Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
$japh="Just another Perl hacker,\n";@j=split/(?= )/,$japh;for my $i
(0..3){*{(($x)=$j[3-$i]=~/\w+/g)[0]}=sub(@){print$j[$i]}}eval$japh;


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

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

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 5210
**************************************


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