[32121] in Perl-Users-Digest
Perl-Users Digest, Issue: 3386 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 18 18:09:24 2011
Date: Wed, 18 May 2011 15:09:07 -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 Wed, 18 May 2011 Volume: 11 Number: 3386
Today's topics:
"Bareword found" in 'print $fh fun();' <RedGrittyBrick@spamweary.invalid>
Re: "Bareword found" in 'print $fh fun();' <RedGrittyBrick@spamweary.invalid>
Re: "Bareword found" in 'print $fh fun();' <uri@StemSystems.com>
Re: "Bareword found" in 'print $fh fun();' <kst-u@mib.org>
Re: a program that looks up majority item <tadmc@seesig.invalid>
Re: a program that looks up majority item <jimsgibson@gmail.com>
Re: a program that looks up majority item <ela@yantai.org>
Just askin'... <Joey@still_Learning.invalid>
Re: Just askin'... <uri@StemSystems.com>
Re: Just askin'... <bugbear@trim_papermule.co.uk_trim>
Re: Just askin'... <RedGrittyBrick@spamweary.invalid>
Re: Just askin'... <tzz@lifelogs.com>
Re: Just askin'... <kst-u@mib.org>
Re: Just askin'... <Joey@still_Learning.invalid>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 17 May 2011 17:36:00 +0100
From: RedGrittyBrick <RedGrittyBrick@spamweary.invalid>
Subject: "Bareword found" in 'print $fh fun();'
Message-Id: <4dd2a3f1$0$2504$db0fefd9@news.zen.co.uk>
For the following script, perl 5.8.0 produces the warning message:
Bareword found where operator expected at t1.pl line 6, near "$fh fun"
(Missing operator before fun?)
----------------------------8<---------------------------------
#!/usr/bin/perl
use strict;
use warnings;
open my $fh, '>>', 't1.txt' or die "can't open t1.txt - $!\n";
print $fh fun();
close $fh;
sub fun {
return "fun\n";
}
----------------------------8<---------------------------------
Have I blundered?
I can avoid this warning by changing fun() to &fun() but is there a
better way?
--
RGB
------------------------------
Date: Tue, 17 May 2011 18:25:41 +0100
From: RedGrittyBrick <RedGrittyBrick@spamweary.invalid>
Subject: Re: "Bareword found" in 'print $fh fun();'
Message-Id: <4dd2af96$0$12154$fa0fcedb@news.zen.co.uk>
On 17/05/2011 17:36, RedGrittyBrick wrote:
> For the following script, perl 5.8.0 produces the warning message:
>
> Bareword found where operator expected at t1.pl line 6, near "$fh fun"
> (Missing operator before fun?)
>
> ----------------------------8<---------------------------------
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> open my $fh, '>>', 't1.txt' or die "can't open t1.txt - $!\n";
> print $fh fun();
> close $fh;
>
> sub fun {
> return "fun\n";
> }
> ----------------------------8<---------------------------------
>
> Have I blundered?
>
> I can avoid this warning by changing fun() to &fun() but is there a
> better way?
>
Forward declare fun.
----------------------------8<---------------------------------
#!/usr/bin/perl
use strict;
use warnings;
sub fun();
open my $fh, '>>', 't1.txt' or die "can't open t1.txt - $!\n";
print $fh fun();
close $fh;
sub fun() {
return "fun\n";
}
----------------------------8<---------------------------------
Apologies for noise.
--
RGB
------------------------------
Date: Tue, 17 May 2011 13:36:30 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: "Bareword found" in 'print $fh fun();'
Message-Id: <874o4ttejl.fsf@quad.sysarch.com>
>>>>> "R" == RedGrittyBrick <RedGrittyBrick@spamweary.invalid> writes:
R> Forward declare fun.
R> sub fun();
R> open my $fh, '>>', 't1.txt' or die "can't open t1.txt - $!\n";
R> print $fh fun();
R> close $fh;
you could probably put + before the call to fun() so perl knows it is an
expression. also i don't like the indirect handle style so you could do
$fh->print( fun() ) ;
you may need to load IO::Handle or something that supports the OO style.
another solution would be to put the handle in a block and perl will
know what follows is the expression:
print {$fh} fun() ;
i think it is the trailing () on fun that is making perl warn. it is
legal code but something is blowing up the parse like it thinks the ()
are for the print or something.
so there are several solutions other than predeclaring fun().
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Wed, 18 May 2011 10:48:49 -0700
From: Keith Thompson <kst-u@mib.org>
Subject: Re: "Bareword found" in 'print $fh fun();'
Message-Id: <lnei3v527y.fsf@nuthaus.mib.org>
RedGrittyBrick <RedGrittyBrick@spamweary.invalid> writes:
> For the following script, perl 5.8.0 produces the warning message:
>
> Bareword found where operator expected at t1.pl line 6, near "$fh fun"
> (Missing operator before fun?)
>
> ----------------------------8<---------------------------------
> #!/usr/bin/perl
> use strict;
> use warnings;
>
> open my $fh, '>>', 't1.txt' or die "can't open t1.txt - $!\n";
> print $fh fun();
> close $fh;
>
> sub fun {
> return "fun\n";
> }
> ----------------------------8<---------------------------------
>
> Have I blundered?
>
> I can avoid this warning by changing fun() to &fun() but is there a
> better way?
Use a newer version of Perl.
I get the same error with Perl 5.6.1, but not with 5.8.8 or 5.10.1.
(Yes, predeclaring fun() should be a workaround.)
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
------------------------------
Date: Tue, 17 May 2011 08:24:16 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: a program that looks up majority item
Message-Id: <slrnit4te5.riu.tadmc@tadbox.sbcglobal.net>
ela <ela@yantai.org> wrote:
> sub query
> {
> for(my $i=$#{$data{$_[0]}}; $i>=0; $i--)
> {
> foreach my $RANK (sort {$b <=> $a} keys %{$data{$_[0]}->[$i]})
>
> {
> return [$col[$i], $data{$_[0]}->[$i]->{$RANK}, $RANK], if $RANK >= $_[1]
> }
> }
>
> ['',[]]
> }
Something horrible has happened to the formatting of your code...
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.
------------------------------
Date: Tue, 17 May 2011 11:19:43 -0700
From: Jim Gibson <jimsgibson@gmail.com>
Subject: Re: a program that looks up majority item
Message-Id: <170520111119435903%jimsgibson@gmail.com>
In article <iqt2dp$oub$1@ijustice.itsc.cuhk.edu.hk>, ela
<ela@yantai.org> wrote:
> Dear all,
>
> Some months ago a guy (sorry I've forgot his name...) kindly provided me the
> following program and it worked properly. The program is to look up an input
> table that contains rows of entries (classified by the first field/cell, the
> following NODE_124_length_77_cov_13.792208 is one while
> NODE_199_length_77_cov_13.792208 is another) and identifies the major
> category based on a given threshold (e.g. >50%). If threshold of 50% is
> given, the answer "Escherichia coli" should be returned because it occurs 4
> out of 6 times. If larger threshold, say, 80%, then "undef" (5/6) should
> return. If 100% given, Not-available is returned. While now I'd like to
> reuse this program, it doesn't work again. I know the most correct approach
> is to study the whole program again but then it will involve another month
> for me to pick up all the Perl data structure (here complex data structure
> is used...). Since I have to meet up a deadline by this weekend, I was
> wondering if there might be anybody could help figure out the only error
> "Skip line number XXXXX because it have YYYYY". I'd highly appreciate for
> any hints. --Ela
Your program reads the first line to get what look like column headers
and then reads in data lines, which are expected to have some number of
columns based upon the number of columns in the header line. If the
number of columns in a data line are not what is expected, the line is
skipped and the warning message "Skip line ..." is printed.
However, your program calls ReadData() to read in the data file. Within
that subroutine, it uses the value of $start to figure out where the
first column of interest is.
The program then returns to the main program, where is re-opens the
input file and reads the first line to figure out which column contains
the header 'Superkingdom' and sets the value of $start to the index of
that column.
That would seem to be a logic error.
If you want more help, please do this:
1. Reformat your program so that it is readable.
2. Replace the output file with simple print statements.
3. Replace the input file with data following a __DATA__ line.
4. Set the value of $thr so we don't have to guess what the input
parameter might be.
Thanks.
<program snipped>
--
Jim Gibson
------------------------------
Date: Wed, 18 May 2011 23:21:10 -0700
From: "ela" <ela@yantai.org>
Subject: Re: a program that looks up majority item
Message-Id: <ir0khg$39k$1@ijustice.itsc.cuhk.edu.hk>
"Jim Gibson" <jimsgibson@gmail.com> wrote in message
news:170520111119435903%jimsgibson@gmail.com...
> In article <iqt2dp$oub$1@ijustice.itsc.cuhk.edu.hk>, ela
> <ela@yantai.org> wrote:
>
> If you want more help, please do this:
>
> 1. Reformat your program so that it is readable.
> 2. Replace the output file with simple print statements.
> 3. Replace the input file with data following a __DATA__ line.
> 4. Set the value of $thr so we don't have to guess what the input
> parameter might be.
>
> Thanks.
>
> Jim Gibson
Thanks a lot! I'll first read your comments and try to revise it. :-)
------------------------------
Date: Tue, 17 May 2011 19:23:52 -0700
From: "Joey@still_Learning.invalid" <Joey@still_Learning.invalid>
Subject: Just askin'...
Message-Id: <o6b6t654m3vkj26t9e2anspfb0l2n2lace@4ax.com>
Trying to learn...
I create a variable, say $abc, by setting bits. Later, I want to test
whether any of the first several bits are set. I tried $abc && 191, but
always get 191. If I compare $abc & 191, I get the correct result. Why do
I have to do a bit comparison?
--
Joey
------------------------------
Date: Wed, 18 May 2011 00:21:10 -0400
From: "Uri Guttman" <uri@StemSystems.com>
Subject: Re: Just askin'...
Message-Id: <87ei3wmyfd.fsf@quad.sysarch.com>
>>>>> "JLi" == Joey@still Learning invalid <Joey@still_Learning.invalid> writes:
JLi> I create a variable, say $abc, by setting bits. Later, I want to
JLi> test whether any of the first several bits are set. I tried $abc
JLi> && 191, but always get 191. If I compare $abc & 191, I get the
JLi> correct result. Why do I have to do a bit comparison?
read perldoc perlop. & and && are VERY different operators. and you
should use hex, octal or even binary constants to deal with
bits. decimals are not easy to convert in our heads to bit masks.
uri
--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------
------------------------------
Date: Wed, 18 May 2011 09:39:28 +0100
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: Just askin'...
Message-Id: <2pydnQAfsN1dGE7QnZ2dnUVZ8g-dnZ2d@brightview.co.uk>
Uri Guttman wrote:
>>>>>> "JLi" == Joey@still Learning invalid<Joey@still_Learning.invalid> writes:
>
> JLi> I create a variable, say $abc, by setting bits. Later, I want to
> JLi> test whether any of the first several bits are set. I tried $abc
> JLi> && 191, but always get 191. If I compare $abc& 191, I get the
> JLi> correct result. Why do I have to do a bit comparison?
>
> read perldoc perlop.& and&& are VERY different operators. and you
> should use hex, octal or even binary constants to deal with
> bits. decimals are not easy to convert in our heads to bit masks.
A mere coupla' years practice works for most people ;-)
BugBear
------------------------------
Date: Wed, 18 May 2011 12:04:29 +0100
From: RedGrittyBrick <RedGrittyBrick@spamweary.invalid>
Subject: Re: Just askin'...
Message-Id: <4dd3a7bf$0$12172$fa0fcedb@news.zen.co.uk>
On 18/05/2011 09:39, bugbear wrote:
> Uri Guttman wrote:
>>>>>>> "JLi" == Joey@still Learning invalid<Joey@still_Learning.invalid>
>>>>>>> writes:
>>
>> JLi> I create a variable, say $abc, by setting bits. Later, I want to
>> JLi> test whether any of the first several bits are set. I tried $abc
>> JLi> && 191, but always get 191. If I compare $abc& 191, I get the
>> JLi> correct result. Why do I have to do a bit comparison?
>>
>> read perldoc perlop.& and&& are VERY different operators. and you
>> should use hex, octal or even binary constants to deal with
>> bits. decimals are not easy to convert in our heads to bit masks.
>
> A mere coupla' years practice works for most people ;-)
Same as the 10 years it takes to properly understand the use of binary?
--
RGB
------------------------------
Date: Wed, 18 May 2011 08:57:56 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Just askin'...
Message-Id: <87ipt8rtzv.fsf@lifelogs.com>
On Wed, 18 May 2011 12:04:29 +0100 RedGrittyBrick <RedGrittyBrick@spamweary.invalid> wrote:
R> On 18/05/2011 09:39, bugbear wrote:
>> Uri Guttman wrote:
>>> decimals are not easy to convert in our heads to bit masks.
>> A mere coupla' years practice works for most people ;-)
R> Same as the 10 years it takes to properly understand the use of binary?
A binary adder walks into a bar and says "can you make me overflow
before 11?"
Ted
------------------------------
Date: Wed, 18 May 2011 10:42:48 -0700
From: Keith Thompson <kst-u@mib.org>
Subject: Re: Just askin'...
Message-Id: <lnipt752hz.fsf@nuthaus.mib.org>
"Joey@still_Learning.invalid" <Joey@still_Learning.invalid> writes:
> Trying to learn...
>
> I create a variable, say $abc, by setting bits. Later, I want to test
> whether any of the first several bits are set. I tried $abc && 191, but
> always get 191. If I compare $abc & 191, I get the correct result. Why do
> I have to do a bit comparison?
You have to do a bit comparison because you're comparing bits.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
------------------------------
Date: Wed, 18 May 2011 13:33:28 -0700
From: "Joey@still_Learning.invalid" <Joey@still_Learning.invalid>
Subject: Re: Just askin'...
Message-Id: <08b8t6hak201jr0m1nrmq8pfrdgs4gd9u4@4ax.com>
Keith Thompson wrote:
>"Joey@still_Learning.invalid" <Joey@still_Learning.invalid> writes:
>> Trying to learn...
>>
>> I create a variable, say $abc, by setting bits. Later, I want to test
>> whether any of the first several bits are set. I tried $abc && 191, but
>> always get 191. If I compare $abc & 191, I get the correct result. Why do
>> I have to do a bit comparison?
>
>You have to do a bit comparison because you're comparing bits.
Thanks, Keith.
--
Joey
------------------------------
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:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#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 V11 Issue 3386
***************************************