[25664] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7905 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Mar 22 14:05:28 2005

Date: Tue, 22 Mar 2005 11:05:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 22 Mar 2005     Volume: 10 Number: 7905

Today's topics:
    Re: == operator acts differently in perl 5.005_03 and 5 (Anno Siegel)
    Re: @ARGV not getting command line arguments <tim@vegeta.ath.cx>
    Re: @ARGV not getting command line arguments <felix.geerinckx@gmail.com>
        [perl-python] sorting matrixes <xah@xahlee.org>
    Re: [perl-python] sorting matrixes <tzot@sil-tec.gr>
        Extracting words using Regular Expressions <nospam@nospam.com>
    Re: Extracting words using Regular Expressions <mritty@gmail.com>
    Re: Extracting words using Regular Expressions <noreply@gunnar.cc>
        how to capture large output in a perl variable <vinay.sambamurthy@gmail.com>
    Re: how to capture large output in a perl variable xhoster@gmail.com
    Re: Net::FTP <mritty@gmail.com>
    Re: piping cmd output  problem xhoster@gmail.com
        regular expression Help <jtripo@hotmail.com>
    Re: regular expression Help <1usa@llenroc.ude.invalid>
    Re: regular expression Help <Im.so.HuckinFappy@spamgourmet.com>
        The error "Use of uninitialized value " <metri.jain@gmail.com>
    Re: The error "Use of uninitialized value " <phaylon@dunkelheit.at>
    Re: The error "Use of uninitialized value " (Gary E. Ansok)
    Re: The error "Use of uninitialized value " <1usa@llenroc.ude.invalid>
    Re: The error "Use of uninitialized value " <Im.so.HuckinFappy@spamgourmet.com>
    Re: The error "Use of uninitialized value " <1usa@llenroc.ude.invalid>
    Re: The error "Use of uninitialized value " <spamtrap@dot-app.org>
    Re: The error "Use of uninitialized value " (Gary E. Ansok)
    Re: The error "Use of uninitialized value " <spamtrap@dot-app.org>
    Re: The error "Use of uninitialized value " <1usa@llenroc.ude.invalid>
    Re: The error "Use of uninitialized value " <1usa@llenroc.ude.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 22 Mar 2005 17:44:57 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: == operator acts differently in perl 5.005_03 and 5.8.2
Message-Id: <d1plip$2p3$1@mamenchi.zrz.TU-Berlin.DE>

Jürgen Exner <jurgenex@hotmail.com> wrote in comp.lang.perl.misc:
> Yahav wrote:
> > Second, my current solution is to multiply each of the numbers by one,
> > and then i get the same number...
> > Maybe there's other (maybe better) ways of overtaking this..
> 
> Arrrrg, if you quoting Tad's hint for the FAQ, then why don't you actually 
> read _and_follow_ it?
> Obviously you must have missed the first class in Introduction to Computer 
> Numerics, therefore here a summary:
> 
>     Thou shalt not compare floating point numbers for equality!
> 
> If you must then use an epsilon distance instead.

A quick and dirty way is to use string compare for floats.

Anno


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

Date: Tue, 22 Mar 2005 16:34:00 GMT
From: Tim Hammerquist <tim@vegeta.ath.cx>
Subject: Re: @ARGV not getting command line arguments
Message-Id: <slrnd40i7q.skt.tim@vegeta.saiyix>

bkimelman@hotmail.com <bkimelman@hotmail.com> wrote:
[ snip ]
>  When I run a Perl script from the DOS command line the parameters
>  I specify are not placed into @ARGV !!! (This does not happen on my
>  Windows XP PC at home !)
>  
[ snip ]
>  
>  When I call the above script (named args.pl) as follows :
>  
>  args.pl hello world
>  
>  the output is :     ARGS [0]
>  
>  Where are my missing parameters ?

Run the script as "perl args.pl hello world" and see if the args show up
in @ARGV when run that way.  If this method works, it sounds like
a CMD.EXE issue that I've run into before, and it wouldn't be a perl
issue.  Maybe a Windows perl guru can help, as I gave up the WinHabit
several years ago.

HTH,
Tim Hammerquist


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

Date: Tue, 22 Mar 2005 17:25:58 GMT
From: "Felix Geerinckx" <felix.geerinckx@gmail.com>
Subject: Re: @ARGV not getting command line arguments
Message-Id: <xn0e029an17dcf003@news.easynews.com>

On 22/03/2005, bkimelman@hotmail.com wrote:

> When I run a Perl script from the DOS command line the parameters I
> specify are not placed into @ARGV !!! 

When you type 

	ftype Perl

at the CMD prompt, do you get something like

	Perl="C:\Perl\bin\perl.exe" "%1" %*

If not, type

	help ftype

-- 
felix


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

Date: 22 Mar 2005 09:02:51 -0800
From: "Xah Lee" <xah@xahlee.org>
Subject: [perl-python] sorting matrixes
Message-Id: <1111510971.238323.82120@g14g2000cwa.googlegroups.com>

Today we'll write a program that can sort a matrix in all possible
ways.

Here's the Perl documentation. I'll post a Perl and Python version in 2
days.

-----------

sort_matrix( $matrix, [[$n1, $stringQ, $directionQ], [$n2, $stringQ,
$directionQ], ...]) sorts a matrix by $n1 th column then $n2 th...and
so on.

$matrix must be a reference to references of arrays, having the form
[[$e1, $e2,...], [...], ...].  $stringQ is a boolean indicating
whether to treat corresponding columns as a strings instead of as
number in the sorting process. True means string. $directionQ is a
boolean indicating ascending sort or not for the correpsonding
column. In the column spec $n1 $n2 ..., index counting starts at 0.

 Example:

 my $ref_matrix =
 [
   [3, 99, 'a'],
   [2, 77, 'a'],
   [1, 77, 'a']
 ];

sort_matrix( $ref_matrix,  [ [2,1,1], [1,0,1] ]);
# this means sort by third column, regarding it as strings,
# and in ascending order. If tie, sort by second column,
# regarding it as number, in ascending order.

# returns [[2,77,'a'],[1,77,'a'],[3,99,'a']];

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

Note: in the above, ignore the "must be a reference to references of
arrays". That's technical point, because Perl the language do nested
lists thru workaround of "references".

http://xahlee.org/perl-python/sort_matrix.html



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

Date: Tue, 22 Mar 2005 20:19:00 +0200
From: Christos "TZOTZIOY" Georgiou <tzot@sil-tec.gr>
Subject: Re: [perl-python] sorting matrixes
Message-Id: <vao041peld7jv1ghgdvnl5v06i5m0jmh7j@4ax.com>

On 22 Mar 2005 09:02:51 -0800, rumours say that "Xah Lee" <xah@xahlee.org> might
have written:

>Today we'll write a program that can sort a matrix in all possible
>ways.
>
>Here's the Perl documentation. I'll post a Perl and Python version in 2
>days.

Don't bother writing a Python version... list.sort and its arguments are fine
and send their greetings.
-- 
TZOTZIOY, I speak England very best.
"Be strict when sending and tolerant when receiving." (from RFC1958)
I really should keep that in mind when talking with people, actually...


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

Date: Tue, 22 Mar 2005 13:43:39 -0500
From: "daniel kaplan" <nospam@nospam.com>
Subject: Extracting words using Regular Expressions
Message-Id: <1111517101.699735@nntp.acecape.com>

Hi All,

Am goign through an email to extract a particualr set of characters.
Actually I have no problem finding the line that has the characters I am
looking for:

if ( $line =~ /\&ck=[0-9]{4}/ )

That works great, but am unable to easily figure out then how to extract
just that word.  I realize it's a s/// scenario, but I can't seem to find
how to say to do so for everything BUT.  Character class wise I can, but not
for my own combo.

If anyone could point me to the right section or throw me a hint I would
appreciate it.

Thanks.





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

Date: Tue, 22 Mar 2005 18:51:41 GMT
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Extracting words using Regular Expressions
Message-Id: <1PZ%d.31803$db6.25283@trndny02>

daniel kaplan wrote:
> Hi All,
> 
> Am goign through an email to extract a particualr set of characters.
> Actually I have no problem finding the line that has the characters I am
> looking for:
> 
> if ( $line =~ /\&ck=[0-9]{4}/ )

'[0-9]' is more compactly written '\d'

> That works great, but am unable to easily figure out then how to extract
> just that word.  

What word?


> I realize it's a s/// scenario, 

It is?  What are you trying to search, and what are you trying to 
replace?  You don't mention replacing anywhere else in this post.

 > but I can't seem to find how to say to do so

to do what?

> for everything BUT.  

for everything BUT what???

> Character class wise I can, but not for my own combo.

What does this mean?

> If anyone could point me to the right section or throw me a hint I would
> appreciate it.

You need to take the time to more carefully compose a post.  This is all 
very jumbled, and it's not at all clear what you're trying to do.  You 
also haven't posted any sample input or desired output.  Have you read 
the Posting Guidelines for this group yet?

As a complete guess, I'd say you're looking to capture part of a match. 
  That involves the use of parentheses, which surround the part of the 
match you want to capture, which is then stored in $1, $2, $3, etc. 
Read more about them in

perldoc perlrequick
perldoc perlretut
perldoc perlre

If that's not what you're looking for, please try to restate your question.

Paul Lalli


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

Date: Tue, 22 Mar 2005 20:00:57 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Extracting words using Regular Expressions
Message-Id: <3ab87tF6alhluU1@individual.net>

daniel kaplan wrote:
> Am goign through an email to extract a particualr set of characters.
> Actually I have no problem finding the line that has the characters I am
> looking for:
> 
> if ( $line =~ /\&ck=[0-9]{4}/ )

The & character is not special in regular expressions, and [0-9] can be 
written \d

     if ( $line =~ /&ck=\d{4}/ )

> That works great, but am unable to easily figure out then how to extract
> just that word.

Just use parentheses to capture it.

     if ( $line =~ /(&ck=\d{4})/ ) {
         print 'Extracted string: ', $1, "\n";
     }

> I realize it's a s/// scenario,

The s/// operator is for substituting something, but if you just want to 
extract it, you don't need s///.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: 22 Mar 2005 09:04:20 -0800
From: "vsmurthy" <vinay.sambamurthy@gmail.com>
Subject: how to capture large output in a perl variable
Message-Id: <1111511060.614577.130790@z14g2000cwz.googlegroups.com>

Hi,
     I have just begun to use Perl for CGI programming. I have a
situation where I run a command on the server through my perl script
and try to retrieve the result of the command into a perl variable and
then I try to display it on the web page:

my $var = `property <dataid>`;
print "<td align="middle">$var</td>";

This command (property) sometimes produces an output of size almost
0.5Mb to 1Mb for some values of <dataid>(I checked the size of the
output by executing the "property" command on the web server CLI).

   I have 2 problems in capturing this output in the perl variable:
1] Only part of the output of the command is captured in the variable
when the output is large (i.e, when output size is greater than 0.1Mb).
How should I take care of this? Is there any feature in Perl to capture
very large output?

2] The other problem is that the output of the command has some XML in
it and when I capture it in the perl variable, the XML part is lost
(From the example below, all text between and including <List> and
</List> don't appear in the variable). How should one capture such data
since its not completely XML? Should I be using any PERL/XML functions?

Sample output:

Data <dataid> is not empty
Content has xxx entires:
------ similar text -------
------ similar text -------
  <List>
     <List1>123</List1>
     <List2>345</List2>
     ------------------
     ------------------
     <Listn>23</Listn>
  </List>
Loc has 40 files:
  filename-1
  filename-2
  ----------
  ----------
  ----------
  filename-40

Any help is greatly appreciated.

Thanks,
Vinay



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

Date: 22 Mar 2005 17:24:07 GMT
From: xhoster@gmail.com
Subject: Re: how to capture large output in a perl variable
Message-Id: <20050322122407.440$h0@newsreader.com>

"vsmurthy" <vinay.sambamurthy@gmail.com> wrote:
 ...

> my $var = `property <dataid>`;
> print "<td align="middle">$var</td>";
>
> This command (property) sometimes produces an output of size almost
> 0.5Mb to 1Mb for some values of <dataid>(I checked the size of the
> output by executing the "property" command on the web server CLI).
>
>    I have 2 problems in capturing this output in the perl variable:
> 1] Only part of the output of the command is captured in the variable
> when the output is large (i.e, when output size is greater than 0.1Mb).

I don't believe you:

$ perl
my $var = `perl -e 'print "x" x 100_000_000'`;
print length $var;
__END__
100000000


> How should I take care of this? Is there any feature in Perl to capture
> very large output?

You are doing something wrong.  Post a short working example that
demonstrates your problem, and we'll help you figure out what you are doing
wrong.


> 2] The other problem is that the output of the command has some XML in
> it and when I capture it in the perl variable, the XML part is lost

Again, I don't believe you.  The XML is in the variable.  But since
you print the variable contents without escaping html entities (or whatever
they are called), the web browser is probably trying to interpret the XML
as HTML. Do the proper escaping.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: Tue, 22 Mar 2005 16:30:51 GMT
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Net::FTP
Message-Id: <%KX%d.17740$Ue6.4762@trndny04>

lucas wrote:
> having trouble listing the files using Net::FTP:
> 
>    print ">Connecting...";
>    my $ftp = Net::FTP->new($addy, Port => $port, Debug => $debug) || die
> "Could Not Connect\n";
>    print "Done\n";
> 
>    print ">Logging in...";
>    $ftp->login($user,$pass) || die "Can't Log In\n";
>    print "Done\n";
> 
>    print ">Listing files...";
>    @_ = $ftp->ls();
>    print "Done\n";
>    print "@_\n";
> 
> this code returns:
> 
> Net::FTP=GLOB(0x82de9d8)>>> PORT 192,168,0,2,129,26
> Net::FTP=GLOB(0x82de9d8)<<< 200 PORT command successful.
> Net::FTP=GLOB(0x82de9d8)>>> NLST
> Net::FTP=GLOB(0x82de9d8)<<< 150 Opening ASCII mode data connection for file
> list.
> Net::FTP=GLOB(0x82de9d8)<<< 226 Transfer complete.
> 
>>Listing files...Done
> 
> ARRAY(0x8308ef8)
> 
> printing @_ just shows "ARRAY(0x8308ef8)".  this is the way it's done in the
> examples.  anybody know what's wrong with it?

That script works fine for me with Perl 5.8.0 on Solaris, using Net::FTP 
2.65.  Have you examined the contents of @_ using Data::Dumper to see 
what's actually in the reference @_ contains?  Try adding these lines:

use Data::Dumper;
print Dumper(\@_);

Also, what versions of Perl and Net::FTP are you using?
perl -v
perl -MNet::FTP -e'print $Net::FTP::VERSION;'

If you're not using at least Perl 5.80 and Net::FTP 2.65, consider 
upgrading.


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

Date: 22 Mar 2005 17:13:36 GMT
From: xhoster@gmail.com
Subject: Re: piping cmd output  problem
Message-Id: <20050322121336.540$UY@newsreader.com>

dimsol@gmail.com wrote:
> Hi
>
> I have the following scenarion:
>
> open(FILE, "some_cmd |") || die "some error message";
> my $output = <FILE>;
> close(FILE) || die "some error message";
>
> The problem is that some_cmd failes (exit status 1) and prints error
> message to STDOUT.
>
> The return value of open() according to man pages is the pid of forked
> process.
> Now, the problem, how I can find out that some_cmd failed.

Since you say it prints the error message to its STDOUT, which has been
redirected into Perl's file handle FILE, why don't you just read the error
message from FILE?  Alternatively, inspect $! and/or $? when either the
open or the close fails.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service                        $9.95/Month 30GB


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

Date: 22 Mar 2005 09:54:17 -0800
From: "jtripo" <jtripo@hotmail.com>
Subject: regular expression Help
Message-Id: <1111514057.175208.228670@l41g2000cwc.googlegroups.com>

I have the following text

blah blah blah blah System Is Working blah blah blah blah

I need a regular expression that will show true only if System Is
Working is missing. Is there a way to do this?

Thanks
Jeff



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

Date: Tue, 22 Mar 2005 18:01:30 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: regular expression Help
Message-Id: <Xns9621848378AABasu1cornelledu@127.0.0.1>

"jtripo" <jtripo@hotmail.com> wrote in news:1111514057.175208.228670
@l41g2000cwc.googlegroups.com:

> I have the following text
> 
> blah blah blah blah System Is Working blah blah blah blah
> 
> I need a regular expression that will show true only if System Is
> Working is missing. Is there a way to do this?

Why this requirement?

Why can't you use (untested):

my $s = q{blah blah blah blah System Is Working blah blah blah blah};
unless(index($s, q{System Is Working}) > -1) {
    	# system is not working
}

Sinan


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

Date: Tue, 22 Mar 2005 11:06:30 -0700
From: Jeff <Im.so.HuckinFappy@spamgourmet.com>
Subject: Re: regular expression Help
Message-Id: <d1pmr7$cuu1@xco-news.xilinx.com>

jtripo wrote:
> I have the following text
> 
> blah blah blah blah System Is Working blah blah blah blah
> 
> I need a regular expression that will show true only if System Is
> Working is missing. Is there a way to do this?

There's no doubt some ugliness you can create using negative lookahead 
or somesuch, but it would seem a lot easier and more maintainable to 
just do something like:

unless ( $text =~ /System Is Working/ ) {
    # Do whatever you wanted to if 'System Is Working' was missing
} else {
    # It's there, so do whatever....
}

~Jeff


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

Date: 22 Mar 2005 08:42:50 -0800
From: "geek" <metri.jain@gmail.com>
Subject: The error "Use of uninitialized value "
Message-Id: <1111509770.079356.323180@g14g2000cwa.googlegroups.com>

Hi all,

I am getting this error in my perl script at the line "else {stat();)"
See the code at the bottom.

Any help will be appreciated.
Thanks,
MJ
########################################################

 if( param('Get')){ date();}
 else { stat();}

sub stat {
  print header(), start_html("The Statistics for Administrator");
 open(fileHandle,"./outputFile") or die "The file cannot be opened";
 my @fileData = <fileHandle>;
 my $count1=0;
 my $count2=0;
 my $count3=0;
 my $count4=0;
 my $count5=0;
 my $count6=0;
 my $count7=0;
 my $count8=0;
 my $count9=0;
 my $countt=0;
 my @array;
 foreach my $word(@fileData){
 @array=split(/ /, $word);
 foreach my $element(@array){
 if($element eq "CS5375"){
 $count1++;
 }
 if($element eq "cd"){
 $count2++;
 }
 if($element eq "cp"){
 $count3++;
 }
 if($element eq "vim"){
 $count4++;
 }
 if($element eq "%ls-l"){
 $count5++;
 }
 if($element eq "man"){
 $count6++;
 }
 if($element eq "perl-v"){
 $count7++;
 }
 if($element eq "all"){
 $count8++;
 }
 if($element eq "finger"){
 $count9++;
 }
 if($element eq "ftp\n"){
 $countt++;
# print "hello";
 }
}
}
   my $noLine;
   open( fileHandle,"<./outputFile");
   $noLine++ while <fileHandle>;
   print "Number of lines in the file is $noLine";
   my $noUsers= $noLine/2;
   print br;
   print "Number of users is $noUsers";
   print br;
   my $avg;
   my $finalAvg=0;
   open(handGrade,"./gradeFile") or die "gradeFile cannot be opened";
   my @avgarr = <handGrade>;
   my $tmpAvg;
   foreach $avg(@avgarr){
   $tmpAvg="$finalAvg"+"$avg";
   $finalAvg=$tmpAvg/2;
   }
  print "The average is $finalAvg";
  print br;
  my $percentage1=($count1/$noUsers)*100;
  print " The percentage for first question is $percentage1";
}
###########################################################################



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

Date: Tue, 22 Mar 2005 17:51:38 +0100
From: phaylon <phaylon@dunkelheit.at>
Subject: Re: The error "Use of uninitialized value "
Message-Id: <pan.2005.03.22.16.51.38.316988@dunkelheit.at>

geek wrote:

> Any help will be appreciated.

Only if you rewrite that and use more Hashes.

-- 
http://www.dunkelheit.at/
codito, ergo sum.



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

Date: Tue, 22 Mar 2005 17:06:45 +0000 (UTC)
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: Re: The error "Use of uninitialized value "
Message-Id: <d1pjb5$2ms$1@naig.caltech.edu>

In article <1111509770.079356.323180@g14g2000cwa.googlegroups.com>,
geek <metri.jain@gmail.com> wrote:
>Hi all,
>
>I am getting this error in my perl script at the line "else {stat();)"
>See the code at the bottom.
>
> if( param('Get')){ date();}
> else { stat();}
>
>sub stat {

Perl already has a function called stat(), and I suspect that it is
getting called instead of the subroutine you wrote.

Try renaming your subroutine.

Gary
-- 
Chaos reigns within. 
Reflect, repent, and reboot. 
Order shall return. 


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

Date: Tue, 22 Mar 2005 17:10:35 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: The error "Use of uninitialized value "
Message-Id: <Xns96217BE1FE637asu1cornelledu@127.0.0.1>

"geek" <metri.jain@gmail.com> wrote in
news:1111509770.079356.323180@g14g2000cwa.googlegroups.com: 

> I am getting this error 

which error?

> in my perl script at the line "else {stat();)"
> See the code at the bottom

 ...

>  if( param('Get')){ date();}
>  else { stat();}

Please post a short but complete script that others can easily run.
 
> sub stat {

perldoc -f stat

What, oh what, is the purpose of using the name of a perl built-in?

>   print header(), start_html("The Statistics for Administrator");
>  open(fileHandle,"./outputFile") or die "The file cannot be opened";

Why is the input file called "outputFile"?

Do include the reason for the failure as well as the name of the file in 
your error messages.

>  my @fileData = <fileHandle>;

There is no need to slurp the file if you are going to process it line-
by-line anyway.

>  my $count1=0;
>  my $count2=0;
>  my $count3=0;
>  my $count4=0;
>  my $count5=0;
>  my $count6=0;
>  my $count7=0;
>  my $count8=0;
>  my $count9=0;
>  my $countt=0;
>  my @array;

Whenever you find yourself writing tedious stuff like this, please take 
a moment to actually think about the problem you are attempting to 
solve.

You have provided no information on the format of the data you are 
trying to process, so it is really hard to figure out what you are 
trying to do, but I suspect the following noise

>  foreach my $word(@fileData){
>  @array=split(/ /, $word);
>  foreach my $element(@array){
>  if($element eq "CS5375"){
>  $count1++;
>  }
>  if($element eq "cd"){
>  $count2++;
>  }
>  if($element eq "cp"){
>  $count3++;
>  }
>  if($element eq "vim"){
>  $count4++;
>  }
>  if($element eq "%ls-l"){
>  $count5++;
>  }
>  if($element eq "man"){
>  $count6++;
>  }
>  if($element eq "perl-v"){
>  $count7++;
>  }
>  if($element eq "all"){
>  $count8++;
>  }
>  if($element eq "finger"){
>  $count9++;
>  }
>  if($element eq "ftp\n"){
>  $countt++;
> # print "hello";
>  }

can be replaced with:

#! /usr/bin/perl

use strict;
use warnings;

sub calc_stats {
    my $filename = shift;
    open my $fh, '<', $filename
        or die "Cannot open $filename: $!";

    my %stats;
    
    while(my $line = <$fh>) {
        my @words = split / /, $line;
        ++$stats{$_} for @words;
    }
    return \%stats;
}

use Data::Dumper;
print Dumper(calc_stats('outputFile'));
__END__

It is now up to you to fix the rest of the jumble. In the process, you 
might also discover what "this" error is. "Use of uninitialized value" 
is a warning, not an error. It is too tedious to try and figure out 
which part of your code is causing the warning to be emitted.

>    my $noLine;
>    open( fileHandle,"<./outputFile");
>    $noLine++ while <fileHandle>;

What is the purpose of opening the same file again (especially since you 
have not closed it yet, to re-read it in its entirety. I have a sneaking 
suspicion (which I cannot be bothered to test, but you should) that no 
lines are being read from the file as it is at EOF now. Hence $noLine is 
uninitialized etc.

Have you read the posting guidelines for this group?


Sinan


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

Date: Tue, 22 Mar 2005 10:18:39 -0700
From: Jeff <Im.so.HuckinFappy@spamgourmet.com>
Subject: Re: The error "Use of uninitialized value "
Message-Id: <d1pk1g$cpf1@xco-news.xilinx.com>

geek wrote:
> I am getting this error in my perl script at the line "else {stat();)"
> See the code at the bottom.
> 
> Any help will be appreciated.
> Thanks,
> MJ
> ########################################################
> 
>  if( param('Get')){ date();}
>  else { stat();}

[Snipping ugly code written by someone who doesn't know what a hash is]

stat() is a perl internal function that requires a value be passed into 
it, or it defaults to using $_ (see perldoc -f stat).  I'm guessing the 
bad practice here of writing your own function with the same name as a 
perl internal causes your error.

I'd also suggest reading perldoc perldata

~Jeff



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

Date: Tue, 22 Mar 2005 17:45:12 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: The error "Use of uninitialized value "
Message-Id: <Xns962181BFAE8A6asu1cornelledu@127.0.0.1>

"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in 
news:Xns96217BE1FE637asu1cornelledu@127.0.0.1:

> I have a sneaking suspicion 

This particular one was wrong. Incidentally, I had never before written 
a function with the same name as a builtin, so I was pleasantly 
surprised when 

#!/usr/bin/perl

use strict;
use warnings;

sub stat {
    print "stat\n";
}

stat();

__END__

produced:

D:\Home> s
Ambiguous call resolved as CORE::stat(), qualify as such or use & at D:
\Home\s.pl line 10.
Use of uninitialized value in stat at D:\Home\s.pl line 10.

which gives a very good explanation of the problem. Why did you waste 
our time?

Sinan.


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

Date: Tue, 22 Mar 2005 12:52:47 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: The error "Use of uninitialized value "
Message-Id: <v_OdnbFyocPyxt3fRVn-oA@adelphia.com>

geek wrote:

> I am getting this error in my perl script at the line "else {stat();)"
> See the code at the bottom.

Rename your stat() function. It conflicts with the builtin function of the
same name.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: Tue, 22 Mar 2005 18:00:41 +0000 (UTC)
From: ansok@alumni.caltech.edu (Gary E. Ansok)
Subject: Re: The error "Use of uninitialized value "
Message-Id: <d1pmg9$3u1$1@naig.caltech.edu>

In article <Xns962181BFAE8A6asu1cornelledu@127.0.0.1>,
A. Sinan Unur <1usa@llenroc.ude.invalid> wrote:
>Incidentally, I had never before written 
>a function with the same name as a builtin, so I was pleasantly 
>surprised when 
>
>#!/usr/bin/perl
>
>use strict;
>use warnings;
>
>sub stat {
>    print "stat\n";
>}
>
>stat();
>
>__END__
>
>produced:
>
>D:\Home> s
>Ambiguous call resolved as CORE::stat(), qualify as such or use & at D:
>\Home\s.pl line 10.
>Use of uninitialized value in stat at D:\Home\s.pl line 10.
>
>which gives a very good explanation of the problem. Why did you waste 
>our time?

In the original poster's code, the call to stat() was *before* the
definition of his own stat subroutine.

In that case, the built-in stat() is called and no warning is produced.
(Probably one should be, but that's a different issue and not the
original poster's fault.)

Gary
-- 
Any attempt to brew coffee with a teapot should result in the error code
"418 I'm a teapot". The resulting entity body MAY be short and stout. 
        -- RFC 2324, Hyper Text Coffee Pot Control Protocol (HTCPCP)/1.0


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

Date: Tue, 22 Mar 2005 13:03:48 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: The error "Use of uninitialized value "
Message-Id: <lMydnccCm92bw93fRVn-rQ@adelphia.com>

A. Sinan Unur wrote:

> which error?

Don't be ridiculous. The error is in the subject. Complaining because he
didn't repeat it in the message body is petty.

> It is too tedious to try and figure out
> which part of your code is causing the warning to be emitted.

It took me all of three seconds to realize that his stat() function
conflicted with the builtin. The only thing that's tedious here is reading
your pedantic line-by-line bitching about points that aren't one bit
relevant to the question.

> Have you read the posting guidelines for this group?

Have you? I distinctly recall something being said there about posting
helpful responses, not attacks.

Posting an answer to the question, while adding a few minor points of style,
would have been helpful. Posting page after page of moaning about trivia,
and then refusing to actually answer the question because it's "too
tedious" to do so, was not.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: Tue, 22 Mar 2005 18:15:17 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: The error "Use of uninitialized value "
Message-Id: <Xns962186D9944A4asu1cornelledu@127.0.0.1>

ansok@alumni.caltech.edu (Gary E. Ansok) wrote in news:d1pmg9$3u1$1
@naig.caltech.edu:

> In article <Xns962181BFAE8A6asu1cornelledu@127.0.0.1>,
> A. Sinan Unur <1usa@llenroc.ude.invalid> wrote:
>>Incidentally, I had never before written 
>>a function with the same name as a builtin, so I was pleasantly 
>>surprised when 
 ...
>>
>>produced:
>>
>>D:\Home> s
>>Ambiguous call resolved as CORE::stat(), qualify as such or use & at 
>>D:\Home\s.pl line 10.
>>Use of uninitialized value in stat at D:\Home\s.pl line 10.
>>
>>which gives a very good explanation of the problem. Why did you waste 
>>our time?
> 
> In the original poster's code, the call to stat() was *before* the
> definition of his own stat subroutine.

Ah! I missed that. 

> In that case, the built-in stat() is called and no warning is
> produced. (Probably one should be, but that's a different issue and
> not the original poster's fault.)

Indeed, you are right.

Thank you for the correction.

Sinan.


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

Date: Tue, 22 Mar 2005 18:55:12 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: The error "Use of uninitialized value "
Message-Id: <Xns96218D9E8229Aasu1cornelledu@127.0.0.1>

Sherm Pendley <spamtrap@dot-app.org> wrote in
news:lMydnccCm92bw93fRVn-rQ@adelphia.com: 

> A. Sinan Unur wrote:
> 
>> which error?
> 
> Don't be ridiculous. The error is in the subject. Complaining because
> he didn't repeat it in the message body is petty.

Oh, but I am being petty in a different way: I was complaining that the 
message was a "warning", not an "error" as I pointed out later in my 
response.

>> It is too tedious to try and figure out
>> which part of your code is causing the warning to be emitted.
> 
> It took me all of three seconds to realize that his stat() function
> conflicted with the builtin. 

Well, I have never written a function with the same name as a builtin. I 
assumed a more verbose warning, such as:

Ambiguous call resolved as CORE::stat(), qualify as such or use & at ...

would have been produced if the builtin was being called rather than his 
version. As Gary Ansok pointed out, the warning is only produced if the 
user defined function is in scope, but I did not realize it.

> The only thing that's tedious here is reading your pedantic line-by-
> line bitching about points that aren't one bit relevant to the
> question.

I had a theory which was wrong. I stated the theory. I thought the 
warning was being caused by one of the of the variables that were being 
assigned to in convoluted ways. It was hard to test this because the 
script the OP posted was not self-contained at all.

> Posting an answer to the question, while adding a few minor points of
> style, would have been helpful. Posting page after page of moaning
> about trivia, and then refusing to actually answer the question
> because it's "too tedious" to do so, was not.

I did answer the question. My answer turned out to be wrong. All the 
moaning was emitted in the process of trying to reduce the code to 
something I could comprehend.

Sinan.


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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