[9268] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 2863 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jun 13 03:07:15 1998

Date: Sat, 13 Jun 98 00:00:47 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 13 Jun 1998     Volume: 8 Number: 2863

Today's topics:
    Re: $a: numeric or NOT ? <bowlin@sirius.com>
    Re: $a: numeric or NOT ? <tchrist@mox.perl.com>
        Best way to traverse an acyclic graph in perl <dformosa@st.nepean.uws.edu.au>
    Re: Best way to traverse an acyclic graph in perl (Mark-Jason Dominus)
    Re: Best way to traverse an acyclic graph in perl (Mark-Jason Dominus)
    Re: Certified Perl Programmers (Abigail)
    Re: Certified Perl Programmers <webmaster@fccjmail.fccj.cc.fl.us>
    Re: Command line substitution thru subdirectories <ebohlman@netcom.com>
    Re: Have we got a good free Perl manual? (Abigail)
    Re: Have we got a good free Perl manual? (Abigail)
    Re: HELP! <ebohlman@netcom.com>
    Re: Is this insane? (Steve Vertigan)
    Re: Most common element of array. <dformosa@st.nepean.uws.edu.au>
    Re: New module/pragma "enum.pm" (was "fields.pm") (Jim Britain)
    Re: novice problem? <psdspss@execpc.com>
    Re: novice problem? <psdspss@execpc.com>
    Re: offline mode? <ebohlman@netcom.com>
    Re: question on a process mgmt (how to kill a child pro <dformosa@st.nepean.uws.edu.au>
    Re: reverse sorting <sdh1@anchor.hotmail.com>
    Re: reverse sorting <ebohlman@netcom.com>
        Rounding Numbers <jesse@savalas.com>
    Re: Rounding Numbers <tchrist@mox.perl.com>
        splitting config file fascist@posix.org
        Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Fri, 12 Jun 1998 22:56:13 -0700
From: Jim Bowlin <bowlin@sirius.com>
To: "Michael D. Schleif" <mike.schleif@aquila.com>
Subject: Re: $a: numeric or NOT ?
Message-Id: <3582147D.DEC86EE5@sirius.com>

Michael D. Schleif wrote:
> 
> I've been struggling with this, off and on, for quite some time: what is
> the most efficient way to test whether or not a variable is numeric, and
> therefore subject to numeric calculations without complaining about "-w"
> and "use strict?"
> 
> If I assume that $a is integer, that is fairly simple; but, I am not
> clearly optimal.  Real numbers are an entirely different animal.
> 
> Are there pointers in the Camel or manpages that I have missed?

The camel book says Perl uses atof() for string to numeric conversion.
I looked up atof() (Borland C++ 5.0 Programmer's Guide) and found this 
description:

   The characters must match this generic format:
   [whitespace] [sign] [ddd] [.] [ddd] [e|E[sign]ddd]


I would try

sub is_num {
    $_[0] =~ m/^\s*[\+\-]?(\d+.?\d*|\.\d+)(e[\+\-]?\d+)?$/i ? 1 : 0;
}

This should return true if and only if the first argument will convert
to a number successfully.

HTH -- Jim Bowlin


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

Date: 13 Jun 1998 06:22:51 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: $a: numeric or NOT ?
Message-Id: <6lt5rr$hr1$2@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    "Michael D. Schleif" <mike.schleif@aquila.com> writes:
:I've been struggling with this, off and on, for quite some time: what is
:the most efficient way to test whether or not a variable is numeric, and
:therefore subject to numeric calculations without complaining about "-w"
:and "use strict?"

You mean beyond the ways outlined in the standard perldata manpage or
the standard Perl FAQ?  The answer is still yes, but you should look
there first.

--tom, who isn't supposed to point out that these FAQs keep
       coming from Prisoners of $Bill.
-- 
    "Oh, I'm totally outrageous--I just never seem to inspire any outrage.  :-)"
    	--Larry Wall


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

Date: 13 Jun 1998 03:50:09 GMT
From: ? the platypus {aka David Formosa} <dformosa@st.nepean.uws.edu.au>
Subject: Best way to traverse an acyclic graph in perl
Message-Id: <897709809.660117@cabal>

I am working with an acylic graph that has nodes something like this

$node0 = {
  NAME => "Fortran",
  CHILD => [\$node1,\$node3,\$node4]
}

$node1 = {
  NAME => "Algol",
  CHILD => [\$node3,\$node4],
}

$node2 = {
  NAME => "COBOL",
  CHILD => [\$node4],
}

$node3 = {
  NAME => "Basic",
  CHILD => [],
}

$node4 = {
  NAME => "PL/I",
  CHILD => [],
}

Now say I start with Fortran, I wish to see a list of all its decendents
without seeing Basic and PL/I.  I suppost I could add a flag "visted" to
the node.  However this adds complexaties that is don't wish to deal with
(clearing the falg afterwoulds comes to mind).


--
I'm a perl programer; if you need perl programing, hire me. 
Please excuse my spelling as I suffer from agraphia; see the url. Support NoCeM
http://www.cit.nepean.uws.edu.au/~dformosa/Spelling.html  http://www.cm.org/ 
I'm sorry but I just don't consider 'because its yucky' a convincing argument


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

Date: 13 Jun 1998 01:43:23 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Best way to traverse an acyclic graph in perl
Message-Id: <6lt3hr$idn$1@monet.op.net>


In article <897709809.660117@cabal>,
? the platypus {aka David Formosa}  <dformosa@st.nepean.uws.edu.au> wrote:
>I am working with an acylic graph that has nodes something like this
>
>$node0 = {
>  NAME => "Fortran",
>  CHILD => [\$node1,\$node3,\$node4]
>}
>I wish to see a list of all its decendents

Use

	@STACK = $node0;
	while (@STACK) {
	  my $cur = shift @STACK;
	  next if $seen{$cur}++;
	  print $cur->{NAME}, "\n"; # Or do something else with $cur
	  push @STACK, @{$cur->{CHILD}};
	}

Isn't that easy?  It also works on graphs with cycles.

Replace `push' with `unshift' to get depth-first instead of
breadth-first traversal.

Note: Not only is this untested (as usual) but I'm also sleep-
deprived, so please check it carefully before you depend on it.




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

Date: 13 Jun 1998 01:45:29 -0400
From: mjd@op.net (Mark-Jason Dominus)
Subject: Re: Best way to traverse an acyclic graph in perl
Message-Id: <6lt3lp$iec$1@monet.op.net>

In article <897709809.660117@cabal>,
? the platypus {aka David Formosa}  <dformosa@st.nepean.uws.edu.au> wrote:
>I am working with an acylic graph that has nodes something like this
>
>$node0 = {
>  NAME => "Fortran",
>  CHILD => [\$node1,\$node3,\$node4]
>}
>
>$node3 = {
>  NAME => "Basic",
>  CHILD => [],
>}
>
>Now say I start with Fortran, I wish to see a list of all its decendents
>without seeing Basic and PL/I. 

No, now I'm confused.  If you start at fortran, why don't you want to
see Basic, which is a descendant of fortran?   Maybe you meant to say
you didn't want to see it twice?  


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

Date: 13 Jun 1998 05:52:45 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Certified Perl Programmers
Message-Id: <6lt43d$d8i$1@client3.news.psi.net>

Mark-Jason Dominus (mjd@op.net) wrote on MDCCXLVII September MCMXCIII in
<URL: news:6lsk5k$hba$1@monet.op.net>:
++ In article <1998061223230300.TAA21653@ladder01.news.aol.com>,
++ Bbirthisel <bbirthisel@aol.com> wrote:
++ >You should make it downloadable from CPAN and indicate where to find
++ >it in the FAQ. That would establish a suitable skill set - since anyone who
++ >couldn't do that probably shouldn't have one.
++ 
++ But I want everyone to have one!


Well, you could write a program that harvests email addresses, and then
sends certificates to those addresses....

Or maybe not :)


Abigail
-- 
perl -MTime::JulianDay -lwe'@r=reverse(M=>(0)x99=>CM=>(0)x399=>D=>(0)x99=>CD=>(
0)x299=>C=>(0)x9=>XC=>(0)x39=>L=>(0)x9=>XL=>(0)x29=>X=>IX=>0=>0=>0=>V=>IV=>0=>0
=>I=>$r=-2449231+gm_julian_day+time);do{until($r<$#r){$_.=$r[$#r];$r-=$#r}for(;
!$r[--$#r];){}}while$r;$,="\x20";print+$_=>September=>MCMXCIII=>()'


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

Date: Fri, 12 Jun 1998 11:33:09 -0400
From: "Bill Jones, FCCJ Webmaster" <webmaster@fccjmail.fccj.cc.fl.us>
Subject: Re: Certified Perl Programmers
Message-Id: <35814A35.F982A0C4@fccjmail.fccj.cc.fl.us>

Chris Nandor wrote:
> 
> In article <m3wwaptgbv.fsf@mail.biol.sc.edu>, Dean Pentcheff
> <dean@mail.biol.sc.edu> wrote:
> 
> # mjd@op.net (Mark-Jason Dominus) writes:
> # [I'm a little disturbed, though, that no one in this thread has flamed
> # another poster.  Aren't we overdue for that?]
> 
> F*** you.  Hitler.
> 
> --
> Chris Nandor          mailto:pudge@pobox.com         http://pudge.net/


Y'all are weird!

____________________________________________________________________________
Bill Jones | FCCJ Webmaster | Voice 1-904-632-3089 | Fax 1-904-632-3007
Florida Community College at Jacksonville | 501 W. State St. | Jax, FL 32202
mailto:webmaster@fccjmail.fccj.org | http://webmaster.fccj.org/Webmaster


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

Date: Sat, 13 Jun 1998 05:55:23 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: Command line substitution thru subdirectories
Message-Id: <ebohlmanEuH74B.Buw@netcom.com>

Scratchie <upsetter@ziplink.net> wrote:
: : As I said, porting the OS specific stuff is left as an exercise
: : to the reader - if you need help with that, ask in a group
: : that's specific to your OS. That falls beyond the scope of this
: : group.

: So your advice to perl beginners on the Wintel platform is that they write
: their own versions of any unix utility they need?

I don't see how that follows from what he said.  It sounds more like his 
advice is for the beginner to use the various Web and Usenet resources 
available to him to find such things as Win32 ports of Unix utilities.  
IMHO, it would actually be disrespectful to the beginner to assume that 
he were incapable of doing that.  A lot of people have put a lot of 
unpaid time into creating those resources; why should they go to waste?

In the case where no ports or the like are available, then sometimes the 
answer has to be "what you want to do is easy and fun with the 
appropriate tools, but difficult and tedious without them.  People 
generally don't want to do difficult and tedious work for free just to 
answer a newsgroup post, so if you really need this, you may have to pay 
someone to do it for you."

FWIW, I do the majority of my development work on Win32 systems.



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

Date: 13 Jun 1998 05:21:42 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Have we got a good free Perl manual?
Message-Id: <6lt296$d12$1@client3.news.psi.net>

David Kastrup (dak@mailhost.neuroinformatik.ruhr-uni-bochum.de) wrote on
MDCCXLVI September MCMXCIII in <URL: news:m290n2nvz2.fsf@mailhost.neuroinformatik.ruhr-uni-bochum.de>:
++ lehman@visi.com (Todd Lehman) writes:
++ 
++ > [dak:]
++ > >
++ > > This is nonsense.  It is a loss to the community period.  If they were
++ > > under some cosmic obligation, the community would not encounter any
++ > > loss because it could sue them for providing the stuff.  As they are
++ > > not under an obligation, it is a loss to the community for good.
++ > 
++ > Aren't you confusing loss with non-gain?  Was the documentation sold
++ > to O'Reilly once freely available?  If so, then you could consider it a
++ > loss.  If not, then to call it a loss is to presume that it would have
++ > and should have been contributed to the community all along, and that is
++ > up to the authors and -no one- else.
++ 
++ No, that it *could* have been contributed to the community.  Once you
++ have signed over your marketing rights exclusively to some publisher,
++ this option is gone.


If I put the free (GPLed) manuals next to the "Programming Perl" book
from O'Reilly, I have to conclude that that hasn't happened.



Abigail
-- 
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'


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

Date: 13 Jun 1998 05:28:18 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Have we got a good free Perl manual?
Message-Id: <6lt2li$d12$2@client3.news.psi.net>

Christopher Browne (cbbrowne@news.hex.net) wrote on MDCCXLVII September
MCMXCIII in <URL: news:6lsm5u$14p$30@blue.hex.net>:
++ On 12 Jun 1998 22:29:27 GMT, Paul David Fardy <pdf@morgan.ucs.mun.ca>
++ wrote: 
++ >Odd...  Why don't they need "a good free manual for TeX"?
++ 
++ An interesting question. 
++ 
++ Until the recent proliferation of "Yet Another Thick Book About The
++ Internet for Thick People", there was *considerably* more literature out
++ there on the TeX family of document processors than there was for Perl.
++ 
++ Subtract the "Thick Books for Thick People" entrants, and the Perl
++ literature set is probably smaller than the TeX literature set.
++ 
++ Mind you, Knuth *does* distribute the TeXBook in TeXable form as an
++ example of a TeX work of significant size and complexity, albeit with
++ certain restrictions... 


Perhaps you care a multi megabyte posting of FREE (GPL/ALed) Perl manuals
which almost completely cover the "Programming Perl" book?

Except that the manuals aren't out of date.


Why does anyone keep ignoring GPL/ALed manuals?



Abigail
-- 
perl -wle 'print "Prime" if (0 x shift) !~ m 0^\0?$|^(\0\0+?)\1+$0'


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

Date: Sat, 13 Jun 1998 06:12:42 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: HELP!
Message-Id: <ebohlmanEuH7x6.D2B@netcom.com>

Martien Verbruggen <mgjv@comdyn.com.au> wrote:
: Perl works magically. One sits down in a pentagram, drawn with the
: blood of a freshly slaughtered black hen, clad in a black robe and
: black pointy hat with silvery stars, and chants the ancient commands
: that are needed to invoke perl. (The black pointy hat isn't really
: necessary, but the addition of the stars made it fashionable somewhere
: in 1991, so every Wizard now wears one). Sometimes lighting 7 black
: candles will help tremendously, especially when chanting MS (Master of
: Sourcery, yes, Sourcery) commands, since everyone knows they are less
: predictable and reliable, and the black candles will protect you from
: the possible nasal daemons that might attack you.

Refresh my memory: which release eliminated the need for the sharpened 
walrus tusks?



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

Date: Sat, 13 Jun 1998 14:27:51 +0800
From: steve@vertigan.iinet.net.au (Steve Vertigan)
Subject: Re: Is this insane?
Message-Id: <199806130627.OAA29429@opera.iinet.net.au>

Mike Whitaker wrote:

> Install Perl for NT.
> You won't regret it.
>
> And, no, I'm not being facetious. In the 10 hours you've spent, you
> could have a working NT Perl talking to IIS and running CGI's.

I don't doubt it but what I forgot to make clear in my original post was 
that I don't have access to the NT machine :(

The situation is that I'm working for a web development company and a client 
has requested the scripts be installed in his account on an ISP that's 
running NT with IIS 4.0 and nothing else.  To make things even more 
difficult the ISP isn't even in the same country as us.  At this point I'm 
about ready to tell my boss that it's not going to be worth the time and 
trouble to support this woeful environment but I thought I'd see if anyone 
has any suggestions first.

Regards,
--Steve


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

Date: 13 Jun 1998 04:42:46 GMT
From: ? the platypus {aka David Formosa} <dformosa@st.nepean.uws.edu.au>
Subject: Re: Most common element of array.
Message-Id: <897712958.461013@cabal>

In <6lq57u$673@mozo.cc.purdue.edu> gebis@albrecht.ecn.purdue.edu (Michael J Gebis) writes:

>(Note: Flames via e-mail only, please.)

[...]

>I have an array:
>#pragma DWIM
>@array=('duck','duck','duck','duck','goose','duck','goose');

>I'd like to find the most common element in the array:

>print most_common(@array);	#prints "duck"

This is how I would do it.

@array=('duck','duck','duck','duck','goose','duck','goose');

for (@array) {
  $count{$_}++;
}

for (keys %count) {
  if ($count{$biggest}<$count{$_}) {
   $biggest=$_;
  }
}

print $biggest;

[...]

>What I did was create a hash mapping values->number of occurences.  I
>can then find the key with the maximum value in that hash, and there
>you go.

>However, my code is ugly--too ugly to post, in fact.  This feels
>like something that could be a one-liner.

Ok lets do some line reduction

@array=('duck','duck','duck','duck','goose','duck','goose');
for (keys %{for (@array) {$_{$_}++};\%_}) {$big=$_ if ($_{$big}<$_{$_})};

Seems to be the smallest I can do.


--
I'm a perl programer; if you need perl programing, hire me. 
Please excuse my spelling as I suffer from agraphia; see the url. Support NoCeM
http://www.cit.nepean.uws.edu.au/~dformosa/Spelling.html  http://www.cm.org/ 
I'm sorry but I just don't consider 'because its yucky' a convincing argument


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

Date: Sat, 13 Jun 1998 05:09:25 GMT
From: jbritain@home.com (Jim Britain)
Subject: Re: New module/pragma "enum.pm" (was "fields.pm")
Message-Id: <3582084e.6292392@news>

On 13 Jun 1998 00:31:26 GMT, Zenin <zenin@bawdycaste.org> wrote:

>	Speaking of which, anyone know an efficient way to see if a number
>	is a power of 2 without needing a lookup table?

take the binary value of the integer
shift right two
value =1 stop (4) yes
while 2^1 position == 0
shift right
value = 1 ? stop yes.




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

Date: Fri, 12 Jun 1998 23:40:44 -0500
From: Deva Seetharam <psdspss@execpc.com>
Subject: Re: novice problem?
Message-Id: <6lsvd0$3qj@newsops.execpc.com>

Computing Services wrote:

> I'm trying to read in the contents of a directory then change the file
> names based on what the user inputs (see code below). I put the old and
> new file names into "file_names.txt".  This *did* work until I tried to
> have the user input the directory with this code:
>
> print "Enter the directory where the files are located: ";
> chop($directory = <STDIN>);
> chdir($directory) || die "ERROR: cannot change to $directory";
>
> and now everytime I run it,  I keep getting the error "No such file or
> directory".  I removed the code and I still get this problem, even when
> I'm running the script from the same directory where I'm trying to
> change the files. I also tried rebuilding the script from scratch, which
> worked until I tried the directory input.
>
> Why would this make such a difference? Can anyone point out what I'm
> doing wrong? I've run out of ideas.
>
> Thanks,
> Naomi
>
> ----------------------------------
> $fnames_file = "file_names.txt";
> &get_fnames;
> &rename_fnames;
>
> sub get_fnames {
>
>  local($file, @file_list);
>
>  #open the directory to read
>  opendir(DIR,'.') || die "ERROR: cannot open $directory";
>  @file_list = readdir(DIR);
>  closedir(DIR);
>
>  #set up file to copy file names into, will not overwrite if the file
> exists
>  if (-e $fnames_file) { #remove file if it already exists
>   unlink($fnames_file);
>  }
>
>  open(OUT,">>$fnames_file") || die "ERROR: cannot open $fnames_file\n";
>
>  foreach $file (@file_list) {
>   if ($file =~ /.c\b/i) {  #match .c at the end of the word and ignore
> case
>    $extension = ".c";
>   }
>   elsif ($file =~ /.h\b/i) { #match .h at the end of the word and ignore
> case
>    $extension = ".h";
>   }
>   elsif ($file =~ /.o\b/i) { #match .o at the end of the word and ignore
> case
>    $extension = ".o";
>   }
>   elsif ($file =~ /.sh\b/i) { #match .sh at the end of the word and
> ignore case
>    $extension = ".sh";
>   }
>   elsif ($file =~ /.a\b/i) { #match .a at the end of the word and ignore
> case
>    $extension = ".a";
>   }
>   elsif ($file =~ /.awk\b/i) { #match .awk at the end of the word and
> ignore case
>    $extension = ".awk";
>   }
>   else {
>    print "no substitution rule for $file\n";
>    next;
>   }
>   print ("Enter the new file name for $file: ");
>   chop ($new_filename = <STDIN>);
>   if ($new_filename eq "") {  #if no file name was given, just write the
> old name
>    $file = $file.":"."\n";
>   }
>   else {     #if a new file name was give write to file
>    $file = $file.":".$new_filename.$extension."\n";
>
>   }
>   $file =~ tr/a-z/A-Z/; #translate all lower case to upper
>   print OUT $file;
>  }
>  close(OUT);
> }
>
> sub rename_fnames {
>
>  local(%list);
>
>  #name and open the file where the old and new file names are kept
>  open(FNAMES,$fnames_file) || die "ERROR: cannot open $fnames_file for
> reading";
>
>  #input the old and new file names into an associative array
>  while (<FNAMES>) {
>
>   if (/^\#/) {
>    next;  #ignore comments
>   }
>   elsif (/^\s/) {
>    next; #ignore blank lines
>   }
>   else {
>    ($old_name,$new_name) = split(/:/, $_); #read the info in
>    chop($new_name);   #remove the end of line
>    $list{$old_name} = $new_name;           #load the info into the
> associative array
>   }
>   #print "Old: $old_name, New: $new_name\n";
>  }
>  close(FNAMES);
>
>  foreach $key (keys %list) {
>   print "Old: $key, New: $list{$key}\n";
>   rename($key, $key{$list}) || print "$!";
>
>  }
> }

print "Enter the directory where the files are located: ";
chop($directory = <STDIN>);chdir($directory) || die "ERROR: cannot change to
$directory";

Atleast this portion of the code looks right to me.
(Infact, I cut and pasted above lines and tried to execute.
 It **did** work.)
Possible problems could be access permissions on the directory to which you
are doing chdir.
And also, path specified by the user should be correct.

You can use perl -c ... to check syntax.
And also try perl -w ... to get detailed messages.
Ofcourse, try perl -d to step through your code.

Probably, you can use chomp instead of chop. (As recommended by camel)
chomp removes any line ending;
whereas chop removes the last character of string.
Changing chop to chomp will not solve your problem.
Just a matter a better programming.

hope this helps.




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

Date: Sat, 13 Jun 1998 01:24:35 -0500
From: Deva Seetharam <psdspss@execpc.com>
Subject: Re: novice problem?
Message-Id: <6lt5fm$fba@newsops.execpc.com>



Computing Services wrote:

> I'm trying to read in the contents of a directory then change the file
> names based on what the user inputs (see code below). I put the old and
> new file names into "file_names.txt".  This *did* work until I tried to
> have the user input the directory with this code:
>
> print "Enter the directory where the files are located: ";
> chop($directory = <STDIN>);
> chdir($directory) || die "ERROR: cannot change to $directory";
>
> and now everytime I run it,  I keep getting the error "No such file or
> directory".  I removed the code and I still get this problem, even when
> I'm running the script from the same directory where I'm trying to
> change the files. I also tried rebuilding the script from scratch, which
> worked until I tried the directory input.
>
> Why would this make such a difference? Can anyone point out what I'm
> doing wrong? I've run out of ideas.
>
> Thanks,
> Naomi
>
> ----------------------------------
> $fnames_file = "file_names.txt";
> &get_fnames;
> &rename_fnames;
>
> sub get_fnames {
>
>  local($file, @file_list);
>
>  #open the directory to read
>  opendir(DIR,'.') || die "ERROR: cannot open $directory";
>  @file_list = readdir(DIR);
>  closedir(DIR);
>
>  #set up file to copy file names into, will not overwrite if the file
> exists
>  if (-e $fnames_file) { #remove file if it already exists
>   unlink($fnames_file);
>  }
>
>  open(OUT,">>$fnames_file") || die "ERROR: cannot open $fnames_file\n";
>
>  foreach $file (@file_list) {
>   if ($file =~ /.c\b/i) {  #match .c at the end of the word and ignore
> case
>    $extension = ".c";
>   }
>   elsif ($file =~ /.h\b/i) { #match .h at the end of the word and ignore
> case
>    $extension = ".h";
>   }
>   elsif ($file =~ /.o\b/i) { #match .o at the end of the word and ignore
> case
>    $extension = ".o";
>   }
>   elsif ($file =~ /.sh\b/i) { #match .sh at the end of the word and
> ignore case
>    $extension = ".sh";
>   }
>   elsif ($file =~ /.a\b/i) { #match .a at the end of the word and ignore
> case
>    $extension = ".a";
>   }
>   elsif ($file =~ /.awk\b/i) { #match .awk at the end of the word and
> ignore case
>    $extension = ".awk";
>   }
>   else {
>    print "no substitution rule for $file\n";
>    next;
>   }
>   print ("Enter the new file name for $file: ");
>   chop ($new_filename = <STDIN>);
>   if ($new_filename eq "") {  #if no file name was given, just write the
> old name
>    $file = $file.":"."\n";
>   }
>   else {     #if a new file name was give write to file
>    $file = $file.":".$new_filename.$extension."\n";
>
>   }
>   $file =~ tr/a-z/A-Z/; #translate all lower case to upper
>   print OUT $file;
>  }
>  close(OUT);
> }
>
> sub rename_fnames {
>
>  local(%list);
>
>  #name and open the file where the old and new file names are kept
>  open(FNAMES,$fnames_file) || die "ERROR: cannot open $fnames_file for
> reading";
>
>  #input the old and new file names into an associative array
>  while (<FNAMES>) {
>
>   if (/^\#/) {
>    next;  #ignore comments
>   }
>   elsif (/^\s/) {
>    next; #ignore blank lines
>   }
>   else {
>    ($old_name,$new_name) = split(/:/, $_); #read the info in
>    chop($new_name);   #remove the end of line
>    $list{$old_name} = $new_name;           #load the info into the
> associative array
>   }
>   #print "Old: $old_name, New: $new_name\n";
>  }
>  close(FNAMES);
>
>  foreach $key (keys %list) {
>   print "Old: $key, New: $list{$key}\n";
>   rename($key, $key{$list}) || print "$!";
>
>  }
> }

  print "Enter the directory where the files are located: ";
chop($directory = <STDIN>);chdir($directory) || die "ERROR: cannot change to

$directory";

Atleast this portion of the code looks right to me.
(Infact, I cut and pasted above lines and tried to execute.
 It **did** work.)
Possible problems could be access permissions on the directory to which you
are doing chdir.
And also, path specified by the user should be correct.

You can use perl -c ... to check syntax.
And also try perl -w ... to get detailed messages.
Ofcourse, try perl -d to step through your code.

Probably, you can use chomp instead of chop. (As recommended by camel)
chomp removes any line ending;
whereas chop removes the last character of string.
Changing chop to chomp will not solve your problem.
Just a matter a better programming.

hope this helps.

Deva




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

Date: Sat, 13 Jun 1998 05:39:30 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: offline mode?
Message-Id: <ebohlmanEuH6Du.AJo@netcom.com>

- <root.noharvest.\@not_even\here.com> wrote:
: I've been trying to tell people there is a difference between a user
: and a techinically literate person.  Just because a GUI enables just
: about any drooling fool to USE a computer doesn't make them any easier
: to program, administer, or understand.  Unfortunately, with NT, we're
: seeing a lot more of these users attempting to be administrators and
: network engineers and programmers.  It's a shame because these people
: are truly inept and lack any real understanding.

One of the problems is that software vendors (not only M$, but they're an
obvious example) market their software primarily to PWPH (People With
Pointy Hair).  PWPH generally believe that training is a waste of money,
so a popular way of marketing software to them is to claim that it's so
"easy to use" that it will allow, say, an employee with no knowledge of
system administration to perform the tasks of a system administrator.  The
PWPH then buy the software and dump sophisticated tasks on employees who 
don't have the appropriate background and already have a full workload.  
Many of them, through no fault of their own, flounder.  It's not that 
they're not smart enough to learn, it's that they're expected to produce 
results without taking the time (which they don't have) to learn.

Interestingly, to PWPH by far the most common metaphor for a business 
operation is a (gridiron) football team, though some less jockish PWPH 
will mention a symphony orchestra.  The most notable thing, though, about 
a sports team or a performing arts group is that if it's any good, it 
spends far more time practicing or rehearsing than actually playing or 
performing.  Yet somehow managers almost universally regard time spent on 
developmental activities as slack time rather than work time.  *Why* 
someone would actually take pride in viewing himself (it's usually a 
himself) as the coach of a football team that never practices is beyond 
me, but then I don't have enough hair to have points.

The "Web Designer" crowd suffers from a different problem.  Many of them 
seem to completely disdain the very concepts of structure and syntax 
because they're not "kewl."  Some of them will insist that there's no 
such thing as syntactically valid or invalid HTML and that any HTML that 
produces results that look good on their particular version of a browser 
on a particular platform is "valid" and that if it doesn't work for the 
2% of Lynx users who want boring text-only pages, too bad.  They will 
repeat this assertion even after it's been pointed out that every single 
major release of Netscape's browsers has caused pages with certain 
syntactically invalid HTML constructs to break, in some cases to the 
point of unreadability.

Now that the marketplace for "Web Designers" who know nothing more than 
HTML has saturated, many of them are approaching programming the same way 
they approached markup.  They treat programs as sets of isolated commands 
that don't relate to each other in any way.  They don't understand the 
need for error checking, or for handling input that isn't what they 
expect it to be.  They think that if something works 75% of the time, 
it's "good enough."  They want to write programs, but they don't want to 
study how to write programs.

Some would say that this is because "Designers" tend to be 
"right-brained, artistic" types rather than "left-brained, logical" 
types.  I personally think that popular notions of hemispheric dominance 
are oversimplified and overblown.  Another possibility is that they have 
trouble bridging the gap between art, where it's no meaningful to say 
that something is "right" or "wrong," to technology, where there are 
definitely right and wrong ways to do something (even though TMTOWTDTR).  
But IMHO, it takes a rather rigid personality to be unable to see the 
difference.  I suspect that the real reason is that they simply regard 
programming as a necessary evil that they're not really interested in.

Another possibility is that at least some of them are just very 
superficial, hype-driven people who can't see beyond surfaces and 
packages.  Maybe they should go into politics...

One thing I strongly doubt is that they lack the general intelligence to 
be good programmers.  Gerald Weinberg, in _The Psychology of Computer 
Programming_ (a true classic), found that of all invidual factors, 
variations in intelligence accounted for the least amount of variation in 
programming performance; everybody he studied was highly intelligent, 
enough so that variations in their IQ's amounted basically to noise.  As 
he pointed out, few programmers can remember a co-worker who wasn't 
intelligent enough to do his work, but almost all can remember one who 
was temperamentally unsuited to it.






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

Date: 13 Jun 1998 05:46:06 GMT
From: ? the platypus {aka David Formosa} <dformosa@st.nepean.uws.edu.au>
Subject: Re: question on a process mgmt (how to kill a child process without creating zombie)
Message-Id: <897716766.901189@cabal>

In <6lrksd$jqr$5@csnews.cs.colorado.edu> Tom Christiansen <tchrist@mox.perl.com> writes:

> [courtesy cc of this posting sent to cited author via email]

>In comp.lang.perl.misc, Justin Vallon <vallon@bear.com> writes:
>:(suppose NFS is down, kill -9 is blocked).

>I disbelieve, strenuously--as, I would imagine, does your kernel.

If you don't beleave me I shall quote the armadillo book page 294

Occasionally, processes will not die even after being sent the KILL
signal.

[...]

* Processes waiting for unavailable NFS resources [...] will not die if
sent a KILL signal.  use the QUIT signal or the INT signal to kill such
processes.

--
I'm a perl programer; if you need perl programing, hire me. 
Please excuse my spelling as I suffer from agraphia; see the url. Support NoCeM
http://www.cit.nepean.uws.edu.au/~dformosa/Spelling.html  http://www.cm.org/ 
I'm sorry but I just don't consider 'because its yucky' a convincing argument


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

Date: Thu, 11 Jun 1998 22:57:10 -0400
From: "Scott" <sdh1@anchor.hotmail.com>
Subject: Re: reverse sorting
Message-Id: <6lspum$e61$1@camel21.mindspring.com>

I've been playing with about 3-4 different languages lately, so I'm a little
confused,
but can't you just do a "reverse sort"?  I don't have my book handy.


Kwon Soon Son wrote in message <6lnkv5$vd1$1@news.postech.ac.kr>...
>hi i'm perl newbie but dare developing a data ananysis tool using perl.
>
>what i'm trying to to is reverse sorting.
>
>here is part of my source code.
>
>--------
>......
>$size{$2} += $1;
>$totalbytes += $1;
>$totalpackets += 1;
>}
>elsif(/^(\w*)$/)
>{
>$totalbytes += $1;
>$totalpackets += 1;
>}
>}
>
>foreach $srchost (sort (keys %size)){
>print "$size{$srchost} bytes from $srchost \n";
>......
>--------
>
>i want to sort in reverse order.
>please let me know what part should i rewrite.
>
>
>thanks in advance.
>
>p.s. sorry for my bad english.
>--
>-*-*-*-*-*-*-*-*-*- KLDP                          -*-*-*-*-*-*-*
>           (o_                                           _o)
>(o_  (o_   //\         http://kldp.linux-kr.org          //\
>(/)_ (/)_  V_/_        cessi@kldp.linux-kr.org           V_/_
>-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*- JOIN NOW!!! -*-*




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

Date: Sat, 13 Jun 1998 06:10:08 GMT
From: Eric Bohlman <ebohlman@netcom.com>
Subject: Re: reverse sorting
Message-Id: <ebohlmanEuH7sw.Cw5@netcom.com>

Scott <sdh1@anchor.hotmail.com> wrote:
: I've been playing with about 3-4 different languages lately, so I'm a little
: confused,
: but can't you just do a "reverse sort"?  I don't have my book handy.

You certainly can, but that may not be the best way to do it if the list 
to be sorted is big, because it needs enough memory to hold three copies 
of the list (the original, the forward-sorted intermediate copy, and the 
final result).  Of course, there are many situations where that will be a 
trivial amount of memory, in which case "reverse sort" is probably the 
clearest way to do it.

In cases where you can't spare memory, the trick is to remember that the 
<=> and cmp operators return -1, 0, or 1 depending on the relationship 
between the comparands, and that all it takes is a unary minus to reverse 
the result.


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

Date: Fri, 12 Jun 1998 22:53:53 -0700
From: Jesse Rosenberger <jesse@savalas.com>
Subject: Rounding Numbers
Message-Id: <358213F0.2655013B@savalas.com>

okay...I need to know how to round numbers in a couple different
ways...I'll give examples of each.

Let's say I have the number "56.5267391304348"  I want Perl to shorten
it to the hundreds place, and round, so that the output would be "56.53"
(note the hundredths position was rounded up), how would I go about
this.

Now the second part, I'm sure is fairly similiar, I now have the number
"56.53" I want to be able to have this number round up, and turn into
"57"...how about this?

If anyone could show me, or tell me a way that I could do this, it would
be greatly appreciated.

Thanks in advance,
Jesse Rosenberger



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

Date: 13 Jun 1998 06:20:53 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: Rounding Numbers
Message-Id: <6lt5o5$hr1$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, 
    Jesse Rosenberger <jesse@savalas.com> writes:
:If anyone could show me, or tell me a way that I could do this, it would
:be greatly appreciated.

Please read the perl FAQ.  As I say to this question every day
as it comes up.   *THAT'S WHY IT'S A FAQ*

--tom
-- 
    Perl is designed to give you several ways to do anything, so
    consider picking the most readable one.
            --Larry Wall in the perl man page


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

Date: 13 Jun 1998 06:42:56 GMT
From: fascist@posix.org
Subject: splitting config file
Message-Id: <6lt71g$cv7$3@eve.enteract.com>

I've got a problem that I really couldn't find an appropriate 
solution to by reading the book..


I've got a file that looks very much like an html file.  What 
I'd like to do with said file should be easy, I just can't 
figure it out.  Take this little snippet for example:

<blah>
bleh: 1
stuffhere
</blah>

<blah>
bleh: 2
morestuffhere
</here>

ok, I'd like to be able to parse the file in a specific way 
that I could perform a specific set of operations on each
<blah>...</blah> chunk independently.  I would be most 
greatful if someone could point me in the right direction 
on this one.  Thanks!




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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
Message-Id: <null>


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 2863
**************************************

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